akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;




void main() {
    int n, m;
    scan(n, m);

    auto tasks = new int[][](m, 0);

    foreach (i ; 0 .. n) {
        int ai, bi;
        scan(ai, bi);
        if (m - ai < 0) continue;
        tasks[m - ai] ~= bi;
    }

    debug {
        writefln("%(%s\n%)", tasks);
    }

    long ans;
    auto bh = new BinaryHeap!(Array!int, "a < b")();

    foreach_reverse (i ; 0 .. m) {
        foreach (bi ; tasks[i]) {
            bh.insert(bi);
        }

        if (!bh.empty) {
            ans += bh.front;
            bh.popFront();
        }
    }

    writeln(ans);
}


















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 5884
#include <bits/stdc++.h>
using namespace std;
stack<char>a;
int main()
{
    for(int i=0; ;i++){
        char ch;
        scanf("%c",&ch);
        if(ch=='\n') break;
        if(ch=='C'&&a.empty()) a.push(ch);
        else if(ch=='F'&&!a.empty()&&a.top()=='C') a.push(ch);
    }
    if(a.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  int mod=A%B;
  if(mod==C){
    cout << "YES" << endl;
    return 0;
  }
  for(int i=2;;i++){
    int x=A*i%B;
    if(x==C){
      cout << "YES" << endl;
      return 0;
    }
    if(x==mod){
      cout << "NO" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, A, B;
  cin >> N >> A >> B;

  A = abs(A-B);

  if(A%2 == 1) cout << "Borys" << endl;
  else cout << "Alice" << endl;

  return 0;
}

Measured memory_bytes: 256
<?php
$input = trim(fgets(STDIN));
$exploded = explode(" ", $input);

while($input){
  $arr[] = $exploded;
  $input = trim(fgets(STDIN));
  $exploded = explode(" ", $input);
};

$n = $arr[0][0];
$m = array_count_values($arr[1]);

for($i = 1; $i <= $n; $i++){
  
	if(array_key_exists($i, $m)){
      echo $m[$i]."\n";
    } else {
      echo "0\n";
    };
		
};

?>

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


pair<Weight, Edges> Prim(const Graph &g, int r = 0)
{
  int n = g.size();
  Edges T;
  Weight total = 0;

  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) );
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    vrep(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}

int V, E;
int s, t;
Weight w;

int main()
{
  cin >> V >> E;
  Graph g(V);
  rep(i, E){
    cin >> s >> t >> w;
    g[s].pb(Edge(s, t, w));
    g[t].pb(Edge(t, s, w));
  }

  cout << Prim(g).first << endl;

  return 0;
}

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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      v.begin(), v.end()
#define UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

const double PI = acos(-1);

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

    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

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

    if (N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll cnt5 = 0;
    ll b = 5;
    while (b <= N) {
        cnt5 += N / b / 2;
        b *= 5;
    }

    ll cnt2 = 0;
    b = 2;
    while (b <= N) {
        cnt2 += N / b;
        b *= 2;
    }
    cout << min(cnt2, cnt5) << endl;
}


Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_A
 */
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>

using namespace std;

void
printv(const vector<int> a)
{
    stringstream ss;
    for (auto it = a.cbegin(); it != a.cend(); it++) {
        if (it != a.begin()) {
            ss << ' ';
        }
        ss << *it;
    }
    cout << ss.str() << endl;
}

void
bubblesort(const vector<int> a)
{
    vector<int> work(a);

    bool flag = true;
    int count = 0;
    while (flag) {
        flag = false;
        for (auto it = work.rbegin(); it != work.rend(); it++) {
            auto nit = next(it);
            if (*it < *nit) {
                iter_swap(nit, it);
                flag = true;
                count++;
            }
        }
    }
    printv(work);
    cout << count << endl;
}

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

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

    return 0;
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int n;
  vector<string> w(200);
  cin >> n;
  bool flag = 1;
  for(int i = 0; i < n; i++) {
    cin >> w[i];
    for(int j = 0; j < i; j++) {
      if(w[j] == w[i]) flag = 0;
      if(j == i-1 & w[j].back() != w[i].front())
        flag = 0;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl; 
}

Measured memory_bytes: 3628
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] a= new int[N+2][4];
        int[][] b = new int[N+2][4];
        for(int i = 1; i<3; i++) {
            for(int j = 1; j<N+1; j++) {
                a[j][i] = sc.nextInt();
            }
        }
        for(int i = 1; i<N+1; i++) {
            for(int j = 1; j<3; j++) {
                a[i][j] = Math.max(a[i-1][j]+a[i][j], a[i][j-1]+a[i][j]);
            }
        }
        System.out.println(a[N][2]);
    }
}

