akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    new Main().run();
  }

  public void run() {

    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int q = Integer.parseInt(br.readLine());
      StringBuilder buf  = new StringBuilder();

      for(int i=0; i<q; i++) {
        buf.append( deriveLcs(br.readLine(), br.readLine()) )
           .append("\n");
      }

      System.out.print(buf);
    }
    catch (IOException e) {
      System.out.println("IOException!");
    }
  }

  private int deriveLcs(String seqX, String seqY) {
    int m = seqX.length();
    int n = seqY.length();
    int size = m > n ? m+1 : n+1;
    int[][] subSeq = new int[size][size];
    int maxSubSeq = 0;

    for(int i=1; i<=m; i++) subSeq[i][0] = 0;
    for(int j=1; j<=n; j++) subSeq[0][j] = 0;

    for(int i=1; i<=m; i++) {
      for(int j=1; j<=n; j++) {
        if(seqX.charAt(i-1) == seqY.charAt(j-1))
          subSeq[i][j] = subSeq[i-1][j-1] + 1;
        else
          subSeq[i][j] = Math.max(subSeq[i-1][j], subSeq[i][j-1]);

        maxSubSeq = Math.max(maxSubSeq, subSeq[i][j]);
      }
    }

    return maxSubSeq;
  }
}


Measured memory_bytes: 64032
#include<iostream>
#include<algorithm>
#include<vector>
using lint=int64_t;
using namespace std;


