akhauriyash/Code-Regression huggingface dataset:
import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._
  val n = readInt()
  for (_ ← 0 until n) {
    val messenger = readLine.trim
    val message = readLine.trim
    val original =
      messenger.foldRight(new Pure(message): Message) {
        case ('J', m) ⇒ m.rotateLeft
        case ('C', m) ⇒ m.rotateRight
        case ('E', m) ⇒ m.swap
        case ('A', m) ⇒ m.reverse
        case ('P', m) ⇒ m.decrement
        case ('M', m) ⇒ m.increment
        case _ ⇒ ???
      }
    println(original.indices.map(original).mkString(""))
  }
}

sealed trait Message extends ((Int) ⇒ Char) {
  def rotateLeft: Message = new RotateLeft(this)
  def rotateRight: Message = new RotateRight(this)
  def swap: Message = new Swap(this)
  def reverse: Message = new Reverse(this)
  def increment: Message = new Increment(this)
  def decrement: Message = new Decrement(this)
  def apply(index: Int): Char
  def indices: Range = 0 until length
  def length: Int
}
case class Pure(message: String) extends Message {
  override def apply(index: Int): Char = message(index)
  override def length: Int = message.length
}
class RotateLeft(private val message: Message) extends Message {
  override def apply(index: Int): Char = message((index + length - 1) % length)
  override val length: Int = message.length
}
class RotateRight(private val message: Message) extends Message {
  override def apply(index: Int): Char = message((index + 1) % length)
  override val length: Int = message.length
}
class Swap(private val message: Message) extends Message {
  override def apply(index: Int): Char = {
    if ((0 until length / 2).contains(index)) message((length + 1) / 2 + index)
    else if ((((length + 1) / 2 until length)).contains(index)) message(index - (length + 1) / 2)
    else message(index)
  }
  override def length: Int = message.length
}
class Reverse(private val message: Message) extends Message {
  override def apply(index: Int): Char = message(length - 1 - index)
  override def length: Int = message.length
}
class Increment(private val message: Message) extends Message {
  override def apply(index: Int): Char = {
    message(index) match {
      case c if c.isDigit ⇒ ((c.asDigit + 1) % 10 + '0').toChar
      case c ⇒ c
    }
  }
  override def length: Int = message.length
}
class Decrement(private val message: Message) extends Message {
  override def apply(index: Int): Char = {
    message(index) match {
      case c if c.isDigit ⇒ ((c.asDigit + 9) % 10 + '0').toChar
      case c ⇒ c
    }
  }
  override def length: Int = message.length
}




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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