Measured memory_bytes: 23764
A = int(input())
B = int(input())
C = int(input())
X = int(input())

res = 0
for i in range(A + 1):
    for j in range(B + 1):
        m = X - 500 * i - 100 * j
        if m % 50 == 0 and m >= 0 and m // 50 <= C:
            res += 1
print(res)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define MOD 1000000007
#define pb push_back

vector<int> e[555];
bool vis[555];
int ans=0;

void dfs(int i)
{
    vis[i]=1;
    for (vector<int>::iterator j=e[i].begin();j!=e[i].end();++j)
        if (!vis[*j])
        {
            ++ans;
            dfs(*j);
        }
}

int main()
{
    int n,m,x,y;
    cin>>n>>m;
    for (int i=1;i<=m;++i)
    {
        cin>>x>>y;
        e[x].pb(y);
        e[y].pb(x);
    }
    for (int i=1;i<=n;++i)
        if (!vis[i])
            dfs(i);
    cout<<(m-ans)<<endl;
    return 0;
}

Measured memory_bytes: 1296
N = int(input())
S = list(input())

ans = 0

for n in range(1000):
    pin = str(n).zfill(3)
    head = 0
    for c in S:
        if c == pin[head]:
            head += 1
        if head == 3:
            ans += 1
            break

print(ans)


Measured memory_bytes: 43356
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
using namespace std;
int a[200005], b[100005];

int main()
{
	int n;
	int m;
	while (cin >> n >> m)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		int l = 0;
		while (m--)
		{
			int x;
			scanf("%d", &x);
			b[l++] = x;
		}
		for (int i = l - 1; i >= 0; i--)
		{
			if (a[b[i]] == 0)
			{
				printf("%d\n", b[i]);
				a[b[i]] = 1;
			}
		}
		for (int i = 1; i <= n; i++)
		{
			if (a[i] == 0)
				printf("%d\n", i);
		}

	}

	return 0;
}

Measured memory_bytes: 4392
import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			int c=sc.nextInt();
			int d=sc.nextInt();
			int e=sc.nextInt();
			int f=sc.nextInt();
			double det=(double)(a*e-b*d);
			double x=(double)(c*e-b*f)/det;
			double y=(double)(c-a*x)/b;
			System.out.println(new BigDecimal(x).setScale(3, BigDecimal.ROUND_FLOOR)+" "+new BigDecimal(y).setScale(3, BigDecimal.ROUND_HALF_UP));
			//System.out.printf("%.3f %.3f\n",x,y);
		}
sc.close();
	}
}

Measured memory_bytes: 18164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59



