akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<set>
#define INF 1e8
using namespace std;
int main(void){
    // Your code here!
int a,b,c;
cin>>a>>b>>c;

if((a==b && b!=c) || (a==c && a!=b)||(b==c && b!=a))
    cout<<"Yes";
else
    cout<<"No";

}


Measured memory_bytes: 3640
N = gets.to_i
(1 .. 3500).each do |a|
  (a .. 3500).each do |b|
    next if (4 * a * b  - N * b  - N  * a) < 1
    c,m = (N * a * b).divmod(4 * a * b  - N * b  - N  * a ) 
    next if m > 0
    puts [a,b,c].join(' '); exit
  end
end


Measured memory_bytes: 14380
h, w = map(int, input().split())
s_list = [list(input()) for i in range(h)]
for i in range(h):
    for j in range(w):
        if s_list[i][j] == "#":
            flg = False
            if i != 0:
                if s_list[i - 1][j] == "#":
                    flg = True
            if i != h - 1:
                if s_list[i + 1][j] == "#":
                    flg = True
            if j != 0:
                if s_list[i][j - 1] == "#":
                    flg = True
            if j != w - 1:
                if s_list[i][j + 1] == "#":
                    flg = True
            if not flg:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 39280
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

static const int INF = 1e9;

int erace(int n, vector<int> v, int num, int c){//??°???????????°?????°????????????????????????????????´??? ?????????????????????
	int n_tmp = n;
	int l = num;//??????????????´????????????
	int r = num + 1;
	int color = c;//???????????´????????°?????????????????????
	while(1){
		// rep(i, n) printf("%d", v[i]);
		// printf("\n");
		int cnt = 0;//????????°????????£?¶???????????????°
		//?????´???????????????????????£?¶????????????????
		while(0 <= l && v[l] == color){
      		cnt++;
      		l--;//??????????????°???
    	}
    	//?????´???????????????????????£?¶????????????????
    	while(r < n && v[r] == color){//n??????????????£????????°??£???
      		cnt++;
      		r++;//??????????????°???
    	}
    	// printf("num %d l %d r %d\n", num, l, r);
   		if(cnt >= 4){
   			// printf("num %d l %d r %d\n", num, l, r);
    		n_tmp -= cnt;//??£?¶?????????°??????????¶????
    		if(v[l] == v[r]){
	    		color = v[l];//?¬?????¶????????¶???????????????´??°??????
	    		// printf("color %d\n", color);
	    	}
    		else break;//?¶???????????????????????????????????????§???????????°???????????\????¶????????????¨?????????
    	}else{
    		break;//???????¶???????????????°???????????\????¶????????????¨?????????
    	}
	}
	return n_tmp;
}