ll dp[1 << 13] = {0};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ps(m);
  for (int i = 0; i < m; i++) {
    int t;
    cin >> ps[i].first >> t;
    for (int j = 0; j < t; j++) {
      int k;
      cin >> k;
      k--;
      ps[i].second = ps[i].second | (1 << k);
    }
  }
  ll INF = 1LL << 40;
  for (int i = 0; i < (1 << n); i++) dp[i] = INF;
  dp[0] = 0;

  for (int i = 0; i < (1 << n); i++) {
    for (int j = 0; j < m; j++) {
      dp[i | ps[j].second] = min(dp[i | ps[j].second], dp[i] + ps[j].first);
    }
  }

  if (dp[(1 << n) - 1] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[(1 << n) - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;

const int N = 1000010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

char s[N];

ll D[N], M[N];
ll DM[N];

int main(){
  int n;
  fastScan(n);
  scanf("%s", s);
  for(int i = 0; i < n; i++){
    if(s[i] == 'D'){
      D[i] = 1;
    }
    if(s[i] == 'M'){
      M[i] = 1;
      DM[0]++;
      DM[i]--;
    }
  }
  for(int i = 1; i < n; i++){
    D[i] += D[i - 1];
  }
  for(int i = n; i >= 0; i--){
    M[i] += M[i + 1];
  }
  for(int i = 1; i < n; i++){
    DM[i] += DM[i - 1];
  }
  for(int i = 0; i < n; i++){
    if(s[i] != 'D'){
      DM[i] = 0;
    }
  }
  for(int i = 1; i < n; i++){
    DM[i] += DM[i - 1];
  }
  int q;
  fastScan(q);
  while(q--){
    int k;
    fastScan(k);
    ll answer = 0;
    for(int i = 2; i < n; i++){
      if(s[i] == 'C'){
        ll tmp = DM[i];
        if(i - k >= 0){
          tmp -= DM[i - k];
        }
        //cout << tmp << '\n';
        tmp -= (D[i] - ((i - k) >= 0 ? D[i - k] : 0)) * (M[i] - M[n]);
        answer += tmp;
      }
    }
    printf("%lld\n", answer);
  }
  return 0;
}



Measured memory_bytes: 24704
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())


void solve() {
  int n;
  int a[50];
  cin >> n;
  REP(i, n) cin >> a[i];
  int res = 0;
  FOR(i, 1, n-1) if((a[i] > a[i-1] && a[i] < a[i+1]) || (a[i] < a[i-1] && a[i] > a[i+1])) res++;
  cout << res << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
inline int read() {
	int x=0,s=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return s*x;
}

const int MAXN=400005,Mo=1000000007;
struct Data{
	int x,y,z;
	bool operator <(const Data &B)const{ return x<B.x; }
}A[MAXN];
int n,m,q,a[MAXN],b[MAXN];
int ok(int x,int y){
	if (!(x==0||x==n||y==0||y==m)) return 0;
	if (y==0) return x+1;
	if (x==n) return n+1+y;
	if (y==m) return n+m+(n+1-x);
	return n*2+m+(m+1-y);
}
int main(){
	n=read(); m=read(); q=read();
	int tot=0;
	FOR(i,1,q) {
		int x1=read(),y1=read(),x2=read(),y2=read();
		int tmp1=ok(x1,y1),tmp2=ok(x2,y2);
		if (tmp1&&tmp2) {
			if (tmp1>tmp2) swap(tmp1,tmp2);
			A[++tot]=(Data){tmp1,1,i};
			A[++tot]=(Data){tmp2,-1,i};
		}
	}
	sort(A+1,A+1+tot);
	int top=0,flag=1;
	FOR(i,1,tot) {
		if (A[i].y==1) a[++top]=A[i].z;
		else {
			if (!top||a[top]!=A[i].z) { flag=0; break; }
			else top--;
		}
	}
	if (flag) puts("YES"); else puts("NO");
	
	return 0;
}

/*
*/


Measured memory_bytes: 4480
def find(x):
    if vertices[x] != x:
        vertices[x] = find(vertices[x])
    return vertices[x]

nv, ne = map(int, input().split(' '))
vertices = [i for i in range(nv)]
edges = []
for i in range(ne):
    s, t, w = map(int, input().split(' '))
    edges.append((s, t, w))

sum = 0
forest = [[v] for v in range(nv)]
edges.sort(key=lambda tup: tup[2])
for s, t, w in edges:
    u = find(s)
    v = find(t)
    if u != v:
        vertices[u] = v
        sum += w

print(sum)

Measured memory_bytes: 28096
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<long>A(N),B(N),C(N);
  for(long i=0;i<N;i++)cin>>A[i];for(long i=0;i<N;i++)cin>>B[i];
  for(long i=0;i<N;i++)C[i]=A[i]-B[i];
  long c=0;
  for(long i=0;i<N;i++){
    if(C[i]<0){
      c+=(-C[i]+1)/2;
      C[i]=(-C[i])%2;
    }
  }
  for(long i=0;i<N;i++)c-=C[i];
  cout<<(c>=0?"Yes":"No");
}

Measured memory_bytes: 512
N  = int(input())

A = [int(n) for n in input().split()]

min = 100*(200)**2+10

for n in range(-100,101):
    tmp = 0
    for a in A:
        if a == n:
            pass
        else:
            tmp += (a - n)**2

    if min > tmp:
        min = tmp

print(min)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<long double>p(n);
	for (int i = 0; i < n; i++)cin >> p[i];
	vector<vector<long double>>dp(n + 1, vector<long double>(n + 1));
	dp[1][0] = 1 - p[0];
	dp[1][1] = p[0];
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j - 1 >= 0)dp[i][j] += dp[i - 1][j - 1] * (p[i - 1]);
			dp[i][j] += dp[i - 1][j] * (1 - p[i - 1]);
		}
	}
	long double ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i > n - i)ans += dp[n][i];
	}
	cout << setprecision(12);
	cout << ans;
	return 0;
}

Measured memory_bytes: 141056
#
# abc112 c
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """4
2 3 5
2 1 5
1 2 5
3 2 5"""
        output = """2 2 6"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
0 0 100
1 1 98"""
        output = """0 0 100"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """3