int main(){
  ll i,j;
  ll n,k;
  cin>>n>>k;
  ll r=1;
  while(r*r<=n) r++;
  r+=(ll)10;
  VVI dp1(k+2,VI(r+1,0));
  VVI dp2(k+2,VI(r+1,0));

  ll d[r+1];
  for(i=1;i<=r;i++) d[i]=n/i;

  for(j=1;j<r;j++){
    dp1[1][j]=j;
  }
  ll fl=0;

  for(j=r-1;j>=1;j--) {
      dp2[1][j]=dp2[1][j+1];
      if(d[j+1]<r&&d[j]>=r) dp2[1][j]+=(d[j]-r+1);
      else if(d[j+1]>=r) dp2[1][j]+=(d[j]-d[j+1]);
      dp2[1][j]%=Mod;
  }

  for(i=2;i<=k+1;i++){
    for(j=1;j<r;j++) {
      dp1[i][j]=dp1[i][j-1];
      dp1[i][j]+=dp1[i-1][min(d[j],r-1)];
      dp1[i][j]%=Mod;
      dp1[i][j]+=dp2[i-1][j];
      dp1[i][j]%=Mod;
    }
    
    for(j=r-1;j>=1;j--) {
      dp2[i][j]=dp2[i][j+1];
      if(d[j+1]<r&&d[j]>=r) dp2[i][j]+=(d[j]-r+1)*dp1[i-1][j];
      else if(d[j+1]>=r) dp2[i][j]+=(d[j]-d[j+1])*dp1[i-1][j];
      dp2[i][j]%=Mod;
    }
  }

  cout<<dp1[k+1][1]<<endl;
  
  return 0;  
}

Measured memory_bytes: 51208
#include <bits/stdc++.h>
#define For(i,l,r) for (register int i=l; i<=r; i++)
using namespace std;
typedef unsigned long long LL;
typedef signed long long ll;
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll a, b;
int main() {
	read(a); read(b);
	if (b == 1) return puts("0"), 0;
	//if (b % a == 0) cout << b/a;
	//	else cout << b/a+1;
	int l = 1, r = (b/a)*2;
	while (l <= r) {
		int mid = ((r-l+1)>>1) + l;
		if (mid*a-(mid-1) >= b) r = mid-1;
			else l = mid+1;
	}
	cout << l;
	getchar();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int x=0;
    cin >> x;

    int t=0;
    while(1){
        if(x<= (t+1)*t/2 )
            break;
        t++;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    int S = stdin.nextInt();
    int h = S / 3600;
    int m = S % 3600 / 60;
    int s = S % 3600 % 60;
    System.out.println(h + ":" + m + ":" + s);
  }

}

Measured memory_bytes: 17356
#include <bits/stdc++.h>
using namespace std;
signed main(){
  long long h,w,a,b;
  cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(j<a && i<b)
	cout<<"0";
      else if(a-1<j && b-1<i)
	cout<<"0";
      else
	cout<<"1";
    }
    cout<<endl;
  }
      return(0);
}

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

using namespace std;

using ll = long long;

constexpr ll INF = 1e18;
constexpr char newl = '\n';
constexpr int LOGK = 30;

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

    int n, K;
    cin >> n >> K;

    vector< vector<int> > pos(LOGK, vector<int>(n, -1));
    for (int i = 0; i < n; i++) {
        cin >> pos[0][i];
        --pos[0][i];
    }
    
    vector< vector<ll> > score(LOGK, vector<ll>(n, -INF));
    vector< vector<ll> > max_score(LOGK, vector<ll>(n, -INF));
    for (int i = 0; i < n; i++) {
        cin >> score[0][i];
        max_score[0][i] = score[0][i]; 
    }

    for (int i = 1; i < LOGK; i++) {
        for (int j = 0; j < n; j++) {
            pos[i][j] = pos[i - 1][pos[i - 1][j]];
            score[i][j] = score[i - 1][pos[i - 1][j]] + score[i - 1][j];
            max_score[i][j] = max(max_score[i - 1][j], score[i - 1][j] + max_score[i - 1][pos[i - 1][j]]);
        }
    }

    ll ans = -INF;
    for (int i = 0; i < n; i++) {
        ll sum = 0;
        int cur = i;
        for (int j = 0; j < LOGK; j++) {
            if (K >> j & 1) {
                ans = max(ans, sum + max_score[j][cur]);
                sum += score[j][cur];
                cur = pos[j][cur];
            }
        }
    }
    cout << ans << newl;

    return 0;
}

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

int main() {
    int n, c, k;
    cin >> n >> c >> k;
    vector<int> t(n);
    rep(i,n) {
        cin >> t[i];
    }
    sort(t.begin(), t.end());
    t.push_back(t[n-1] + k + 100);
    int capa = c;
    int go_time;
    int i = 0;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (capa == c) {
            go_time = t[i] + k;
        }
        if (capa > 0 && go_time >= t[i]) {
            capa--;
        }        
        if (capa == 0 || go_time < t[i+1]) {
            ans++;
            capa = c;
        }
    }
    cout << ans << endl;
}

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

