akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define range 524289
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define _ <<" "<<

using namespace std;

typedef  long long int ll;
typedef vector <ll> vi;
typedef vector<vi> vvi;
typedef pair <ll, ll> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
typedef vector<iii> viii;


vi a;
vi dp;
int n;


vi seg;


ll query(int l, int r, int tl, int tr, int v){
    if(l>r) return LONG_MIN;
    if(l>tr||r<tl) return LONG_MIN;
    if(l>=tl&&r<=tr){
        return seg[v];
    }
    // cout<<l<<" "<<r<<" "<<tl<<" "<<tr<<endl;
    int mid = l +(r-l)/2;
    ll lol = query(l, mid, tl, tr, 2*v);
    ll cat = query(mid+1, r, tl, tr, 2*v+1);
    return max(lol, cat);
}



void update(int l, int r, ll val, int pos, int v){
    if(l>r) return;
    if(l==r){
        seg[v] = max(seg[v], val);
        // cout<<"here"<<endl;
        return;
    }

    int mid = l +(r-l)/2;
    if(pos<=mid) update(l, mid, val, pos, 2*v);
    else update(mid+1, r, val, pos, 2*v+1);
    seg[v] = max(seg[2*v+1], seg[2*v]);
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	// cin>>t;
	while(t--){
        cin>>n;
        a = vi(n+1);
        vi h(n+1);
        dp = vi(n+1);
        for (int i = 1; i <= n; ++i)
        {
            /* code */
            cin>>h[i];
        }
        for (int i = 1; i <= n; ++i)
        {
            /* code */
            cin>>a[i];
            dp[h[i]] = a[i];
        }

        seg = vi(4*(n+1)+5);
        ll res = 0;
        for (int i = 1; i <=n; ++i)
        {
            ll maxm = query(1, n, 1, h[i]-1, 1);
            if(h[i]==1) maxm = 0;
            dp[h[i]] = max(dp[h[i]], a[i]+maxm);
            res = max(dp[h[i]], res);
            update(1, n, dp[h[i]], h[i], 1);
        }

        cout<<res<<endl;





	}

    return 0;
}


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int n, a[100];
ll dp[100]; 
int main() {
  cin >> n;
  dp[0] = 1000;
  rep(i,n) cin >> a[i];

  for (int i = 1; i <= n; i++)
  {
    dp[i] = dp[i-1];
    for (int j = 0; j < i; j++)
    {
      ll v = dp[j] / a[j];
      dp[i] = max(dp[i], dp[j] + v*(a[i]-a[j]));
    } 
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3556
n = int(input())

memo = [0 for _ in range(45)]

def fib_memo(n):
    if memo[n] != 0:
        return memo[n]
    elif (n == 0) or (n == 1):
        return 1
    else:
        memo[n] = fib_memo(n-1) + fib_memo(n-2)
        return memo[n]
    
print(fib_memo(n))

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n,ans=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        int a;
        a = i*1.08;
        if(a == n) ans = i;
    }
if(ans != 0) cout << ans << endl;
else    cout <<":(" << endl;
}

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

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

  bool can = false;
  for (int i = 1; i < 10; i++) {
    if (can) break;
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        can = true;
      }
    }
  }

  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

int N;
string S;
int cnt[100010];

bool func()
{
	rep(i, 1, N)
	{
		if (cnt[i] > 0)
		{
			if (S[i] == 'o')
			{
				if (cnt[(i - 1 + N) % N] > 0)
				{
					cnt[(i + 1) % N]++;
				}
				else
				{
					cnt[(i + 1) % N]--;
				}
			}
			else
			{
				if (cnt[(i - 1 + N) % N] > 0)
				{
					cnt[(i + 1) % N]--;
				}
				else
				{
					cnt[(i + 1) % N]++;
				}
			}
		}
		else
		{
			if (S[i] == 'o')
			{
				if (cnt[(i - 1 + N) % N] > 0)
				{
					cnt[(i + 1) % N]--;
				}
				else
				{
					cnt[(i + 1) % N]++;
				}
			}
			else
			{
				if (cnt[(i - 1 + N) % N] > 0)
				{
					cnt[(i + 1) % N]++;
				}
				else
				{
					cnt[(i + 1) % N]--;
				}
			}
		}

		if (cnt[(i + 1) % N] == 0)
		{
			return false;
		}
	}

	rep(i, 0, N)
	{
		if (cnt[i] > 0)cout << 'S';
		else cout << 'W';
	}
	cout << endl;
	return true;
}

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

	cin >> N >> S;
	
	if (S[0] == 'o')
	{
		fill(cnt, cnt + N, 0);
		cnt[0] = 1;
		cnt[N - 1] = cnt[1] = 1;
		if (func())return 0;
		
		fill(cnt, cnt + N, 0);
		cnt[0] = 1;
		cnt[N - 1] = cnt[1] = -1;
		if (func())return 0;

		fill(cnt, cnt + N, 0);
		cnt[0] = -1;
		cnt[N - 1] = 1, cnt[1] = -1;
		if (func())return 0;

		fill(cnt, cnt + N, 0);
		cnt[0] = -1;
		cnt[N - 1] = -1, cnt[1] = 1;
		if (func())return 0;
	}
	else
	{
		fill(cnt, cnt + N, 0);
		cnt[0] = -1;
		cnt[N - 1] = cnt[1] = 1;
		if (func())return 0;

		fill(cnt, cnt + N, 0);
		cnt[0] = -1;
		cnt[N - 1] = cnt[1] = -1;
		if (func())return 0;

		fill(cnt, cnt + N, 0);
		cnt[0] = 1;
		cnt[N - 1] = 1, cnt[1] = -1;
		if (func())return 0;

		fill(cnt, cnt + N, 0);
		cnt[0] = 1;
		cnt[N - 1] = -1, cnt[1] = 1;
		if (func())return 0;
	}

	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1360
