akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;

ll n;
char s[100001];
ll lj[100001], ljo[100001], ri[100001], roi[100001], joi;

int main() {
  scanf("%lld%s", &n, s);
  for (ll i = 0; i < n; i++) {
    if (i == 0) lj[i] = ljo[i] = joi = 0;
    else lj[i] = lj[i - 1], ljo[i] = ljo[i - 1];
    if (s[i] == 'J') lj[i]++;
    if (s[i] == 'O') ljo[i] += lj[i];
    if (s[i] == 'I') joi += ljo[i];
  }
  for (ll i = n - 1; i >= 0; i--) {
    if (i == n - 1) ri[i] = roi[i] = 0;
    else ri[i] = ri[i + 1], roi[i] = roi[i + 1];
    if (s[i] == 'I') ri[i]++;
    if (s[i] == 'O') roi[i] += ri[i];
  }
  ll ans = max(ljo[n - 1], roi[0]);
  for (ll i = 0; i < n - 1; i++) {
    ans = max(ans, lj[i] * ri[i + 1]); // O
    ans = max(ans, roi[i + 1]); // J
    ans = max(ans, ljo[i]); // I
  }
  printf("%lld\n", ans + joi);
}



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

void move_N(int D[]){
	int tmp=D[0];
	D[0]=D[1];
	D[1]=D[5];
	D[5]=D[4];
	D[4]=tmp;
}
void move_S(int D[]){
	int tmp=D[0];
	D[0]=D[4];
	D[4]=D[5];
	D[5]=D[1];
	D[1]=tmp;
}
void move_E(int D[]){
	int tmp=D[0];
	D[0]=D[3];
	D[3]=D[5];
	D[5]=D[2];
	D[2]=tmp;
}
void move_W(int D[]){
	int tmp=D[0];
	D[0]=D[2];
	D[2]=D[5];
	D[5]=D[3];
	D[3]=tmp;
}
void move_right(int D[]){//上から見て時計回り
	int tmp=D[1];
	D[1]=D[2];
	D[2]=D[4];
	D[4]=D[3];
	D[3]=tmp;
}

int get_up(int D[]){
	int count[6];
	int min=0;
	for(int i=0;i<6;i++){
		count[i]=0;
		for(int j=0;j<6;j++){
			if(D[i]==D[j]){
				count[i]++;
			}
		}
		if(count[min]>count[i]){
			min=i;
		}
	}

	return min;
}

void set_D(int D[],int up){
	for(int i=0;i<3;i++){
		if(D[0]==up){
			break;
		}
		move_N(D);
	}
	for(int i=0;i<3;i++){
		if(D[0]==up){
			break;
		}
		move_E(D);
	}
}
void show(int D[]){
	for(int i=0;i<6;i++){
		printf("%d ",D[i]);
	}printf("\n");
}
int calc(int D0[],int D1[]){
	//D0を基準に、D1を回し検証
	//D0の上を決定する。
	int up=get_up(D0);
	int flag=0;

	set_D(D0,D0[up]);
	
	//printf("\n\n");
	
	for(int i=0;i<3;i++){
		//show(D1);
		if(D1[0]==D0[0]){
			flag=1;
			break;
		}
		move_N(D1);
	}
	if(flag==0){//printf(".\n");
		for(int i=0;i<3;i++){
			//show(D1);
			if(D1[0]==D0[0]){				
				break;
			}
			move_E(D1);
		}		
	}
	//printf("//\n");
	for(int i=0;i<3;i++){
		//show(D1);
		if(D1[1]==D0[1]){
			break;
		}
		move_right(D1);
	}
	//show(D1);
	for(int i=0;i<6;i++){
		if(D0[i]!=D1[i]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 1;
}

int main(){
	int D0[6],D1[6];

	for(int i=0;i<6;i++){
		scanf("%d",&D0[i]);
	}
	for(int i=0;i<6;i++){
		scanf("%d",&D1[i]);
	}

	
	calc(D0,D1);
	

	return 0;
}


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

public class Main {
	private static final byte MASK_RIGHT = 0x0F;//右4bit数値化用マスク
	private static int[][] paper = new int[10][10];//都合の良い方眼紙

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 128);
		String sLine;
		while ((sLine = reader.readLine()) != null) {
			droppingInk(sLine.charAt(0) & MASK_RIGHT, sLine.charAt(2) & MASK_RIGHT, sLine.charAt(4) & MASK_RIGHT);
		}
		calcResult();
	}

	/**
	 *都合の良い滴下
	 */
	private static void droppingInk(int x, int y, int size) {
		sinking(x, y - 1);
		sinking(x - 1, y);
		sinking(x, y);
		sinking(x + 1, y);
		sinking(x, y + 1);
		if (size == 1) {
			return;
		}

		sinking(x - 1, y - 1);
		sinking(x + 1, y - 1);
		sinking(x - 1, y + 1);
		sinking(x + 1, y + 1);
		if (size == 2) {
			return;
		}

		sinking(x, y - 2);
		sinking(x - 2, y);
		sinking(x + 2, y);
		sinking(x, y + 2);
	}

	/**
	 * 床は汚さないようにする
	 */
	private static void sinking(int x, int y) {
		if (x >= 0 && x < 10 && y >= 0 && y < 10) {
			paper[x][y]++;
		}
	}

	/**
	 *紙の染みを数え、損害を報告する
	 */
	private static void calcResult() {
		int white = 0;//綺麗な部分
		int max = 0;//一番ひどい汚れ
		for (int[] row : paper) {
			for (int colum : row) {
				if (colum == 0) {
					white++;
				} else if (colum > max) {
					max = colum;
				}
			}
		}
		System.out.println(white);
		System.out.println(max);
	}
}