int main()
{
	double v;
	while (cin >> v)
	{
		int n = 1;
		v *= v;
		while (v > 19.6 * (n * 5 - 5))
		{
			n++;
		}
		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000; //配列のサイズ

int main(){

	int R[MAX], n;
	cin >> n;

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

	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++)
	{
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}


Measured memory_bytes: 3888
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n, x, count = 0;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < n - 1; ++i) {
		if (x >= a[i]) {
			++count;
			x -= a[i];
		}
		else break;
	}
	if (x == a[n - 1])++count;
	cout << count << endl;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  long long happy = 0;
  
  for (int i = 0; i < N; i++) {
    if (i == 0) {
      if (S.at(i) == 'R' && S.at(i+1) == 'R')
        happy++;
    }
    else if (i == N - 1) {
      if (S.at(i) == 'L' && S.at(i-1) == 'L')
        happy++;
    }
    else {
      if (S.at(i) == 'R' && S.at(i+1) == 'R')
        happy++;
      else if (S.at(i) == 'L' && S.at(i-1) == 'L')
        happy++;
    }
  }

  long long happy_max = happy;
  if (happy + 2 * K < N - 1)
    happy_max = happy + 2 * K;
  else
    happy_max = N - 1;
  
  cout << happy_max << endl;
}

Measured memory_bytes: 512
from bisect import bisect_right
from itertools import accumulate


N = int(input())
A = sorted(map(int, input().split()))
acc_A = list(accumulate(A))
ans = 0
for i in range(N):
    prev = i
    while True:
        idx = bisect_right(A, 2 * acc_A[prev], lo=prev) - 1
        if idx == N - 1:
            ans += 1
            break
        if idx == prev:
            break
        prev = idx
print(ans)


