akhauriyash/Code-Regression huggingface dataset:
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

use input::*;

fn search(graph: &Vec<Vec<(usize, isize)>>, longest: &mut Vec<Option<isize>>, n: usize) -> bool {
    let mut flag = false;
    for (from, node) in graph.iter().enumerate() {
        for edge in node {
            let cost = edge.1;
            let to = edge.0;
            if let None = longest[from] {
                continue;
            }
            if let None = longest[to] {
                longest[to] = Some(longest[from].unwrap() + cost);
                continue;
            }
            if longest[from].unwrap() + cost > longest[to].unwrap() {
                longest[to] = Some(longest[from].unwrap() + cost);
                if to == n {
                    flag = true;
                }
            }
        }
    }
    flag
}
fn main() {
    let (n, m): (usize, usize);
    input!(n, m);
    let mut graph = vec![Vec::new(); n];
    let mut longest = vec![None; n];
    longest[0] = Some(0);
    for _ in 0..m {
        let (a, b, c): (usize, usize, isize);
        input!(a, b, c);
        graph[a - 1].push((b - 1, c));
    }
    for _ in 1..n {
        search(&graph, &mut longest, n - 1);
    }
    if search(&graph, &mut longest, n - 1) {
        println!("inf");
    } else {
        println!("{}", longest[n - 1].unwrap());
    }
}

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