99 1 191
100 1 192
99 0 192"""
        output = """100 0 193"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """4
59 3 0
64 94 56
5 62 11
3 93 14"""
        output = """55 80 79"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    XYH = [list(map(int, input().split())) for _ in range(N)]
    XYH.sort(key=lambda x: x[2], reverse=True)

    CX = CY = H = 0
    flag = False
    for cx in range(101):
        if flag == True:
            break
        for cy in range(101):
            H = XYH[0][2]+abs(XYH[0][0]-cx)+abs(XYH[0][1]-cy)
            for xyh in XYH[1:]:
                x, y, h = xyh
                if h != max(H - abs(x-cx) - abs(y-cy), 0):
                    break
            else:
                flag = True
                CX = cx
                CY = cy
                break

    print(f"{CX} {CY} {H}")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16328
from math import gcd

mod = 1000000007

n = int(input())
counter = {}
zeros = 0
for i in range(n):
    a, b = map(int, input().split())
    if (a == 0 and b == 0):
        zeros += 1
        continue
    g = gcd(a, b)
    a //= g
    b //= g
    if (b < 0):
        a = -a
        b = -b
    if (b == 0 and a < 0):
        a = -a
    rot90 = a <= 0
    if rot90:
        a, b = b, -a
    count = counter.get((a, b), [0, 0])
    if rot90:
        count[0] += 1
    else:
        count[1] += 1
    counter[(a, b)] = count

ans = 1
for k, pairs in counter.items():
    s_count = pairs[0]
    t_count = pairs[1]
    now = pow(2, s_count, mod)-1
    now += pow(2, t_count, mod)-1
    now += 1
    ans *= now
    ans %= mod
print((ans - 1 + zeros) % mod)


Measured memory_bytes: 60576
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    ll X;
    cin >> X;
    ll i = 100, cnt = 0;
    while(i < X){
        i = i + i / 100;
        cnt++;
    }
    PRINT(cnt);
    return 0;
}

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

