akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

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

    ll money = 1000;

    for(int i = 0; i<n-1; i++){
        ll stocks = 0;
        if(a[i] < a[i+1])stocks = money/a[i];
        money += stocks*(a[i+1] - a[i]);
    }

    cout << money << "\n";
    return 0;
}

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

const int maxN = 1e5+10;
int a[maxN];

int main() {
  int n;
  cin >> n;
  int res = 0;
  for(int i=0; i<n; i++) {
    int x;
    cin >> x;
    for(int j=0; j<=2; j++) {
      ++a[x+j];
      res = max(res, a[x+j]);
    }
  }
  cout << res;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        long fiveHCoins = x / 500;
        x -= fiveHCoins * 500;
        long fiveCoins = x / 5;
        long ans = fiveHCoins * 1000 + fiveCoins * 5;

        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
m,l = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
go = 0
ok = 0
m.times do |i|
  go = a[i-1] + a[i] if(i>=1)
  if(go >= l)
    ok = i
    puts "Possible"
    break
  end
end
if ok == 0
  puts "Impossible"
  exit
end
(1..(ok-1)).each{|i| puts "#{i}"}
((ok+1)..m-1).reverse_each{|i| puts "#{i}"}
puts ok

Measured memory_bytes: 13580
#include <iostream>
#include <string>
#include<sstream>
#include<cmath>
#include <iomanip>
#include<vector>
#include<utility>
#include<queue>
 
using namespace std;
 
int main() {
	int n; 
	cin >> n;
	vector<vector<pair<int,int>>> tree(n);
	vector<int> colors(n,-1);
	queue<int>queue;
	vector<bool>visited(n,true);
 
	for (int i = 0; i < n - 1; i++) {
		int v1, v2, w ; bool color;
		cin >> v1 >> v2 >> w;
			if(w%2==0){
				color=true;
			}
			else if(w%2==1){
				color=false;
			}
			pair<int,bool>node;
			node.first=v1-1;
			node.second=color;
			tree[v2-1].push_back(node);
			node.first=v2-1;
			tree[v1-1].push_back(node);
		
	}

	
	colors[0]=0;
	visited[0]=false;
	queue.push(0);

	while(queue.size()!=0){
		int curr = queue.front();
		queue.pop();
		for(int i= 0 ; i< tree[curr].size() ; i++){
			if(visited[tree[curr][i].first]){
				visited[tree[curr][i].first]=false;
				queue.push(tree[curr][i].first);
				if(tree[curr][i].second){
					colors[tree[curr][i].first]=colors[curr];
				}
				else{
					if(colors[curr]==0){
						colors[tree[curr][i].first]=1;
					}
					else{
						colors[tree[curr][i].first]=0;
					}
				}
			}
		}
	}

	for(int i = 0 ; i< n ; i++){
		cout<<colors[i]<<endl;
	}


 
}

Measured memory_bytes: 6784
import numpy as np

N=int(input())
a,b= map(int,input().split())
P = list(map(int, input().split()))
# P
# P=np.sort(P)

a1=[]
a2=[]
a3=[]

for i in range(0,N):
    # print(i)
    if(P[i]<=a):
        a1.append(P[i])
    elif(P[i]<=b):
        a2.append(P[i])

    else:
        a3.append(P[i])

print(np.min([len(a1),len(a2),len(a3)]))
        
        

Measured memory_bytes: 21376
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 10;
int n, m;

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  cout << (n==m ? "Yes" : "No") << endl;
}

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