int main()
{
	int N,K;
	lint V[55]={};
	lint lsum[55]={};
	lint rsum[55]={};

	cin >> N >> K;
	for(int i=1;i<=N;i++)
	{
		cin >> V[i];
		lsum[i]=V[i];
		rsum[i]=V[i];
	}
	for(int i=1;i<=N;i++)
		lsum[i]+=lsum[i-1];
	for(int i=N-1;i>=0;i--)
		rsum[i]+=rsum[i+1];

	lint ans=0;
	for(int i=0;i<=K;i++)
	{
		if(i>N)break;
		int rmlim=K-i;
		for(int l=0;l<=i;l++)
		{
			int r=i-l;
			vector<lint> v;
			for(int j=1;j<=l;j++)
				v.push_back(V[j]);
			for(int j=0;j<r;j++)
				v.push_back(V[N-j]);
			sort(v.begin(),v.end());
			lint tans=0;
			int rmcnt=0;
			for(int j=0;j<v.size();j++)
			{
				if(v[j]<0 && rmcnt<rmlim)
				{
					rmcnt++;
					continue;
				}
				tans+=v[j];
			}
			ans=max(ans,tans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
s = input()
s1 = s[::-1]
l=len(s)

check = 0
if(s==s1):
    if(s[0:int((l-1)/2)] == s1[int((l+3)/2)-1:l]):
        if(s[int((l+3)/2)-1:l] == s1[0:int((l-1)/2)]):
            print("Yes")
            check =1
if(check ==0):
    print("No")



Measured memory_bytes: 3064
n = int(input())
L = list(map(int, input().split()))
tmp = 0
result = 0

for i in range(n-1):
    if L[i] >= L[i+1]:
        tmp += 1
    else:
        if tmp > result:
            result = tmp
        tmp = 0
if tmp > result:
    result = tmp
print(result)

Measured memory_bytes: 14252
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          string Al="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
          int[] a= Input.ScanIntArray();
          int i,k;
          string res="";
          for(i=0;i<a[0];i++){
            string[] w = Input.ScanStrArray();
            for(k=0;k<a[1];k++)
              if(w[k]=="snuke") res = $"{Al[k]}{i+1}";
          }
          Console.WriteLine(res);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n-1; i >= 0LL; i--)
#define FOR(i, n, m) for(ll i = n; i < (ll)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define INFD 1e18
#define PI 3.14159265358979
#define MOD 1000000007
// #define MOD 998244353
#define VL vector<ll>

vector<ll> dx = {-1, 1, 0,  0, -1, -1,  1, 1};
vector<ll> dy = { 0, 0, 1, -1, -1,  1, -1, 1};

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }



template< typename T >
struct edge {
	int src, to;
	T cost;

	edge(int to, T cost) : src(-1), to(to), cost(cost) {}

	edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

	edge &operator=(const int &x) {
		to = x;
		return *this;
	}

	operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
/*
WeightedGraph<ll> g(V);
g[a].emplace_back(b, c);
*/
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int main()
{
	ll A, B, H, M;
	cin >> A >> B >> H >> M;
	double angA = 360 / 12 * H + 0.5 * (M);
	double angB = 360 / 60 * M;
	angA = angA * PI / 180.;
	angB = angB * PI / 180.;
	pair<double, double> pA = make_pair(A * cos(angA), A * sin(angA));
	pair<double, double> pB = make_pair(B * cos(angB), B * sin(angB));

	// pA = P(cos(angA) * pA.first - sin(angA) * pA.second, sin(angA) * pA.first + cos(angA) * pA.second);
	// pB = P(cos(angB) * pB.first - sin(angB) * pB.second, sin(angB) * pB.first + cos(angB) * pB.second);
	pair<double, double> pC = make_pair(pA.first - pB.first, pA.second - pB.second);
	double ans = sqrt(pC.first * pC.first + pC.second * pC.second);
	PRINT(setprecision(20) << ans);
	return 0;
}


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

const ll INF = 1LL << 60;

ll N, A, B, C;
vector<ll> v;
ll ans = INF;

void dfs(int i, vector<ll> a) {
    if (i == N) {
        // A: 0 
        // B: 1
        // C: 2
        // 使わない: 3 
        map<ll, ll> mp;
        rep(k, a.size()) {
            if (a[k] == 3) continue;
            mp[a[k]]++;
        }
        if (mp.size() != 3) return;

        // 3種類ある
        ll x, y, z;
        x = y = z = 0;
        rep(k, a.size()) {
            if (a[k] == 0) {
                x += v[k];
            } else if (a[k] == 1) {
                y += v[k];
            } else if (a[k] == 2) {
                z += v[k];
            }
        }

        // cout << endl;
        // cout << endl;
        // rep(k, a.size()) {
        //     cout << a[k] << " ";
        // }
        ll connect_num = (mp[0] - 1) + (mp[1] - 1) + (mp[2] - 1);
        ll tmp = abs(A - x) + abs(B - y) + abs(C - z) + 10 * connect_num;
        // cout << tmp << endl;
        ans = min(ans, tmp);
        
        return;
    }

    map<ll, ll> mp;
    for (int j = 0; j < 4; j++) {
        a[i] = j;
        dfs(i + 1, a);
    }
}

int main() {
    cin >> N >> A >> B >> C;
    v.resize(N);
    rep(i, N) cin >> v[i];

    vector<ll> tmp(N, 0);
    dfs(0, tmp);

    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n, k, c; cin>>n>>k>>c;
    string s; cin>>s;

    int cnt = 0;
    map<int, int> day;
    for(int i=0; i<n; i++){
        if(s[i] == 'o'){
            cnt++;
            day[i]++;
            i += c;
        }

        if(k < cnt){
            return 0;
        }
    }

    reverse(all(s));
    cnt = 0;
    for(int i=0; i<n; i++){
        if(s[i] == 'o'){
            cnt++;
            day[n-i-1]++;
            i += c;
        }

        if(k < cnt){
            return 0;
        }
    }

    for(auto i:day){
        if(i.second == 2) cout << i.first + 1 << endl;
    }

    return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	string ans = "";
	int len = s.length();
	for (int i = 0; i < len; i++) {
		if (s[i] == '0') {
			ans += '0';
		} else if (s[i] == '1') {
			ans += '1';
		} else {
			if (ans != "") {
				ans.pop_back();
			}
		}
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<numeric>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<map>
#include<utility>
#include<cmath>
#include<tuple>
#include<string>
#include<bitset>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
typedef long long ll;

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

    int a=n[n.length()-1]-'0';
    if(a==2||a==4||a==5||a==7||a==9) cout<<"hon"<<endl;
    else if(a==0||a==1||a==6||a==8) cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = (1ll << 31) - 1;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;


void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }

    mint nPk(int n, int k) {
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fact[n] * ifact[n - k];
    }

} combination(10000);


int main() {
    int n, k;
    cin >> n >> k;

    mint ans = combination(n - 1, k - 1);

    cout << ans.x << endl;

}





Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <string>

using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;
	int min_i = -l + 1;
	if (min_i < 1)
		min_i = 1;
	else if (min_i > n)
		min_i = n;

	int sum = 0;
	for (int i = 1; i <= n; i++) {
		if (i == min_i)
			continue;
		sum += l + i - 1;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
  int n,i,ans=0;
  string s[3];
  cin >> n;
  for (i=0;i<3;i++) cin >> s[i];
  for (i=0;i<n;i++){
    if (s[0][i]==s[1][i] && s[1][i]==s[2][i]) continue;
    else if (s[0][i]==s[1][i] || s[1][i]==s[2][i] || s[2][i]==s[0][i]) ans++;
    else ans+=2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void){
    long long A=0;
    long long B=0;
    long long maxA=0;
    long long ans=0;
    int N;
    
    cin >> N;

    for(int i=0;i<N;i++){
        cin >> A >> B;
        if(maxA < A){
            ans = A + B;
            maxA = A;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long; using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll INF = 1e9;
ll vx[] = {1,0,-1,0};
ll vy[] = {0,-1,0,1};
signed main(){
  init_io();
  ll h,w,ch,dh,cw,dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  vector<string> s(h);
  vector<vector<ll>> d(h,vector<ll>(w,INF));
  priority_queue<TP,vector<TP>,greater<TP>> que;
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  ch--;
  cw--;
  dh--;
  dw--;
  que.push(TP(0,ch,cw));
  d[ch][cw] = 0;
  while(!que.empty()){
    auto [di,x,y] = que.top();
    que.pop();
    if(di>d[x][y]) continue;
    for(int i=0;i<4;i++){
      ll nx = x + vx[i];
      ll ny = y + vy[i];
      if(nx>=0&&ny>=0&&nx<h&&ny<w){
        if(di<d[nx][ny]&&s[nx][ny]=='.'){
          d[nx][ny] = di;
          que.push(TP(di,nx,ny));
        }
      }
    }
    for(int dx=-2;dx<=2;dx++){
      for(int dy=-2;dy<=2;dy++){
        ll nx = x + dx;
        ll ny = y + dy;
        if(nx>=0&&ny>=0&&nx<h&&ny<w){
          if(di+1<d[nx][ny]&&s[nx][ny]=='.'){
            d[nx][ny] = di+1;
            que.push(TP(di+1,nx,ny));
          }
        }
      }
    }
  }
  if(d[dh][dw]==INF) d[dh][dw] = -1;
  cout << d[dh][dw]<<endl;
}


Measured memory_bytes: 12760
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n, m;
	cin >> n >> m;
	cout << n - m + 1 << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

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

  int vmin = 1e9;
  for (int c6 = 0; c6 <= N/6; c6++) {
    for (int c9 = 0; c9 <= N/9; c9++) {
      int x = N - c6 * 6 - c9 * 9;
      if (x < 0) continue;

      int a = c6;
      int y = 0;
      while (a > 0) {
        y += a % 6;
        a /= 6;
      }

      int b = c9;
      int z = 0;
      while (b > 0) {
        z += b % 9;
        b /= 9;
      }

      vmin = min(vmin, x + y + z);
    }
  }
  cout << vmin << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int disT[100010];
int disA[100010];

void dfs(int now, vector<bool> & visited, vector<vector<int>>& G, bool flag) {
  for (auto it : G[now]) {
    if (!visited[it]) {
      if (flag) {
        // takahashi
        disT[it] = disT[now] + 1;
        visited[now] = true;
        dfs(it, visited, G, flag);
      } else {
        disA[it] = disA[now] + 1;
        visited[now] = true;
        dfs(it, visited, G, flag);
      }
    }
  }
}

int main() {
  int n, u, v;
  cin >> n >> u >> v;
  u --, v --;
  vector<vector<int>> G(n);
  rep(i, n-1) {
    int a,b;
    cin >> a >> b;
    a--, b--;
    G[b].push_back(a);
    G[a].push_back(b);
  }

  vector<bool> visited(n), visitedb(n);
  dfs(u, visited, G, true);
  dfs(v, visitedb, G, false);

  int ans = 0;
  rep(i, n) {
    if (disA[i] > disT[i]) {
      chmax(ans, disA[i] - 1);
    }
  }

  cout << ans << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

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

  string s; cin >> s;
  int n=s.size();
  rep(i,1,n){
    if((n-i)%2==0){
      if(s.substr(0,(n-i)/2)==s.substr((n-i)/2,(n-i)/2)){
        cout<<n-i<<endl;
        break;
      }
    }

  }

  return 0;
}


Measured memory_bytes: 256
n=int(input())
pn=[2];A=2000
for L in range(3,A):
    chk=True
    for L2 in pn:
        if L%L2 == 0:chk=False
    if chk==True:pn.append(L)

l=[]
for i in pn:
    if i%5==1:
        l.append(i)

print(*l[:n])


Measured memory_bytes: 39024
import collections
def inverse_lookup(d, x):
    cList = []
    for k,v in d.items():
        if x == v:
            l = k
            cList.append(l) 
    return cList

n = int(input())
List=[input() for i in range(n)]
c = collections.Counter(List)

n = max(c.values())
out=sorted(inverse_lookup(c,n))
for word in out:
    print(word)




Measured memory_bytes: 35572
class Doubling():
    def __init__(self,N,log_k,perm):
        """
        与えられた順列のダブリング配列を作成する.

        Parameters
        ----------
            N :  int
                順列の数
            log_k : int
                最大移動回数の対数(切り上げ)
            perm : [int]
                1-indexed の順列が格納されたリスト
        """
        self.N = N
        self.log_k = log_k
        self.doubling = [[0]*(self.N+1) for _ in range(log_k)]

        for i in range(1,self.N+1):
            self.doubling[0][i] = perm[i]

        for j in range(1,self.log_k):
            for i in range(1,self.N+1):
                prev = self.doubling[j-1][i]
                self.doubling[j][i] = self.doubling[j-1][prev]
        
    def query(self,pos,k):
        """
        位置iからk回移動したときの移動先を計算する.

        Parameters
        ----------
            pos : int
                移動元の位置
            k : int
                移動回数(1<=k<=2^(log_k+1)-1)

        Returns
        ----------
            dest : int
                移動先の位置
        """
        for i in range(self.log_k):
            if k & (1<<i) == 0:continue
            pos = self.doubling[i][pos]
        dest = pos
        
        return dest

def main():
    n,k = tuple([int(t)for t in input().split()])

    a = [int(t) for t in input().split()]

    a.insert(0,0)
    log_k = k.bit_length()+1

    doubling = Doubling(n,log_k,a)
    print(doubling.query(1,k))

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 173880
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = pow(2, 31) - 1;
#define ll long long
#define DEBUG(x) cout << "DEBUG>" << #x << ":" << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main() {
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  int ans = 0;
  ans += (A[2] - A[0]) / 2;
  ans += (A[2] - A[1]) / 2;
  A[0] += ((A[2] - A[0]) / 2) * 2;
  A[1] += ((A[2] - A[1]) / 2) * 2;
  if(A[0] == A[1] && A[1] == A[2]) {
    cout << ans << endl;
  } else {
    if(A[2] - A[0] == 1 && A[2] - A[1] == 1) {
      ans++;
    } else {
      ans += 2;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
const ll INF = 1e15;
const int MX = 305;
int n,k,h[MX],un[MX],e;
ll dp[MX][MX][MX],ans=INF;
map<int,int> zp;
int main(){
	scanf("%d%d", &n, &k);
	rep(i,n){
		scanf("%d", h+i);
		un[i] = h[i];
	}
	sort(un, un+n+1);
	e = (int)(unique(un,un+n+1) - un);
	rep(i,e) zp[un[i]] = i;
	fill(dp[0][0],dp[n+1][k+1],INF);
	dp[0][0][0] = 0;
	rep(i,n+1){
		rep(j,k+1) rep(l,e){
			dp[i+1][j][zp[h[i]]] = min(dp[i+1][j][zp[h[i]]], dp[i][j][l] + (h[i] < un[l] ? un[l] - h[i]: 0));
		}
		if(i<n) rep(j,k) rep(l,e) dp[i+1][j+1][l] = min(dp[i+1][j+1][l], dp[i][j][l]);
	}
	rep(i,e) ans = min(ans,dp[n+1][k][i]);
	printf("%lld\n", ans);
}

Measured memory_bytes: 221440
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<time.h>
#include<random>
using namespace std;
int main() {
    int64_t h; 
    cin >> h;

    int c = 0;
    while (h != 1) {
        h /= 2;
        c++;
    }

    int64_t ret = 1;
    for (int i = 0; i <= c; ++i) {
        ret *= 2;
    }
    ret -= 1;

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll A, B;
  std::cin >> A >> B;
  std::string S;
  std::cin >> S;

  bool judge = true;
  for (ll i = 0; i < A + B + 1; i++) {
    if (i == A) {
      if (S[i] != '-') judge = false;
    } else {
      if (S[i] < '0' || S[i] > '9') judge = false;
    }
  }

  if (judge) print("Yes");
  else print("No");

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int min(int a, int b)
{
	if (a > b){
		return (b);
	}
	return (a);
}

int main(void)
{
	int sp[3], j[2];
	int i;
	
	for (i = 0; i < 3; i++){
		scanf("%d", &sp[i]);
	}
	for (i = 0; i < 2; i++){
		scanf("%d", &j[i]);
	}
	
	printf("%d\n", min(sp[0], min(sp[1], sp[2])) + min(j[0], j[1]) - 50);
	
	return (0);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))


int main(void){
    // Your code here!
    int N;
    int h[100001],dp[100001];
    int i,j;
    
    scanf("%d",&N);
    
    for(i=1;N>=i;i++){
        scanf("%d",&h[i]);
    }
    
    for(i=1;N>=i;i++){
        if(i==1){
            dp[i] = 0;
        }
        else if(i==2){
            dp[i] = abs(h[i]-h[i-1]);
        }
        else{
            dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
    }
    
    printf("%d\n",dp[N]);
    
    return 0;   
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;

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

  int n;
  cin >> n;

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

  vector<int> c(n + 1, 0);
  c[0] = 3;
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    int cnt = a[i];

    if (c[cnt] == 0) {
      cout << 0 << endl;
      return 0;
    }

    ans *= c[cnt];
    ans %= MOD;
    c[cnt]--;
    c[cnt + 1]++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
w = input()
w = list(w)
w.sort()
judge = 1

if(len(w)%2 == 1):
  print('No')
else:
  for i in range(int(len(w)/2)):
    if(w[2*i] != w[2*i+1]):
      judge = 0
      break

  if(judge == 1):
   print('Yes')
  else:
   print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector <long> vec(n);
    int count = 0;
    for(int i=0;i<n;i++){
        long a;
        cin >> a;
        if(a<0) count++;
        vec.at(i)=abs(a);
    }
    count %=2;
    sort(vec.begin(),vec.end(),greater<long>());
    
    int s,t;
    if (count ==0){
        s=n;
        t=n-1;
    }
    else{
        s=n-1;
        t=n-2;
    }
    
    long tasu=0;
    
    for (int i=0;i<s;i++){
        tasu+=vec.at(i);
    }
    
    long hiku=0;
    for (int i=n-1;i>t;i--){
        hiku+=vec.at(i);
    }
    
    long ans=tasu-hiku;
    
    cout << ans << endl;
    
}





Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define ll long long 

int main(){
  ll n;
  cin >> n;
  ll a[n], sum=0;
  map<ll,ll> mp;
  for(ll i=0;i<n;i++){	cin >> a[i]; sum+=a[i]; mp[a[i]]++;}
  ll q;
  cin >> q;
  while(q--){
    ll bi, ci;
    cin >> bi >> ci;
    sum+=(ci-bi)*mp[bi];
    ll temp=mp[bi];
    mp[bi]=0;
    mp[ci]+=temp;
    cout << sum << endl;
  }
   return 0;                   
}

Measured memory_bytes: 10328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] list = str.split(" ");
		int count5 = 0;
		int count7 = 0;

		for(int i=0; i<list.length; i++){
			if(list[i].equals("5")){
				count5 = count5 + 1;
			}else if(list[i].equals("7")){
				count7 = count7 + 1;
			}
		}

		if(count5 == 2 && count7 == 1){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 20692
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , a[N] , dp[N];
int main(){
    scanf("%d", &n);
    for(int i = 0 ; i < n ; i++){
        scanf("%d", &a[i]);
    }
    dp[0] = 0;
    dp[1] = dp[0] + abs(a[0] - a[1]);
    for(int i = 2 ; i < n ; i++){
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]) , dp[i - 2] + abs(a[i] - a[i - 2]));
    }
    cout<<dp[n - 1];
    return 0;
}

Measured memory_bytes: 1024
require "matrix"
a, b = gets.split.map(&:to_i)
ary1, ary2 = [], []
a.times{ary1<<gets.split.map(&:to_i)}
b.times{ary2<<gets.to_i}
m = Matrix[*ary1]
mb = Matrix.column_vector(ary2)
v = m * mb

v.each{|z| puts z}

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

namespace ABC_138A
{
    class Program
    {
        static void Main(string[] args)
        {
          
            int a;

            a = int.Parse(Console.ReadLine());

            String s = Console.ReadLine();

            if (a < 3200)
                Console.WriteLine("red");
          
            else  Console.WriteLine(s);

            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,d;
    cin>>n>>d;
    set<int> st;
    for(int i=0;i<10;++i)st.insert(i);
    while(d--){int x;cin>>x;st.erase(x);}
    bool xx=false;
    for(int i=0;!xx;++i)
    {
        int gg=n+i;
        //cout<<gg<<endl;
        string ss=to_string(gg);
        bool yes=true;
        for(auto x:ss){
            if(st.find(x-'0')==st.end()){
                yes=false;
                break;
            }
        }
        if(yes)
        {
            cout<<gg;
            xx=true;
        }

    }

    return 0;
}

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

#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define forj(a,b) for(int j=a;j<b;j++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testcases=1;
    //cin>>testcases;
    //cout<<t;
    //scanf("%d",&t);
    while(testcases--){  
        int n;
        cin>>n;
        if(n%1000==0){
            cout<<0;
            continue;
        }
        int d=n/1000;
        d++;
        int x=d*1000;
        cout<<x-n<<endl;
    }                                                                                          
    
    return 0;
}


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

#define REP(i,a,b) for(int i=a,i##_end_=b;i<=i##_end_;++i)
#define DREP(i,a,b) for(int i=a,i##_end_=b;i>=i##_end_;--i)
#define MREP(i,x) for(int i=beg[x],v;v=to[i],i;i=las[i])
#define debug(x) cout<<#x<<"="<<x<<endl
#define fi first
#define se second
#define mk make_pair
#define pb push_back
typedef long long ll;

using namespace std;

void File(){
	freopen("pyramid.in","r",stdin);
	freopen("pyramid.out","w",stdout);
}

template<typename T>void read(T &_){
	T __=0,mul=1; char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')mul=-1;
		ch=getchar();
	}
	while(isdigit(ch))__=(__<<1)+(__<<3)+(ch^'0'),ch=getchar();
	_=__*mul;
}

const int maxn=4e6+10;
int n,a[maxn],c[maxn];
int b[2][maxn];

/*void tran(){
	read(n);
	int now=0,las=1;
	REP(i,1,n*2-1)read(b[las][i]);
	REP(i,1,n){
		REP(j,1,n*2-1){
			if(j<i || j>n*2-i)cout<<"  ";
			else cout<<b[las][j]<<" ";
		}
		cout<<endl;
		if(i==n)break;
		REP(j,1+i,n*2-1-i){
			int c[2]={0};
			++c[b[las][j]];
			++c[b[las][j-1]];
			++c[b[las][j+1]];
			b[now][j]=c[0]>c[1] ? 0 : 1;
		}
		swap(las,now);
	}
}*/

bool judge(int x){
	REP(i,1,n*2-1)c[i]=(a[i]>x);
	if(c[n]==c[n-1] || c[n]==c[n+1])return !c[n];
	int L=n,R=n,len;
	while(L>2 && c[L-1]!=c[L-2] && c[L-1]!=c[L])--L;
	while(R<n*2-2 && c[R+1]!=c[R+2] && c[R+1]!=c[R])++R;
	len=min(n-L+1,R-n+1);
	if(len%2)return c[n];
	return !c[n];
}

int main(){
	//File();
	read(n);
	REP(i,1,n*2-1)read(a[i]);
	if(n==1)return printf("%d\n",a[1]),0;
	int l=1,r=n*2-1;
	while(l<r){
		int mid=(l+r)>>1;
		if(judge(mid))r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 6400
import sys
#input = sys.stdin.buffer.readline

def main():
    K = input()
    D = int(input())
    MOD = 10**9+7
    
    dp = [[0]*D for _ in range(2)]
    dp[1][0] = 1
    n = 0
    for st in K:
        num = int(st)
        n += num
        use = [0]*D
        for i in range(D):
            for j in range(10):
                use[(i+j)%D] += dp[0][i]
            if num != 0:
                for j in range(num):
                    use[(i+j)%D] += dp[1][i]
        dp[0] = use
        for i in range(D):
            dp[0][i] %= MOD
        dp[1] = [0]*D
        dp[1][n%D] += 1
    
    print((dp[0][0]+dp[1][0]-1)%MOD)

if __name__ == "__main__":
    main()


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

const int MAXN = 100000+5;
const int MAXK = 100+5;


int N,K;
int KS[MAXK];
int h[MAXN];
int minimo;
long sums[MAXN];
int aux;

int main() {
	cin>>N>>K;
	for(int i=0;i<N;i++) cin>>h[i];
	sums[1]=abs(h[1]-h[0]);
	for(int i=2;i<N;i++){
		minimo = sums[i-1] + abs(h[i]-h[i-1]); 
		for(int j=1;j<=i;j++){
			if(j>K)break;
			KS[j]=sums[i-j] + abs(h[i]-h[i-j]);
			minimo = min(KS[j],minimo);
		}
		sums[i]=minimo;
	}
	cout<<sums[N-1];
	return 0;
}

Measured memory_bytes: 1408
# ABC099D - Good Grid
import sys
input = sys.stdin.readline

from collections import Counter
from itertools import product


def main():
    N, C = map(int, input().split())
    D = [0] + list([0] + list(map(int, input().split())) for _ in range(C))
    grid = tuple(tuple(map(int, input().split())) for _ in range(N))
    cost = [Counter() for _ in range(3)]
    for i, g in enumerate(grid):
        for j in range(3):
            cost[j].update(g[(j - i) % 3 :: 3])
    dist = [[] for _ in range(3)]
    for i, target in product(range(3), range(1, C + 1)):
        cur = sum(D[source][target] * cnt for source, cnt in cost[i].items())
        dist[i].append(cur)
    ans = 1 << 60
    for i, j in product(range(C), repeat=2):
        if i == j:
            continue
        cur = dist[0][i] + dist[1][j]
        cur += min(dist[2][k] for k in range(C) if k not in (i, j))
        ans = min(ans, cur)
    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 107;

int a[M];
int m, n;

void read() {
  cin >> m >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a, a + n);
}

void kill() {
  int mx = a[n - 1];
  int rest = m - mx;
  if (rest >= mx - 1) {
    cout << 0 << endl;
    return;
  }
  cout << mx - 1 - rest << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import collections


def solve(N: int, K: int, A: "List[int]"):
    C = collections.Counter(A)
    M = len(C) - K
    if M <= 0:
        print(0)
    else:
        print(sum([c[1] for c in reversed(C.most_common())][0:M]))


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 53216
#include <bits/stdc++.h>
#include <stdlib.h>
#include <numeric>
#include <string>
using namespace std;
int main(){
  	int N, i, j;
  	double A[1000];
    double s=1, b=1;
  	double sum=0;
    cin >> N;
    for(i=0; i<N; i++){
      cin >> A[i];
      s=s*A[i];
    }
    for(i=0; i<N; i++){
      for(j=0; j<N; j++){
        if(i==j){

        }else{
          b=b*A[j];
        }
      }
      sum=sum+b;
      b=1;
      
    }
  	double ans=s/sum;
  	
    cout <<std::fixed<< ans <<endl;
 
}

Measured memory_bytes: 256
CONST=10**100
ss=list(input())
res=[0]*len(ss)
lc=0
rc=0
pos=-1
for i,s in enumerate(ss):
  if i < len(ss)-1 and s=='R' and ss[i+1]=='L':
    # last
    lc+=1
    pos=i
    continue
  if (i < len(ss)-1 and s=='L' and ss[i+1]=='R') or i==len(ss)-1:
    # border
    rc+=1
    res[pos] = (lc+1)//2 + rc//2
    res[pos+1] = lc//2 + (rc+1)//2
    lc=0
    rc=0
    continue
  if s=='L':
    rc+=1
  else:
    lc+=1
print(*res)

Measured memory_bytes: 7092
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	int W, a, b;
	cin >> W >> a >> b;

	if (a <= b && b <= a + W) {
		cout << 0 << endl;
		return 0;
	}

	if (a <= b + W && b + W <= a + W) {
		cout << 0 << endl;
		return 0;
	}

	cout << min(abs(a + W - b), abs(b + W - a)) << endl;
	return 0;
}

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

int main(){
    int n,m;
    while(1){
        cin >> n >> m;
        if(n==0 && m==0) break;
        int a[n];
        for(int i=0; i<n; i++)
            cin >> a[i];

        int max=0;
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(i!=j && a[i]+a[j]<=m && a[i]+a[j]>max){
                    max = a[i]+a[j];
                }
            }
        }

        if(max==0){
            cout << "NONE" << endl;
        }else{
            cout << max << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main(void){
  string O, E;
  cin >> O >> E;
  for(int i = 0; i < O.length(); i++){
    cout << O[i];
    if(i >= E.length()) break;
    cout << E[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
def pow(a, b, mod):
    result = 1
    while b:
        if b&1: result = (result * a) %mod
        a = (a * a) % mod
        b >>= 1
    return result

n = int(input())
if n <= 1:
    print(0)

else:

    mod = 10 ** 9 + 7

    print((mod + pow(10, n, mod) - 2 * pow(9, n, mod) +  pow(8, n, mod)) % mod)

Measured memory_bytes: 9192
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<pair<int, int>> A;
    A.reserve(n);
    for (int i = 0; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        A.push_back(make_pair(x, y));
    }
    sort(A.begin(), A.end());
    for (auto it = A.begin(); it != A.end(); it++)
    {
        cout << it->first << " " << it->second << endl;
    }
    return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<string> strs(3);
  for(auto&i:strs)cin>>i;
  int ans = 0;
  for(int i=0;i<n;++i){
    set<char> s;
    for(int j=0;j<3;++j){
      s.emplace(strs[j][i]);
    }
    ans += s.size() - 1;
  }
  cout << ans << endl;
}


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

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

  int w,h,n;
  cin>>w>>h>>n;
  int x,y,c;
  int left=0, right=w, up=h, down=0;
  for (int i = 0; i < n; ++i)
  {
  	cin>>x>>y>>c;
  	if(c==1)
  	{
  		if(x>=left)
  			left = x;
  	}
  	else if(c==2)
  	{
  		if(x <= right)
  			right = x;
  	}
  	else if(c==3)
  	{
  		if(y >= down)
  			down = y;
  	}
    else if(c==4)
    {
    	if(y<= up)
    		up=y;
    }
  }

  if(left <right && up>down)
  	cout<<((right - left)*(up-down));
  else
  	cout<<0;


  return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
Ps = gets.chomp.split(" ").map(&:to_i)
count = 0
 
Ps.each_with_index do |e,i|
  if i ==0 || i == N-1
    next
  elsif (Ps[i-1]<e&&e<Ps[i+1])||(Ps[i-1]>e&&e>Ps[i+1])
    count += 1
  end
end
 
puts count

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

int main(void){
    int N, K, dbuf, Abuf;
    cin >> N >> K;
    vector<bool> HavingSnack(N, false);
    for(int i=0; i<K; i++){
        cin >> dbuf;
        for(int j=0; j<dbuf; j++){
            cin >> Abuf;
            HavingSnack[Abuf-1] = true;
        }
    }
    int res = 0;
    for(int i=0; i<N; i++){
        if(!HavingSnack[i])res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define sc1(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define sc3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sc4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
using namespace std;
typedef long long LL;
int gcd(int a,int b){if (b == 0) return a; return gcd(b , a%b);}
int lcm(int a, int b){ return a/gcd(a,b)*b;}
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch^48); ch=getchar();}
    return x*f;
}
int main(){
    int a,b;
    cin >> a >> b ;
    cout << a*b-a-b+1 << endl;
    return 0;
}



Measured memory_bytes: 256