def onTile tile, x, y
  (0 <= x && x < tile[0].length) && (0 <= y && y < tile.length)
end

def onArrow tile, x, y
  tile[y][x] == ">" || tile[y][x] == "<" || tile[y][x] == "^" || tile[y][x] == "v"
end

def createTile width, height
  tile = Array.new
  height.times do
    tile << $stdin.gets.chomp.split("")
  end
  tile
end

def solve tile, x, y
  visited = Array.new(tile.length).map{Array.new(tile[0].length, false)}
  while (onTile(tile, x, y) && !visited[y][x] && onArrow(tile, x, y)) do
    visited[y][x] = true
    case tile[y][x]
    when ">" then
      x += 1
    when "v" then
      y += 1
    when "<" then
      x -= 1
    when "^" then
      y -= 1
    else
      #do nothing
    end
  end
  visited[y][x] ? "LOOP" : (x.to_s + " " + y.to_s)
end

height, width = $stdin.gets.chomp.split(" ").map(&:to_i)
while width > 0 && height > 0 do
  puts solve(createTile(width, height), 0, 0)
  height, width = $stdin.gets.chomp.split(" ").map(&:to_i)
end

Measured memory_bytes: 6840
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
typedef unsigned long long ui64;

int main(int argc, char *argv[]) {
  ui64 N, M;
  ui64 i, j;
  cin >> N >> M;

  vi a(M);
  vector<ui64> k(M, 0);

  REP(0, M, i) {
    cin >> a[i];
    ui64 b;
    cin >> b;
    
    REP(0, b, j) {
      ui64 t;
      cin >> t;
      k[i] |= (1 << (t-1));
    }
  }

  ui64 S = 1 << N;
  vi c(S, -1);
  c[0] = 0;
  REP(0, M, i) { // iterate over keys
    vi c_new(S);
    REP(0, S, j) {
      ui64 S0 = j & (~k[i]);
      //cout << "S: " << j << " k: " << k[i] << " S0: " << S0 << endl;
      if(c[S0] == -1) {
	c_new[j] = -1;
      }
      else {
	c_new[j] = a[i] + c[S0];
	if(c[j] != -1) {
	  c_new[j] = min(c_new[j], c[j]);
	}
      }
      //cout << c_new[j] << " ";
    }
    //cout << endl;
    c = c_new;

  }

  cout << c[S-1] << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n,k,x,y,sum=0;

int main(){
    cin>>n>>k>>x>>y;
    rep(i,0,n){
        if(i+1<=k){
            sum+=x;
        }else{
            sum+=y;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline

#複数入力
a,b=(int(x) for x in input().split())

def factorize(n):
    b = 2
    #本当は[]
    fct = [1]
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

print(len((set(factorize(a))&set(factorize(b)))))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
bool isPrime(long long x){
	for(long long i = 2; i * i <= x; i++) if(x % i == 0) return false;
	return true;
}
void init(){
	for(int i = 2; i <= 3000; i++) if(isPrime(i)) primes.push_back(i);
}
int main(){
	init();
	int n;
	cin >> n;
	unordered_map<long long, long long> rev, occ;
	for(int i = 0; i < n; i++){
		long long x; cin >> x;
		long long Norm = 1, Pair = 1;
		for(int v : primes){
			int cnt = 0;
			while(x % v == 0) x /= v, cnt++;
			cnt %= 3;
			if(!cnt) continue;
			if(cnt == 1){
				Norm *= v;
				Pair *= v;
				Pair *= v;
			} else {
				Norm *= v;
				Norm *= v;
				Pair *= v;
			}
		}
		if(x > 1){
			long long sq = sqrtl(x);
			while(sq * sq <= x) sq++;
			while(sq * sq > x) sq--;
			if(sq * sq == x){
				Norm *= x;
				Pair *= sq;
			} else {
				Norm *= x;
				Pair *= x;
				Pair *= x;
			}
		}
		rev[Norm] = Pair;
		rev[Pair] = Norm;
		occ[Norm]++;
		occ[Pair];
	}
	int ans = 0;
	for(auto it : occ) if(it.first != 1) ans += max(it.second, occ[rev[it.first]]);
	ans /= 2;
	if(occ[1]) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16784
#include<stdio.h>

int main(void){
    int a,b,c,d,p,y,ky;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&p);
    if (p <= c){
        if (b < a * p){
            y = b;
        }
        else{
            y = a * p;
        }
        printf("%d\n",y);
    }
    else{
        ky = b + (p - c) * d;
        if (ky < a * p){
            y = ky;
        }
        else{
            y = a * p;
        }
        printf("%d\n",y);
    }
    return 0;
}

Measured memory_bytes: 596
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	cnt := 0
	for i := 1; i < n-1; i++ {
		list := []int{a[i-1], a[i], a[i+1]}
		sort.Ints(list)
		if a[i] == list[1] {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 512
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    while(T --> 0)
    {
        string s;
        cin>>s;
        if(s[2]==s[3] and s[4]==s[5])
            cout<<"Yes";
        else
            cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	//6=>5=>6=>5...
	ll ans = (x/11)*2;
	x %= 11;
	if(x > 6)ans += 2;
	else if(x > 0) ans ++;
	cout << ans << endl; 
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int h1,m1,h2,m2,k;
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    int r=60*h2+m2-(60*h1+m1)-k;
    printf("%d",r);
    return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
LL facctorialMethod(int k);
int main(){
    LL k,s_len;
    string s;
    cin >> k;
    cin >> s;
    s_len = s.size();
    if(k < s_len) {
        cout << s.substr(0,k) << "..." << endl;
    }else{
        cout << s << endl;
    }

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3616
#絶対値小さくできるか？
#振動しそうなので
from itertools import dropwhile
from collections import deque
n=int(input())
ans=deque([["",n]])
def bfs(d):
    global ans
    l=len(ans)
    for i in range(l):
        x=ans.popleft()
        new1=[x[0]+"0",x[1]]
        if abs(new1[1])<abs((-2)**d):
            ans.append(new1)
        new2=[x[0]+"1",x[1]-(-2)**d]
        if abs(new2[1])<abs((-2)**d):
            ans.append(new2)
    if d!=0:
        bfs(d-1)
bfs(32)
#全探索

for i in ans:
    if i[1]==0:
        ans=list(dropwhile(lambda x:x=="0",i[0]))
        if len(ans)==0:
            print(0)
        else:
            print("".join(ans))
        break

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

void Fill_Reg (int x_st, int x_en, int y_st, int y_en, vector< vector<bool> > &fill)
{

  int i, j;

  for( i = y_st;  i < y_en;  i++ )
  {
    for( j = x_st; j < x_en;  j++ )
    {
      fill.at(i).at(j) = false;
    }
  }

  return ;

}

int main (void) 
{

  /* Variable_Proclamation */
  int W, H;    // input
  int N;    // input

  int i, j;    // subscript
  int count;


  /* Input, Array_Proclamation */
  cin >> W >> H >> N;
  vector<int> x(N), y(N);
  vector<int> a(N);

  vector< vector<bool> > region(H, vector<bool>(W, true));


  for(i=0; i<N; i++)
  {
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }


  /* Initialize */
  count = 0;


  /* Calculation */
  for(i=0; i<N; i++)
  {

    if( a.at(i) == 1 )
    {
      Fill_Reg(0, x.at(i), 0, H, region);
    }
    else if( a.at(i) == 2 )
    {
      Fill_Reg(x.at(i), W, 0, H, region);
    }
    else if( a.at(i) == 3 )
    {
      Fill_Reg(0, W, 0, y.at(i), region);
    }
    else if( a.at(i) == 4 )
    {
      Fill_Reg(0, W, y.at(i), H, region);
    }

  }

  for(i=0; i<H; i++)
  {
    for(j=0; j<W; j++)
    {
      if(region.at(i).at(j) == true)
      {
        count++;
      }
    }
  }
  

  /* Output */
  cout << count << endl;


  return 0;

}


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

signed main() {
        int n;
        cin >> n;
        vector<long long> x(n);
        for (int i = 0; i < n; i ++) cin >> x[i];
        vector<long long> d(n - 1);
        for (int i = 0; i < n - 1; i ++) d[i] = x[i + 1] - x[i];
        long long m, k;
        cin >> m >> k;
        vector<long long> a(m);
        for (int i = 0; i < m; i ++) { 
                cin >> a[i];
                a[i] --;
        }
        vector<long long> move(n - 1);
        for (int i = 0; i < n - 1; i ++) move[i] = i;
        for (int i = 0; i < m; i ++) swap(move[a[i]], move[a[i] - 1]);
        vector<vector<long long> > swp(n - 1, vector<long long> (61));
        for (int i = 0; i < n - 1; i ++) swp[move[i]][0] = i;
        for (int i = 1; i < 61; i ++) { 
                for (int j = 0; j < n - 1; j ++) { 
                        swp[j][i] = swp[swp[j][i - 1]][i - 1];
                }
        }
        for (int b = 0; b < 61; b ++) {
                if ((k >> b) & 1) {
                        vector<long long> next(n - 1);
                        for (int i = 0; i < n - 1; i ++) next[swp[i][b]] = d[i];
                        for (int i = 0; i < n - 1; i ++) d[i] = next[i];
                }
        }
        long long prev = x[0];
        cout << prev << endl;
        for (int i = 0; i < n - 1; i ++) { 
                prev = d[i] + prev;
                cout << prev << endl;
        }
        return 0;
}                                         


Measured memory_bytes: 55920
let partition (a : int array) p r =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let rec doit i j =
    if j = r then begin
      swap (i + 1) r;
      i + 1
    end else if a.(j) <= a.(r) then begin
      swap (i + 1) j;
      doit (i + 1) (j + 1)
    end else doit i (j + 1) in
  doit (p - 1) p

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  let k = partition a 0 (n - 1) in
  Array.iteri (fun i e -> Printf.printf (if i = 0 then "%d" else if i = k then " [%d]" else " %d") e) a;
  print_newline ()

Measured memory_bytes: 5380
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _dbg(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _dbg(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_dbg(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=2e5+1;
int a[N];
int32_t main() {

    string s;
    cin>>s;
    int n=s.size(),ans=0;
    for(int i=0;i<n;++i){
        if(i)a[i]=a[i-1];
        if(s[i]=='A')a[i]++;
        else a[i]=0;
        if(i>=2&&s[i]=='C'&&s[i-1]=='B'&&s[i-2]=='A'){
            s[i]='A';
            a[i]=a[i-2];
            ans+=a[i];
        }
    }
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)
struct R {int from,to,len;};
vector<int> c;
vector<R> s;
int main(){
  int n,k,t;
  bool b;
  while(cin>>n>>k,n){
    b=0;
    c.clear();
    loop(_,k){
      cin>>t;
      if(!t)b=1;
      else c.push_back(t);
    }
    sort(c.begin(),c.end());
    loop(i,c.size()){
      if(!s.empty()&&s.back().to+1==c[i]){
        s.back().to=c[i];
        s.back().len++;
      }else{
        s.push_back({c[i],c[i],1});
      }
    }
    int m=0;
    loop(i,s.size()){
      m=max(m,s[i].len);
    }
    if(b){
      m++;
      loop(i,s.size()){
        if(!i)continue;
        if(s[i-1].to+2==s[i].from){
          m=max(m,s[i-1].len+1+s[i].len);
        }
      }
    }
    cout<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N, K, S;
  cin >> N >> K >> S;

  rep(i, K) cout << S << " ";
  int n = (S == 1e9) ? 1 : S+1;
  rep(i, N-K) cout << n << " ";
  cout << endl;

}

Measured memory_bytes: 1280
#include<cstdio>
using namespace std;
int main(){
    long n,a[100000],sum=0,d[100000],k;
    scanf("%ld",&n);
    for(long i=0;i<n;i++){
        scanf("%ld",&a[i]);
        sum+=a[i];
    }
    if(sum%(n*(n+1)/2)){
        printf("NO\n");
        return 0;
    }
    k=sum/(n*(n+1)/2);
    for(long i=0;i<n;i++){
        d[i]=a[i]-a[(i+1)%n]+k;
    }
    sum=0;
    for(long i=0;i<n;i++){
        if(d[i]%n||d[i]<0){
            printf("NO\n");
            return 0;
        }
        else{
            sum+=d[i];
        }
    }
    if(sum==n*k){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N, C, K;
  cin >> N >> C >> K;
  int T[N];
  for (int i = 0; i < N; i++) cin >> T[i];

  sort(T, T + N);

  int ans = 1; // 必要なバスの数
  int bus = T[0] + K; // バスの出る時間は最大限遅くする
  int cnt = 1; // バスに乗っている客の数
  for (int i = 1; i < N; i++) {
    if (T[i] <= bus && cnt < C) {
      cnt++;
    } else {
      ans++;
      bus = T[i] + K;
      cnt = 1;
    }
  }

  // 解答
  cout << ans << endl;

  return 0;
}


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

class DisjointSet{
public:
  vector<int> rank,p;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i=0;i<size;i++)makeSet(i);
  }

  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }

  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }

  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }

  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
    }
    else {
      p[x]=y;
      if(rank[x]==rank[y]){
	rank[y]++;
      }
    }
  }

  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
};

int main()
{
  int n,q;
  int t,a,b;

  cin>>n>>q;

  DisjointSet ds(n);

  for(int i=0;i<q;i++){
    cin>>t>>a>>b;
    if(t==0)ds.unite(a,b);
    else {
      if(ds.same(a,b))cout<<1<<endl;
      else cout<<0<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N, K;
  cin >> N >> K;
  vector<int>A(N);
  for (int i = 0; i < N; i ++) cin >> A[i];
  for (int i = 0; i < N - K; i ++) {
    cout << (A[i] < A[i + K] ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 4044
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, W; cin >> n >> W;
	vector<int> w(n), v(n);
	rep(i, 0, n - 1)cin >> w[i] >> v[i];
	int ng = 1001001001;
	vector<vector<int>> dp(n + 1, vector<int>(100100, ng));
	dp[0][0] = 0;

	rep(i, 0, n - 1)rep(j, 0, 1000 * (i + 1))
	{
		if (dp[i][j] == ng)continue;

		dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
		if (dp[i][j] + w[i] <= W)dp[i + 1][j + v[i]] = min(dp[i + 1][j + v[i]], dp[i][j] + w[i]);
	}
	int ans = 0;
	rep(i, 0, 100010)if (dp[n][i] != ng)ans = i;
	cout << ans << endl;
}


Measured memory_bytes: 40192
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const long long llinf=LLONG_MAX;
const int inf=INT_MAX;
const int nmax=1e5+5;
const int mod=1e9+7;
using namespace std;
int i,n,nr=1,x;
int main()
{
    //freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n;
    for(i=1;i<=n;i++)
	{
		cin>>x;
		if(!(x&1))nr*=2;
	}
	cout<<pow(3,n)-nr<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
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; }

signed main(){
    int n, k;
    cin >> n >> k;
    vector<bool> have_snack(n);
    rep(i, k){
        int d;
        cin >> d;
        rep(i, d){
            int a;
            cin >> a;
            --a;
            have_snack[a] = true;
        }
    }

    int ans = 0;
    rep(i, n){
        if(!have_snack[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import heapq
n, m = map(int, input().split(" "))
liste = list(map(int, input().split(" ")))
liste = [(-1 * i) for i in liste]
heapq.heapify(liste)
for i in range(m):
    maxi = heapq.heappop(liste)
    maxi /= 2
    heapq.heappush(liste, int(maxi))
sum = 0
for i in liste:
    sum += (-1 * i)
print(sum)

Measured memory_bytes: 14180
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N){
  ll ans=0;
  FOR(i,1,1000001){
    if(i*i>N)break;
    if(N%i==0){
      ans=i;
    }
  }
  cout<<ans+(N/ans)-2<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXH = 400, MAXW = 400;

char grid[MAXH + 2][MAXW + 2];
bool vis[MAXH + 2][MAXW + 2];

#define mp make_pair

queue<pair<int, int>> q;
void go(int x1, int y1, int x2, int y2) {
	char a = grid[x1][y1], b = grid[x2][y2];
	if(!vis[x2][y2] && (a == '.' && b == '#' || a == '#' && b == '.')) {
		vis[x2][y2] = true;
		q.push(mp(x2, y2));
	}
}

int main() {
	int H, W;
	cin >> H >> W;
	for(int i = 0; i < H; i++)
		cin >> grid[i];
	ll ans = 0;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			if(grid[i][j]) {
				q.push(mp(i, j));
				vis[i][j] = true;
				int b = 0, w = 0;
				do {
					pair<int, int> xy = q.front();
					q.pop();
					int x = xy.first, y = xy.second;
					if(grid[x][y] == '.')
						b++;
					else
						w++;
					if(x + 1 < H)
						go(x, y, x + 1, y);
					if(x > 0)
						go(x, y, x - 1, y);
					if(y + 1 < W)
						go(x, y, x, y + 1);
					if(y > 0)
						go(x, y, x, y - 1);
				} while(!q.empty());
				ans += (ll)b * w;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
function Main(input) {
  let args = input.trim().split("\n");
  let n = parseInt(args[0], 10);

  let table = Array.from(new Array(4), () => new Array(13).fill(false));
  for (let i = 0; i < n; i++) {
    let mark = args[i + 1].split(" ")[0];
    let value = parseInt(args[i + 1].split(" ")[1], 10);
    if (mark === "S") {
      table[0][value - 1] = true;
    }
    if (mark === "H") {
      table[1][value - 1] = true;
    }
    if (mark === "C") {
      table[2][value - 1] = true;
    }
    if (mark === "D") {
      table[3][value - 1] = true;
    }
  }

  const m = ["S", "H", "C", "D"];
  for (let mark = 0; mark < 4; mark++) {
    for (let v = 0; v < 13; v++) {
      if (table[mark][v] === false) {
        console.log(m[mark] + " " + String(v + 1));
      }
    }
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15180
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] kokuban=new int[3];
		for(int i=0;i<3;i++) {
		try{kokuban[i]=sc.nextInt();}
		catch(Exception e) {//System.out.print(e);
		System.exit(1);}
		}
		int K=0;
		try {K=sc.nextInt();}
		catch(Exception e) {//System.out.print(e);
		System.exit(1);}

	/*	for(int i=0;i<3;i++) {
			System.out.print(kokuban[i]+" ");
			}
*/
		//System.out.println("");
		//System.out.println(K);
		for(int i=0;i<3;i++) {
		if(kokuban[i]<1||kokuban[i]>50) {
			//System.out.println(i+"番目の値が不正です");
			System.exit(1);
			}
		}
		if(K<1||K>10) {
			//System.out.println("Kの値が不正です");
			System.exit(1);
			}
		int max=-1;
		for(int z=0;z<K;z++) {
		if(kokuban[0]>=kokuban[1]&&kokuban[0]>=kokuban[2]) {max=0;}
		else if(kokuban[1]>=kokuban[2]&&kokuban[1]>=kokuban[0]) {max=1;}
		else if(kokuban[2]>=kokuban[0]&&kokuban[2]>=kokuban[0]) {max=2;}
		kokuban[max]*=2;
		}
		int sum=0;
		for(int i=0;i<3;i++)sum+=kokuban[i];
		System.out.print(sum);
		}
	}


Measured memory_bytes: 20820
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
cnt = defaultdict(int)

for i in a:
    cnt[i] += 1

ans = 1
if n % 2 == 0:
    for _ in range(n // 2):
        ans *= 2
        ans %= mod
    if cnt[0] == 0:
        check = [2 * i + 1 for i in range(n // 2)]
        for i in check:
            if cnt[i] != 2:
                ans = 0
                break
    else:
        ans = 0

else:
    for _ in range((n-1)//2):
        ans *= 2
        ans %= mod
    if cnt[0] == 1:
        check = [2 * i + 2 for i in range((n-1)//2)]
        for i in check:
            if cnt[i] != 2:
                ans = 0
                break

    else:
        ans = 0

print(ans)



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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

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

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

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

  sort(p.begin(), p.end());
  ll ans = 0;
  for (ll i = 0; i < k; ++i) {
    ans += p[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3596
// 5_abc142_e
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e9)
#define MOD (1000000007)
typedef long long ll;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    vector<vector<int>> c(m);
    rep(i, m){
        cin >> a[i] >> b[i];
        c[i].resize(b[i]);
        rep(j, b[i]){
            cin >> c[i][j];
            c[i][j]--;
        }
    }

    vector<int> dp(1 << n);
    rep(i, 1 << n){
        dp[i] = INF;
    }
    dp[0] = 0;

    rep(i, m){
        int state = 0;
        rep(j, b[i]){
            state |= 1 << c[i][j];
        }

        rep(j, 1 << n){
            dp[j | state] = min(dp[j | state], dp[j] + a[i]);
        }
    }

    int ans = dp[(1 << n) - 1];
    if(ans == INF) cout << - 1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
a = int(input())

b = [[i-1,i,i+1]for i in range(0,10)]
b = [[j for j in i if j >= 0 and j < 10]for i in b]

c = [i for i in range(1,10)]

for i in c:
  istr = str(i)
  for k in b[int(istr[-1])]:
    n = i*10 + k
    c.append(n)
  if len(c) >= a:
    break

print(c[a-1])

Measured memory_bytes: 7320
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<list>
using namespace std;
 
#define MAX_N 500000
#define INF 1145141919
 
vector<int>G[MAX_N];
list<int> out;
bool V[MAX_N];
int N, M, b, c[MAX_N], d;
int indeg[MAX_N];
queue<int>Q;
 
void bfs(int s) {
    Q.push(s);
    V[s] = true;
    while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        out.push_back(u);
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            indeg[v]--;
            if (indeg[v] == 0 && V[v] == false) { V[v] = true; Q.push(v); }
        }
    }
}
 
void Tsort() {
    for (int i = 0; i < N; i++) {
        indeg[i] = 0;
    }
    for (int u = 0; u < N; u++) {
        for (int i = 0; i < G[u].size(); i++) {
            int v = G[u][i];
            indeg[v]++;
        }
    }
    for (int u = 0; u < N; u++) {
        if (indeg[u] == 0 && V[u] == false) {
            bfs(u);
        }
    }
    b = 0; d = 0;
    for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
        cout << *it + 1 << endl;
        c[b] = *it;
        if (b >= 1) {
            for (int i = 0; i < G[c[b - 1]].size(); i++) {
                if (G[c[b - 1]][i] == c[b]) {
                    goto F;
                }
            }
            d = 1;
        F:;
        }
        b++;
    }
    cout << d << endl;
}
 
int main() {
    int s, t;
    for (int i = 0; i < MAX_N; i++) { G[i].clear(); }
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        scanf("%d%d",&s,&t); s--; t--;
        G[s].push_back(t);
    }
    Tsort();
    return 0;
}

Measured memory_bytes: 15644
import java.util.*
import kotlin.math.sin

fun main() {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    val t = sc.next()
    val cnt = calc(s, t)
    println(t.length - cnt)
}

fun calc(s: String, t: String): Int {
    var oldCnt = 0
    var newCnt = 0
    s.forEachIndexed { index, c ->
        val index2 = getIndex(index, t.length)
        (0..index2).forEach { tindex ->
            val lastIndex = getLastIndex(s, t, index)
            newCnt = check(s, t, index, tindex, lastIndex)
            if (oldCnt < newCnt) {
                oldCnt = newCnt
            }
        }
    }
    if (oldCnt < newCnt) oldCnt = newCnt
    return oldCnt
}

fun check(s: String, t: String, index: Int, index2: Int, lastIndex: Int): Int {
    var sindex = index
    if (s.length - sindex - 1 < t.length - index2 - 1) return 0
    var cnt = 0
    (index2..lastIndex).forEach {
        if (sindex >= s.length) return cnt
        if (s[sindex] == t[it]) cnt += 1
        sindex++
    }
    return cnt
}

fun getIndex(index: Int, length: Int): Int {
    return if (index > length - 1) length - 1 else index
}

fun getLastIndex(s: String, t: String, sIndex: Int): Int {
    return t.length - 1
}

Measured memory_bytes: 45624
q="C"
if q=="A":
	S=input()
	print(sum((i=="+")-(i=="-")for i in S))
if q=="B":
	a=int(input())
	b=sum(int(i) for i in str(a))
	print("Yes" if a%b==0 else "No")
if q=="C":
	N,K=map(int,input().split())
	A=[int(i) for i in input().split()]
	func=lambda a,b:int(a/b) if a%b==0 else int(a/b+1)
	print(1+func((len(A)-K),K-1))
if q=="D":
	K=int(input())
	S=lambda x:sum(int(i) for i in str(x))
	#for i in range(1,110):
	r=0
	for i in range(1,10**15):
		a=i
		b=int(K/10)*10+9
		if a/S(a)<=b/S(b):
			print(a)
			r+=1
			if r==K:
				break



Measured memory_bytes: 13880
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
// const int N = 2005;


int32_t main() {

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

    int a,b,c;
    cin >> a >> b >> c;
    if((c > a and c < b) || (c < a and c > b))
    	cout << "Yes\n";
    else
    	cout << "No\n";
}

Measured memory_bytes: 256
s = input()
t = input()

n = len(s)
m = len(t)
s += s
next = [[-1] * 26 for _ in range(len(s) + 1)]

# 場所iから、次の文字jへの場所、みたいなテーブル
# 後ろから更新してくと最短距離になる
# next[i]は場所iを含む
for i in range(len(s) - 1, -1, -1):
    c = ord(s[i]) - ord('a')
    for j in range(26):
        if j == c:
            next[i][j] = i
        else:
            next[i][j] = next[i + 1][j]
now = 0
ans = 0
for i in range(m):
    c = ord(t[i]) - ord('a')
    if next[now][c] == -1:
        print(-1)
        exit()
    ans += next[now][c] - now + 1
    now = next[now][c] + 1
    if now >= n:
        now -= n
print(ans)


Measured memory_bytes: 132704
n=int(input())
l=list(map(int,input().split()))
dp=[10**55 for i in range(n)]
dp[0]=0
dp[1]=abs(l[1]-l[0])
for i in range(2,n):
    dp[i] = min(dp[i], dp[i-1] + abs(l[i] - l[i - 1]))
    dp[i] = min(dp[i], dp[i-2] + abs(l[i] - l[i - 2]))
print(dp[n-1])



Measured memory_bytes: 90888
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<ll,ll> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll A,B,C;

int main(){
    cin>>A>>B>>C;

    ll ans;
    if(A&1 && B&1 && C&1){
        ans=min(A*B,min(B*C,C*A));
    }else{
        ans=0;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3584
#include <stdio.h>

int main() {
  int A, B, ans;
  scanf("%d %d", &A, &B);
  if (A == 1) {
    if (B == 2) {
      ans = 3;
    }
    else {
      ans = 2;
    }
  }
  else if (A == 2) {
    if (B == 3) {
      ans = 1;
    }
    else {
      ans = 3;
    }
  }
  else{
    if (B == 1) {
      ans = 2;
    }
    else {
      ans = 1;
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A, B, K;
        A = scanner.nextInt();
        B = scanner.nextInt();
        K = scanner.nextInt();

        for (int i = 0; i < K; i++) {
            if (i % 2 == 0) {
                B += A / 2;
                A /= 2;
            } else {
                A += B / 2;
                B /= 2;
            }
        }
        System.out.printf("%d %d\n", A, B);
    }
}

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

using namespace std;

int main() {
	int k, n; cin >> k >> n;
	vector<int> a(n);
	for (auto& e : a) cin >> e;
	int ans = k;
	for (int i = 0; i < n; ++i) {
		int t1 = a[(i + 1) % n] - a[i];
		t1 = (t1 < 0 ? k + t1 : t1);
		ans = min(ans, k - t1);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1152
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

P = [None] + P
C = [None] + C

all_max = C[1]
for st in range(1, N + 1):
    p = P[st]
    scores = [C[p]]

    while p != st and len(scores) < K:
        p = P[p]
        scores.append(C[p])

    num_elem = len(scores)
    all_sum = sum(scores)

    q, r = divmod(K, num_elem)

    max_ = scores[0]
    temp = scores[0]

    max_r = scores[0]
    temp_r = scores[0]
    for x in range(1, num_elem):
        if x < r:
            temp_r += scores[x]
            max_r = max(max_r, temp_r)

        temp += scores[x]
        max_ = max(max_, temp)

    temp_max = scores[0]
    if all_sum > 0 and q > 0:
        if r > 0:
            temp_max = max(all_sum * (q - 1) + max_, all_sum * q + max_r)
        else:
            temp_max = all_sum * (q - 1) + max_
    else:
        temp_max = max_

    all_max = max(all_max, temp_max)


print(all_max)


Measured memory_bytes: 81080
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	long long N, K;
	long long a[100001] = { 0 };

	cin >> N >> K;

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

	long long count = 0;
	for (long long i = 1; i <= K; i++)
	{
		count += a[i];
		if (count >= K)
		{
			cout << i << endl;
			break;
		}
	}

	return 0;
}




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

using namespace std;

using ll = long long;

template<class T>
std::vector<std::pair<T, T>> PrimeFactorization(T n) {
    std::vector<std::pair<T, T>> pf;
    T m = n;
    for (T i = 2; i * i <= n; ++i) {
        if (m % i != 0) continue;
        T cnt = 0;
        while (m % i == 0) { ++cnt; m /= i; }
        pf.emplace_back(std::make_pair(i, cnt));
    }
    if (1 < m) pf.emplace_back(std::make_pair(m, 1));

    return pf;
}

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

    int n;
    cin >> n;

    map<int, int> pm;
    for (int i = 2; i <= n; ++i) {
        auto pf = PrimeFactorization(i);
        for (const auto &it : pf) {
            pm[it.first] += it.second;
        }
    }

    vector<int> cnt;
    for (const auto &it : pm)
        cnt.push_back(it.second);
    sort(cnt.begin(), cnt.end());

    ll ans = 0;
    const int size = cnt.size();
    for (int i = 0; i < size; ++i) {
        if (74 <= cnt[i]) ++ans;

        for (int j = i + 1; j < size; ++j) {
            if (2 <= cnt[i] && 24 <= cnt[j]) ++ans;
            if (24 <= cnt[i] && 2 <= cnt[j]) ++ans;

            if (4 <= cnt[i] && 14 <= cnt[j]) ++ans;
            if (14 <= cnt[i] && 4 <= cnt[j]) ++ans;

            for (int k = j + 1; k < size; ++k) {
                if (2 <= cnt[i] && 4 <= cnt[j] && 4 <= cnt[k]) ++ans;
                if (4 <= cnt[i] && 2 <= cnt[j] && 4 <= cnt[k]) ++ans;
                if (4 <= cnt[i] && 4 <= cnt[j] && 2 <= cnt[k]) ++ans;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256