int main () {
  int n;
  cin >> n;
  int ans = 64;
  rep(i,n) {
    int a;
    int j = 0;
    cin >> a;
    while(a % 2 == 0) {
      a = (a >> 1);
      j++;
    }
    ans = min(ans, j);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = int(input())
a_list = list(map(int, input().split()))

count = 1
ans = 0
for a in a_list:
    if a != count:
        ans += 1
    else:
        count += 1

if(count == 1):
    ans = -1

print(ans)


Measured memory_bytes: 26140
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int N;
	public void solve() {
		N = nextInt();

		out.println(N*800 - N/15*200);
	}
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

//zaki_SegmentTree

const int INF = 2147483647;
class SegmentTree
{
    int n;
    std::vector<int> node;

  public:
    // v を基に初期化
    SegmentTree(const std::vector<int> &v)
    {
        // n は v.size() 以上の最小の2冪
        n = 1;
        while (n < int(v.size()))
            n *= 2;
        node.resize(2 * n - 1, INF);

        // i の子 -> 2*i+1, 2*i+2 , 親 -> (i-1)/2
        for (int i = 0; i < int(v.size()); i++)
            node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; i--)
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
    }
    // x 番目を val に更新
    void update(int x, int val)
    {
        x += n - 1;
        node[x] = val;
        while (x > 0)
        {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    // v[x] を M::op(v[x], val) に更新
    void add(int x, int val)
    {
        x += n - 1;
        node[x] = min(node[x], val);
        while (x > 0)
        {
            x = (x - 1) / 2;
            node[x] = min(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    // [a, b) の op
    // k := 今居るノード
    int query(int a, int b, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = n;
        if (r <= a || b <= l)
            return INF;
        if (a <= l && r <= b)
            return node[k];

        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> com(q), x(q), y(q);
    REP(i, q) cin >> com[i] >> x[i] >> y[i];
    vector<int> a(n, INF);

    SegmentTree st(a);

    REP(i, q){
        if(com[i]) cout << st.query(x[i], y[i] + 1) << endl;
        else st.update(x[i], y[i]);
    }
    return 0;
}


Measured memory_bytes: 5448
//#include <conio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	int *colors = new int[n + 1];
	for (int i = 1; i <= n; i++)
		scanf("%d", &colors[i]);

	int **grid = new int*[h];
	for (int i = 0; i < h; i++)
		grid[i] = new int[w];

	bool side = false; // false for right ; true for left;
	
	int count = 0;
	int pColor = 1;

	for (int i = 0; i < h; i++)
	{
		if (!side)
		{
			for (int j = 0; j < w; j++)
			{
				if (colors[pColor] == 0)
					pColor++;
	

				grid[i][j] = pColor;
				colors[pColor]--;
			}

		}
		else{

			for (int j = w - 1; j >= 0; j--)
			{
				if (colors[pColor] == 0)
					pColor++;
				
				grid[i][j] = pColor;
				colors[pColor]--;
			}
		}
		if (side) side = false;
		else side = true;

	}

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			printf("%d \n", grid[i][j]);
	
	//_getch();
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++){
    cin >> b.at(i);
    
  } 
  sort(b.begin(), b.end());
  reverse(b.begin(), b.end());
  
  int alice = 0;
  int bob = 0;
  int r = 1;
  for (int i = 0; i < b.size(); i++){
    if (i  % 2 == 0){
    alice += b.at(i);
    }
  else if(i % 2 == 1){
    bob += b.at(i);
  }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n)    for(int i=a; i<=n; ++i)
#define rep1(i,a,n)   for(int i=a; i>=n; --i)
#define pb            push_back
#define int           long long
#define fr            first
#define sc            second
#define vc            vector
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define M             1000000007
#define MM            998244353
#define PI            3.14159265358979
#define INF           1000000000000000

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mii;

int n,m,ans; string str;

int a[200005];
vi v;
int solve(){
    cin>>n;
    rep(i,0,n-1){
        int t; cin>>t;
        v.pb(t);
        a[t]++;
    }
    rep(i,1,n){
        ans+=a[i]*(a[i]-1)/2;
    }
    rep(i,0,n-1){
        int t=a[v[i]];
        cout<<ans-t*(t-1)/2+(t-1)*(t-2)/2<<"\n";
    }
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  int price = 700;
  if(s[0]=='o') price += 100;
  if(s[1]=='o') price += 100;
  if(s[2]=='o') price += 100;
  
  cout << price << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define LLint long long int
#define Lint long int
#define Ldouble long double

// class UnionFind;

// bool sortBySec(const pair<int, int>& a, const pair<int, int>& b);
// int modExp(int x, int n, int m);
// int mmi(int x, int m);

int s, w;

void solve() {
    cin >> s >> w;
    if (w >= s) {
        cout << "unsafe";
    }
    else {
        cout << "safe";
    }
}

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

    solve();

    return EXIT_SUCCESS;
}

// Helpers.
/*
bool sortBySec(const pair<int, int>& a, const pair<int, int>& b) {
    return (a.second < b.second);
}
*/
// Modular arithmetic.
/*
int modExp(const int x, const int n, const int m) {
    if (n == 0) {
        return 1;
    }
    LLint u = modExp(x, n / 2, m);
    return n % 2 == 0 ? (u * u) % m : (((u * u) % m) * x) % m;
}
*/
/*
int mmi(const int x, const int m) { return modExp(x, m - 2, m); }
*/
// Union find data structure.
/*
class UnionFind {
   public:
    vector<int> link;
    vector<int> size;

    UnionFind(int n) {
        link = vector<int>(n);
        size = vector<int>(n);
        for (int i = 0; i < n; i++) {
            link[i] = i;
            size[i] = 1;
        }
    }

    int find(int x) {
        while (x != link[x]) {
            x = link[x];
        }
        return x;
    }

    bool same(int a, int b) { return find(a) == find(b); }

    void unite(int a, int b) {
        a = find(a);
        b = find(b);
        if (size[a] < size[b]) {
            swap(a, b);
        }
        size[a] += size[b];
        link[b] = a;
    }
};
*/


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

long long dp[100][2];

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    
    for (int i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1;
    dp[45][0] = 0;
    for (int d = 44; d >= 0; --d) {
        long long mask = 1LL<<d;
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;
        
        if (dp[d+1][1] >= 0) chmax(dp[d][1], dp[d+1][1] + mask * max(num, N-num));
        if (dp[d+1][0] >= 0) {
            if (K & (1LL<<d)) {
                chmax(dp[d][1], dp[d+1][0] + mask * num);
                chmax(dp[d][0], dp[d+1][0] + mask * (N-num));
            }
            else {
                chmax(dp[d][0], dp[d+1][0] + mask * num);
            }
        }
    }
    cout << max(dp[0][0], dp[0][1]) << endl;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str ;
    cin>>str;
    if(str=="MON")
    {
    	cout<<6<<endl;
	}
	else if(str=="TUE")
	{
		cout<<5<<endl;
	}
	else if(str=="WED")
	{
		cout<<4<<endl;
	}
	else if(str=="THU")
	{
		cout<<3<<endl;
	}
	else if(str=="FRI")
	{
		cout<<2<<endl;
	}
	else if(str=="SAT")
	{
		cout<<1<<endl;
	}
	else
	{
		cout<<7<<endl;
	}
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    rrep(j, i + 1, n) { ans += a[i] * a[j]; }
  }
  Cout(ans);
  return 0;
}

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

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

    int r;
    cin >> r;

    cout << 3 * r * r << endl;

    return 0;
}


Measured memory_bytes: 256
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define size 2100000
lld fac [size];
lld ifac[size];
lld inv [size];
void fac_mod ()
{
      fac[0] = 1;
      fac[1] = 1;
      for(lld i = 2; i < size; i++){
            fac[i] = fac[i-1]*i%MOD;
      }
}
void ifac_mod()
{
      ifac[0] = 1;
      ifac[1] = 1;
      inv [1] = 1;
      for(lld i = 2; i < size; i++){
            inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
            ifac[i]= ifac[i - 1] * inv[i] % MOD;
      }
}
lld nCk_ (lld n, lld k)
{
      if (n < k) return 0;
      if (n < 0 || k < 0){
            return 0;
      }
      return fac[n]*(ifac[k]*ifac[n-k]%MOD)%MOD;
}
int main ()
{
      FastIO
      lld n, k;
      cin >> n;
      cin >> k;
      fac_mod();
      ifac_mod();
      for(lld i = 1; i <= k; i++){
            cout << (nCk_(k-1,i-1)*nCk_(n-k+1,i))%MOD << "\n";
      }
      return 0;
}

Measured memory_bytes: 49536
using System;
using System.Text;

namespace ALDS1_4_C {
    class Problem {
        // 5?????°???444444444444=244140624
        bool[] _memo = new bool[244140625];

        public void Run() {
            int n = int.Parse(Console.ReadLine());
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                if (input[0] == "insert")
                    Insert(input[1]);
                else
                    sb.AppendLine(Find(input[1]) ? "yes" : "no");
            }
            Console.Write(sb);
        }

        private void Insert(string source) {
            _memo[Convert(source)] = true;
        }
        private bool Find(string source) {
            return _memo[Convert(source)];
        }

        private int Convert(string source) {
            int ret = 0;
            for (int i = 0; i < source.Length; i++) {
                ret = ret * 5 + CharToInt(source[i]);
            }
            return ret;
        }

        private int CharToInt(char ch) {
            switch (ch) {
                case 'A':
                    return 1;
                case 'C':
                    return 2;
                case 'G':
                    return 3;
                case 'T':
                    return 4;
            }
            return -1;
        }
    }

    class Program {
        static void Main(string[] args) {
            Problem p = new Problem();
            p.Run();
        }
    }
}

Measured memory_bytes: 374152
#include<bits/stdc++.h>
using namespace std;
#define deb(x) cout<<#x<<" "<<x<<endl;  //for debugging variables 
#define check cout<<"check"<<endl; // checking 







void solve(){


int n;

cin>>n;


// vector<int>v(n);


// for(int i=0;i<n;i++) cin>>v[i];



cout<<10-(n/200)<<endl;













}






int main(){


// #ifndef ONLINE_JUDGE

//       freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);
// #endif 

int t;
//cin>>t;

t=1;
while(t--){
solve();
}
	return 0;
} 

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std; 

int main()
{
	vector<int> len(4);
	fill(len.begin(), len.end(), 1000000000);
	while(cin >> len[0] >> len[1] >> len[2])
	{
		if(!len[0] && !len[1] && !len[2])
			break;
		float rad;
		sort(len.begin(), len.end() );
		rad = sqrt(len[0]*len[0] + len[1]*len[1]);

		int num, enter[10100];
		cin >> num;

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

		for(int i = 0; i < num; i++)
		{
			if(2 * enter[i] > rad) cout << "OK" << endl;
			else cout << "NA" << endl; 
		}
	}
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int N;
	cin >> N;
	vector<int> D(2 * N);
	Rep(i, 2 * N) cin >> D[i];
	for (int i = 0; i < 2 * N - 5; i++) {
		if (D[i] == D[i + 1] && D[i + 2] == D[i + 3] && D[i + 4] == D[i + 5]) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main()
{
	int n;
	scanf("%d", &n);

	using vd = std::vector<double>;
	using vvd = std::vector<vd>;
	vd percentage(2 * n + 2);
	for (int i{2}; i < 2 * n + 2; i += 2)
		scanf("%lf", &percentage[i]);
	for (int i{1}; i < 2 * n + 2; i += 2)
		scanf("%lf", &percentage[i]);

	vvd dp(n + 1, vd(n + 1, 9));
	for (int i{}; i <= n; i++)
		dp[i][i] = 0;

	for (int i{1}; i < 2 * n + 2; i++)
		percentage[i] += percentage[i - 1];

	for (int width{1}; width <= n; width++)
		for (int left{}; left + width <= n; left++)
		{
			int right{left + width};
			for (int root{right}; root > left; root--)
				dp[left][right] = std::min(dp[left][right],
				dp[left][root - 1] + percentage[2 * root - 1] - percentage[2 * left]
				+ dp[root][right] + percentage[2 * right + 1] - percentage[2 * root]
				);
		}

	std::cout << std::fixed << std::setprecision(6) << dp[0][n] + 1 << std::endl;

	return 0;
}


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

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

	ll ans1 = 0, ans2 = 0;
	ll S = 0;
	for (int i = 0; i < n; i++) {
		S += a[i];
		if (i % 2 == 0 && S <= 0) {
			ans1 += 1 - S;
			S = 1ll;

		}
		else if (i % 2 == 1 && S >= 0) {
			ans1 += S + 1;
			S = -1ll;
		}
	}
	S = 0;
	for (int i = 0; i < n; i++) {
		S += a[i];
		if (i % 2 == 1 && S <= 0) {
			ans2 += 1 - S;
			S = 1ll;

		}
		else if (i % 2 == 0 && S >= 0) {
			ans2 += S + 1;
			S = -1ll;
		}
	}
	cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int res = 0;

        for(int i = 1; i <= N; i++) {
            int count = 0;
            for(int j = 1; j <= i; j++) {
                if(i%2!=0 && i%j==0) count++;
            }
            if(count == 8) res++;
        }
        System.out.println(res);
    }
}


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

int main()
{
      int n,k;
      cin>>n>>k;
      vector<int> arr(n);
      for(int i=0;i<n;i++)
        cin>>arr[i];
      sort(arr.begin(),arr.end());
      int sum=0;
        k--;
    for(int i=k;i>=0;i--)
        sum+=arr[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <map>
#include <cstdio>
using namespace std;
int isPrime[1000001];
int main()
{
  map<int,int>prime;
  fill(isPrime,isPrime + 1000001,1);
  isPrime[0] = isPrime[1] = 0;
  for(int i = 2 ; i*i < 1000001 ; i++ )
    {
      if(isPrime[i]){
	for(int j = i*2 ; j < 1000001 ; j+=i )isPrime[j] = 0;
      }
    }
  int p = 0;
  for(int i = 0 ; i < 1000001 ; i++ )if(isPrime[i])prime[p++] = i;
  int n;
  while(cin >> n,n)
    {
      int sum = 0,res = 0;
      int back = 0,front = 0;
      while(sum >= 0 && front < p){
	if(sum + prime[front] <= n) {
	  sum += prime[front];
	  front++;
	} else if(sum + prime[front] > n) {
	  sum -= prime[back];
	  back++;
	}
	if(sum == n)res++; 
      }
      cout << res << endl;
    }
  return 0;
}

Measured memory_bytes: 8776
#include <bits/stdc++.h>
using namespace std;
int main(){
int A, B, M, i, ans=2*(1e5); cin >> A >> B >> M;
vector<int> a(A), b(B), x(M), y(M), c(M);
for(i=0; i<A; i++){ cin >> a[i]; }
for(i=0; i<B; i++){ cin >> b[i]; }
for(i=0; i<M; i++){ cin >> x[i] >> y[i]>> c[i]; }  
for(i=0; i<M; i++){ ans=min(ans, a[x[i]-1]+b[y[i]-1]-c[i]); }    
sort(a.begin(), a.end());sort(b.begin(), b.end());
ans=min(ans, a[0]+b[0]);
cout << ans << "\n";
}

Measured memory_bytes: 2176
#include<cstdio>
const int N=3000;
bool g[N+10][N+10]={1};
int main(){
	int a,b,c,d,e,f,up=0,down=0; scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	for(int i=0;i<=f;++i) for(int j=0;j<=f;++j) if(g[i][j]){
		if(i+a*100<=f) g[i+a*100][j]=1;
		if(i+b*100<=f) g[i+b*100][j]=1;
		if(j+c<=f) g[i][j+c]=1;
		if(j+d<=f) g[i][j+d]=1;
		if(i+j&&i+j<=f) if(100*j<=e*i) if(!up&&!down){
			up=j; down=i+j;
		}else if(j*down>up*(i+j)){
			up=j; down=i+j;
		}
	}
	printf("%d %d",down,up); return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#define waru 1000000000+7

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i,n){
        int buf;
        cin >> buf;
        a[i] = buf;
    }
    // showa(a)
    double one = 1;
    double c = 0;
    for(int i = 0; i < n; i++){
        double b = one/a[i];
        c += b;
        // show(c)
    }
    // cout << one/c;
    printf("%.6f"  ,one/c);
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int inf=0x3f3f3f3f;
char a[100010];
int ans,cnt;
int main()
{
	scanf("%s",a);
	int l=strlen(a);
	for(int i=0;i<l;++i)
	{
		if(cnt>0)
		{
			if(a[i]=='g')
				++ans;
			--cnt;
		}
		else
		{
			if(a[i]=='p')
				--ans;
			++cnt;
		}
	}
	cout<<ans;
    return 0;
}



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

void reverse(string &s) {
	int l = 0, r = s.length()-1;
	while(l<r) {
		char temp = s[l];
		s[l] = s[r];
		s[r] = temp;
		l++;
		r--;
	}
}

int main() {
	string s,t;
	cin>>s>>t;
	int l1 = s.length(), l2 = t.length();
	vector<vector<int>> dp(l1+1, vector<int> (l2+1, 0));
	for(int i=1;i<=l1;i++) {
		for(int j=1;j<=l2;j++) {
			if(s[i-1]==t[j-1]) {
				dp[i][j] = 1 + dp[i-1][j-1];
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string temp;
	int i = l1, j = l2;
	while(i>0 && j>0) {
		if(s[i-1]==t[j-1]) {
			temp += s[i-1];
			i--;
			j--;
		} else if(dp[i-1][j] > dp[i][j-1]) {
			i--;
		} else {
			j--;
		}
	}
	reverse(temp);
	cout<<temp<<endl;
	
	return 0;
}


Measured memory_bytes: 35584
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<vector>

using namespace std;

int main(){
	string s;
	cin >> s;
	int c[4]={0};
	for(int i=0;i<s.size();i++){
		if(s[i]=='W')c[0]=1;
		if(s[i]=='E')c[1]=1;
		if(s[i]=='S')c[2]=1;
		if(s[i]=='N')c[3]=1;
	}
	int ans = 1;
	if(c[0]^c[1]) ans=0;
	if(c[2]^c[3]) ans=0;
	if(ans)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var X = int.Parse(Console.ReadLine());
            while (true)
            {
                if (IsPrime(X))
                {
                    break;
                }

                X++;
            }

            Console.WriteLine(X);
        }

        public static bool IsPrime(int num)
        {
            if (num < 2) return false;
            else if (num == 2) return true;
            else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

            double sqrtNum = Math.Sqrt(num);
            for (int i = 3; i <= sqrtNum; i += 2)
            {
                if (num % i == 0)
                {
                    // 素数ではない
                    return false;
                }
            }

            // 素数である
            return true;
        }
    }
}


Measured memory_bytes: 11092
use std::io::*;
use std::str::*;

fn read <T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

pub fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    let n: u32 = read(&mut stdin).unwrap();
    let nums: Vec<u32> = (0..n).map(|_x| read(&mut stdin).unwrap()).collect();

    // let mut res: Vec<u32> = Vec::with_capacity(n as usize);
    // for i in 0..n as usize {
    //     let x = nums[i];

    //     if !res.contains(&x) {
    //         res.push(x);
    //     }
    // }

    // println!("{:?}", res.len());

    let mut res: [u32; 100] = [0; 100];
    for num in nums {
        let num = (num - 1) as usize;
        res[num] += 1;
    }
    let result = res.iter().filter(|x| x > &&0).fold(0, |acc, _x| acc + 1);
    println!("{:?}", result);
}


Measured memory_bytes: 4352
n = gets.to_i

cnt = {AC: 0, WA: 0, TLE: 0, RE: 0}
n.times do
  s = gets.chomp
  cnt[s.to_sym] += 1
end

puts "AC x #{cnt[:AC]}"
puts "WA x #{cnt[:WA]}"
puts "TLE x #{cnt[:TLE]}"
puts "RE x #{cnt[:RE]}"

Measured memory_bytes: 14372
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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);
    int N; cin >> N;
    vector<int> D(N);
    rep(i,N) cin >> D[i];
    int M; cin >> M;
    vector<int> T(M);
    rep(i,M) cin >> T[i];

    unordered_map<int ,int> dic;
    rep(i,N) dic[D[i]]++;
    rep(i,M) {
        if (dic[T[i]] == 0) {
            cout << "NO" << endl;
            return 0;
        } else dic[T[i]]--;
    }

    cout << "YES" << endl;
}

Measured memory_bytes: 10056
"""
どれとペアになるかは最初から確定
位置を決めれば後は転倒数
"""
import sys

def bitadd(a,w,bit): #aにwを加える(1-origin)
 
    x = a
    while x <= (len(bit)-1):
        bit[x] += w
        x += x & (-1 * x)
 
def bitsum(a,bit): #ind 1～aまでの和を求める
 
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & (-1 * x)
    return ret


S = input()

dic = {}

for i,s in enumerate(S):

    if s not in dic:

        dic[s] = []

    dic[s].append(i)

pair = [None] * len(S)
lis = [None] * len(S)

for i in dic:

    for j in range(len(dic[i]) // 2):

        pair[dic[i][j]] = dic[i][-1-j]
        pair[dic[i][-1-j]] = -1

numnone = 0
for i in pair:
    if i == None:
        numnone += 1

if numnone > 1:
    print (-1)
    sys.exit()

nmax = 0
for i,num in enumerate(pair):

    if num == None:
        lis[i] = len(S)//2

    if num != None and num >= 0:
        
        lis[i] = nmax
        lis[num] = len(S)-1-nmax
        nmax += 1

BIT = [0] * (len(S)+1)
ans = 0
lis.reverse()

for i,num in enumerate(lis):

    num += 1
    ans += bitsum(num,BIT)
    bitadd(num,1,BIT)

print (ans)


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

int main(){

	int n;
	int hand[100];

	while (cin >> n && n != 0){

		memset(hand, 0, sizeof(hand));
		int field = 0;
		int num = 0;

		for (int i = 0; i < 100; i++){

			char c;
			cin >> c;
			if (c == 'M') hand[num]++;
			else if (c == 'S'){ field += hand[num] + 1; hand[num] = 0; }
			else { hand[num] += field + 1; field = 0; }
			if (num + 1 < n) num++; else num = 0;
		}

		sort(hand, hand + n);

		for (int i = 0; i < n; i++)
			cout << hand[i] << ' ';
		cout << field << endl;
	}
}

Measured memory_bytes: 1180
#include<cstdio>
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
const ll NCK_MAX = 510000;

ll *fac, *finv, *inv;

void nCk_init(ll mod) {
  fac = new ll[NCK_MAX];
  finv = new ll[NCK_MAX];
  inv = new ll[NCK_MAX];
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < NCK_MAX; i++) {
    fac[i] = fac[i-1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i-1] * inv[i] % mod;
  }
}

ll nCk(ll n, ll k, ll mod) {
  if (fac == NULL) nCk_init(mod);
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

ll n, k, a[100], dp[101][100001];

int main() {
  scanf("%lld%lld", &n, &k);
  for (ll i = 0; i < n; i++) scanf("%lld", &a[i]);
  /*
  dp[0][0] = 1;
  for (ll i = 0; i < n; i++) for (ll j = 0; j <= k; j++) {
    dp[i+1][j] = (dp[i][j] + (j == 0 ? 0LL : dp[i+1][j-1]) - (j-a[i]-1 < 0 ? 0LL : dp[i][j-a[i]-1]) + mod) % mod;
  }
  printf("%lld\n", dp[n][k]);
  */
  // (1 + T + ... + T^a_1) (1 + T + ... + T^a_2) ... (1 + T + ... + T^a_n)
  // (1 - T^(a_1+1)) / (1 - T) ...
  // Mul (1 - T^(a_i+1)) / (1 - T) ^ n
  // Mul (1 - T^(a_i+1)) * sum (i+n-1 C n-1 T^i)
  for (ll i = 0; i <= k; i++) dp[0][i] = nCk(i+n-1, n-1, mod);
  for (ll i = 0; i < n; i++) for (ll j = 0; j <= k; j++) {
    dp[i+1][j] = (dp[i][j] - (j - a[i] - 1 < 0 ? 0 : dp[i][j-(a[i]+1)]) + mod) % mod;
  }
  printf("%lld\n", dp[n][k]);
}


Measured memory_bytes: 91136
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const ll inf=1e9+7;
#define y1 _y_1_
#ifndef gc
	#define gc getchar
#endif
#ifndef pc
	#define pc putchar
#endif
inline ll read(){ll f=0,x=0;register char c=gc();while(!isdigit(c))f^=c=='-',c=gc();while(isdigit(c))x=(x<<3)+(x<<1)+(c^'0'),c=gc();return x=f?-x:x;}
inline ll read(ll&x){ll f=0;x=0;register char c=gc();while(!isdigit(c))f^=c=='-',c=gc();while(isdigit(c))x=(x<<3)+(x<<1)+(c^'0'),c=gc();return x=f?-x:x;}
inline void writeln(){pc('\n');}
inline void write(ll x){if(x<0)pc('-'),x=-x;if(x>9)write(x/10);pc(x%10+'0');}
inline void writeln(const ll&x){write(x),pc('\n');}
using namespace std;
ll Q;
const ld eps=1e-6;
struct vec{
	ld x,y;
	inline bool is_zero(){return (abs(x)<=eps)&(abs(y)<=eps);}
	inline void scan(){x=read(),y=read();}
	inline vec(){x=y=0;}
	inline vec(const ld&X,const ld&Y){x=X,y=Y;}
	inline friend vec operator +(const vec&A,const vec&B){return vec(A.x+B.x,A.y+B.y);}
	inline friend vec operator -(const vec&A,const vec&B){return vec(A.x-B.x,A.y-B.y);}
	inline ld len(){return sqrt(x*x+y*y);}
	inline ld len(const ll&X,const ll&Y){return sqrt((x-X)*(x-X)+(y-Y)*(y-Y));}
	inline ld k(){return (x==0)?inf:y/x;}
	inline ld k(const ll&X,const ll&Y){return (x==X)?inf:(y-Y)/(x-X);}
	inline friend ld Dot(const vec&A,const vec&B){return A.x*B.x+A.y*B.y;}
	inline friend ld Cross(const vec&A,const vec&B){return A.x*B.y-B.x*A.y;}
	inline friend ld Theta(vec A,vec B){return acos(Cross(A,B)/A.len()/B.len());}
}p0,p1,p2;
signed main(){
	p0.scan(),p1.scan(),p1=p1-p0;
	read(Q);while (Q--){
		p2.scan(),p2=p2-p0;
		if (Cross(p1,p2)>=eps) puts("COUNTER_CLOCKWISE");
		else if (Cross(p1,p2)<-eps) puts("CLOCKWISE");
		else if (Dot(p1,p2)<-eps) puts("ONLINE_BACK");
		else puts(p1.len()<p2.len()?"ONLINE_FRONT":"ON_SEGMENT");
	}
	fclose(stdin);fclose(stdout);return 0;
}


Measured memory_bytes: 3100
D=int(input())
c=[int(i) for i in input().split()]
s=[]
for d in range(D):
    s.append([int(i) for i in input().split()])

t=[]
for d in range(D):
    t.append(int(input()) - 1)

v = [0]*D
last = [[0 for i in range(26)] for d in range(D)]

for d in range(D):
    if d>=1:
        last[d] = last[d-1][:]
    last[d][t[d]] = d+1

for d in range(D):
    v[d] = s[d][t[d]] - sum([c[i]*(d+1 - last[d][i]) for i in range(26)])

v_sum=0
for d in range(D):
    v_sum+=v[d]
    print(v_sum)

Measured memory_bytes: 9348
import java.util.Scanner;

class Main {
    private static final int[] DATE = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31,
            30, 31};

    private static final String[] DAY_OF_THE_WEEK = {"Wednesday", "Thursday",
            "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};

    public static void main(String[] args) {
        Scanner sc = null;
        try {
            sc = new Scanner(System.in);
            while (sc.hasNextInt()) {
                int month = sc.nextInt();
                int day = sc.nextInt();
                if (month == 0 || day == 0) {
                    break;
                }

                System.out.println(getDayOfTheWeek(month, day));

            }
        } finally {
            sc.close();
        }
    }

    private static String getDayOfTheWeek(int m, int d) {
        int sum = 0;
        for (int i = 0; i < m - 1; i++) {
            sum += DATE[i];
        }
        sum += d;
        return DAY_OF_THE_WEEK[sum % 7];
    }
}

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

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

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

	int *X = new int[M];
	int *diff = new int[M-1];
	int sum = 0;
	for( int i = 0; i < M; i++ )
	{
		cin >> X[i];
	}
	sort( X, X + M );
	for( int i = 0; i < M - 1; i++ )
	{
		diff[i] = X[i + 1] - X[i];
		sum += diff[i];
	}

	sort( diff, diff + M - 1 );

	for( int j = M-2; j > M-2-N+1 ; j-- )
	{
		sum -= diff[j];
	}

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf 1000000000
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  string s;
  cin >> s;
  vector<int> R, L, ans(s.size());
  for(int i = 0; i < s.size()-1; i++){ 
    if(s[i] == 'R' && s[i+1] == 'L') {
      R.push_back(i);
      L.push_back(i+1);
    }
  }  
  R.push_back(inf);
  L.push_back(inf);
  int p = 0;
  for(int i = 0; i < s.size(); i++) {
    if(i > R.at(p))p++;
    if(s[i] == 'R'){
      if((R.at(p) - i) % 2 == 0)ans.at(R.at(p))++;
      else  ans.at(L.at(p))++;
    }else{
      if((i - L.at(p-1)) % 2 == 0) ans.at(L.at(p-1))++;
      else ans.at(R.at(p-1))++;
    }
  }
  for(int i = 0; i < s.size(); i++) {
    cout << ans.at(i) << " ";
  }
}

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

const int maxn = 100010;

char str[maxn];

int main()
{
    scanf("%s",str);
    int n = strlen(str);
    int curc = str[0], curcnt = 1, cnt=0;
    for (int i=1;i<n;i++)
    {
        if (str[i] == curc)
        {
            curcnt++;
            continue;
        }
        else
        {
            curc = str[i];
            curcnt = 1;
            cnt++;
        }
    }
    if (curcnt != 0) cnt++;
    cout << cnt-1 << endl;
    return 0;
}

Measured memory_bytes: 384
s = gets.chomp.split(//)
k = gets.chomp.to_i

ans = 0

if s.all?{|c| s[0]==c}
  puts s.size * k / 2
  exit
end

if s.first == s.last
  firstc = 0
  lastc = 0
  s.each do |c|
    if c == s.first
      firstc += 1
    else
      break
    end
  end
  s.reverse.each do |c|
    if c == s.last
      lastc += 1
    else
      break
    end
  end
  # p [firstc, lastc]
  ans += firstc / 2 + lastc / 2
  ans += ((firstc + lastc) /2) * (k-1)

  s = s.slice(firstc, s.size - firstc - lastc)
end
count = 0
#p [ans, s]

ren = 1
(s.length-1).times do |i|
  if s[i] == s[i+1]
    ren += 1
  else
    if 0<ren
      count += ren/2
      ren = 1
    end
  end
end
count += ren/2

puts ans + count * k


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll h,w,a,b,ans=0;
const ll MAX = 200000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool Main(){
    cin>>h>>w>>a>>b;
    COMinit();
    For(i,b,w){
       ans+=(COM(h-a-1+i,i)*COM(w-i+a-2,a-1))%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

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

typedef long long ll;
typedef map<ll, ll> M;
typedef pair<ll, ll> P;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) ((ll)(x).size())

int main() {
  string S, T;
  cin >> S >> T;
  ll tmp, result = 1001;
  REP(i, SIZE(S)-SIZE(T)+1) {
    tmp = 0;
    REP(j, SIZE(T)) {
      if (S[i+j] != T[j]) tmp++;
    }
    if (tmp < result) result = tmp;
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3632
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

bool comp(pair<int,int> a , pair<int,int > b){
    return a.second<b.second;
}


int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  
    int n;
    cin>>n;
    int arr[n], l[n];
    rep(i,0,n)cin>>arr[i]>>l[i];

    vector<pair<int,int>>v(n);
    for(int i = 0 ; i < n;i++){
        v[i].first = arr[i]-l[i];
        v[i].second = arr[i]+l[i];
    }

    sort(all(v), comp);

    int curr = numeric_limits<int>::min();
    int ans  = 0;
    for(auto i : v){
        if(curr <= i.first){
            ans++;
            curr = i.second;
        }
    }
    

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


Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int M;

int main() {
  INCANT;
  
  cin >> M;
  ll a,b;
  ll digit = 0ll;
  ll SUM = 0ll;
  rep(i, M) {
    cin >> a >> b;
    digit+=b;
    SUM+=a*b;
  }
  cout << digit-1+(SUM-1)/9 << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int h, w;
    cin >> h >> w;
    
    vector<int> a(26);
    rep(i, h*w){
        char c; cin >> c;
        a[c-'a']++;
    }

    int p = 0, q = 0;
    rep(i, 26){
        if (a[i] % 4 != 0) p++;
        if (a[i] % 2 != 0) q++;
    }

    int t = ((h%2) * w + (w%2) * h) / 2;

    if (q <= 1 & p <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
    

    return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m, k;
  cin >> n >> m >> k;
  
  vector<ll> a(n), b(m);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 0; i < m; i++) cin >> b.at(i);
  
  vector<ll> x(n + 1), y(m + 1);
  for (int i = 0; i < n; i++) x.at(i + 1) = x.at(i) + a.at(i);
  for (int i = 0; i < m; i++) y.at(i + 1) = y.at(i) + b.at(i);
  
  ll ans = 0;
  for (ll i = 0; i <= n; i++) { // i: from A
    if (x.at(i) > k) continue;
    int l = 0, r = m + 1;
    while (r - l > 1) {
      int mid = (l + r) / 2;
      if (y.at(mid) + x.at(i) <= k) l = mid;
      else r = mid;
    }
    ans = max(ans, i + l);
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 9532