akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	string s;
	cin >> s;
	bool b[27];
	fill(b, b + 27, 1);
	if (s.length() != 26) {
		for (int i = 0; i < s.length(); i++) {
			b[s[i] - 'a'] = 0;
		}
		cout << s;
		for (int i = 0; i < 26; i++) {
			if (b[i]) {
				cout << (char)(i + 'a') << endl;
				break;
			}
		}
	} else if (s.compare("zyxwvutsrqponmlkjihgfedcba") == 0) {
		cout << "-1\n";
	} else {
		for (int i = 25; i >= 0; i--) {
			b[s[i] - 'a'] = 0;
			for (int j = s[i] - 'a' + 1; j < 26; j++)
			if (!b[j]) {
				cout << s.substr(0, i) << (char)(j + 'a') << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <climits>
#include<set>
using namespace std;

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

#define INF INT_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)

int main(){
	int N,K;
	cin>>N>>K;
	vector<int> arr(N);
	
	REP(i,N)cin>>arr[i];
	
	bool flag = false;	
	
	int max_num = 0;
	for(auto& s: arr)max_num = max(max_num,s);
	
	if(max_num < K){
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
	
	int max_yaku = 0;
		int a;
		int b = arr[0];
		int r;
	for(int i = 0; i <N - 1; i++){
		
		a = max(b,arr[i+1]);
		b = min(b,arr[i+1]);
		while(1){
			 r = a % b;
			 if(r == 0)break;
			 a = b;
			 b = r;
		}
	}
	max_yaku = b;
	if(max_yaku == 0)flag = true;
	else if(K % max_yaku  == 0)flag = true;
	
	
	cout<< (flag ? "POSSIBLE" : "IMPOSSIBLE" ) <<endl;
	return 0;
}


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

int main() {

    //input from txt （提出時にこの箇所は削除すること）
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    
    int N;
    cin >> N;
    int64_t MINF = -1e9;
    map<int64_t,int64_t> mp;
    vector<int64_t> vec(N+2,MINF);
    for(int i=1; i<N+1; i++){
        cin >> vec[i];
        mp[vec[i]] = i;
    }
    
    vector<int64_t> left(N+2);
    vector<int64_t> right(N+2);
    
    priority_queue<int64_t> PQ;
    PQ.push(MINF);
    
    for(int i=1; i<N+2; i++){
        if(vec[i] > PQ.top()){
            PQ.push(vec[i]);
        }
        else{
            while(vec[i] < PQ.top()){
                int64_t x = PQ.top();
                PQ.pop();
                int64_t y = mp[x];
                left[y] = i - y;
            }
            PQ.push(vec[i]);
        }
    }
    
    PQ.push(MINF);
    
    for(int i=N+1; i>=0; i--){
      if(vec[i] > PQ.top()){
          PQ.push(vec[i]);
      }
      else{
          while(vec[i] < PQ.top()){
              int64_t x = PQ.top();
              PQ.pop();
              int64_t y = mp[x];
              right[y] = y - i;
          }
          PQ.push(vec[i]);
      }
  }
    
    /*for(int i=0; i<N+2; i++){
        cout << left[i] << " " << right[i] << endl;
    }*/
    
    int64_t ans = 0;
    for(int i=1; i<N+1; i++){
        ans += left[i] * right[i] * vec[i];
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 19572
def min(a,b) a<b ? a:b end
MAX=10**5 + 10
N=gets.to_i
b=gets.split.map(&:to_i)
b.unshift(MAX)
b.push(MAX)

ans=0
N.times do |i|
  ans += min(b[i],b[i+1])
end
p ans

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

int main()
{
  int A, B, C, Z;
  cin >> A >> B >> C >> Z;
  int res = 0;
  for (int a = 0; a <= A; a++)
  {
    for (int b = 0; b <= B; b++)
    {
      for (int c = 0; c <= C; c++)
      {
        int sum = 500 * a + 100 * b + 50 * c;
        if (sum == Z)
          res++;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int t;cin>>t;while(t--)
#define N 100003
#define M 1003
//typedef tree<int,null_type,less_equal <int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;    //multiset
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>ordered_set;        //set
//*X.find_by_order("index")
//X.order_of_key("key")
int mod=1e9+7;
//int mod=998244353;

int fast_power(int base, int power)
{
    int result = 1;
    while(power > 0)
    {
        if(power % 2 == 1)
            result = (result*base) % mod;
        base = (base * base) % mod;
        power = power / 2;
    }
    return result;
}

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

    int n;
    string s;
    cin>>n>>s;
    int freq[26];
    fill(freq,freq+26,0);
    int i;
    for(i=0;i<n;++i)
        freq[s[i]-'a']++;
    int ans=1;
    for(i=0;i<26;++i)
    {
        ans=(ans*(freq[i]+1))%mod;
    }
    --ans;
    cout<<ans;



    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	string N;
	cin >> N;

	bool jdg = false;

	for (int i = 0; i < N.size(); i++) {
		if (N.substr(i,1) == "7") {
			jdg = true;
		}
	}

	if (jdg == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3628
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Unboxed as VU
import Data.List
import Data.Char
import Control.Monad

main = do
    s <- B.getLine
    t <- B.getLine
    xs <- VUM.replicate 26 (0 :: Int)
    ys <- VUM.replicate 26 (0 :: Int)
    forM_ [0..B.length s - 1] $ \i -> do
        let s' = B.index s i
        let t' = B.index t i
        VUM.modify xs (+1) (ord s' - ord 'a')
        VUM.modify ys (+1) (ord t' - ord 'a')
    xs' <- sort . VU.toList <$> VU.unsafeFreeze xs
    ys' <- sort . VU.toList <$> VU.unsafeFreeze ys
    putStrLn $ if and $ zipWith (==) xs' ys' then "Yes" else "No"

Measured memory_bytes: 1148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			int x = 800 * N;
			int y = N / 15*200;
			Console.WriteLine(x-y);
		}
	}
}


Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const LL MOD = 1000000007LL;
int main() {
	string s;
	cin >> s;
	int N = 0, S = 0, E = 0, W = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'N') N++;
		else if (s[i] == 'S') S++;
		else if (s[i] == 'E') E++;
		else W++;
	}
	if (((N > 0) ^ (S > 0)) | ((W > 0) ^ (E > 0))) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

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

int A[300];

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

    int len = s.size();

    for(int i = 0; i < len; i++) {
        A[s[i]]++;
    }

    for(int i = 'a'; i <= 'z'; i++) {
        if(A[i] % 2 != 0) {
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    return 0;
}


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

int main() {
  const int64_t inf = 1e18;
  int n;
  cin >> n;
  vector<int64_t> a(n + 2);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  vector<vector<int64_t>> dp(n + 3, vector<int64_t>(n % 2 + 2, -inf));
  for (int i = 0; i < n % 2 + 2; i++) dp.at(i + 1).at(i) = a.at(i);
  for (int i = 1; i <= n + 2; i++) {
    for (int j = 0; j < n % 2 + 2; j++) {
      for (int k = 0; k <= j; k++) {
        if (i - 2 + k - j < 0) continue;
        dp.at(i).at(j) = max(dp.at(i).at(j), dp.at(i - 2 + k - j).at(k) + a.at(i - 1));
      }
    }
  }
  cout << dp.at(n + 2).at(n % 2 + 1) << endl;
}


Measured memory_bytes: 15668
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if( a+b < c+d ) cout << "Right" << endl;
  else if( a+b > c+d ) cout << "Left" << endl;
  else cout << "Balanced" << endl;
  return 0;
}




//


Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())

lr = 'left'

def reverse_list(lr):
    if lr == 'right':
        return 'left'
    else:
        return 'right'

def moji_tuika(S, f, c, lr):
    if f == 1 and lr == 'left':
        S.appendleft(c)
    elif f == 1 and lr == 'right':
        S.append(c)
    elif f == 2 and lr == 'left':
        S.append(c)
    else:
        S.appendleft(c)
    return S

q = []
for i in range(Q):
    temp = input().split()
    if len(temp) == 1:
        q.append(1)
    else:
        q.append(temp)

S = deque(list(S))
for i in q:

    if type(i) == int:
        lr = reverse_list(lr)
    elif int(i[0]) == 2:
        S = moji_tuika(S,int(i[1]),i[2],lr)
if lr == 'right':
    S.reverse()

S = ''.join(S)
print(S)


Measured memory_bytes: 44516
#include <iostream>

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

using namespace std;



int main() {
    int a,b;
    cin>>a>>b;
    int payment=b;
    if(a<=5)payment=0;
    else if(a<=12)payment=payment/2;

    cout<<payment<<endl;

    return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
cnt=0
for n in range(1,N+1):
    total=0
    total+=n%10
    total+=int(n/10)%10
    total+=int((n/10)/10)%10
    total+=int(((n/10)/10)/10)%10
    total+=int((((n/10)/10)/10)/10)%10
    if A<=total<=B:
        cnt+=n
print(cnt)

Measured memory_bytes: 3064
n,q = map(int,input().split())
s,a = input(),[0]*n
for i in range(1,n):
    if s[i-1]=='A' and s[i]=='C': a[i] = a[i-1]+1
    else: a[i]=a[i-1]
for i in range(q):
    x,y = map(int,input().split())
    print(a[y-1]-a[x-1])

Measured memory_bytes: 6060
#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);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n) ans += i & 1 ^ 1 && a[i] & 1;
    cout << ans << endl;
}

Measured memory_bytes: 3640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	while (true) {
		int t; cin >> t;
		if (t == 0)break;
		int n; cin >> n;

		int sum = 0;
		rep(i, n) {
			int s, f; cin >> s >> f;
			sum += f - s;
		}
		if (sum >= t)puts("OK");
		else cout << t - sum << endl;
	}
}


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

int main() {
  map<char, pair<i64, i64>> dir;
  dir['N'] = {0, 1};
  dir['S'] = {0, -1};
  dir['E'] = {1, 0};
  dir['W'] = {-1, 0};
  i64 N;
  while(cin >> N, N) {
    vector<vector<i64>> je(21, vector<i64>(21));
    rep(i,0,N) {
      i64 x, y;
      cin >> x >> y;
      je[x][y]++;
    }
    i64 x = 10;
    i64 y = 10;
    i64 M;
    cin >> M;
    i64 cnt = 0;
    rep(q,0,M) {
      char d;
      i64 l;
      cin >> d >> l;
      i64 dx = dir[d].first;
      i64 dy = dir[d].second;
      rep(i,0,l) {
        x += dx;
        y += dy;
        cnt += je[x][y];
        je[x][y] = 0;
      }
    }
    if(cnt == N) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}



Measured memory_bytes: 3168
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();

		ArrayList<Integer> list = new ArrayList<>();

		for (int i = 0; i < s.length() - t.length() + 1; i++) {

			int count = 0;
			for (int j = 0; j < t.length(); j++) {
				if (t.charAt(j) != s.charAt(i + j)) {
					count++;
				}

			}
			list.add(count);

		}

		int minReplace = list.stream().mapToInt(x -> x).min().getAsInt();

		System.out.println(minReplace);

	}
}

Measured memory_bytes: 37004
antennas = [int(input()) for _ in range(5)]
k = int(input())

ok = True
for i in range(4):
    left = antennas[i]
    for a in antennas[i+1:]:
        if a - left > k:
            ok = False
            break
    if not ok:
        break

if ok:
    print('Yay!')
else:
    print(':(')


Measured memory_bytes: 2940
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    READAR(A,N);
    ll ans=0;
    FORI(i,0,N)
    {
        if (A[i]==ans+1)
        {
            ans++;
        }
    }
    if (ans==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        cout<<N-ans<<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 1792
while True:
  n,r=map(int,input().split())
  if n==0 and r==0:
    break
  yama=[i for i in range(1,n+1)]
  for i in range(r):
    p,c=map(int,input().split())
    yama1=[]
    for i in range(n-(p-1)-c,n-(p-1)):
      a=yama[i]
      yama1.append(a)
    #print(yama1)
    for i in range(len(yama1)):
      if yama1[i] in yama:
        yama.remove(yama1[i])
    yama=yama+yama1
    #print(yama)
  print(yama[n-1])


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
char a[1000005],b[1000005];
vector<int>from;
vector<int>to;
vector<int>pos[26];
int main(){
    int n;
	scanf("%d%s%s",&n,&a,&b);
	for(int i=0;i<n;i++) if(a[i] != b[i]) goto nxt;
	puts("0"); return 0; nxt:;
	for(int i=0;i<n;i++) pos[a[i]-'a'].pb(i);
	bool dif = 0;
	int pre = INF;
	for(int i=n-1;i>=0;i--){
		if(i == 0 || (i > 0 && b[i-1] != b[i])){
			int id = b[i]-'a';
			int x = POSU(pos[id],min(pre-1,i));
			if(x == 0){
				puts("-1");
				return 0;
			}
			from.pb(pos[id][x-1]);
			to.pb(i);
			if(pos[id][x-1] != i) dif = 1;
			pre = pos[id][x-1];
		}
	}
	int ret = 0;
	for(int i=0;i<to.size();i++){
		//(lb,ub]
		int lb = -1,ub = i+1;
		while(ub-lb > 1){
			int mid = (lb+ub)/2;
			int x = from[i-mid]-mid;
			if(x >= to[i]) ub = mid;
			else lb = mid;
		}
		ret = max(ret,ub+1);
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 17452
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    int N;
    cin >> N;
    vector<ll> a(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    
    ll n = a[0];
    ll r = a[1];
    for(int i = 2; i < N; i++){
        if(abs(n - 2*r) > abs(n - 2*a[i])){
            r = a[i];
        }
    }
    cout << n << " " << r << endl;
    
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Gift from the Goddess of Programming
 */
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			Map<String, Map<String, Deque<int[]>>> logbook = new HashMap<>();

			for (int i = 0; i < n; i++) {
				StringTokenizer st = new StringTokenizer(br.readLine());

				String day = st.nextToken();
				String time = st.nextToken();
				char e = st.nextToken().charAt(0);
				String p = st.nextToken();

				logbook.putIfAbsent(day, new HashMap<>());
				logbook.get(day).putIfAbsent(p, new ArrayDeque<>());
				if (e == 'I') {
					logbook.get(day).get(p).add(new int[]{timeValue(time), 0});
				} else {
					logbook.get(day).get(p).peekLast()[1] = timeValue(time);
				}
			}

			//
			int max = 0;
			Map<String, Integer> blessed = new HashMap<>();

			for (String day : logbook.keySet()) {
				Map<String, Deque<int[]>> logs = logbook.get(day);

				if (logs.get("000") == null) continue;

				for (String p : logs.keySet()) {
					if (!p.equals("000")) {
						blessed.putIfAbsent(p, 0);
						for (int[] r1 : logs.get(p)) {
							for (int[] r0 : logs.get("000")) {
								int i = blessed.get(p);
								i += intersect(r0, r1);
								blessed.put(p, i);
								max = Math.max(max, i);
							}
						}
					}
				}
			}
			System.out.println(max);
		} //end while
	} //end main

	static int timeValue(String time) {
		int c = time.indexOf(':');
		return parseInt(time.substring(0, c)) * 60 +
				parseInt(time.substring(c + 1));
	}

	static int intersect(int[] r1, int[] r2) {
		int ret = 0;
		if (r1[1] <= r2[0]) {
			ret = 0;
		} else if (r1[0] >= r2[1]) {
			ret = 0;
		} else if (r1[0] <= r2[0] && r2[1] <= r1[1]) {
			ret = r2[1] - r2[0];
		} else if (r2[0] <= r1[0] && r1[1] <= r2[1]) {
			ret = r1[1] - r1[0];
		} else if (r1[0] <= r2[0] && r1[1] <= r2[1]) {
			ret = r1[1] - r2[0];
		} else {
			ret = r2[1] - r1[0];
		}
		return ret;
	}
}

Measured memory_bytes: 35068
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort(key = lambda x:-x)
minus.sort()

#print(plus, minus)

"""
貪欲チックに求める
numplus … 前からnumplus番目まで掛け合わせる
numminus … 前からnumminus番目まで掛け合わせる

入力例2に合わせるのは場合分けが必要だが, minusは2個単位で管理する.
"""

numplus = k
numminus = 0

"""
kがplusを超える場合, うまく処理ができないのでリスト参照できる範囲まで下げる.
"""
while numplus > len(plus):
	numplus -= 2
	numminus += 2

#print(numplus, numminus)

while numplus-2 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
	else:
		break

#print(numplus, numminus)

ans = 1

if numplus >= 0 and numminus >= 0 and numminus <= len(minus) and numplus <= len(plus):
	for i in range(numplus):
		ans = ans * plus[i] % mod
	for i in range(numminus):
		ans = ans * minus[i] % mod
else:
	"""
	これは, ansが負になる場合や, minusが1個だけの場合, minusしかない場合, plusしかない場合に使える.
	"""
	#print("ここに来ました！")
	tmp = sorted(a, key=lambda x:-x)
	for i in range(k):
		ans = ans * tmp[i]%mod

print(ans)

Measured memory_bytes: 30928
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> cnt;
  for (int i = 0; i < n; i++)
  {
    cnt[a[i]+1]++;
    cnt[a[i]]++;
    cnt[a[i]-1]++;
  }
  int maxval = 0;
  for (auto itr = cnt.begin(); itr != cnt.end(); itr++)
    maxval = max((*itr).second, maxval);
  cout << maxval << endl;
}

Measured memory_bytes: 8072
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto as = new long[](10^^5+1);
    long S;
    foreach (a; readln.split.to!(long[])) {
        S += a;
        ++as[a];
    }
    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto bc = readln.split.to!(int[]);
        auto B = bc[0];
        auto C = bc[1];
        S -= as[B] * B;
        S += as[B] * C;
        writeln(S);
        as[C] += as[B];
        as[B] = 0;
    }
}

Measured memory_bytes: 7376
#include<iostream>

using namespace std;

string mark(int i, int j)
{
  if ( (i + j) % 2 == 0 )
    return "#";
  else
    return ".";
}

int main()
{
  int h, w;

  cin >> h >> w;

  while(true)
    {
      if ( h == 0 && w == 0 ) break;

      for ( int i = 0; i < h; i++ )
        {
          for ( int j = 0; j < w; j++ )
            {
              cout << mark(i, j);
            }
          cout << endl;
        }
      
      cout << endl;
      cin >> h >> w;
    }
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  //i cant belive how can they be so wrong in the statement
  //when you want both the characters to be present in the string but you dont mention
  int res = 0;
  for (int i = 0; i < N; i++){
    vector<bool> X(26,false);
    for (int j = 0; j < i; j++){
      X[S[j] - 'a'] = true;
    }
    vector<bool> Y(26,false);
    for (int j = i; j < N; j++){
      Y[S[j] - 'a'] = true;
    }
    int count = 0;
    for (int j = 0; j < 26; j++) if (X[j] && Y[j]) count++;
    res = max(res,count);
  }
  cout << res;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <queue>

using namespace std;

const char *X, *Y;
int X_length, Y_length;

int table_lcs[1001][1001];

int lcs(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	bool alreadySeenTable[256];
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}
	
	for (i = 0; i < 256; i++) {
		alreadySeenTable[i] = false;
	}
	i = x_begin;
	to = Y_length-1;
	while(i <= X_length-1) {
		j = y_begin;
		if (alreadySeenTable[X[i]] == true) {
			i++;
			continue;
		}
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			alreadySeenTable[X[i]] = true;
			i++;
		}
		else {
			alreadySeenTable[X[i]] = true;
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int lcs2(int x_begin, int y_begin) {
	int i, j, to;
	int max = 0;
	int v_lcs;
	if (table_lcs[x_begin][y_begin] != -1) {
		return table_lcs[x_begin][y_begin];
	}

	i = x_begin;
	to = Y_length - 1;
	while (i <= X_length - 1) {
		j = y_begin;
		bool found = false;
		while (j <= to) {
			if (X[i] == Y[j]) {
				v_lcs = lcs(i + 1, j + 1) + 1;
				if (v_lcs > max) {
					max = v_lcs;
				}
				found = true;
				break;
			}
			else {
				j++;
			}
		}
		if (found == false) {
			i++;
		}
		else {
			i++;
			to = j - 1;
		}
	}
	return table_lcs[x_begin][y_begin] = max;
}

int main() {

	int N;
	cin >> N;
	string stringX, stringY;

	for (int i = 1; i <= N; i++) {
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				table_lcs[i][j] = -1;
			}
		}
		cin >> stringX >> stringY;
		X = stringX.c_str();
		X_length = stringX.size();
		Y = stringY.c_str();
		Y_length = stringY.size();
		printf("%d\n", lcs(0, 0));
	}
	return 0;
}

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

int main() {
  int N,K,A,B,C;
  cin >>K>>A>>B;
  for(int i=A;i<=B;i++){
    if(i%K==0){
      cout<<"OK"<<endl;
        return 0;
    }
  }
  cout <<"NG"<< endl;
}


Measured memory_bytes: 3620
import numpy as np


def main():
    N, D = map(int, input().split())
    X = [None] * N
    for n in range(N):
        X[n] = [int(x) for x in input().split()]

    X = np.array(X)
    dist = np.sum((X[:, None] - X[None, :]) ** 2, axis=-1) ** 0.5

    count = 0
    for i in range(N):
        for j in range(i):
            if float(dist[i, j]).is_integer():
                count += 1
    
    print(count)

main()


Measured memory_bytes: 12424
import java.util.Scanner;

public class Main{
		public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		boolean[] uru = new boolean[3001];
		for(int i=0;i<=3000;i++) {
			if(i%4==0   && i%100!=0 || i%400==0)
				uru[i] = true;
			else uru[i] = false;
		}
		int cnt = 0;
		while(true){
            int from = sc.nextInt();
            int to = sc.nextInt();
            if(from +to == 0) break;
 
            if(cnt==0) cnt++;
            else System.out.println();
 
            boolean flg = true;
            for(int i=from;i<=to;i++){
                if(uru[i]){
                    flg = false;
                    System.out.println(i);
                }
            }
 
            if(flg) System.out.println("NA");
        }
	}
}



Measured memory_bytes: 27396
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int c,int d){
    return d ? gcd(d, c % d) : c;
}



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

    int k,a,b; cin >> k >> a >> b;
    if(b-a <= 2){
        cout << k+1 << endl;
        return 0;
    }

    int ans = 1;
    for(int i = 0;i < k;i ++){
        if(ans < a || i == k-1) ans ++;
        else{
            ans += b - a;
            i ++;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
// This template is based on Mr. tonymontaro's template (https://atcoder.jp/users/tonymontaro).
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();
        StringBuilder result = new StringBuilder();

        // Start: int型の整数n mを取得する
        // // N M 形式
        // int n = in.intNext();
        // int m = in.intNext();
        // End: int型の整数n mを取得する

        // Start: int型の整数Nと配列Aを取得する
        // // N
        // // A1 A2 A3... AN 形式
        int n = in.intNext();
        int[] A = in.nextIntArray(n);
        // End: int型の整数Nと配列Aを取得する

        // result.append(n);
        int sum = 0;
        boolean continueFlag = true;
        while (continueFlag) {
          for (int i = 0; i < n; i++) {
            if (A[i] % 2 != 0) {
              continueFlag = false;
            } else {
              A[i] = A[i] / 2;
            }
          }
          if (continueFlag) sum++;
        }
        result.append(sum);

        // Start: Char型の文字をInt型に変換する
        // Integer.parseInt(String.valueOf(charText))
        // End: Char型の文字をInt型に変換する

        // Start: 文字列を1文字ずつ出力する
        // String text = in.next();
        // char[] work = new char[text.length()];
        // for(int i = 0; i < text.length(); i++){
        //   work[i] = text.charAt(i); // Char型の文字
        //   out.println(work[i]);
        // }
        // End: 文字列を1文字ずつ出力する

        out.println(result);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}

Measured memory_bytes: 22612
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class CExceptionHandling {
public:
    void solve(istream& cin, ostream& cout) {
        int n; cin >> n;
        vector<int> a;
        for(int i=0; i<n; i++) {
            int tp; cin >> tp;
            a.push_back(tp);
        }
        int max1  = -1, max_cnt = 0, max2 = -1;
        for(auto k: a) {
            if(k > max1) {
                max1 = k;
                max_cnt = 1;
            } else if (k == max1) {
                max_cnt++;
            }
        }
        if(max_cnt > 1) {
            for(int i=0; i<n; i++) cout << max1 << '\n';
        } else {
            for (auto k: a) {
                if (k == max1) continue;
                max2 = max(max2, k);
            }
            for(int i=0; i<n; i++) {
                if(a[i] == max1) cout << max2 << '\n';
                else cout << max1 << '\n';
            }
        }
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    CExceptionHandling solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int a,m=10,ans=0,x=0;
    REP(i,5){
        cin>>a;
        ans+=(a/10)*10;
        if(a%10>0){ 
            x++;
            m=min(m,a%10);
        }
    }
    if(m==10){
        m=0;
        x=1;
    }
    cout<<ans+m+(x-1)*10<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	A, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	B, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	if answer := A - 2*B; answer > 0 {
		fmt.Println(answer)
	} else {
		fmt.Println(0)
	}
}



Measured memory_bytes: 1832
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,d;
  cin >> n >> d;

  int ans = n / (2 * d + 1);

  cout << ans + (n % (2 * d + 1) == 0 ? 0 : 1) ;
  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<double> que;
    rep(i, n){
        double a;
        cin >> a;
        que.push(a);
    }

    rep(i, m){
        double a = que.top();
        que.pop();
        que.push(a/2);
    }

    ll ans = 0;
    rep(i, n){
        int a = que.top();
        que.pop();
        ans += a;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

#define NUM 3

typedef struct STATUS{
    int num;                    //????????????????????????????????°
    int board[NUM * NUM];       //?????¢?????¶???
    int x,y;                    //?????¢???0???????????????????????§?¨?
}STATUS;

bool checked[9*8*7*6*5*4*3*2*1];

/* ?????¢?????¶????????????????????? */
int change_number( int *board )
{
    int work[NUM*NUM];
    static int fact_table[NUM*NUM] = {
        40320, 5040, 720, 120, 24, 6, 2, 1, 0,
    };
    int j, k, value = 0;
    memcpy( work, board, sizeof(int)*NUM*NUM );
    for( j = 0; j < NUM*NUM - 1; j++ ){
        value += fact_table[j] * work[j];
        for( k = j + 1; k < NUM*NUM; k++ ){
            if( work[j] < work[k] ) work[k]--;
        }
    }
    return value;
}


int search(STATUS in){
    
    int x = 0, y = 0;
    int chk_num,goal_num;
    
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};
    
    int goal[9] = {1,2,3,4,5,6,7,8,0};
    STATUS out;
    goal_num = change_number(goal);
    
    //?????¢?????¶????????????????????????????????\???
    queue<STATUS> qu;
    qu.push(in);
    
    //?????\???????????????????????§?¶???????
    while (!qu.empty()) {
        
        in = qu.front();
        qu.pop();
        chk_num = change_number(in.board);
        if (goal_num == chk_num){
            return in.num;
        }
        else{
            checked[chk_num] = true;
        }
        for (int i = 0; i < 4; i++) {
            //?????¢???0???????????????????????§?¨????x,y???????????????
            x = in.x;
            y = in.y;
            if (x + dx[i] >=0 && x+dx[i] < NUM && y+dy[i] >=0 && y+dy[i] < NUM) {
                memcpy(&out, &in, sizeof(STATUS));
                swap(out.board[NUM*y + x], out.board[NUM*(y+dy[i]) + x + dx[i]] );
                
                chk_num = change_number(out.board);
                if (checked[chk_num] == true){
                    continue;
                }
                else{
                    out.num++;
                    out.x = x + dx[i];
                    out.y = y + dy[i];
                    qu.push(out);
                }
            }
        }
    }
    
    //?????¢???goal?????°??????????????£?????´??????-1?????????
    return -1;
}


int main(){
    
    int val, ans;
    
    STATUS init;
    init.num = 0;
    
    for (int i = 0; i < NUM; i++) {
        for (int j = 0; j < NUM; j++) {
            cin >> val;
            init.board[i*NUM +j] = val;
            if (val == 0){
                init.x = j;
                init.y = i;
            }
        }
    }
    
    ans = search(init);
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <list>
#include <string>

int main() {
  std::string s;
  std::cin >> s;
  std::list<bool> li;
  for (auto c : s) li.push_back(c=='1');
  for (auto itr = li.begin(); itr != li.end(); ) {
    if (itr != li.begin() && *std::prev(itr) != *itr) {
      li.erase(std::prev(itr));
      itr = li.erase(itr);
    } else itr++;
  }
  std::cout << s.size()-li.size() << std::endl;
}


Measured memory_bytes: 3456
'''
最短でans == s == t
最長でans == (s + t)
'''
n = int(input())
s = input()
t = input()

ans = s
i = 0
while True:
    if ans[(-1) * n:] == t:
        break
    else:
        ans = s + t[(-1) * (i+1):]
        i += 1
        if i == n:
            break
print(len(ans))

Measured memory_bytes: 3064
n=int(input())
num=[0 for i in range(5)]
for i in range(n):
  s=input()
  if s[0]=="M":
    num[0]+=1
  if s[0]=="A":
    num[1]+=1
  if s[0]=="R":
    num[2]+=1
  if s[0]=="C":
    num[3]+=1
  if s[0]=="H":
    num[4]+=1
ans=0
ans=num[0]*num[1]*(num[2]+num[3]+num[4])
ans+=num[0]*num[2]*(num[3]+num[4])
ans+=num[0]*num[3]*num[4]
ans+=num[1]*num[2]*(num[3]+num[4])+num[1]*num[3]*num[4]
ans+=num[2]*num[3]*num[4]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
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 NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
  int N, M; cin >> N >> M;
  int maxL = 0;
  int minR = N;
  for (int i = 0; i < M; ++i) {
    int l ,r; cin >> l >> r;
    maxL = max(maxL, l);
    minR = min(minR, r);
  }
  int ans = minR - maxL + 1;
  if (ans < 0) cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3572
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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(a>b){a=b;return 1;}return 0;}

ll x, ans, n, a;

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

  cin >> n >> a;

  ll dp[60][5010] = {};
  dp[0][0] = 1;

  REP(i,n) {
    cin >> x;    
    ROF(j,50,1){
      ROF(k,2500-x,0){
	dp[j][k+x] += dp[j-1][k];
      }
    }
  }  
  FOR(i,1,n+1) {
    //cerr << i*a << endl;
    ans += dp[i][i*a];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3192
n = int(input())
h = list(map(int, input().split()))

ans = 'Yes'
for i in range(n - 1):
    if h[i + 1] - h[i] >= 1:
        h[i + 1] -= 1
    elif h[i + 1] - h[i] == 0:
        continue
    else:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <complex>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <sstream>
#include <numeric>
#include <functional>
#include <bitset>
#include <iomanip>

using namespace std;


#define INF (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back
#define EACH(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)

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

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// conversion
template<class T> inline string toStr(T a) { ostringstream oss; oss << a; return oss.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }
/////////////////////////

struct Cake
{
  int w, d;
  Cake() {}
  Cake(int w, int d) : w(w), d(d) {}
  
  bool operator < (const Cake& c) const {
    return w * d < c.w * c.d;
  }
};

void CDump(vector<Cake> &cont) {
  cout << "-------------------" << endl;
  cout << "dump container:" << endl;
  EACH(it, cont) {
    cout << it->w << " " << it->d << endl;
  }
  cout << "-------------------" << endl;
}

int main() {
  
  int N, W, D;
  while(cin >> N >> W >> D && (N|W|D)) {
    
    vector<Cake> cakes;
    cakes.PB( Cake(W,D) );

    int p, s;
    for(int i=0; i<N; i++) {
      cin >> p >> s; p--;
      
      Cake cp = cakes[p]; cakes.erase(cakes.begin()+p);
      
      s %= (cp.w*2 + cp.d*2);
      int angle = -1;
      int temp = -s;
      
      rep(i, 2) {
	angle++; temp += cp.w;
	if(temp > 0) goto SKIP;
	angle++; temp += cp.d;
	if(temp > 0) goto SKIP;
      }
      
    SKIP:;
      switch(angle) {
      case 0: case 2:
	{
	  int a = temp, b = cp.w-temp;
	  if(b < a) { swap(a, b); }
	  cakes.PB( Cake(a, cp.d) );
	  cakes.PB( Cake(b, cp.d) );
	}
	break;
	
      case 1: case 3:
	{
	  int a = temp, b = cp.d-temp;
	  if(b < a) { swap(a, b); }
	  cakes.PB( Cake(cp.w, a) );
	  cakes.PB( Cake(cp.w, b) );
	}
	break;
      }
    }
    
    sort(ALL(cakes));
    for(int i=0; i<cakes.size(); i++) {
      if(i) cout << " ";
      cout << cakes[i].w * cakes[i].d;
    }
    cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1200