int main(){
    int a, b;
    int c;
    cin >> a >> b;
    c = ((a*10) + (b*10)) / 2;
    if(c % 10   > 0)
        c= (a+b)/2 + 1;
    else
        c= (a+b)/2;
    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : aaaa.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

long long gcd(vector<long long>& B, int dep) {
	if (dep < B.size() - 1) {
		long long n = B[dep];
		long long m = gcd(B, dep + 1);
		static long long r;

		while (n != 0) {
			r = m % n;
			m = n;
			n = r;
		}
		return m;
	} else {
		return B[dep];
	}
}

int main() {
	int N;
	long long X;
	cin >> N >> X;
	vector<long long> A;
	A.push_back(X);
	for (int i = 0; i < N; ++i) {
		long long a;
		cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());

	vector<long long> B;
	for (int i = 1; i < A.size(); ++i) {
		B.push_back(A[i] - A[i - 1]);
	}
	sort(B.begin(), B.end());

	cout << gcd(B, 0) << endl;
}


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

int main() {
  int N,L;
  cin >> N>>L;
  vector<string>vec(N);
  for (int i = 0;i < N;++i) 
    cin>>vec[i];
  sort(vec.begin(),vec.end());
  for (int i = 0;i < N;++i) 
    cout<<vec[i];
  cout<<endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    }
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! chmax {
    ($x:expr, $e:expr) => {
        if $x < $e {
            $x = $e;
        }
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        if $x > $e {
            $x = $e;
        }
    };
}

const INF: usize = 1 << 60;

use std::iter::IntoIterator;

fn join_string<T, S>(elems: T) -> String
where
    T: IntoIterator<Item = S>,
    S: ToString,
{
    elems
        .into_iter()
        .map(|i| i.to_string())
        .collect::<Vec<String>>()
        .join(" ")
}

struct Solver {
    counter: Vec<usize>,
}

impl Solver {
    fn new(N: usize) -> Solver {
        Solver { counter: vec![0; N] }
    }
    fn dfs(&mut self, i: usize, graph: &Vec<Vec<usize>>, p: usize, mut acc: usize) {
        let tmp = self.counter[i];
        self.counter[i] += acc;
        acc += tmp;
        for &j in &graph[i] {
            if j == p {
                continue;
            }
            self.dfs(j, graph, i, acc);
        }
    }
}

fn main() {
    input!{
        N: usize,
        Q: usize,
        ab: [(usize1, usize1); N-1],
        px: [(usize1, usize); Q],
    }
    let mut graph = vec![Vec::new(); N];
    for (a, b) in ab {
        graph[a].push(b);
        graph[b].push(a);
    }
    let mut solver = Solver::new(N);
    for i in 0..Q {
        let (p, x) = px[i];
        solver.counter[p] += x;
    }
    solver.dfs(0, &graph, INF, 0);
    let ans = join_string(solver.counter);
    println!("{}", ans);
}


Measured memory_bytes: 51576
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a;
  b = a%10;
  if (b == 3) {
    cout << "bon";
  } else if (b == 0 || b == 1 || b == 6 || b == 8) {
    cout << "pon";
  } else {
    cout << "hon";
  }
}