int main(){
	long long h,w;
  	cin>>h>>w;
  	if(h==1 || w==1){
    	cout<<1;
    }
  else{
  	cout<<(h*w + 1)/2;
  }
  	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define prinf printf

int main(){
  char a[200];
  int stack[100];
  int i,j,k;
  int len;
  int head=0;
  char dummy;

  while(scanf("%s",a)!=EOF){
    if(a[0]=='+'){
      stack[head-2]=stack[head-2]+stack[head-1];
      head--;
    }else if(a[0]=='-'){
      stack[head-2]=stack[head-2]-stack[head-1];
      head--;
    }else if(a[0]=='*'){
      stack[head-2]=stack[head-2]*stack[head-1];
      head--;
    }else{
      stack[head]=atoi(a);
      head++;
    }
  }
  
  prinf("%d\n",stack[0]);
  
  return 0;
}
  

Measured memory_bytes: 2752
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;
int dp[110][5][2];

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  rep(i, k) h.push_back(INF);
  vector<int> dp(n + k + 1, INF);
  dp[0] = 0;
  rep(i, n) {
    for(int j = 1; j <= k; ++j) {
      dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
typedef long long int llint;

int main(void){
  int h, n;
  std::cin >> h >> n;

  llint total = 0;
  for(int i=0; i<n; i++){
    int tmp;
    std::cin >> tmp;
    total += tmp;
  }

  std::cout << ((h-total<=0)?"Yes":"No") << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
typedef pair<int, int> P;
char maze[51][51];
const int INF=1e7;

ll N, M,ans;

int main(void)
{
	cin >> N >> M;
	for (ll i = N; i <= M; i *= 2) {
		ans++;
	}
	ct(ans);
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const LL MOD = 1e9+ 7;
LL powMod(LL x, LL y, LL m) {
    LL r = 1;
    for(;y;y>>=1) {
	if (y & 1) r = r * x % m;
	x = x * x % m;
    }
    return r;
}

int N;
int A[100111];
int B[100111];

int main() {
    scanf("%d", &N);
    REP (i, N) scanf("%d", A+i);
    int cur = N-1;
    REP (i, N/2) {
	B[i*2] = B[i*2+1] = cur;
	cur-=2;
    }
    sort(A, A+N);
    sort(B, B+N);
    REP (i, N) if (A[i] != B[i]) {
	puts("0");
	return 0;
    }
    
    printf("%lld\n", powMod(2, N/2, MOD));



    return 0;
}



Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	if (A == B) {
		cout << C << endl;
	}
	else if (B == C) {
		cout << A << endl;
	}
	else {
		cout << B << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5000000+10;
int m,d;
int main()
{
	cin>>m>>d;
	int cnt=0;
	for(int i=0;i<=d;i++)
	{
		int ys=i%10;
		int zs=i/10;
		if(ys<2||zs<2)
		continue;
		if(ys*zs<=m)
		cnt++;
	}
	cout<<cnt<<endl;
}

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


class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] floor = new int[N];
        floor = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int cnt = 0;
        int cnt_max = 0;

        if (floor.Length == 1)
        {
            Console.WriteLine("0");
            return;
        }

            for (int j = 1; j < N; j++)
            {
            if (floor[j - 1] >= floor[j])
            {
                cnt++;
            }
            else
            {
                if (cnt > cnt_max)
                {
                    cnt_max = cnt;
                    cnt = 0;
                }
                cnt = 0;
            }
            }
            if (cnt > cnt_max)
            {
                cnt_max = cnt;
                cnt = 0;
            }
           
        

        Console.WriteLine(cnt_max);

    }
}



Measured memory_bytes: 26588
#include <bits/stdc++.h>
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 repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
int x;
int ans[200001];
bool past[200001];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n>>x;
  if(x==1 || x==2*n-1){
    cout<<"No"<<"\n";
  }else{
    cout<<"Yes"<<"\n";
    if(n==2){
      cout<<1<<" "<<2<<" "<<3<<endl;
      return 0;
    }
    if(x==2){
      ans[n-2]=x+2;
      ans[n-1]=x;
      ans[n]=x-1;
      ans[n+1]=x+1;
      past[x-1]=1,past[x]=1,past[x+1]=1,past[x+2]=1;
      int now=1;
      for(int i=0;i<2*n-1;i++){
        if(i>n-3 && i<n+2)continue;
        while(1){
          if(past[now])now++;
          else break;
        }
        ans[i]=now;
        past[now]=1;
      }
    }else{
      ans[n-2]=x-1;
      ans[n-1]=x;
      ans[n]=x+1;
      ans[n+1]=x-2;
      past[x-2]=1,past[x-1]=1,past[x]=1,past[x+1]=1;
      int now=1;
      for(int i=0;i<2*n-1;i++){
        if(i>n-3 && i<n+2)continue;
        while(1){
          if(past[now])now++;
          else break;
        }
        ans[i]=now;
        past[now]=1;
      }
    }
    for(int i=0;i<2*n-1;i++){
      if(i!=2*n-2)cout<<ans[i]<<" ";
      else cout<<ans[i]<<"\n";
    }
  }
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






Measured memory_bytes: 2560
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
#include<string.h>
using namespace std;
int map[85][85][13900],mmap[90][90];
int main() {
	int n, m, i, j,k;
	scanf("%d %d", &n, &m);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			scanf("%d", &mmap[i][j]);
		}
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			int x;
			scanf("%d", &x);
			x = abs(x - mmap[i][j]);
			if (i == 1 && j == 1) { map[i][j][x] = 1; continue; }
			for (k = 0; k <= 13600; k++) {
				if (map[i][j - 1][k] == 1) {
					map[i][j][k + x] = 1;
					map[i][j][abs(k - x)] = 1;
				}
				if (map[i - 1][j][k] == 1) {
					map[i][j][k + x] = 1;
					map[i][j][abs(k - x)] = 1;
				}
			}
		}
	}
	for (i = 0; i <= 13600; i++) {
		if (map[n][m][i] == 1) { printf("%d", i); return 0; }
	}
	return 0;
}

Measured memory_bytes: 370816
#include <cstdlib>
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 100005
#define pb push_back
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const double PI  =3.141592653589793238463;
long long MOD = 1000000007;

int stringToInteger(string x){
    int gg=0;
    //stringstream geek(x);
    //geek >> gg;
    return gg;
}

ll powmod(ll a,ll b,ll m)
{
    ll ans=1;
    while(b>0){ if(b%2)
        {ans*=a; ans%=m;}
         b/=2; a=a*a; a=a%m;
        }
        return ans%m;
}
ll gcd(ll a,ll b)
{

    return __gcd(a,b);
}
ll mulmod(ll a,ll b,ll m)
{  ll ans=0;
    a %=m;
    while (b>0)
    {       if(b&1) ans = (ans + a) % m;
        a = (a * 2)%m;
        b /= 2;
    }
    return ans % m;
}

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}
ll modInverse(ll a, ll m)
{
    a = a%m;
    for (int x=1; x<m; x++)
       if ((a*x) % m == 1)
          return x;
}
ll maxDivide(ll a, ll b)
{
  while (a%b == 0)
   a = a/b;
  return a;
}
  set<ll>ans;