Measured memory_bytes: 16852
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (true) {
        int N; cin >> N;
        if (N == 0) break;
        int ans = INF;
        for (int z = 0; z*z*z <= N; z++) {
            for (int y = 0; y*y <= N - z*z*z; y++) {
                int x = N - z*z*z - y*y;
                chmin(ans,x+y+z);
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 3132
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

int main(void)
{
	ll N, K,answer = 0;
	cin >> N >> K;

	//bを固定する。

	if (K == 0) {
		cout << N*N << endl;
		return 0;
	}

	for (ll b = K + 1; b <= N; b++) {
		answer += N / b * (b - K) + std::max(0LL, N % b - K + 1);
	}

	cout << answer << endl;

	return 0;
}



Measured memory_bytes: 256
use proconio::input;
// use proconio::marker::{Bytes, Chars};

fn main() {
    input! {
        n: i128,
        a: [i128; n],
    }

    let mut height = a[0];
    let mut sum = 0;

    for person in a {
        if height > person {
            sum += height - person;
        } else {
            height = person;
        }
    }
    println!("{}", sum);
}

Measured memory_bytes: 7192
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define lli long long int
#define MOD 1000000007
#define MAX 200005
/*方針

1色についてのみ注目する -> 注目する色:C,注目しない色:Xとする
同じ色はいくつ並んでいても出来上がるパターン数は同じなので、1個に固定する
先頭にXがあっても無視できるから先頭はCとする
C,CXC,CXCXCという列のみが存在する

CXC...XCXから出来上がる列全体を(CXC...XCX)と表記する

(CXC...XCXC)=(CXC...XC)XC + (CXC...XC)CC
*/
lli ans = 0;
lli N;
lli C[MAX];
lli DP[MAX];
lli TMP[MAX];

void solve()
{
    cin >> N;
    DP[0] = 1;
    for (int i = 1; i <= N; i++)
    {
        cin >> C[i];
        if (C[i] == C[i-1])
        {
            DP[i] = DP[i - 1];
        }
        else
        {
            DP[i] = (DP[i - 1] + TMP[C[i]]) % MOD;
            TMP[C[i]] += DP[i - 1];
            TMP[C[i]] %= MOD;
        }
    }
    ans = DP[N];
};
int main()
{
    solve();
    cout << ans << endl;
    return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  int ans = 0;

  for (int i = 0; i < N; i++)
  {
    int x;
    cin >> x;
    ans += min(abs(x - 0), abs(x - K));
  }

  cout << ans * 2 << endl;
}


Measured memory_bytes: 256
import numpy as np

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
for i, a in enumerate(A):    
    ans += B[a-1]
    
A_ = [-100] + A[:-1]
A_ = np.array(A_)
A = np.array(A)

A_diff = A - A_

for j in A[A_diff == 1] -1:
    ans += C[j-1]
print(ans)    

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

int main(void)
{
    int N;
    cin >> N;
    string S;
    bool flag = false;

    for (int i = 0; i < N; i++) {
        cin >> S;
        if (S == "Y") {
            flag = true;
            break;
        }
    }

    if (flag) cout << "Four" << endl;
    else cout << "Three" << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let s:String = r.readl();

    let mut ans = "YES";

    let s_sp:Vec<&str> = s.split("eraser").collect();

    for x in s_sp {
        if(x != ""){
            let x_sp:Vec<&str> = x.split("erase").collect();
            for y in x_sp {
                if(y != "") {
                    let y_sp:Vec<&str> = y.split("dreamer").collect();
                    for z in y_sp {
                        if( z != ""){
                            let z_sp:Vec<&str> = z.split("dream").collect();
                            for d in z_sp {
                                if(d != ""){
                                    if(d.len() != 0) {
                                        ans = "NO";
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    println!("{}",ans);

}


Measured memory_bytes: 4352
n=int(input())
S=[0,]*14
H=[0,]*14
C=[0,]*14
D=[0,]*14
for i in range(0,n):
    suit,num=map(str,input().split())
    if suit=='S':
        S[int(num)]=1
    elif suit=='H':
        H[int(num)]=1
    elif suit=='C':
        C[int(num)]=1
    else:
        D[int(num)]=1
for i in range(1,14):
    if S[i]==0:
        print("S "+str(i))
for i in range(1,14):
    if H[i]==0:
        print("H "+str(i))
for i in range(1,14):
    if C[i]==0:
        print("C "+str(i))
for i in range(1,14):
    if D[i]==0:
        print("D "+str(i))


Measured memory_bytes: 5604
using System;
class Program
{
	static void Main(string[] args)
	{
		string s = Console.ReadLine();
		char[] c = s.ToCharArray();
      	int status = 0;
		for(int i = 0; i < c.Length; i++){
          if(c[i] == c[0]){
            status++;
          }
          if(c[i] == c[1]){
            status++;
          }
          if(c[i] == c[2]){
            status++;
          }
          if(c[i] == c[3]){
            status++;
          }
        }
      	
      	if(status == 8){
          Console.WriteLine("Yes");
        }else{
          Console.WriteLine("No");
        }
	}
}

Measured memory_bytes: 13140
#include <stdio.h>

int main()
{
	int r,g,b;
	scanf("%d %d %d",&r,&g,&b);
	if((100*r+10*g+b)%4==0)
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 128
from fractions import gcd
from math import sqrt


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main():
    A, B = map(int, input().split())
    C = gcd(A, B)
    if (A == 1 or B == 1):
        print(1)
        exit(0)
    if (C == 1):
        print(1)
        exit(0)
    arr = factorization(C)
    # print(arr)
    print(len(arr) + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5180
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string a, b; cin >> a >> b;
	while (a.size () < b.size ()) {
		a = '0' + a;
	}
	while (b.size () < a.size ()) {
		b = '0' + b;
	}
	cout << ( a > b ? "GREATER" : a < b ? "LESS" : "EQUAL" ) << endl;
	return 0;
}

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

const int maxn = 2e5 + 10;
int a[maxn], b[maxn], c[maxn], zero[50], one[50], n;

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i ++)
        scanf("%d", &a[i]);
    for(int i = 0; i < n; i ++)
        scanf("%d", &b[i]);
    int ans = 0;
    for(int bit = 0; bit <= 28; bit ++) {
        int t = 1 << bit, k = 1 << bit + 1;
        for(int i = 0; i < n; i ++)
            c[i] = b[i] % k;
        sort(c, c + n);
        int cnt = 0, l, r;
        for(int i = 0; i < n; i ++) {
            r = lower_bound(c, c + n, 2 * t - a[i] % k) - c - 1;
            l = lower_bound(c, c + n, t - a[i] % k) - c;
            cnt += max(0, r - l + 1);
            r = lower_bound(c, c + n, 4 * t - a[i] % k) - c - 1;
            l = lower_bound(c, c + n, 3 * t - a[i] % k) - c;
            cnt += max(0, r - l + 1);
        }
        ans += cnt % 2 << bit;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n,r; cin>>n>>r;
    if(n>=10) cout<<r<<endl;
    else cout<<r+100*(10-n)<<endl;
}

Measured memory_bytes: 256
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    string s; cin >> s;
    int N = s.length(), ans = 0;
    for(int bit=0; bit<(1<<(N-1)); bit++) {
        int tmp = 0, sum = 0;
        for(int i=0; i<N; i++) {
            tmp = tmp * 10 + (s[i] - '0');
            if(bit >> i & 1) {
                sum += tmp;
                tmp = 0;
            } 
        }
        sum += tmp;
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long int32;
typedef unsigned long uint32;
typedef long long int64;
typedef unsigned long long uint64;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rFOR(i,a,b) for(int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x,n) FOR(i,0,n) cout << x[i] << " "; cout << endl

// Custom global variable >>>>>>>>>>>>>



// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
auto main() -> int
{
  #ifdef DEBUG
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
  #endif
  // Fast I/O
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // Code starts here ---

  int n;
  cin >> n;
  vi a(n),b(n-1);
  for(auto &i:b)
    cin >> i;
  int32 res = 0;
  a[0] = b[0];
  a[1] = b[0];
  FOR(i,1,n-1) {
    if(a[i] > b[i]) {
      a[i] = b[i];
    }
    a[i+1] = b[i];
  }
  res = accumulate(a.begin(), a.end(), 0);
  cout << res;

  // --------------------
  #ifdef DEBUG
    cerr << endl << "Time:" << double(clock())/CLOCKS_PER_SEC << " secs" << endl;
  #endif
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define arep(X, Y) for (auto(X) : Y)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl
#define printDouble(x) cout << fixed << setprecision(13) << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

using decendingQueue = priority_queue<ll, vl>;              //降順
using ascendingQueue = priority_queue<ll, vl, greater<ll>>; //昇順

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INT_INF = 1e9;
const ll LL_INF = 1e18;
const int mod = 1000000007;

template <class T> void mySort(vector<T> &X, bool isAscending) {
  // 昇順
  if (isAscending) {
    sort(all(X));
  } else {
    // 降順
    sort(all(X), greater<T>());
  }
}

void solve(std::string S) {
  int ssize = S.size();
  vector<vl> dp(ssize + 1, vl(4, -1));

  dp[0][1] = 0;
  dp[0][2] = 0;
  dp[0][3] = 0;

  rep(i, 0, ssize) {
    // 一文字区切り
    if (S[i + 1] != S[i]) {
      chmax(dp[i + 1][1], dp[i][1] + 1);
    }
    if (i >= 1) {
      chmax(dp[i + 1][1], dp[i - 1][2] + 1);
    }
    if (i >= 2) {
      chmax(dp[i + 1][1], dp[i - 2][3] + 1);
    }

    // 二文字区切り
    chmax(dp[i + 1][2], dp[i][1] + 1);
    if (i >= 2) {
      chmax(dp[i + 1][2], dp[i - 2][3] + 1);
    }

    // 三文字区切り
    chmax(dp[i + 1][3], dp[i][1] + 1);
    if (i >= 1) {
      chmax(dp[i + 1][3], dp[i - 1][2] + 1);
    }
  }

  print(max(dp[ssize][1], max(dp[ssize][2], dp[ssize][3])));
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 14724
n=int(input())
w=[]
flg=0
for i in range(n):
    w.append(input())
    if i != 0:
        if w[i][0] != w[i-1][-1]:
            flg=1
if len(w) != len(set(w)):
    flg=1
print("YNeos"[flg::2])

Measured memory_bytes: 3060
N = int(input())
H = list(map(int, input().split()))
count = 0
pending_count = 0
for i in range(N):
    if i < N-1:
        if H[i] >= H[i+1]:
            count += 1
        else:
            pending_count = max(pending_count, count)
            count = 0
pending_count = max(pending_count, count)

print(pending_count)



Measured memory_bytes: 14224
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N;
  cin >> N;
  string ans;
  while (N) {
    N--;
    ans.pb('a' + N % 26);
    N /= 26;
  }
  reverse(all(ans));
  cout << ans << endl;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int x;
    cin >> x;
    int ans = 1;
    FOR(i,1,x){
        FOR(j,2,x){
            int y;
            y = pow(i, j);
            if(y>x)
                break;
            ans = max(ans, y);
        }
    }
    cout << ans <<"\n";

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        List<Integer> apples = new ArrayList<>();
        for(int i = 0;i < n;i++){
            apples.add(l + i);
        }
        int min = Integer.MAX_VALUE;
        for(int apple : apples){
            if(apple < 0){
                apple *= -1;
            }
            if(min > apple){
                min = apple;
            }
        }
        for(int i = 0;i < apples.size();i++) {
            int apple = apples.get(i);
            if (apple < 0) {
                apple *= -1;
            }
            if (apple == min) {
                apples.remove(i);
                break;
            }
        }
        int r = 0;
        for(int apple : apples){
            r += apple;
        }
        System.out.println(r);
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>
#include <algorithm>
#include <iterator> // std::back_inserter

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    //    vector<tuple<int, int, int>> result;

    n = v.size();
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                int ti = v[i];
                int tj = v[j];
                int tk = v[k];
                if ((ti != tj && ti != tk && tj != tk) && ((tk > ti && tk > tj && ti + tj > tk) || (tj > ti && tj > tk && ti + tk > tj) || (ti > tk && ti > tj && tk + tj > ti)))
                {
                    //                    vector<int> tv = {ti, tj, tk};
                    //                    sort(tv.begin(), tv.end());
                    auto tpl = make_tuple(i, j, k);
                    //                    std::vector<tuple<int, int, int>>::iterator itr;
                    //                    itr = std::find(result.begin(), result.end(), tpl);
                    //                    if (itr == result.end())
                    //                    {
                    count++;
                    //                    result.push_back(tpl);
                    //                    }
                }
            }
        }
    }

    //    for (auto it : result)
    //    {
    //        cout << get<0>(it) + 1 << "," << get<1>(it) + 1 << "," << get<2>(it) + 1 << endl;
    //    }
    cout << count << endl;
}


Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> edge;
const int INF = 1 << 22;
struct state{
  int town, time, fz_time;
  state(int town_, int time_, int fz_time_): town(town_), time(time_), fz_time(fz_time_){}
  bool operator< (const state &other) const{
    return time > other.time; //
  }
};
int N, M, L, K, A, H;
int dijkstra(vector<vector<edge> > graph, bool has_fz[]){
  priority_queue<state> pq;
  pq.push(state(A, 0, M));
  bool visited[N][M+1];
  fill_n((bool*) visited, N*(M+1), false);
  while(!pq.empty()){
    state cur = pq.top(); pq.pop();
    //cout << "town: " << cur.town << ", time: " << cur.time << ", fz: " << cur.fz_time << endl;
    if(cur.town == H){
      return cur.time;
    }
    if(visited[cur.town][cur.fz_time]){
      continue;
    }
    visited[cur.town][cur.fz_time] = true;
    for(int i = 0; i < graph[cur.town].size(); ++i){
      int to = graph[cur.town][i].first;
      int cost = graph[cur.town][i].second;
      int r = 0;
      if(cur.fz_time-cost < 0){
        r = -1 * (cur.fz_time-cost);
      }
      if(r + cur.fz_time <= M){
        pq.push(state(to, cur.time+cost+r, cur.fz_time-cost+r));
      }
    }
  }
  return -1;
}
void compress(vector<vector<edge> > &graph, bool has_fz[]){
  int adj[N][N];
  fill_n((int*) adj, N*N, INF);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < graph[i].size(); ++j){
      int t = graph[i][j].first;
      int c = graph[i][j].second;
      adj[i][t] = c;
    }
  }
  for(int k = 0; k < N; ++k){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
        adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
      }
    }
  }
  graph.clear();
  graph = vector<vector<edge> >(N);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j){
      if(adj[i][j] < INF && has_fz[j]){
        graph[i].push_back(make_pair(j, adj[i][j]));
      }
    }
  }
}
int main(){
  while(true){
    cin >> N >> M >> L >> K >> A >> H;
    if((N|M|L|K|A|H) == 0){
      break;
    }
    bool has_fz[N];
    fill_n(has_fz, N, false);
    has_fz[A] = has_fz[H] = true;
    for(int i = 0; i < L; ++i){
      int tmp;
      cin >> tmp;
      has_fz[tmp] = true;
    }
    vector<vector<edge> > graph(N);
    for(int i = 0; i < K; ++i){
      int a, b, t;
      cin >> a >> b >> t;
      graph[a].push_back(make_pair(b, t));
      graph[b].push_back(make_pair(a, t));
    }
    compress(graph, has_fz);
    int ans = dijkstra(graph, has_fz);
    if(ans == -1){
      cout << "Help!" << endl;
    }
    else{
      cout << ans << endl;
    }
  }
  return 0;
}

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

typedef long long ll;
int N;
string s;
const ll MOD = 1e9 + 7;
ll dp[3010][3010];
ll psum[3010];

int main()
{
    cin >> N >> s;
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < N; i++) dp[0][i] = 1;
    memset(psum, 0, sizeof(psum));
    psum[0] = 0;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < N - i; j++) 
        {
            psum[j + 1] = psum[j] + dp[i][j];
            psum[j + 1] %= MOD;
        }
        for(int j = 0; j < N - i; j++)
        {
            if(s[i] == '>')
            {
                dp[i + 1][j] = psum[N - i] - psum[j + 1];
                if(dp[i + 1][j] < 0) dp[i + 1][j] += MOD;
            }
            else dp[i + 1][j] = psum[j + 1];
            dp[i + 1][j] %= MOD;
        }
        memset(psum, 0, sizeof(psum));
    }
    ll res = 0;
    for(int i = 0; i < N; i++)
    {
        res += dp[N][i] % MOD;
        res %= MOD;
    }

    cout << res << endl;
    
}


Measured memory_bytes: 71168
#include <iostream>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

int cnt(string s) {
    bitset<10> f;
    for(const auto c: s) {
        f[c - 'a'] = true;
    }
    return f.count();
}

int main() {
    int N;
    cin >> N;
    queue<string> q;
    q.push("a");
    while(!q.empty()){
        string s = q.front();
        q.pop();
        if(s.length() == N) {
            cout << s << endl;
            continue;
        }
        char c = 'a';
        int n = cnt(s);
        for(int j = 0; j < n + 1; j++, c++) {
            q.push(s + c);
        }
    }
}

Measured memory_bytes: 4224
import java.util.Scanner;

class BLOK{
	int left,down,right,up;
	BLOK(){
		this.left=0;
		this.down=0;
		this.right=0;
		this.up=0;
	}
}

public class Main {
	static int n;
	static BLOK b[];
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int i,k,posi;

		while(true){
			n=sc.nextInt();
			if(n==0) break;
			b=new BLOK[n];
			b[0]=new BLOK();
			for(i=1;i<n;i++){
				k=sc.nextInt();
				posi=sc.nextInt();
				b[i]=new BLOK();
				if(posi==0){
					b[i].left=b[k].left+1;
					b[i].down=b[k].down;
					b[i].right=b[k].right;
					b[i].up=b[k].up;
				}
				if(posi==1){
					b[i].left=b[k].left;
					b[i].down=b[k].down+1;
					b[i].right=b[k].right;
					b[i].up=b[k].up;
				}
				if(posi==2){
					b[i].left=b[k].left;
					b[i].down=b[k].down;
					b[i].right=b[k].right+1;
					b[i].up=b[k].up;
				}
				if(posi==3){
					b[i].left=b[k].left;
					b[i].down=b[k].down;
					b[i].right=b[k].right;
					b[i].up=b[k].up+1;
				}
			}
			answer();
		}
	}
	static void answer(){
		int i;
		int l,d,r,u;
		l=d=r=u=0;
		for(i=0;i<n;i++){
			if(l<b[i].left-b[i].right){
				l=b[i].left-b[i].right;
			}
			if(r<b[i].right-b[i].left){
				r=b[i].right-b[i].left;
			}
			if(u<b[i].up-b[i].down){
				u=b[i].up-b[i].down;
			}
			if(d<b[i].down-b[i].up){
				d=b[i].down-b[i].up;
			}
		}
		System.out.println((l+r+1)+" "+(u+d+1));
	}
}

Measured memory_bytes: 12000
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

int main(){
    char S[4];
    scanf("%s",S);
    if(strlen(S)==2){
        printf("%s\n",S);
    }else{
        printf("%c",S[2]);
        printf("%c",S[1]);
        printf("%c",S[0]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    vector <ll> a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    ll count = n;
    ll mi = a[0];
    while(1) {
        if (count == 1) break;
        sort(a.begin(),a.end());
        mi = a[0];
        rep(i,1,a.size()) {
            if (count == 1) break;
            a[i] = a[i] % mi; 
            if(a[i] == 0) {
                a.erase(a.begin() + i);
                count--;
                continue;
            }
            mi = min(mi,a[i]);
        }
    }
    cout << mi << endl;
    
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

const int v[] = {-1,1};

int main(){

 	int n;
 	string st;
 	cin >> n >> st;
 	st += st;
 	V<int> tests(n*2);
 	rep(i,n*2) {
 		if(st[i] == 'o') tests[i] = 1;
 		if(st[i] == 'x') tests[i] = -1;
 	}

 	for(int f : v) for(int s : v) {
 		V<int> ans(n*2+3);
 		ans[0] = f;
 		ans[1] = s;
 		Rep(i,n*2-1) ans[i+1] = ans[i] * ans[i-1] * tests[i];

 		bool ok = true;
 		rep(i,n) {
 			ok &= (ans[i] == ans[i+n]);
 		}
 		if(ok) {
 			rep(i,n) cout << (ans[i] == 1 ? 'S' : 'W');
 			cout << endl;
 			return 0;
 		}
 	}

 	cout << -1 << endl;
 	return 0;
}

Measured memory_bytes: 5036
package main

import "fmt"

func main() {
	var n, k, max int
	fmt.Scan(&n, &k)
	a := make([]int, n+1)
	for i := 1; i < n+1; i++ {
		fmt.Scan(&a[i])
		a[i] += a[i-1]
		if i >= k && max < a[i]-a[i-k] {
			max = a[i] - a[i-k]
		}
	}
	fmt.Println(float64(max+k) / 2)
}


Measured memory_bytes: 4992
from collections import defaultdict

def gcd(a, b):
    return gcd(b, a%b) if b else a

mod = 10 ** 9 + 7
N = int(input())
X = defaultdict(lambda: [0, 0])
# X = dict()
x = 0
y = 0
z = 0
for i in range(N):
    a, b = map(int, input().split())
    g = abs(gcd(a, b))
    if a * b > 0:
        X[(abs(a) // g, abs(b) // g)][0] += 1
    elif a * b < 0:
        X[(abs(b) // g, abs(a) // g)][1] += 1
    else:
        if a:
            x += 1
        elif b:
            y += 1
        else:
            z += 1
# suppose we have a super head point which can put togother with every point.
ans = 1
pow2 = [1]
for i in range(N):
    pow2 += [pow2[-1] * 2 % mod]
for i in X.values():
    ans *= pow2[i[0]] + pow2[i[1]]- 1
    ans %= mod
ans *= pow2[x] + pow2[y] - 1
print((ans+z-1)%mod)


Measured memory_bytes: 68480
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <climits>
#define INF 1000000000000000
#define ll long long
using namespace std;
int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)<abs(x-b)){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    double t, a;
    cin>>n>>t>>a;
    double m = 1001001001;
    int ans = -1;
    rep(i, n) {
        double h;
        cin>>h;
        double r = abs(a - (t - h * 0.006));
        if (r < m) {
            m = r;
            ans = i + 1;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int red = 0, blue = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '0') {
            red++;
        } else {
            blue++;
        }
    }
    cout << min(red, blue) * 2 << endl;
    return 0;
}

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

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

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    string s; cin>>s;
    int n = s.size();

    int ans = 0;
    for(int i=0; i<n; i++){
        ans += (s[i] != s[n-1-i]);
    }

    cout << ans / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#include<vector>
#include<functional>
template<typename T>
struct lazysegtree{
	using F=function<T(T,T)>;
	using G=function<T(T,T,int,int)>;
	const F calcfn,lazycalcfn;
	const G updatefn;
	int n;
	T defvalue,lazydefvalue;
	vector<T>dat,lazy;
	vector<bool>lazyflag;
	lazysegtree(int n_=0,T defvalue_=0,
		const F calcfn_=[](T a,T b){return a+b;},
		const F lazycalcfn_=[](T a,T b){return a+b;},
		const G updatefn_=[](T a,T b,int l,int r){return a+b*(r-l);},
		T lazydefvalue_=0
	):defvalue(defvalue_),lazydefvalue(lazydefvalue_),
		calcfn(calcfn_),lazycalcfn(lazycalcfn_),updatefn(updatefn_)
	{
		n=1;
		while(n<n_)n<<=1;
		dat.assign(2*n-1,defvalue);
		lazy.assign(2*n-1,lazydefvalue);
		lazyflag.assign(2*n-1,false);
	}
	void copy(const vector<T>&v)
	{
		for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
		for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
	}
	void eval(int i,int l,int r)
	{
		if(lazyflag[i])
		{
			dat[i]=updatefn(dat[i],lazy[i],l,r);
			if(r-l>1)
			{
				lazy[2*i+1]=lazycalcfn(lazy[2*i+1],lazy[i]);
				lazy[2*i+2]=lazycalcfn(lazy[2*i+2],lazy[i]);
				lazyflag[2*i+1]=lazyflag[2*i+2]=true;
			}
			lazy[i]=lazydefvalue;
			lazyflag[i]=false;
		}
	}
	void update(int a,int b,T x,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return;
		else if(a<=l&&r<=b)
		{
			lazy[k]=lazycalcfn(lazy[k],x);
			lazyflag[k]=true;
			eval(k,l,r);
		}
		else
		{
			update(a,b,x,2*k+1,l,(l+r)/2);
			update(a,b,x,2*k+2,(l+r)/2,r);
			dat[k]=calcfn(dat[2*k+1],dat[2*k+2]);
		}
	}
	T query(int a,int b,int k=0,int l=0,int r=-1)//[a,b)
	{
		if(r<0)r=n;
		eval(k,l,r);
		if(b<=l||r<=a)return defvalue;
		else if(a<=l&&r<=b)return dat[k];
		else return calcfn(
			query(a,b,2*k+1,l,(l+r)/2),
			query(a,b,2*k+2,(l+r)/2,r)
		);
	}
};
long mod=998244353;
int N;
main()
{
	cin>>N;
	vector<int>X;
	X.push_back(-2e9);
	vector<pair<int,int> >LR;
	for(int i=0;i<N;i++)
	{
		int x,d;cin>>x>>d;
		d+=x;
		X.push_back(x);
		X.push_back(d);
		LR.push_back(make_pair(x,d));
	}
	sort(X.begin(),X.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	for(pair<int,int>&lr:LR)
	{
		lr.first=lower_bound(X.begin(),X.end(),lr.first)-X.begin();
		lr.second=lower_bound(X.begin(),X.end(),lr.second)-X.begin();
	}
	sort(LR.begin(),LR.end());
	auto f=[](long a,long b){return (a+b)%mod;};
	auto g=[](long a,long b){return b;};
	auto h=[](long a,long b,int l,int r){return b*(r-l)%mod;};
	lazysegtree<long>P(X.size(),0,f,g,h);
	P.update(0,1,1);
	for(pair<int,int>lr:LR)
	{
		long sum=P.query(0,lr.second);
		P.update(lr.first,lr.second,0);
		P.update(lr.second-1,lr.second,sum);
	}
	cout<<P.query(0,X.size())<<endl;
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] c =  br.readLine().toCharArray();
		char res = c[0]++;
		System.out.println(c);
	}

}


Measured memory_bytes: 19284
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [float("inf") for i in range(n)]
dp[0] = 0

for i in range(n - 1):
    for j in range(1, k + 1):
        try:
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
        except IndexError:
            pass

print(dp[n - 1])



Measured memory_bytes: 57184
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

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

    vec<ll> P(N);
    rep(i, N) cin >> P[i], --P[i];

    vec<ll> C(N);
    rep(i, N) cin >> C[i];

    ll ans = -1e18 - 9;
    rep(i, N) {
        ll now = i;
        ll smS = 0;
        vec<ll> t;
        while (1) {
            smS += C[now];
            t.push_back(smS);
            now = P[now];
            if (now == i) break;
        }
        int L = t.size();
        rep(j, L) {
            ll zan = K - (j + 1);
            if (zan < 0) break;
            ll tmp = t[j];
            if (smS > 0) {
                ll e = zan / L;
                tmp += smS * e;
            }
            ans = max(ans, tmp);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3820
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

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

    vector<long> a(87);

    a[0] = 2;
    a[1] = 1;
    for(int i = 2; i <= 86; i++){
        a[i] = a[i-1] + a[i-2];
    }

    cout << a[n] << endl;

    return 0;
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {
	
}

int main()
{
    FAST_INP;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt","r", stdin);
//    freopen("output.txt","w", stdout);
//    #endif

//    int tc; cin >> tc;
//    TC(tc) solve();
	int x;
	cin >> x;
	OUT(!x);
    return 0;
}

Measured memory_bytes: 3572
def main():
    N = int(input())
    A = [0]*N
    for i in range(N):
        A[i] = int(input())

    d = {}
    for a in A:
        d[a] = d.get(a, 0)+1

    print(sum(v % 2 for k, v in d.items()))
main()


Measured memory_bytes: 16236
x, y = list(map(int, input().split()))

# すべて亀
legs = 4 * x

if legs == y:
    print("Yes")
    exit()

if legs < y or y % 2 == 1:
    print("No")
    exit()

# 亀を鶴に置き換えていく
for i in range(x):
    legs -= 2
    if legs == y:
        print("Yes")
        exit()

print("No")


Measured memory_bytes: 9108