Measured memory_bytes: 14432
import bisect
n = int(input())
L = sorted(map(int,input().split()))
ans = 0
# a<b<cとしてa,bを決めると c < b+aだけ確かめれば良い!
for i in range(n-1):
    for j in range(i+1,n):
        # bisectで初めてa+b以上になる元のindexを見つける
        # j番以降の元であればc>bを満たす.
        ans += bisect.bisect_left(L, L[i]+L[j]) - j - 1
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int main() {
	int n, p, x, ans;

	scanf("%d", &n);
	ans = 0;
	x = n + 1;
	while (n--) {
		scanf("%d", &p);
		if (x > p)
			x = p;
		if (p <= x)
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")

#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x);
		y = y >> 1;
		x = (x * x);
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, m;
	cin >> n >> m;
	priority_queue<ll> arr;
	ll sum = 0;
	f(i, 0, n)
	{
		ll temp;
		cin >> temp;
		sum += temp;
		arr.push(temp);
	}
	f(i, 0, m)
	{
		ll maxi = arr.top();
		arr.pop();
		sum -= maxi;
		maxi /= 2;
		sum += maxi;
		arr.push(maxi);
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 1400
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class B {
    static StreamWriter Out = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static void Main(string[] args) {
        int N, K;
        Input(out N, out K);
        Console.WriteLine(Log(N, K) + 1);
    }
    static int Pow(int a, int b) {
        if(b == 0) {
            return 1;
        } else {
            if(b % 2 == 0) {
                return Pow(a * a, b / 2);
            } else {
                return a * Pow(a, b - 1);
            }
        }
    }
    static int Log(int a, int b) {
        for(int i = 0; true; i++) {
            if(a < Pow(b, i)) {
                return i - 1;
            }
        }
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
    static void Print<T>(T s) => Out.WriteLine(s);
    static void Print<T>(params T[] s) => Out.WriteLine(string.Join(" ", s));
    static void Print<T>(IEnumerable<T> e) => Out.WriteLine(string.Join(" ", e));
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;

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; }
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
    
  
    
    char a, b, c, d, e, f;
    cin>>a>>b>>c>>d>>e>>f;
    if(a==f&&b==e&&c==d)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
using namespace std;
int g[1<<17],n,k,a[100];
main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<=k;i++)
	{
		set<int>S;
		for(int j=0;j<n&&a[j]<=i;j++)S.insert(g[i-a[j]]);
		int j=0;
		for(;S.find(j)!=S.end();j++);
		g[i]=j;
	}
	cout<<(g[k]?"First":"Second")<<endl;
}

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

int main(){
  string s;
  int N,ans;
  ans=0;
  cin>>N>>s;
  for(int i=0;i<N-2;i++){
    if(s.at(i)!='A')continue;
   else if(s.at(i+1)!='B')continue;
    else if(s.at(i+2)!='C')continue;
    ans++;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#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>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<int> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

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

signed main() {
    int t, n;
    while(cin >> t >> n, t || n) {
        set<pii> used, obstacle;
        rep(i,0,n) {
            int x, y; cin >> x >> y;
            obstacle.insert(pii(x, y));
        }
        int x, y; cin >> x >> y;

        queue< pair<P, int> > q;
        q.push(make_pair(P(x, y), 0));
        used.insert(pii(x, y));
        while(!q.empty()) {
            pair<P, int> cur = q.front(); q.pop();
            if(cur.second == t) continue;

            int sx = cur.first.X, sy = cur.first.Y;
            rep(i,0,6) {
                int nx = sx + dx[i];
                int ny = sy + dy[i];
                if(obstacle.count(pii(nx, ny))) continue;
                if(used.count(pii(nx, ny))) continue;
                used.insert(pii(nx, ny));
                q.push(make_pair(P(nx, ny), cur.second+1));
            }
        }
        cout << used.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long

int n, ans, a[200], b[200];
int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	ans = 0;
	cin >> n;
	for(int i = 0; i < n-1; ++i) cin >> b[i];
	a[0] = b[0];
	for(int i = 1; i < n; ++i) {
		a[i] = min(b[i], b[i-1]);
	}
	a[n-1] = b[n-2];
	for(int i = 0; i < n; ++i) ans += a[i];
	cout << '\n' << ans;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> lst(N+1);
  int cnt;
  int ans = 0;
  for (int i = 1; i <= N; i = i+2) {
    cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) cnt++;
    }
    if (cnt == 8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ld long double
#define pll pair < long long , long long >
#define endl "\n"
using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    vector < ll > v(n);
    for( int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    sort(rall(v));
    ll answ = 0;
    for( int i = 0; i < n; i++)
    {
        if(!k)
        {
            answ+=v[i];
        }
        else
        {
            k--;
        }
    }
    cout << answ;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A, B, C, D; 
 cin >> A >> B >> C >> D;
  
  if ( A <= C && C <= B && B <= D ) cout << B - C << endl;
  else if ( A <= C && C <= B && A <= D && B >=D ) cout << D - C << endl;
  else if ( A >= C && A <= D && B >=D ) cout << D - A << endl;
  else if ( C <= A && B <= D ) cout << B- A << endl; 
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s >> t;
    intl cnt = 0;
    rep(i,3){
        cnt += (s[i]==t[i]);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
namespace FastIO{const char* ln="\n";struct Reader{char buf[1<<20],*s,*t;bool EOF_FLG;Reader():s(buf),t(buf),EOF_FLG(false) {};char gt() {return s==t&&((t=(s=buf)+fread(buf,1,1<<20,stdin))==s)?EOF:(*s++);}Reader& operator>>(char* str) {if(EOF_FLG)return *str=0,*this;while((*str=gt())!=' '&&*str!='\n'&&*str!=EOF)++str;if(*str==EOF)EOF_FLG=true;*str=0;return *this;}template<typename T>Reader&operator>>(T&x) {if(EOF_FLG)return *this;char c=0,d;while(c!=EOF&&(c<'0'||c>'9'))d=c,c=gt();if(c==EOF){EOF_FLG=true;return *this;}else x=0;while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+c-'0',c=gt();if(d=='-')x=-x;return *this;}}in;struct Writer{char buf[1<<20],*s,*t;Writer():s(buf),t(buf+(1<<20)){}~Writer(){fwrite(buf,1,s-buf,stdout);}void pt(char c){(s==t)?(fwrite(s=buf,1,1<<20,stdout),*s++=c):(*s++=c);}template<typename T>Writer&operator<<(T x){if(!x)return pt('0'),*this;if(x<0)pt('-'),x=-x;char a[40],t=0;while(x)a[t++]=x%10,x/=10;while(t--)pt(a[t]+'0');return *this;}Writer&operator<<(const char*s) {while(*s)pt(*s++);return *this;}}out;}using namespace FastIO;
namespace ZDY{
    #define ll long long
    #define db double
    #define sht short
    #define MB template <class T>
    #define Fur(i,x,y) for(int i=x;i<=y;i++)
    #define fur(i,x,y) for(i=x;i<=y;i++)
    #define Fdr(i,x,y) for(int i=x;i>=y;i--)
    #define fdr(i,x,y) for(i=x;i>=y;i--)
    #define clr(x,y) memset(x,y,sizeof(x))
    #define cpy(x,y) memcpy(x,y,sizeof(x))
    #define inf 0x3f3f3f3f
    #define fin(s) freopen(s".in","r",stdin)
    #define fout(s) freopen(s".out","w",stdout)
    #define l2(n) (int(log2(n)))
    #define fl(i,x) for(int i=head[x],to;to=e[i].to,i;i=e[i].nxt)
    #define fcin ios::sync_with_stdio(false)
    MB T ABS(T x){return x>0?x:-x;}
    MB T MAX(T x,T y){return x>=y?x:y;}
    MB T MIN(T x,T y){return x<=y?x:y;}
    MB T GCD(T x,T y){return y?GCD(y,x%y):x;}
    void SWAP(int &x,int &y){x^=y;y^=x;x^=y;}
}using namespace ZDY;using namespace std;
#define N 1000001
int main(){
    int n;
    db ans=0,x;
    char p[100];
    scanf("%d",&n);
    Fur(i,1,n){
        scanf("%lf%s",&x,p);
        if(p[0]=='B')x=x*(db)380000.0;
        ans+=x;
    }
    printf("%lf\n",ans);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n;
  cin >> n;
  
  for(int i = 1; i*i <= n && i <= 9; i++)
  {
    if(n%i == 0)
    {
      if(i <= 9 && n/i <= 9)
      {
        cout << "Yes\n";
        
        return 0;
      }
    }
  }
  
  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
N_set = set(range(N+1))
N_set = N_set - {0}
kari = []
for i in range(2*K):
  if i % 2 == 0:
    a = input()
    pass
  else:
    kari.append([int(k) for k in input().split()])
flatten = lambda x: [z for y in x for z in (flatten(y) if hasattr(y, '__iter__') and not isinstance(y, str) else (y,))]
kari = set(flatten(kari))
sa = N_set - kari
print(len(sa))

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
template <typename Container>
void print(const Container &c, char end = '\n', char sep = ' ')
{
    for (const auto &x : c)
        cout << x << sep;
    cout << end;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

   long long  int a, b;
    cin >> a >> b;
    cout << lcm(a, b);
    return 0;
}

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

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


}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define FOR(i, N) for (long i = 0; i < (N); i++)

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

    long K;
    cin >> K;
    long mod = 7 % K;
    for (int k = 0; k < K; k++) {
        if (mod == 0) {
            cout << k + 1 << endl;
            return 0;
        } else {
            mod = (mod * 10 + 7) % K;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fast_input() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main(void) {
    long long a, b, c; cin >> a >> b >> c;
    long long now = 0;
    for (int i = 0; i < 10000000; i++) {
        if (c%(a+b) <= a) {
            cout << c << endl;
            return 0;
        }
        c += 60;
    }
    cout << -1 << endl;
    return 0;
}


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

int main()
{
  int N, X;
  cin >> N >> X;
  vector<int> D(N+1);
  D[0] = 0;
  for(int i = 1; i < N+1; i++){
    int x;
    cin >> x;
    D[i] = D[i-1] + x;
  }

  int ans = 0;
  for(int i = 0; i <= N; i++){
    if(D[i] <= X) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def operationA(num):
    number = num * 2
    return number


def operationB(num, k):
    number = num + k
    return number


start = 1
n = int(input())
k = int(input())

for i in range(n):
    if start * 2 > start + k:
        start = operationB(start, k)

    else:
        start = operationA(start)


print(start)


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n; sc(n)
    vector<int> A(n);
    for (int i = 0; i < n; i++) sc(A[i])
    sort(A.begin(), A.end());
    int cnt = 0;
    for (int i = 0; i < n - 1; i++){
        if (A[i] == A[i + 1]) cnt += 1;
    }
    if (cnt % 2 == 1) cout << n - cnt - 1 << endl;
    else cout << n - cnt << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <stdlib.h>
#include <stdio.h>      /* printf */
#include <math.h>       /* pow */
#include <vector>
#include <stack>
#include <algorithm>
#include <string>

bool binarySearch(std::vector<int>& list, int L, int R, int T) {
    if (L>R) return false;
    int m = floor((L+R)/2);
    if (T<list[m]) {
        return binarySearch(list,L,m-1,T);
    } else if (T>list[m]) {
        return binarySearch(list,m+1,R,T);
    } else {
        return true;
    }
}

int linearSearch(std::vector<int>& list, std::vector<int>& seq) {
   int found = 0;
   for (int i=0; i<seq.size();i++) {
        if(std::binary_search(list.begin(),list.end(),seq[i])) found++;
   }
   return found;
}

int main(void){
    int value;
    std::vector<int> list;
    int n;
    std::cin >> n;
    for(int i=0; i<n; i++) {
        std::cin >> value;
        list.push_back(value);
    } 
    std::vector<int> seq;
    int q;
    std::cin >> q;
    for(int j=0; j<q; j++) {
        std::cin >> value;
        seq.push_back(value);
    }
    std::cout << linearSearch(list,seq) << std::endl;
    return 0;
}

Measured memory_bytes: 1800
#include<bits/stdc++.h>
using namespace std;
map<string,long long> str;
int main()
{
	long long n;
	cin>>n;
	long long a[n+1]={0};
	string x;
	long long s=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		sort(x.begin(),x.end());
		if(str[x]==0)
		{
			s++;
			str[x]=s;
			a[s]++;
		}
		else
		{
			a[str[x]]++;
		}
	}
	long long ans=0;
	for(int i=1;i<=s;i++)
	{
		ans+=(a[i]*a[i]-a[i])/2;
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int X;
  cin >> X;
  int ans = 0;
  if (X == 2){
    cout << 2 << endl;
  }
  else{
    while (true){
      int i = 2;
      while (true){
        if (X % i == 0){
          ans = -1;
          break;
        }
        if (X < i * i){
          ans = 1;
          break;
        }
        i++;
      }
      if (ans == 1){
        break;
      }
      X++;
    }
    cout << X << endl;
  }
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
vector<pair<ll, pii> > data;
vi tree[114514];
pii depth[114514];
queue<int> Q;
int iro[114514]={0};
int oya[114514];
void dfs(int hoge,int from){
	oya[hoge]=from;
	if(hoge!=0){
		depth[hoge].first=depth[from].first+1;
	}
	rep(i,tree[hoge].size()){
		int nex=tree[hoge][i];
		if(depth[nex].first==-1){
			dfs(nex,hoge);
		}
	}
}
int N;
void outtree(){
	rep(i,N){
		cout<<i+1<<" "<<iro[i]<<endl;
	}
	
}
int main(){
	cin>>N;
	rep(i,N)depth[i]=mp(-1,i);
	rep(i,N-1){
		int x,y;
		cin>>x>>y;
		x--;y--;
		tree[x].pb(y);
		tree[y].pb(x);
	}
	// 1:white 2:black
	depth[0]=mp(0,0);
	dfs(0,-1);
	sort(depth,depth+N);
	reverse(depth,depth+N);
	for(int i=0;i<N;i++){
		int koko=depth[i].second;
		if(iro[koko]==0){
			if(oya[koko]==-1){
				iro[koko]=1;
			}else if(iro[oya[koko]]==0){
				iro[koko]=2;
				iro[oya[koko]]=1;
			}else{
				cout<<"First"<<endl;
				//outtree();
				return 0;
			}
		}
	}
	//outtree();
	rep(i,N){
		bool flag=true;
		if(iro[i]==1){
			rep(j,tree[i].size()){
				if(iro[tree[i][j]]!=1)flag=false;
			}
			if(flag){
				cout<<"First"<<endl;
				return 0;
			}
		}
	}
	cout<<"Second"<<endl;
}


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

using namespace std;

unsigned long long A, B, s, d;

unsigned long long solve(){
    for(unsigned long long i=1; i <= max(A,B); ++i){
        
        if((s * i) % max(A,B) == 0)
            return s * i;
    }
    return -1;
}

int main(void){
    cin >> A >> B;
    s = min(A,B);

    cout << solve() << endl;

    return 0;
}

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

int main()
{
ll r , c , k ;
cin >> r >> c >> k ;
vector<vector<vector<ll>>> v(r, vector<vector<ll>>(c, vector<ll>(3,-(1LL<<60))));
vector<vector<ll>> vv(r, vector<ll>(c,0) );
rep(i,k){
  ll rr , cc , vvv ;
  cin >> rr >> cc >> vvv ;
  vv[rr-1][cc-1]=vvv;
}
v[0][0][0]=vv[0][0];
rep(i,r){
  rep(j,c){
    v[i][j][0]=vv[i][j];
    rep(l,3){
      if(j!=0)v[i][j][l]=max(v[i][j][l],v[i][j-1][l]);
      if(j!=0&&l!=0)v[i][j][l]=max(v[i][j][l],v[i][j-1][l-1]+vv[i][j]);
      if(i!=0)v[i][j][l]=max(v[i][j][l],*max_element(v[i-1][j].begin(),v[i-1][j].end())+vv[i][j]);
    }
  }
}
cout << *max_element(v[r-1][c-1].begin(),v[r-1][c-1].end()) << endl;
return 0;
}

Measured memory_bytes: 565964
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	String s=sc.next();
    int n=s.length();
    for(int i=2;i<n;i+=2){
      String a=s.substring(0,(n-i)/2),b=s.substring((n-i)/2,n-i);
      if(a.equals(b)){
        System.out.println(n-i);
        break;
      }
      s=s.substring(0,n-2-i);
      
    }
  }
}


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

int main(){
  int h,w;
  cin>>h>>w;
  string s = "";
  char x;
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<w;j++){
      if (j==0) s += "#";
      if (i==0 || i==h+1){
        s += "#";
      }else{
        cin >> x;
        s += x;
      }
      if (j==w-1) s+="#";
      if (j==w-1) {
        cout << s << endl;
        s = "";
      }
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,c,d,s=0;
  cin >> a >> b >> c >> d;
  if(a>=d)
  {
    cout << d << endl;
  }
  else{
    d=d-a;
    s+=a;
    if(d>b)
    {
    	d=d-b;
    	s-=d;
    	
    }
    cout << s <<endl;
  }
  return 0;
}


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

int main(){
    double a, b, c;
    std::cin >> a >> b >> c;
    c = c / 180.0 * M_PI;
    printf("%10.8f\n", a * b * std::sin(c) / 2 );
    printf("%10.8f\n", a + b + std::sqrt(a*a + b*b - 2*a*b*std::cos(c)));
    printf("%10.8f\n", b * sin(c));
    return 0;
}


Measured memory_bytes: 3560
from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
canA = []

for i in range(0,n):
    canA.append(a[i]-1)
    canA.append(a[i])
    canA.append(a[i]+1)

ans = Counter(canA).most_common(1)
print(ans[0][1])


Measured memory_bytes: 27360