void primeFactors(ll n)
{

    while (n % 2 == 0)
    {
       ans.insert(2);
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            ans.insert(i);
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        ans.insert(n);
}
ll is(ll no)
{   if(no==1) return 0;
    set<ll>::iterator it;
for(it=ans.begin();it!=ans.end();it++){
  no = maxDivide(no, *it);
  if(no==1) return 1;
//  if()
 // no = maxDivide(no, 3);
 // no = maxDivide(no, 5);
}
//if(no==1) return 1;
//for(it=ans.begin();it!=ans.end();it++){
//if(no==*it) return 1;
//}
  return 0;
}

int comp(string a,string b)
{
    string aa = a.append(b);
    string bb = b.append(a);

    return aa.compare(bb) > 0 ? 1: 0;

}
int main()
{
    //cout<<powmod(2,7,9)<<endl;
int t;
t=1;
while(t--){

       //int n,k;
       int n;
       cin>>n;
       int a[n],b[n];
       for(int i=0;i<n;i++) cin>>a[i];
       for(int i=0;i<n;i++) cin>>b[i];
       int ans=0;
       for(int i=0;i<n;i++) if(a[i]>=b[i]) ans+=a[i]-b[i];
       cout<<ans<<endl;



}
}




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

int64_t kaijo(int64_t P, int64_t C, int64_t div);
int64_t modpow(int64_t a, int64_t dim, int64_t div);

int main(){

    int64_t n, a, b;
    cin >> n >> a >> b;

    int64_t combo_num=0, combo_a=0, combo_b=0, ans=0, div=0;
    int64_t temp_x=0, temp_y=0;

    div = 1e9 + 7;

    //   総組み合わせ数の計算
    combo_num = modpow(2, n, div) - 1;
//    cout << combo_num << endl;

    //  aが含まれる場合の計算
    temp_x = kaijo(n, a, div);
//    cout << "temp_x = " << temp_x << endl;
    temp_y = kaijo(a, a, div);
//    cout << "temp_y = " << temp_y << endl;
    combo_a = ( temp_x*modpow(temp_y, div-2, div) )%div;
//    combo_a = temp_x*modpow(temp_y, div-2, div);
//    cout << "combo_a = " << combo_a << endl;

    //  bが含まれる場合の計算
    temp_x = kaijo(n, b, div);
//    cout << "temp_x = " << temp_x << endl;
    temp_y = kaijo(b, b, div);
//    cout << "temp_y = " << temp_y << endl;
    combo_b = ( temp_x*modpow(temp_y, div-2, div) )%div;
//    combo_b = temp_x*modpow(temp_y, div-2, div);
//    cout << "combo_b = " << combo_b << endl;

    ans = ( combo_num - (combo_a + combo_b)%div + div)%div;

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

//  階乗計算
int64_t kaijo(int64_t P, int64_t C, int64_t div){

    if (C == 0){
        return 1%div;
    }
    else{
        return ( P*kaijo(P-1, C-1, div) )%div;
    }
}

//  繰り返し2乗法
int64_t modpow(int64_t a, int64_t dim, int64_t div){

    if (dim == 1){
        return a%div; 
    }
    else if (dim%2 != 0){
        return ( a*modpow(a, dim-1, div) )%div;
    }
    else{
        return ( modpow(a, dim/2, div) * modpow(a, dim/2, div) )%div;
    }
}

Measured memory_bytes: 6528
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int[][] A = new int[3][];
            for (int i = 0; i < 3; i++) {
                A[i] = in.nextIntArray(3);
            }
            int N = in.nextInt();
            int[] B = in.nextIntArray(N);
            boolean[][] Ab = new boolean[3][3];
            for (int b : B) {
                for (int i = 0; i < 3; i++) {
                    for (int j = 0; j < 3; j++) {
                        if (A[i][j] == b) {
                            Ab[i][j] = true;
                        }
                    }
                }
            }
            for (int i = 0; i < 3; i++) {
                if (Ab[i][0] && Ab[i][1] && Ab[i][2]
                        || Ab[0][i] && Ab[1][i] && Ab[2][i]) {
                    out.println("Yes");
                    return;
                }
            }
            if (Ab[0][0] && Ab[1][1] && Ab[2][2]
                    || Ab[0][2] && Ab[1][1] && Ab[2][0]) {
                out.println("Yes");
                return;
            }
            out.println("No");
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

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

    }
}



Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>