Measured memory_bytes: 3636
void main() {
	auto ip = readAs!(int[]), N = ip[0], K = ip[1];
	auto l = readAs!(int[]);
	l.sort!"a > b"();
	int res;
	foreach(i; 0..K) {
		res += l[i];
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



A, B = list(map(int, sys.stdin.readline().split()))
a = A - B * 2
print(max(a, 0))


Measured memory_bytes: 23596
'''
Created on 2016/08/28

@author: diyosko7
'''

if __name__ == '__main__':
    n = 1
    lines = [str(input()) for i in range(n)]
    line = lines[0]
    strDict = {}

    v = [line[i: i+1] for i in range(0, len(line), 1)]
    
    d = {}
    for s in v:
        d.update({s:0})
    for s in v:
        d[s] += 1  
    
    flg = True
    for k,v in d.items():
        if v%2==0:
            pass
        else:
            flg = False
    if flg==True:
        print("Yes")
    else:
        print("No")

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

using namespace std;

int main()
{
    long long l, x, a, suma = 0;
    bool loop = true;
    cin>>l>>x;
    vector<long long> luz;
    suma+=x;
    luz.push_back(x);
    a = l-x;
    suma+=a;
    luz.push_back(a);
    while(loop)
    {
        sort(luz.begin(),luz.end());
       if(luz[1]%luz[0] == 0)
            loop = false;
        a = luz[1]/luz[0];
        luz[1] -= a*luz[0];
        a*=2;
        if(!loop)
            a--;
        a*=luz[0];
        suma+=a;
    }
    cout<<suma<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/


int main(void) {
  ll i, j, k;
  
  ll a, b, c;
  cin >> a >> b >> c;
  
  if(c-a-b<=0) {
    pt("No");
  }else {
    if(4*a*b<(c-a-b)*(c-a-b)) {
      pt("Yes");
    }else {
      pt("No");
    }
    
    
  }
  
  
  
  
  
}



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

int main(void)
{
    int i, j, k, N, K, a[1000], tmp, sum;
    sum = 0;
    cin >> N >> K;
    for (i = 0; i < N; i++)
    {
        cin >> a[i];
    }
    for (j = 0; j < N; j++)
    {
        for (k = 0; k < j; k++)
        {
            if (a[j] < a[k])
            {
                tmp = a[k];
                a[k] = a[j];
                a[j] = tmp;
            }
        }
    }
    for (i = 0; i < K; i++)
    {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3648
var a,b,c,d,sum,i:longint;
begin
  readln(a);
  readln(b);
  readln(c);
  readln(d);
  if a<b then
   begin
     for i:=1 to a do
       sum:=sum+c;
      writeln(sum);
      halt;
   end;
  for i:=1 to b do
    sum:=c+sum;
    if a>b then begin
     for i:=1 to a-b do
       sum:=sum+D;
      end;
writeln(sum);
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;

struct point {
  int x, y, id;
};
inline bool operator <(const point &a, const point &b) {
  return a.x < b.x || (a.x == b.x && a.y < b.y);
}

int n, a, b, d, par[N];
ll cnte[N], que[N];
point p[N];

int root(int v) {
  return (par[v] < 0) ? v : (par[v] = root(par[v]));
}

void join(int x, int y, ll val) {
  x = root(x); y = root(y);
  cnte[x] += val;
  if (x == y) return;
  if (par[x] > par[y]) swap(x, y);
  par[x] += par[y];
  cnte[x] += cnte[y];
  par[y] = x;
}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> a >> b;
  for (int i = 1, x, y; i <= n; ++i) {
    cin >> x >> y;
    p[i] = {x - y, x + y, i};
    par[i] = -1;
  }
  d = max(abs(p[a].x - p[b].x), abs(p[a].y - p[b].y));

  sort(p + 1, p + 1 + n);
  for (int i = 1; i <= n; ++i) {
    int L = lower_bound(p + 1, p + 1 + n, point({p[i].x + d, p[i].y - d, 0})) - p;
    int R = upper_bound(p + 1, p + 1 + n, point({p[i].x + d, p[i].y + d, 0})) - p - 1;
    if (L == n + 1 || R < L || p[L].x != p[i].x + d) continue;
    join(p[i].id, p[L].id, 1);
    ++que[L]; --que[R];
  }
  for (int i = 1; i <= n; ++i) {
    que[i] += que[i - 1];
    if (que[i]) join(p[i].id, p[i + 1].id, que[i]);
  }

  for (int i = 1; i <= n; ++i) swap(p[i].x, p[i].y);
  sort(p + 1, p + 1 + n);
  for (int i = 1; i <= n; ++i) que[i] = 0;
  for (int i = 1; i <= n; ++i) {
    int L = upper_bound(p + 1, p + 1 + n, point({p[i].x + d, p[i].y - d, 0})) - p;
    int R = lower_bound(p + 1, p + 1 + n, point({p[i].x + d, p[i].y + d, 0})) - p - 1;
    if (L == n + 1 || R < L || p[L].x != p[i].x + d) continue;
    join(p[i].id, p[L].id, 1);
    ++que[L]; --que[R];
  }
  for (int i = 1; i <= n; ++i) {
    que[i] += que[i - 1];
    if (que[i]) join(p[i].id, p[i + 1].id, que[i]);
  }

  cout << cnte[root(a)];
  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
namespace ztd{
    using namespace std;
    #define reg register
    #define ms(a) memset(a,0,sizeof(a))
    #define count(x) __builtin_popcountll(x)
    #define smallest_one(x) __builtin_ffsll(x)
    typedef long long ll;
    typedef unsigned long long ull;
    typedef unsigned int uint;
    typedef double db;
    //basic I/O
    template<typename T> inline T read(T& t) {//fast read
        t=0;short f=1;char ch=getchar();double d = 0.1;
        while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
        while (ch>='0'&&ch<='9') t=t*10+ch-'0',ch=getchar();
        if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
        t*=f;
        return t;
    }
    bool is_prime(ll x){
        for(ll i = 2; i*i <= x; ++i) if(!(x%i)) return 0;
        return x >= 2;
    }
    ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}

    void exgcd(int a, int b, int &x, int &y){
        if(!b) {x = 1, y = 0; return;}
        exgcd(b,a%b,x,y);
        int p = x; x = y; y = p-a/b*y;
     }
    inline ll ksm(ll x, ll y, ll mod){
        ll ret = 1;
        while(y){if(y & 1) ret = ret * x % mod; y >>= 1; x = x*x%mod;}
        return ret;
    }
    inline ll inv(ll x, ll mod){return ksm(x,mod-2,mod);}
}
using namespace ztd;
ll n, x;
signed main(){
    read(n);
    for(int i = 1; i <= n; ++i){
		x = (x * 10 + 7) % n;
		if(x == 0) {
			cout << i << endl;
			return 0;
		}
    }
	cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MOD (long long)(1e9 + 7)
using namespace std;
using ll = long long;
#define all(v) v.begin(), v.end()

ll l, osize, zsize, n;
string z, o;
map<ll, char> ma, hoge;
bool ok(ll lind, char wtp);
bool hogepush(ll ind, char wtp);

long long calcans(long long x) {
  long long ans = 1, now = 26;
  while(x > 0) {
    if(x & 1) (ans *= now) %= MOD;
    (now *= now) %= MOD;
    x >>= 1;
  }
  return ans;
}

signed main() {
  cin >> z >> o >> n;
  osize = o.size();
  zsize = z.size();
  l = 2 * n + zsize + osize;
  for(int i = 0; i < osize; i++) {
    ll lind = min(osize - 1 - i, 2 * n + zsize + i);
    if(!ok(lind, o[i])) {
      cout << 0 << endl;
      return 0;
    }
  } // oを入れ、対応して決まる穂毛をマーク
  // zaki check
  for(int i = 0; i < zsize; i++) {
    ll lind = min(l - 1 - n - i, n + i);
    if(!ok(lind, z[i])) {
      cout << 0 << endl;
      return 0;
    }
  }
  ll lcent = (l - 1) / 2, rcent = l / 2, cnt = 0;
  if(n <= lcent && lcent < n + zsize) {
    long long lef = lcent - n + 1, righ = n + zsize - rcent;
    cnt = max(0LL, n - osize);
  }
  else {
    long long lef = lcent - n - zsize + 1,
              righ = 2 * n + zsize - rcent;
    if(righ < lef)
      cnt = righ;
    else
      cnt = max(0LL, n - osize);
  }
  cout << calcans((cnt + 1) / 2) << endl;
}

bool ok(ll lind, char wtp) {
  ll rind = l - 1 - lind;
  if(ma.find(lind) == ma.end() || ma[lind] == wtp) {
    ma[lind] = wtp;
    if(!hogepush(lind, wtp)) { return false; }
  }
  else
    return false;

  if(ma.find(rind) == ma.end() || ma[rind] == wtp) {
    ma[rind] = wtp;
    if(!hogepush(rind, wtp)) { return false; }
    else
      return true;
  }
  else
    return false;
  return 1;
}

bool hogepush(ll ind, char wtp) {
  if(0 <= ind && ind < n) {
    if(hoge.find(ind) == hoge.end() || hoge[ind] == wtp) {
      hoge[ind] = wtp;
      return true;
    }
    else
      return false;
  }
  else if(n + zsize <= ind && ind < 2 * n + zsize) {
    ind -= n + zsize;
    if(hoge.find(ind) == hoge.end() || hoge[ind] == wtp) {
      hoge[ind] = wtp;
      return true;
    }
    else {
      return false;
    }
  }
  return true;
}




Measured memory_bytes: 24832
#include<bits/stdc++.h>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
#define Hare printf("here\n")
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define x first
#define y second
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))

//first four adjacent,second four corner
//int row[8]={0,-1,0,1,1,-1,-1,1};
//int col[8]={-1,0,1,0,-1,-1,1,1};
using namespace std;

int main(){
    int i,j,k,n,m,val,t=0,cnt,test;
    //freopen("000input.txt","r",stdin);
    cin>>n;
    int arr[n+5];
    for(i=n-1;i>=0;i--)scanf("%d",&arr[i]);
    int ans[n+5];
    ans[0]=0,ans[1]=abs(arr[0]-arr[1]);
    for(i=2;i<n;i++){
        ans[i]=min(ans[i-1]+abs(arr[i-1]-arr[i]),ans[i-2]+abs(arr[i-2]-arr[i]));
    }
    printf("%d\n",ans[n-1]);

    //free();   //if pointer array
    return 0;
}


Measured memory_bytes: 1152
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) {
    cin>>a[i];
    --a[i];
  }
  int re=0;
  rep(i,n) if(i<a[i] && i==a[a[i]]) ++re;
  cout<<re<<endl;
  return 0;
}


Measured memory_bytes: 768
import queue
target = int(input())

q = queue.Queue()

for i in range(1,10):
  q.put(str(i))


for cnt in range(1, target):
  num = q.get()
  mod = int(num) % 10
  
  if mod == 0:
    q.put(num + "0")
    q.put(num + "1")
  elif mod == 9:
    q.put(num + "8")
    q.put(num + "9")
  else:
    q.put(num + str(mod - 1))
    q.put(num + str(mod))
    q.put(num + str(mod + 1))

print(q.get())

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

int calc(int x) {
	int ret = 0;
	while (x % 100 == 0) {
		x /= 100;
		++ret;
	}
	return ret;
}

int main() {
	int D, N;
	cin >> D >> N;
	int cnt = 0, ans = 0;
	while (cnt < N) {
		++ans;
		if (calc(ans) == D) ++cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>d(n);
    rep(i,n)cin>>d[i];
    sort(d.begin(),d.end());
    cout<<d[n/2]-d[n/2-1]<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N, ans = 0;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    for (int i = 1; i < N; i++)
    {
        if (H[i - 1] > H[i])
        {
            ans += (H[i - 1] - H[i]);
        }
    }
    ans += H[N - 1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

string C(const string& S)
{
    const int N = S.size();
    string s;
    s.resize(N);
    for (int i = 0; i < N; i++) {
        s[i] = S[(i + 1) % N];
    }
    return s;
}

string J(const string& S)
{
    const int N = S.size();
    string s;
    s.resize(N);
    for (int i = 0; i < N; i++) {
        s[i] = S[(i + N - 1) % N];
    }
    return s;
}

string E(const string& S)
{
    const int N = S.size();
    const int shift = (N + 1) / 2;
    string s = S;
    for (int i = 0; i < N; i++) {
        if (i + shift < N) {
            s[i] = S[i + shift];
        } else if (i - shift >= 0) {
            s[i] = S[i - shift];
        }
    }
    return s;
}

string A(const string& S)
{
    string s = S;
    reverse(s.begin(), s.end());
    return s;
}

string P(const string& S)
{
    const int N = S.size();
    string s = S;
    for (int i = 0; i < N; i++) {
        if (s[i] >= '1' and s[i] <= '9') {
            s[i]--;
        } else if (s[i] == '0') {
            s[i] = '9';
        }
    }
    return s;
}

string M(const string& S)
{
    const int N = S.size();
    string s = S;
    for (int i = 0; i < N; i++) {
        if (s[i] >= '0' and s[i] <= '8') {
            s[i]++;
        } else if (s[i] == '9') {
            s[i] = '0';
        }
    }
    return s;
}

string op(const char c, const string& S)
{
    switch (c) {
    case 'J':
        return J(S);
    case 'C':
        return C(S);
    case 'E':
        return E(S);
    case 'A':
        return A(S);
    case 'P':
        return P(S);
    case 'M':
        return M(S);
    }
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        reverse(s.begin(), s.end());
        string m;
        cin >> m;
        for (const char c : s) {
            m = op(c, m);
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 3232
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
//#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vi dp(1<<16,-1);
		dp[0]=0;
		while(n--){
			int s,t;
			cin>>s>>t;
			int q=0;
			rep(j,s){
				int a,b;
				cin>>a>>b;
				loop(k,a,b)q|=1<<(k-6);
			}
			rep(j,1<<16)if((j&q)==0){
				dp[j|q]=max(dp[j|q],dp[j]+t);
			}
		}
		ll out=0;
		rep(i,1<<16)out=max(out,dp[i]);
		cout<<out<<endl;
	}
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	double a[n];
	double sum = 0;
	REP(i, n){
		cin >> a[i];
		sum += (1/a[i]);
	}

	printf("%.10lf\n", 1/sum);

}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N;
	int K;
	int min = 0,max = 0;
	
	scanf("%d %d",&N,&K); 
	while(N >= K){
		N -= K;
		min++;
	}
	if(N == 0)	max = min;
  else max = min + 1;
	printf("%d",max - min);
	return 0;
}

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

//　バケット法
int main()
{
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++) cin >> vec.at(i);

    vector<int> vec2(110);
    for (int i=0; i<n; i++)
    {
        vec2.at(vec.at(i))++;
    }

    int ans = 0;
    for (int i =1; i<= 100; i++) {
        if(vec2.at(i)) {
            ans++;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if all(i == -1 for i in (m, f, r)):
        break
    if any(i == -1 for i in (m, f)):
        rank = 'F'
    else:
        score = m + f
        if score >= 80:
            rank = 'A'
        elif score >= 65:
            rank = 'B'
        elif score >= 50:
            rank = 'C'
        elif score >= 30:
            if r >= 50:
                rank = 'C'
            else:
                rank = 'D'
        else:
            rank = 'F'
    print(rank)


Measured memory_bytes: 5604
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define ld long double
#define F first
#define S second
#define mem(v) memset(v,0,sizeof(v))
#define all(v) v.begin(), v.end()
#define srt(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define hell 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; 
if (m == 1) {return 0;} 
while (a > 1) { ll q = a / m; ll t = m;  m = a % m, a = t; t = y; y = x - q * y; x = t; } 
if (x < 0) {x += m0;} return x; } 
inline ll add(ll a, ll b) { return (((a >= hell) ? a % hell : a) + ((b >= hell) ? b % hell : b) + hell) % hell; }
inline ll subt(ll a, ll b) { return (a - b + hell) % hell; }
inline ll mult(ll a, ll b) { return (1ll * ((a >= hell) ? a % hell : a) * ((b >= hell) ? b % hell : b)) % hell; }
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll mylog(ll n,ll b)
{ll i = 1;ll ans = 0;
while(1)
{if(i>n/b){break;} i = i*b;ans++;}return ans;
}
bool compare(const pair<ll,ll> &a,const pair<ll,ll> &b){
if (a.first == b.first)
{return a.second<b.second;} 
return a.first<b.first;
}
bool comparerev(const pair<ll,ll> &a,const pair<ll,ll> &b){
if(a.first == b.first)
{return a.second>b.second;}
return a.first>b.first;
}


int main(){
    long long int n,r=0,g=0,b=0,ans=0;
    string s;
    cin>>n>>s;
   for(int i=0; i<n; i++){
       if(s[i]=='R'){
           r++;
       }
       else if(s[i]=='G'){
           g++;
       }
       else{
           b++;
           }
           
       
   } 
   ans=r*g*b;
   for(int i=0;i<n;i++){
       for(int j=1;i+2*j<n;j++){
           if(s[i]!=s[i+j]&&s[i+2*j]!=s[i]&&s[i+2*j]!=s[i+j]){
               ans=ans-1;
           }
       }
   }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
#define vecout(V) for(int i=0;i<V.size();i++) {cout<<V[i]<<endl;}
typedef long long ll;

int main(void){
    int n;
    cin>>n;
    string s;
    cin>>s;
    rep(i, s.size()) {
        int a=(int)s[i]+n;
        if(a>=91) a-=26; 
        char c=(char)a;
        cout<<c;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = 0, max_index = 0;
long long min_value = MAX, min_index = 0;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> A >> B;
    int delta = B - A;
    rep(i, delta){
        sum += i;
    }
    cout << sum - A;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string a;
    int num[101],cou=0,ans;
    while(cin>>a){
        for(int i=0;i<a.size();i++){
        if(a[i]=='I')num[i]=1;
        if(a[i]=='V')num[i]=5;
        if(a[i]=='X')num[i]=10;
        if(a[i]=='L')num[i]=50;
        if(a[i]=='C')num[i]=100;
        if(a[i]=='D')num[i]=500;
        if(a[i]=='M')num[i]=1000;
    }
    ans=num[a.size()-1];
    for(int i=a.size()-1;i>0;i--){
        if(num[i]>num[i-1])ans=ans-num[i-1];
        if(num[i]<=num[i-1])ans=ans+num[i-1];
    }
    cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 1176
def inpl(): return [int(i) for i in input().split()]
N = int(input())
A = inpl()
B = inpl()
M = sum(B)-sum(A)
ans = 'Yes'
if M < 0:
    ans = 'No'
ca, cb = 0, 0
for i in range(N):
    dba = B[i] - A[i]
    if dba > 0:
        ca += -(-dba//2)
        cb += dba%2
    else:
        cb -= dba
if M != 2*ca-cb or ca > M:
    ans = 'No'
print(ans)

Measured memory_bytes: 4596
#include <cstdio>
#include <algorithm>
#define ll long long
using namespace std;

ll get(ll l, ll r, ll x) {
	return (r / x - l / x + (l % x == 0 ? 1LL : 0LL));
}

ll gcd(ll a, ll b) {
	while (b) {
		a = a % b;
		swap(a, b);
	}
	return a;
}

int main() {
	ll a, b;
	ll c, d;
	scanf("%lld%lld", &a, &b);
	scanf("%lld%lld", &c, &d);
	ll ans = b - a + 1;
	ans -= get(a, b, c) + get(a, b, d) - get(a, b, c *d / gcd(c, d));
	printf("%lld\n", ans);
	return 0;
}

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

int main() {

    int numAmount;
    cin >> numAmount;

    int outOfPlace = 0;

    for (int i = 0; i < numAmount; i++) {
        int x;
        cin >> x;

        if (x != i+1)
            outOfPlace++;
    }

    if (outOfPlace < 3)
        cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#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()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    vector<bool> dp(1e6 + 1, true);

    rep(i, N)
    {
        ll a = A[i];
        if (!dp[a])
            continue;
        if (i < A.size() - 1)
            if (a == A[i + 1])
                dp[a] = false;

        for (int j = 2; j * a <= 1e6; j++)
            dp[a * j] = false;
    }

    ll ans = 0;
    rep(i, N) if (dp[A[i]]) ans++;

    cout << ans << endl;

    return 0;
}


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

int main() {
    long H, W;
    cin>>H>>W;
    long ans = 0;
    ans += H/2*W;
    if(H%2==1){
        if(W%2==1){
            ans += W/2+1;
        }
        else{
            ans += W/2;
        }
    }
    if(H==1 | W==1)cout<<1<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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


int main(){
    
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i,N){
        cin >> a[i];
    }

    int ans=INF;
    FOR(k,-100,101){
        int cost=0;
        REP(i,N){
            int t=a[i]-k;
            cost += t*t;
        }
        ans=min(ans,cost);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
//#include<windows.h>
//#include<errno.h>
 
#define Iset int i,j,l
#define man 10000
#define cn continue
 
int pas[101], dt[101][4][4];
 
using namespace std;
 
int main() {
    int n, k;
    Iset;
    int ans = 0;
    cin >> n >> k;
    for (i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        pas[a] = b;
    }
    dt[0][0][0] = 1;
    for (i = 1; i <= n; i++) {
        if (pas[i] == 0) {
            for (j = 1; j <= 3; j++) {
                for (k = 0; k <= 3; k++) {
                    for (l = 0; l <= 3; l++) {
                        if (j == k && l == k) cn;
                        dt[i][j][k] += dt[i - 1][k][l];
                        dt[i][j][k] %= man;
                    }
                }
            }
        }
        else {
            for (k = 0; k <= 3; k++) {
                for (l = 0; l <= 3; l++) {
                    if (pas[i] == k && l == k)cn;
                    dt[i][pas[i]][k] += dt[i - 1][k][l];
                    dt[i][pas[i]][k] %= man;
                }
            }
        }
    }
    for (i = 1; i <= 3; i++) {
        for (j = 1; j <= 3; j++) {
            ans += dt[n][i][j];
            ans %= man;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;

vector<pair<char,int64_t>> run_length_encode(const string &s){
  vector<pair<char,int64_t>> ret;

  for(auto &x : s){
    if(ret.empty()) ret.push_back({x,1});
    else if(ret.back().fst == x) ++ret.back().snd;
    else ret.push_back({x,1});
  }

  return ret;
}


LLI solve(string s, LLI k){
  LLI ret = 0;
  if(s.back() == s.front()){
    if(count(ALL(s), s[0]) == (int)s.size()){
      ret = ((LLI)s.size() * k) / 2;
    }else{
      auto r = run_length_encode(s);

      FOR(i,1,r.size()-1){
        ret += (LLI)(r[i].snd / 2) * k;
      }

      ret += r.front().snd / 2;
      ret += r.back().snd / 2;

      ret += ((r.front().snd + r.back().snd) / 2) * (k-1);
    }
  }else{
    auto r = run_length_encode(s);
    for(auto &p : r){
      ret += p.snd/2;
    }

    ret *= k;
  }

  return ret;
}


int main(){
  string s;
  LLI k;
  while(cin >> s >> k){
    cout << solve(s,k) << endl;
  }

  return 0;
}


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

using namespace std;

const int MAX_N = 1e5 + 200;

int n, k, ai[MAX_N], pos[MAX_N];

int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &ai[i]);
    printf("%d\n", int(ceil(1.0 * (n - k) / (k - 1)) + 1));
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void) {
    int n,k;
    scanf("%d%d",&n,&k);
    char s[n];
    scanf("%s",s);
    
    s[k-1] = s[k-1] + 32;
    printf("%s\n",s);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long

using namespace std;

inline void Rd(int &res) {
	char c; res = 0;
	while (c = getchar(), c < '0');
	do {
		res = (res << 1) + (res << 3) + (c ^ 48);
	} while (c = getchar(), c >= '0');
}

const int M = (int) 1e5 + 5;

ll ans;
bool flag;
int n, m, Head[M], tot, col[M], sz[3], cntedge;
struct Node {int to, nxt, type;} Edge[M << 1];

inline void Addedge(int a, int b) {
	Edge[tot] = (Node) {b, Head[a], 1}; Head[a] = tot++;
	Edge[tot] = (Node) {a, Head[b], -1}; Head[b] = tot++;
}

void dfs(int x) {
	sz[col[x]]++;
	for (int i = Head[x]; ~i; i = Edge[i].nxt) {
		int to = Edge[i].to;
		cntedge += (Edge[i].type == 1);
		if (col[to] == -1) col[to] = (col[x] + Edge[i].type + 3) % 3, dfs(to);
		else if (col[to] != (col[x] + Edge[i].type + 3) % 3) flag = false;
	}
}

int main() {
	Rd(n), Rd(m);
	memset(col, -1, sizeof(col));
	memset(Head, -1, sizeof(Head));
	while (m--) {
		int a, b;
		Rd(a), Rd(b);
		Addedge(a, b);
	}
	for (int i = 1; i <= n; i++) {
		if (~col[i]) continue;
		col[i] = 0, flag = true, cntedge = 0;
		memset(sz, 0, sizeof(sz));
		dfs(i);
		if (!flag) ans += (ll) (sz[0] + sz[1] + sz[2]) * (sz[0] + sz[1] + sz[2]);
		else if (!sz[1] || !sz[2]) ans += cntedge;
		else ans += (ll) sz[0] * sz[1] + (ll) sz[1] * sz[2] + (ll) sz[2] * sz[0];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
char s[10];
int c;
int main() {
	scanf("%s", s);
	for (int i = 0; i < 3; i++) {
		for (int j = i + 1; j < 4; j++) {
			if (s[i] == s[j])c++;
		}
	}
	if (c == 2)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long T = scan.nextLong();
        List<Pair> zero_list = new ArrayList<>();
        List<Pair> non_zero_list = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            long a = scan.nextLong();
            long b = scan.nextLong();
            Pair p = new Pair(a, b);
            if (a == 0) {
                zero_list.add(p);
            } else {
                non_zero_list.add(p);
            }
        }

        zero_list.sort(new ZeroPairComparator());
        long[] z = new long[zero_list.size()+1];
        for (int i = 0; i < zero_list.size(); i++) {
            z[i + 1] = Math.min(z[i] + zero_list.get(i).b + 1, T + 1);
        }
        TreeMap<Long, Integer> zero_tree = new TreeMap<>();
        for (int i = 0; i < z.length; i++) {
            zero_tree.put(z[i], i);
        }

        non_zero_list.sort(new NonZeroPairComparator());
        long[] dp = new long[41];
        Arrays.fill(dp, T+1);
        dp[0] = 0;
        int len = non_zero_list.size();
        for (int i = 0; i < len; i++) {
            Pair p = non_zero_list.get(i);
            for (int j = 40; 0 <= j; j--) {
                if ( T < dp[j]) {
                    continue;
                }
                long time = dp[j] + 1 + p.a * (dp[j] + 1) + p.b;
                dp[j+1] = Math.min(dp[j+1], time);
            }
        }
        long ans = 0;
        for (int i = 0; i <= 40; i++) {
            if (T < dp[i]) {
                continue;
            }
            long count = i + zero_tree.floorEntry(T - dp[i]).getValue();
            ans = Math.max(ans, count);
        }
        System.out.println(ans);
    }

    class Pair {
        long a;
        long b;
        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    class ZeroPairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            return Long.compare(o1.b, o2.b);
        }
    }

    class NonZeroPairComparator implements Comparator<Pair> {
        @Override
        public int compare(Pair o1, Pair o2) {
            return -Long.compare(o1.a * (o2.b + 1), o2.a * (o1.b+1));
        }
    }
}


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

int main(){

    int n;
    cin >> n;
    vector<int> p(n);
    int cnt = 0;
    for (int i=0; i<n; i++){
        cin >> p.at(i);
    }
    
    for (int i=0; i<n; i++){
        if (p.at(i) != i+1){
            cnt++;
        }
        if (cnt > 2){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0:
        break
    
    first_group_menbers = set(input()[:-1].split(":")[1].split(","))
    d = {}
    for i in range(N-1):
        group, members = input()[:-1].split(":")
        d[group] = set(members.split(","))
        
    for i in range(N-1):
        for group, members in d.items():
            if group in first_group_menbers:
                first_group_menbers.remove(group)
                for m in members:
                    first_group_menbers.add(m)
    
    print(len(first_group_menbers))

Measured memory_bytes: 6780
//Author: kaiyu
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <iomanip>
#include <climits>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<int,int>
#define tt ll t;cin >> t;while(t--)
#define int3(x,y,z) ll x,y,z;cin >> x >> y >> z;
#define int2(x,y) ll x,y;cin >> x >>y;
#define int1(x) ll x;cin>>x;
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}

ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


bool cmp(pair<string,int>p1,pair<string,int>p2) {
    return p1.ss > p2.ss;
}

const int MAXN = 5 * 100000 + 10;

#define int long long

int32_t main() {
    fio
    int n,m;
    cin >> n >> m;
    int h[n+1];
    vector<vi>pk(n+1);
    for (int i = 1; i <= n; ++i) {
        cin >> h[i];
    }
    for (int j = 0; j < m; ++j) {
        int x,y;
        cin >> x >> y;
        pk[x].pb(y);
        pk[y].pb(x);
    }
    int good = 0;
    for (int k = 1; k <= n; ++k) {
        bool cc = 0;
        bool gr = 0;
        for (int i = 0; i < pk[k].size(); ++i) {
            if(h[k] > h[pk[k][i]]) {
                gr = 1;
                cc = 1;
            }
            else{ gr = 0; cc=1 ;break;}

            cc = 1;
        }
        if(gr) good++;
        if(!cc)good++;
    }
    cout << good << endl;
}






Measured memory_bytes: 9780