int main(void){
	while(1){
		int n; scanf("%d", &n);
		if(n == 0) return 0;
		vector<int> v(n);
		rep(i, n) scanf("%d", &v[i]);
		int ans = INF;
		//??¨??¢?´¢
		rep(i, n){//?????????????????¨????????????
			int tmp = v[i];
			//???????????????
			reps(j, 1, 4){
				if(tmp == j) continue;
				v[i] = j;
				ans = min(ans, erace(n, v, i, j));
			}
			v[i] = tmp;//????????????
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

class Dice {
	array<int, 6> m_faces;

public:
	explicit Dice( const array<int, 6>& f ):
		m_faces( f )
	{}

	int top() const {
		return m_faces.at( 0 );
	}

	void roll( char dir ) {
		if( dir == 'N' ) {
			setFace(
				m_faces.at( 1 ),
				m_faces.at( 5 ),
				m_faces.at( 2 ),
				m_faces.at( 3 ),
				m_faces.at( 0 ),
				m_faces.at( 4 ) );
		}
		else if( dir == 'S' ) {
			setFace(
				m_faces.at( 4 ),
				m_faces.at( 0 ),
				m_faces.at( 2 ),
				m_faces.at( 3 ),
				m_faces.at( 5 ),
				m_faces.at( 1 ) );
		}
		else if( dir == 'W' ) {
			setFace(
				m_faces.at( 2 ),
				m_faces.at( 1 ),
				m_faces.at( 5 ),
				m_faces.at( 0 ),
				m_faces.at( 4 ),
				m_faces.at( 3 ) );
		}
		else if( dir == 'E' ) {
			setFace(
				m_faces.at( 3 ),
				m_faces.at( 1 ),
				m_faces.at( 0 ),
				m_faces.at( 5 ),
				m_faces.at( 4 ),
				m_faces.at( 2 ) );
		}
	}

	void setFace( int n0, int n1, int n2, int n3, int n4, int n5 ) {
		m_faces.at( 0 ) = n0;
		m_faces.at( 1 ) = n1;
		m_faces.at( 2 ) = n2;
		m_faces.at( 3 ) = n3;
		m_faces.at( 4 ) = n4;
		m_faces.at( 5 ) = n5;
	}
};

int main() {
	array<int, 6> f;
	for( auto& v: f ) { cin >> v; }

	Dice dice( f );

	string s;
	cin >> s;

	for( auto ch: s ) {
		dice.roll( ch );
	}

	cout << dice.top() << endl;
}



Measured memory_bytes: 3208
fun main(args : Array<String>) {
    val (n, c, k) = readLine()!!.split(" ").map { it.toInt() }
    val tt = IntArray(n) { readLine()!!.toInt() }.sorted()

    var busSum = 1

    var busStart = tt.first()
    var pNum = 0

    tt.forEachIndexed { idx, t ->
        if (pNum < c && t-busStart <= k) {
            pNum++
        } else {
            busSum++
            busStart = t
            pNum = 1
        }
    }

    println(busSum)
}

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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 3e5 + 5;
int a[N], cnt[N], ans[N];

int main()
{
	int n = read();
	for (int i = 1, x; i <= n; ++i) 
		x = read(), ++a[x], ++cnt[a[x]];
	for (int i = 1; i <= n; ++i) cnt[i] += cnt[i - 1];
	
	for (int i = n, j = 1; i >= 1; --i)
	{
		while (j <= n && cnt[j] >= 1LL * i * j) ++j;
		ans[i] = j - 1; 
	}
	for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 4352
# encoding:utf-8
 
def main():
	n, m, d = list(map(int, input().split()))
	if d == 0:
		tmp = n
	else:
		tmp = 2 * (n - d)

	print(tmp * (m - 1) / n ** 2)

 
if __name__ == '__main__':
	main()

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string s;

int main() {
	cin >> s;
	
	cout << (s[1] == s[2] && (s[0] == s[1] || s[2] == s[3]) ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using CompLib.Util;

public class Program
{
    int N;
    long K;
    int[] A;
    public void Solve()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextLong();
        A = sc.IntArray().Select(i => i - 1).ToArray();

        if (K <= N)
        {
            var p = 0;
            for (int i = 0; i < K; i++)
            {
                p = A[p];
            }
            Console.WriteLine(p + 1);
            return;
        }
        else
        {
            int[] cnt = new int[N];
            for (int i = 0; i < N; i++)
            {
                cnt[i] = -1;
            }
            cnt[0] = 0;
            int p = 0;
            long loop = -1;
            long s = -1;
            while (true)
            {
                int next = A[p];
                if (cnt[next] != -1)
                {
                    loop = cnt[p] - cnt[next] + 1;
                    s = cnt[next];
                    break;
                }
                cnt[next] = cnt[p] + 1;
                p = next;
            }

            var m = (K-s) % loop;
            // s移動
            int cur = 0;
            for (int i = 0; i < s + m; i++)
            {
                cur = A[cur];
            }
            Console.WriteLine(cur+1);
        }
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 44660
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
#define MAXN 3100
int main(){
  string s,t;
  cin>>s>>t;
  int a=s.size(),b=t.size();
  int dp[MAXN][MAXN]={0};
  for(int i=0;i<=a;i++)dp[i][0]=i;
  for(int j=0;j<=b;j++)dp[0][j]=j;
  for(int i=0;i<a;i++){
    for(int j=0;j<b;j++){
      if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j];
      else
      dp[i+1][j+1]=min({dp[i+1][j],dp[i][j+1],dp[i][j]})+1;
    }
  }
  cout<<dp[a][b]<<endl;
}


Measured memory_bytes: 40728
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,zx,xc,ii,jj;;
string s;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>s;
    a=s.size();
    s.insert(0,"0");
    for(i=1; i<=a; i++){
        if(s[i]=='?'){
            cout<<'D';
        }else{
            cout<<s[i];
        }
    }
    return 0;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int main()
{
    while (1) {
        int n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> h(n+1), w(m+1);
        loop (n, i) cin >> h[i+1];
        loop (m, i) cin >> w[i+1];

        loop (n, i) h[i+1] += h[i];
        loop (m, i) w[i+1] += w[i];

        vector<int> H, W;
        loop (n+1, i) loop (n+1, j) {
            if (i >= j) continue;
            H.push_back(h[j] - h[i]);
        }
        loop (m+1, i) loop (m+1, j) {
            if (i >= j) continue;
            W.push_back(w[j] - w[i]);
        }
        sort(all(W));

        int ans = 0;
        for (int v : H) {
            ans += distance(lower_bound(all(W), v), upper_bound(all(W), v));
        }

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 20604
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    double a, b;
    scanf("%lf%lf", &a, &b);
    for (double i = floor(min(a * 12.5, b * 10)); ; i += 1) {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
            printf("%d", (int)i);
            return 0;
        } else if (floor(i * 0.08) > a && floor(i * 0.1) > b) {
            printf("-1\n");
            return 0;
        }
    }
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<"\n";
	return 0;
}



Measured memory_bytes: 256
//300
fun a019(args: Array<String>) {
    val (Q, H, S, D) = args[0].split(" ").map { it.toLong() }
    val N = args[1].toLong()
    var price: Long = 0

    if (D <= 2 * S && D <= 4 * H && D <= 8 * Q) {
        price += (N / 2) * D
        if (N % 2 == 1L) {
            if (S <= 2 * H && S <= 4 * Q) {
                price += S
            } else if (2 * H <= S && H <= 2 * Q) {
                price += 2 * H
            } else {
                price += 4 * Q
            }
        }
    } else if (2 * S <= D && S <= 2 * H && S <= 4 * Q) {
        price += N * S
    } else if (4 * H <= D && 2 * H <= S && H <= 2 * Q) {
        price += N * 2 * H
    } else {
        price += N * 4 * Q
    }
    println(price)
}

fun main(args: Array<String>) {
    a019(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 38332
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
ll a[200060],b[300000];
vector<ll>v;
map<ll,ll>mp,mp1;
int main()
{
    IO;
    double i, j, m, k, l=0, g=0, mod,t,tc, n,mn=INT_MAX; ll kk=100;
           cin>>n;
           while(kk<n){
            k=kk*1.01; l++; kk=k;
           }
           cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 3816
#include<iostream>
using namespace std;
int main()
{
	int n,ans=1;cin>>n;
	for(int i=2;i<35;i++)
	{
		int x=i*i;if(x>n) break;
		while(x*i<=n) x*=i;
		if(x>ans) ans=x;
	}
    cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer


object Main {


  def read() = {
    val sc = new Scanner(System.in)
    val a, b, c, d = sc.nextLong()
    (a, b, c, d)
  }

  @tailrec
  def gcd(x: Long, y: Long): Long = {
    assert(x >= 0 && y >= 0)
    if (y == 0) x else gcd(y, x % y)
  }

  def divCeil(a: Long, b: Long): Long = (a - 1) / b + 1

  def divFloor(a: Long, b: Long): Long = a / b


  def solve(a: Long, b: Long, c: Long, d: Long): Long = {

    def nDiv(x: Long) = divFloor(b, x) - divCeil(a, x) + 1


    val lcmCD = c / gcd(c, d) * d

    val nDivCorD = nDiv(c) + nDiv(d) - nDiv(lcmCD)
    (b - a + 1) - nDivCorD

  }

  def main(args: Array[String]): Unit = {
    val (a, b, c, d) = read()
    println(solve(a, b, c, d))
  }
}

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

using namespace std;

typedef long long ll;

template<typename T>
void _dump(const char* s, T&& head)
{
  cerr << s << "=" << head << endl;
}

template<typename T, typename... Args>
void _dump(const char* s, T&& head, Args&&... tail)
{
  while (*s != ',')
    cerr << *s++;
  cerr << "=" << head << ",";
  _dump(s + 1, tail...);
}

template<typename T>
void _dumpv(const char* s, T&& v)
{
  cerr << *s << "=";
  for (auto it = v.begin(); it != v.end(); it++) {
    cerr << *it << " ";
  }
  cerr << endl;
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__)
#define dumpv(...) _dumpv(#__VA_ARGS__, __VA_ARGS__)
// #define dump(...)
// #define dumpv(...)

const ll MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("template.1", "r", stdin);

  ll W, H, x, y;
  cin >> W >> H >> x >> y;
  cout << (double)W * (double)H / 2.0 << " ";
  int ans = 1;
  // dump(x, y, W, H);
  if ((double)W / 2 == x && (double)H / 2 == y)
    ans = 1;
  else
    ans = 0;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
int main(){
    cs
    int a,b,t=0,x=1;
    cin>>a;
    rep(i,a){
        cin>>b;
        if(b==x) {t++;x++;}
    }
    if(!t) cout<<-1;
    else cout<<a-t;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(n < 3200) cout << "red";
  else cout << s;
  return 0;
}

Measured memory_bytes: 256
def main():
    import collections
    S = input()
    q = collections.deque(S)
    Q = int(input())
    isrev = False
    for _ in range(Q):
        query = input()
        if query == "1":
            isrev = isrev ^ True
        else:
            _, f, c = query.split()
            ishead = (f=="1")
            ishead = ishead ^ isrev
            if ishead:
                q.appendleft(c)
            else:
                q.append(c)
    if isrev:
        q = reversed(q)
    print("".join(q))


if __name__ == '__main__':
    main()

Measured memory_bytes: 8556
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;















signed main(){
    int n, m;
    cin >> n >> m;
    cout << n * (n - 1) /2 + m * (m - 1) / 2;




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vi a(n);
    REP(i, n) cin >> a[i];
    int ans = -1;
    REP(i, n) {
        FOR(j, i+1, n) {
            int mul = a[i] * a[j];
            int prev = -1;
            bool valid = true;
            while (mul > 0) {
                if (prev != -1 and prev - 1 != mul % 10) {
                    valid = false;
                    break;
                }
                prev = mul % 10;
                mul /= 10;
            }
            if (valid) {
                chmax(ans, a[i] * a[j]);
            }
        }
    }
    cout << ans << endl;

    return 0;
}



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

typedef struct{
        long long int kosu;
        long long int price;
} enadri;

int cmp( const void *p, const void *q ) {
    return ((enadri*)p)->price - ((enadri*)q)->price;
}


int main()
{

    int tenpo,necc;
    enadri tmp[100000];
    
    scanf("%d%d",&tenpo,&necc);
    int i;
    for(i=0;i<tenpo;i++){
        scanf("%ld%ld",&tmp[i].price,&tmp[i].kosu);
    }

    qsort(tmp,tenpo, sizeof(enadri),cmp);

    long long int total = 0,value=0;

    i=0;
    while(i<=tenpo){
        if(total + tmp[i].kosu > necc){
            break;
        }
        total += tmp[i].kosu;
        value += tmp[i].kosu * tmp[i].price;

        i++;
    }

    long long int rem = necc - total;
    value += rem *tmp[i].price;

    printf("%ld\n",value);

    return 0;
}

Measured memory_bytes: 3324
#include<iostream>
    #include<string>
    using namespace std;
     
    int f[3];
     
    int main(){
      string S;
      cin>>S;
      for(int i=0;i<3;i++){
        if(S[i]=='a')f[0]++;
        else if(S[i]=='b')f[1]++;
        else f[2]++;
      }
      if(f[0]&&f[1]&&f[2])cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
      
      return 0;
    }

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


int main(){
    string s,t;
    cin>>s;
    cin>>t;
    int mini=INT_MAX;
    for(int i=0;i<=(s.length()-t.length());i++){
        int count=0;
        for(int j=i;j<i+t.length();j++){
           if(s[j]!=t[j-i])
           count++;
        }
        mini=min(mini,count);
    }
    cout<<mini;
   return 0;
}


Measured memory_bytes: 3592
N,x=map(int,input().split())
A=[int(a) for a in input().split()]
s=0
for i in range(1,N):
  t=A[i-1]+A[i]
  if t>x:
    s+=t-x
    A[i]=max(0,A[i]+x-t)
    
print(s)

Measured memory_bytes: 14252
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
const int maxn=2010;
const int maxm=maxn*maxn;
const int mod=1e9+7;
LL fac[maxm],inv[maxm];
LL Pow(LL x,LL y){
	LL ret=1;
	while(y){
		if(y&1) ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}
void init(){
	fac[0]=inv[0]=1;
	for(int i=1;i<maxm;i++) fac[i]=fac[i-1]*i%mod;
	inv[maxm-1]=Pow(fac[maxm-1],mod-2);
	for(int i=maxm-2;i>=1;i--) inv[i]=inv[i+1]*(i+1)%mod;
	//for(int i=1;i<=10;i++) printf("%lld ", fac[i]);puts("");
	//printf("%lld\n", fac[100]*inv[100]%mod );
}
LL dp[maxn][maxn];
int n,k;
LL C(int n, int m){
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	init();
	scanf("%d%d",&n,&k);
	if(k==1){
		puts("1");return 0;
	}
	dp[0][0]=1;
	for(int i=0;i<=n;i++){
		for(int j=i;j<=n;j++){
			(dp[i+1][j]+=dp[i][j])%=mod;
			(dp[i][j+1]+=dp[i][j]*C(i+(j+1)*(k-1)-1,k-2))%=mod;
		}
	}
	printf("%lld",dp[n][n]*fac[n]%mod);
	return 0;
}

Measured memory_bytes: 94848
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut ans: Vec<f64> = vec![1.0; n];
    for i in 0..n {
        let mut point = i + 1;
        while point < k {
            point *= 2;
            ans[i] /= 2.0;
        }
    }

    let ans = ans.into_iter().sum::<f64>() / (n as f64);
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
// using System.Globalization;
using System.IO;
using System.Linq;
// using System.Text;

class Program
{
    static void Main()
    {
        FastScanner sc = new FastScanner(Console.OpenStandardInput());
        int N = sc.nextInt();
        int[] A = sc.intArray(N);
        int[] B = sc.intArray(N);
        int[] C = sc.intArray(N - 1);
        int ans = B.Sum();
        for (int i = 1; i < N; i++) ans += A[i - 1] + 1 == A[i] ? C[A[i - 1] - 1] : 0;
        Console.WriteLine(ans);
        return;
    }
}

// FastScanner start
public class FastScanner
{
    public readonly Stream str;
    private readonly byte[] buf = new byte[1024];
    private int len, ptr;
    public bool isEof = false;
    public FastScanner(Stream stream)
    {
        str = stream;
    }
    private T[] enumerate<T>(int n, Func<T> f)
    {
        var a = new T[n];
        for (int i = 0; i < n; ++i) a[i] = f();
        return a;
    }
    public char nextChar()
    {
        byte b = 0;
        do
        {
            b = read();
        }
        while ((b < 33 || 126 < b) && !isEof);
        return (char)b;
    }
    public int nextInt()
    {
        return (isEof) ? int.MinValue : (int)nextLong();
    }
    public long nextLong()
    {
        if (isEof)
        {
            return long.MinValue;
        }
        long ret = 0;
        byte b = 0;
        var ng = false;
        do
        {
            b = read();
        }
        while (b != '-' && (b < '0' || '9' < b));
        if (b == '-')
        {
            ng = true;
            b = read();
        }
        for (; true; b = read())
        {
            if (b < '0' || '9' < b)
            {
                return ng ? -ret : ret;
            }
            else ret = ret * 10 + b - '0';
        }
    }
    public int[] intArray(int n)
    {
        return enumerate(n, nextInt);
    }
    public long[] longArray(int n)
    {
        return enumerate(n, nextLong);
    }
    public char[] charArray(int n)
    {
        return enumerate(n, nextChar);
    }
    private byte read()
    {
        if (isEof)
        {
            return 0;
        }
        if (ptr >= len)
        {
            ptr = 0;
            if ((len = str.Read(buf, 0, 1024)) <= 0)
            {
                isEof = true;
                return 0;
            }
        }
        return buf[ptr++];
    }
}
// FastScanner end

Measured memory_bytes: 26180
N,k=map(int,input().split())
n=3*10**5+10
#####segfunc######
def segfunc(x,y):
    return max(x,y)

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num


for i in range(N):
  x=int(input())
  update(x,query(max(0,x-k),min(n,x+k+1))+1)
print(seg[0])

Measured memory_bytes: 81564
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int n;
vector<vector<int>> g;

vector<int> bfs(int s) {
    vector<int> d(n, INF);
    queue<int> que;
    d[s] = 0;
    que.push(s);
    while(que.size()) {
        int now = que.front();
        que.pop();
        if(d[now] == INF) {
            continue;
        }
        for(int next : g[now]) {
            if(d[next] == INF) {
                d[next] = d[now] + 1;
                que.push(next);
            }
        }
    }
    return d;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].emplace_back(b - 1);
        g[b - 1].emplace_back(a - 1);
    }
    auto f = bfs(0);
    auto s = bfs(n - 1);
    int fcnt = 0, scnt = 0;
    for(int i = 0; i < n; i++) {
        if(f[i] <= s[i]) {
            fcnt++;
        } else {
            scnt++;
        }
    }
    cout << (fcnt <= scnt ? "Snuke" : "Fennec") << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n,m;
	cin>>n>>m;
	map<ll,vector<string> > map;
	for(ll i=1;i<=m;i++){
		ll a;
		string b;
		cin>>a>>b;
		map[a].push_back(b);
	}
	std::map<ll, vector<string> > ::iterator it;
	ll ans1=0,ans2=0;
	for(it=map.begin();it!=map.end();it++){
		vector<string> &v=it->second;
		for(ll i=0;i<v.size();i++){
			if(v[i]=="AC"){
				ans2+=i;
				ans1+=1;
				break;
			}
		}
	}
	cout<<ans1<<" "<<ans2<<endl;
}


Measured memory_bytes: 15872
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let a: Vec<u32> = s
        .trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();

    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let b: Vec<u32> = s
        .trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect();

    println!("{}", if a[1] > b[1] { 1 } else { 0 });
}

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

int main()
{
    int a[3];
    long long sum;
    while(cin>>a[0])
    {
        int k;
        sum=1;
        cin>>a[1]>>a[2];
        cin>>k;
        int t=0;
        for(int i=0;i<3;i++)
        {
                if(a[i]>t)
                    t=a[i];
        }
        for(int i=0;i<k;i++)
        {
            sum=sum*2;
        }
        sum=sum*t+a[0]+a[1]+a[2]-t;
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
// atcoder/soundhound2018-summer-qual/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

double fn(double n, int x)
{
  if (x == 0) return 1;
  if (x == 1) return n;
  double m = fn(n, x / 2);
  m = m * m;
  if (x % 2) m *= n;
  return m;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  double n, m, d;
  while (cin >> n >> m >> d) {
    double x = (n - d) / n / n;
    x *= (m - 1);
    if (d) cout << x * 2 << endl;
    else cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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; }

int main() {
  string s; cin >> s;
  if (s == "ARC")
    cout << "ABC" << endl;
  else
  cout << "ARC" << endl;
  return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
ll a[100005];
int n,c,k;
int main()
{
	cin>>n>>c>>k;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	int ans=0,i=0;
	while(i<n)
	{
		int j=i;
		while(i-j<c&&i<n&&a[i]<=a[j]+k)
			i++;
		ans++;
	}
	cout<<ans;
}
/*
5 3 5
1 6
2 7
3 8
6 11
12 17

6 3 3
2 5
6 9
6 9
7 10
8 11
10 13

7 10 1
1 2
2 3
2 3
2 3
3 4
4 5
5 6
这一次上限>上一次下限 
ans+1 
For example, the following three 
buses are enough:
A bus departing at time 4.5 ,
that carries the passengers arri-
ving at time 2 and 3 .A bus 
departing at time 6 , that ca-
rries the passengers arriving at
 time 1 and 6 .A bus departing 
 at time 12 , that carries the 
 passenger arriving at time 12 .
*/

Measured memory_bytes: 1024
n,w=map(int,input().split())
a=[[int(i) for i in input().split()]for i in range(n)]
dp=[[0 for i in range(w+1)]for i in range(n+1)]
for i in range(n):
    for sum_w in range(1,w+1):
        if sum_w-a[i][0]>=0:
            dp[i+1][sum_w]=max(dp[i][sum_w],dp[i][sum_w-a[i][0]]+a[i][1])
        else:
            dp[i+1][sum_w]=dp[i][sum_w]
print(dp[n][w])

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    
    sort(A.begin(), A.end());
    
    cout << A[A.size()-1]-A[0] << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        long[] a = new long[n];
        long[] b = new long[n];
        for(int i=0; i<n; i++){
            a[i] = (Long.parseLong(sc.next())<<32) | i;
        }
        
        for(int i=0; i<n; i++){
            b[i] = (Long.parseLong(sc.next())<<32) | i;
        }
        
        Arrays.sort(a);
        Arrays.sort(b);
        //前提条件チェック
        for(int i=0; i<n; i++){
            if((a[i]>>32) > (b[i]>>32)){
                System.out.println("No");
                System.exit(0);
            }
        }
        
        //ループが2つ以上ならYes
        UnionFind uf = new UnionFind(n);
        for(int i=0; i<n; i++){
            uf.unite((int)a[i], (int)b[i]);
        }
        for(int i=1; i<n; i++){
            if(!uf.same(0,i)){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        
        //ラストコーナー対策
        for(int i=0; i<n-1; i++){
            if((a[i]>>32)<=(b[i+1]>>32) && (a[i+1]>>32)<=(b[i]>>32)){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        
        System.out.println("No");
    }
}

class UnionFind{
    int[] par;
    int[] size;
    
    public UnionFind(int n){
        par = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
        }
        size = new int[n];
        Arrays.fill(size, 1);
    }
    
    public int find(int x){
        if(par[x] == x){
            return x;
        }else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    
    public boolean unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return false;
        
        if(size[x]<size[y]){
            int tmp = x;
            x = y;
            y = tmp;
        }
        size[x] += size[y];
        par[y] = x;
        return true;
    }
    
    public boolean same(int x, int y){
        return find(x)==find(y);
    }
    
    public int size(int x){
        return size[find(x)];
    }
}


Measured memory_bytes: 63332
words = lambda t : list(map(t, input().split()))
n,x = words(int)
xs = words(int)

def gcd(x,y):
    while not y == 0:
        tmp = y
        y = x%y
        x = tmp
    return x

ys = list(map(lambda y: abs(y-x), xs))
g = ys[0]
for y in ys:
    g = gcd(g,y)

print(g)


Measured memory_bytes: 63640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	int N, M;
	cin >> N >> M;
	vi A(M);
	rep(i, M) {
		cin >> A.at(i);
	}
	if (acc(all(A),0) - N > 0) {
		cout << -1;
	}
	else {
		cout << N - acc(all(A), 0);
	}
	return 0;
}


Measured memory_bytes: 3700
#include<stdio.h>
    int main()
    {
        int n,i,j;
        scanf("%d", &n);
        int data[n];
        for(i = 0;i < n;i++){
        scanf("%d", &data[i]);
        }
        j = n - 1;
        for(i = 0;i <= (n-1)/2;i++){
        printf("%d ",data[j]);
        j = j - 2;
        }
        if(n % 2 == 0) j = 0;
        if(n % 2 == 1) j = 1;
        for(i = 0;i < n/2; i++){
        printf("%d ",data[j]);
        j = j + 2;
        }
        return 0;
    }

Measured memory_bytes: 2816
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from bisect import bisect_left
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

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

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,m = myinput()
a = list(myinput())
bc = mylistinput(m)

a.sort()
bc = mysort(bc,1,True)

d = []
for i in range(m):
    b = bc[i][0]
    c = bc[i][1]
    d_add = [c]*b
    d.extend(d_add)
    if len(d)>=n:
        d = d[:n]
        break
d.sort()
# print(d)

for i in range(n):
    if len(d)==0:
        break
    e = d.pop()
    if a[i]<e:
        a[i]= e
    else:
        break
# print(a)
ans = sum(a)
print(ans)

Measured memory_bytes: 92960
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {
	
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	rep(i, n)scanf("%d", &a[i]);
	ll ans = LINF;
	rep(i, n) {
		ans = min(ans, (ll)abs(accumulate(a.begin(), a.begin() + i, 0) - accumulate(a.begin() + i, a.end(), 0)));
	}
	printf("%lld\n", ans);

	Please AC;
}

Measured memory_bytes: 504
from collections import deque


class Graph:

  def __init__(self, directed=True):
    self.directed = directed
    self.V = set()
    self.E = {}

  def add_edge(self, u, v, weight: float = 1.):
    self.V.add(u)
    self.V.add(v)

    if u not in self.E: self.E[u] = {}
    self.E[u][v] = weight

    if not self.directed:
      if v not in self.E: self.E[v] = {}
      self.E[v][u] = weight


def bfs(graph: Graph, s):
  V, E = graph.V, graph.E

  visited = set()
  pred = {}
  dist = {}
  for v in graph.V: dist[v] = -1

  if not s in E:
    return pred, dist

  visited.add(s)
  dist[s] = 0
  queue = deque()
  queue.append(s)
  while len(queue) > 0:
    u = queue.popleft()
    for v in E[u]:
      if v not in visited:
        pred[v] = u
        dist[v] = dist[u] + 1
        visited.add(v)
        if v in E: queue.append(v)

  return pred, dist


def main():
  graph = Graph()

  N, M = map(int, input().strip().split())
  for _ in range(M):
    u, v = input().strip().split()
    # graph.add_edge(u, v)
    graph.add_edge(u + '_0', v + '_1')
    graph.add_edge(u + '_1', v + '_2')
    graph.add_edge(u + '_2', v + '_0')

  s, t = input().strip().split()

  pred, dist = bfs(graph, s + '_0')
  # pred, dist = bfs(graph, s)
  key = t + '_0'
  if key in dist:
    distance = dist[key]
    if distance % 3 == 0:
      return (distance // 3)

  return -1


print(main())

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

a = []
kaku = []
for x in range(n[1]) :
    a.append(list(map(int, input().split())))

kaku = [0]* len(m)
cou = 0

for x in range(n[1]):
    if m[a[x][0] -1 ] > m[a[x][1] -1 ]:
        kaku[a[x][0] -1 ] += 1
    else:
        kaku[a[x][0] - 1] -= 100000

    if m[a[x][1] -1 ] > m[a[x][0] -1 ]:
        kaku[a[x][1] -1 ] += 1
    else:
        kaku[a[x][1] - 1] -= 100000

for x in range(len(m)):
    if kaku[x] >= 0 :
        cou += 1

print(cou)


Measured memory_bytes: 93276
#include <iostream>
#include <algorithm>
#include <deque>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;

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

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

    deque<int> q;
    int ans = 1;
    q.push_front(A[0]);
    for(int i=1; i<N; i++){
        auto it = lower_bound(q.begin(), q.end(), A[i]);
        if(it == q.begin()){
            ans++;
            q.push_front(A[i]);
        }else{
            it--;
            *it = A[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024