using namespace std;

const int inf = 1 << 30;

int calc(int N, int A, int B, int C, const vector<int> &lengths, const vector<int> &sel)
{
	int cost = 0;
	int X[3] = {};
	
	for (int i = 0; i < N; ++i) {
		if (sel[i] != 0) {
			if (X[sel[i] - 1] != 0) {
				cost += 10;
			}
			X[sel[i] - 1] += lengths[i];
		}
	}
	for (int k = 0; k < 3; ++k) {
		if (X[k] == 0) {
			return inf;
		}
	}

	cost += abs(A - X[0]) + abs(B - X[1]) + abs(C - X[2]);

	return cost;
}

void solve(int N, int A, int B, int C, const vector<int> &lengths, vector<int> &sel, int i, int &ans)
{
	if (i == N) {
		int result = calc(N, A, B, C, lengths, sel);
		if (result < ans) {
			ans = result;
		}
		//ans = min(ans, result);
		return;
	}
	for (sel[i] = 0; sel[i] <= 3; ++sel[i]) {
		solve(N, A, B, C, lengths, sel, i + 1, ans);
	}
}

int main()
{
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	
	vector<int> lengths(N);
	for (auto &x : lengths) {
		cin >> x;
	}

	vector<int> sel(N, 0);
	int ans = inf;
	solve(N, A, B, C, lengths, sel, 0, ans);
	cout << ans << endl;
}


Measured memory_bytes: 256
#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() {
  vector<int> abc(3);
  int sum = 0;
  rep(i, 3) {
    int x;
    cin >> x;
    abc.at(i) = x;
    sum += x;
  }
  sort(abc.rbegin(), abc.rend());
  int maxV = abc.at(0);
  int resultSum = (maxV * 3 % 2 == sum % 2) ? maxV * 3 : (maxV + 1) * 3;
  int res = (resultSum - sum) / 2;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n)
{
	KAKA
	vector<ll> ar(n);
	pragi(0,n)
	{
		cin>>ar[i];
	}
	vector<ll> x(61);
	vector<ll> y(61);
	pragi(0,n)
	{
		ll ele = ar[i];
		pragj(0,61)
		{
			if(ele & (1ll << j))//if jth bit is set
			{
				x[j]++;
			}
			else y[j]++;
		}
	}
	ll sum = 0;
	pragi(0,61)
	{
		ll a = ((x[i] % mod) * (y[i] % mod))%mod;
		ll b = (1ll << i)%mod;
		ll c = ((a % mod) * (b % mod))%mod;
		sum = ((sum % mod) + (c % mod))%mod;
	}
	cout<<sum<<"\n";
}
int main()
{
	KAKA
	ll n;
	cin>>n;
	Compute(n);
}

Measured memory_bytes: 5528
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int p, q, r;
  cin >> p >> q >> r;
  cout << (p + q + r) - max(max(p, q), r) << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3504
import java.util.Scanner;

public class Main {

	public static void main(String Args[]){
		Scanner sc = new Scanner(System.in);
		String[] s = new String[3];
		for (int i = 0;i < 3 ; i++ ) {
			s[i] = sc.next();
		}
		int p = 0;
		while(s[p].length() != 0){
			int np = s[p].charAt(0)-'a';
			s[p] = s[p].substring(1,s[p].length());
			// else s[p] = "";
			p = np;
		}
		System.out.println((char)('A'+p));
	}

}

Measured memory_bytes: 9804
n=int(input())
x,y=zip(*sorted(sorted(map(int,input().split())) for _ in range(n)))
p=max(range(n),key=lambda i:y[i])
r=a=x[-1]
b=d=10**9
for i in range(p):
    a=max(a,y[i])
    b=min(b,y[i])
    d=min(d,a-min(b,x[i+1]))
print(min((x[-1]-x[0])*(y[p]-min(y)),(y[p]-x[0])*d))

Measured memory_bytes: 102416
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,s.size()){
    if(s[i]!=t[i])
      ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));
            int age = Integer.parseInt(input.get(0));
            int charge = Integer.parseInt(input.get(1));

            int result = charge;

            if (age <= 5) {
                result = 0;
            } else if (age <= 12) {
                result = charge / 2;
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21332
#include<cstdio>
const int mod=1000000007;
int N,M,f[310][310][310];
struct item{int l,x;item*next;}a[310],*fir[310];
bool chk(int i,int j,int k){
	for(item*it=fir[i];it;it=it->next)
		if((i>=it->l)+(j>=it->l)+(k>=it->l)!=it->x)return 0;
	return 1;
}
int main(){
	scanf("%d%d",&N,&M);
	for(int i=0;i<M;i++){
		int l,r,x;scanf("%d%d%d",&l,&r,&x);
		a[i]=(item){l,x,fir[r]};fir[r]=a+i;
	}
	f[0][0][0]=1;
	for(int i=0;i<N;i++)for(int j=0;j<=i;j++)for(int k=0,g;k<=j;k++){
		if(g=(chk(i,j,k)?f[i][j][k]:0)){
			(f[i+1][j][k]+=g)%=mod;
			(f[i+1][i][k]+=g)%=mod;
			(f[i+1][i][j]+=g)%=mod;
		}
	}
	int s=0;
	for(int j=0;j<=N;j++)for(int k=0;k<=j;k++)
		if(chk(N,j,k))(s+=f[N][j][k])%=mod;
	printf("%d\n",s);
}

Measured memory_bytes: 112896
#pragma warning(disable: 4996)
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <string>
#include <numeric>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	string s;
	cin >> n >> s;
	int cnt = 0;
	for (int i = 48; i <= 57; ++i) {
		for (int j = 48; j <= 57; ++j) {
			for (int k = 48; k <= 57; ++k) {
				char a = i; char b = j; char c = k;
				string num = "";
				num += a; num += b; num += c;
				
				int p = 0;
				for (int z = 0; z < n; ++z) {
					if (s[z] == num[p]) {
						++p;
						if (p >= 3) {
							++cnt;
							break;
						}
					}
				}
			}
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 512
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		T operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	u32 n;
	::std::cin >> n;
	::std::cout << "Christmas ";
	for (const auto i : rep<>(0, 25 - n))
		::std::cout << "Eve ";
	::std::cout << ::std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;

template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int n, m;
  cin >> n >> m;
  int wa = 0;
  rep(i, m)
  {
    int x;
    cin >> x;
    wa += x;
  }

  if (wa <= n)
  {
    cout << n - wa << endl;
  }
  else
  {
    cout << -1 << endl;
  }
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	int64 N, M;
	cin >> N >> M;
	int64 res = 0;
	FOR(i, 1, sqrt(M)+1){
		if(M%i == 0){
			if(i >= N)
				res = max(res, M/i);
			if(M/i >= N)
				res = max(res, i);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a>=b){
    cout << a+max(a-1,b) << endl;;
  }else{
    cout << b+max(b-1,a) << endl;;
  }
}


Measured memory_bytes: 256
//writer：Sakura
//problem：
//id：
//from：

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
//#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

//快读（可去）
/**/
inline int read(){
	int S=0,W=1;
	char CH=getchar();
	while(CH<='0' || CH>'9'){
		if(CH=='-')W=-1;
		CH=getchar();
	}
	while(CH>='0' && CH<='9')S=S*10+CH-'0',CH=getchar();
	return S*W;
}

int n;
string s;
int W[3*100005],E[3*100005];
int ans=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();
	cin>>s;
	
	if(s[0]=='W')W[0]=1;
	else s[0]=1;
	
	for(int i=1;i<n;i++){
		if(s[i]=='W'){
			W[i]=W[i-1]+1;
			E[i]=E[i-1];
		}
		else{
			W[i]=W[i-1];
			E[i]=E[i-1]+1;
		}
	}
	ans=E[n-1];
	
	for(int i=1;i<n;i++){
		int l=0,r=0;
		l=W[i-1];
		r=E[n-1]-E[i];
		ans=min((r+l),ans);
	}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 2948
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	bool x[3][3] = { false };
	int y[3][3] = { 0 };
	rep(i,3)
	{
		rep(j, 3)
			cin >> y[i][j];
	}
	cin >> n;
	rep(i, n)
	{
		cin >> a;
		rep(j, 3)
		{
			rep(k, 3)
				if (y[j][k] == a)
					x[j][k] = true;
		}
	}
	if ((x[0][0] && x[1][1] && x[2][2]) || (x[0][0] && x[1][0] && x[2][0]) || (x[0][1] && x[1][1] && x[2][1]) || (x[0][2] && x[1][2] && x[2][2]))
	{
		cout << "Yes" << endl; return 0;
	}
	if ((x[0][2] && x[1][1] && x[2][0]) || (x[0][0] && x[0][1] && x[0][2]) || (x[1][0] && x[1][1] && x[1][2]) || (x[2][0] && x[2][1] && x[2][2]))
	{
		cout << "Yes" << endl; return 0;
	}
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        if b == [w[j:j+m] for w in a[i:i+m]]:
            print("Yes")
            break
    else:
        continue
    break
else:
    print("No")

Measured memory_bytes: 3064
N=int(input())
from collections import defaultdict
branch=defaultdict(dict)
for i in range(N-1):
    a,b,c=map(int,input().split())
    branch[a-1][b-1]=c
    branch[b-1][a-1]=c
Q,K=map(int,input().split())
dist=[float('inf')]*N
dist[K-1]=0
check={K-1}
while len(check)>0:
    now=check.pop()
    for nex,d in branch[now].items():
        if dist[nex]>dist[now]+d:
            dist[nex]=dist[now]+d
            check|={nex}
for i in range(Q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])

Measured memory_bytes: 69428
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// using namespace std;

using ll=long long;
// template<class T> using V = vector<T>;
// template<class T, class U> using P = pair<T, U>;
// using vll = V<ll>;
// using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    ::std::cin.tie(0);
    ::std::ios::sync_with_stdio(false);
    int n, tmpn;
    ::std::cin >> n;
    tmpn = n;
    
    ::std::vector<int> div;
    for (int i = 2; i * i <= n; i++) {
        if (tmpn % i == 0) {
            div.emplace_back(i);
            while (tmpn % i == 0) tmpn /= i;
        }
    }
    if (tmpn != 1) div.emplace_back(tmpn);
    
    int sz = div.size(), ans = 0;
    // 素でないものを数え上げ
    for (int bit = 1; bit < (1 << sz); bit++) {
        int popcnt = __builtin_popcount(bit);
        int mul = 1;
        for (int i = 0; i < sz; i++) {
            if ((bit >> i) & 1) mul *= div[i];
        }
        // 集合の数によって場合わけ
        ans += (popcnt & 1 ? 1 : -1) * (n / mul);
    }

    ::std::cout << n - ans << '\n';
    return 0;
}



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

int main(){
  int a, b; cin >> a >> b;
  int k=min(a,b);
  int l=max(a,b);
  int now=1;
  int ans=0;
  for(int i=0;i<l;i++){
    ans+=k*now;
    now*=10;
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n,m = i_map()
    a = set([i_input() for i in range(m)])

    dp = [INF] * (n+1)

    dp[0] = 1
    if 1 not in a:
        dp[1] = 1
    else:
        dp[1] = 0

    for i in range(2,n+1):
        if i  not in a:
            dp[i] = dp[i-1] + dp[i-2]
        else:
            dp[i] = 0
    print(dp[n]%MOD)




if __name__=="__main__":
    main()


Measured memory_bytes: 501740
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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;}

int main(){

    int N;
    cin >> N;
    ll ans;
    cin >> ans;
    for(int i = 1; i < N; i++){
        ll tmp;
        cin >> tmp;
        ans = lcm(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
string s,t;
const int N = 3e3+5;
int dp[N][N];
pii p[N][N];
main() {
    ios::sync_with_stdio(0);
    cin >> s >> t;
    s = "@" + s;
    t = "%" + t;
    int n = s.size() - 1;
    int m = t.size() - 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) {
            if (s[i] == t[j]) {
                dp[i][j] = dp[i-1][j-1] + 1;
                p[i][j] = {i-1,j-1};
            }else {
                if (dp[i-1][j] < dp[i][j-1]) {
                    dp[i][j] = dp[i][j-1];
                    p[i][j] = {i,j-1};
                }
                else {
                    dp[i][j] = dp[i-1][j];
                    p[i][j] = {i-1,j};
                }
            }
        }
    string ans;
    for (int a = n,b = m; a && b;) {
        if (s[a] == t[b]) ans+=s[a];
        pii x = p[a][b];
        a = x.first;
        b = x.second;
    }
    reverse(ans.begin(),ans.end());
    cout << ans;
}


Measured memory_bytes: 214940
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if(abs(a - b) <= (v - w) * t) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3652