akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
    long int n, i = 0, x, count = 0;
    int rem[100000], k;
    scanf("%ld %d", &n, &k);

    while(n>0){
        rem[i] = n%k;
        n/=k;
        i++;
    }
    for(x = i-1; x>=0; x--){
        count++;
    }
    printf("%ld", count);
    return 0;
}


Measured memory_bytes: 128
/* airplain */

#include <stdio.h>

int main(void)
{
  int P, Q, R, atbtc, atctb, btatc, min;

  scanf("%d", &P);
  scanf("%d", &Q);
  scanf("%d", &R);

  atbtc = P + Q;
  min = atbtc;

  atctb = R + Q;
  if(min > atctb){
    min = atctb;
  }

  btatc = P + R;
  if(min > btatc){
    min = btatc;
  }

  printf("%d\n", min);

  return 0;
}
 


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
  	Scanner sc=new Scanner(System.in);
    int N=sc.nextInt();
    long[] A=new long[N];
    long mul=1l;
    boolean flag=false;
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();
      if(A[i]==0){
        mul=0;
        flag=true;
      }
    }
    
    for(int i=0;i<N;i++){
      if(flag){
        break;
      }
      long afterMul=mul*A[i];
      long check=afterMul/A[i];
      
      if(check-1!=mul&&check!=mul&&check+1!=mul){
        mul=-1;
        break;
      }else{
        mul=afterMul;
      }
    }
      if(mul>1000000000000000000l) System.out.println(-1);
      else System.out.println(mul);
  }
}

Measured memory_bytes: 61328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 114514810;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int cost[105][105];
int main()
{
	int n;
	cin >> n;
	REP(i, n)REP(j, n)
	{
		int t;
		cin >> t;
		cost[i][j] = t;
	}
	ll sum = 0;
	REP(i, n)
	{
		FOR(j, i + 1, n)
		{
			sum += min(cost[i][j], cost[j][i]);
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1200
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func dist(x1, y1, x2, y2 int) int {
	return abs(x1-x2) + abs(y1-y2)
}

func main() {
	sc.Split(bufio.ScanWords)
	n, m := nextInt(), nextInt()
	a, b := make([]int, n), make([]int, n)
	c, d := make([]int, m), make([]int, m)

	for i := 0; i < n; i++ {
		a[i], b[i] = nextInt(), nextInt()
	}
	for i := 0; i < m; i++ {
		c[i], d[i] = nextInt(), nextInt()
	}

	for i := 0; i < n; i++ {
		min := dist(a[i], b[i], c[0], d[0])
		minJ := 0
		for j := 1; j < m; j++ {
			if d := dist(a[i], b[i], c[j], d[j]); d < min {
				min = d
				minJ = j
			}
		}
		puts(minJ + 1)
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


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

int main(){
    string S;cin>>S;
    int N=S.size();
    string now=S.substr(0,1);
    int count=1;
    for(int i=1;i<N;i++){
        if(i==N-1){
            if(now.size()==1 and S.substr(i,1)==now)break;
            else count++;
        }
        else if(now.size()==2){
            count++;
            now=S.substr(i,1);
        }
        else if(now.size()==1 and S.substr(i,1)==now){
            count++;
            now=S.substr(i,2);
            i++;
        }
        else if(now.size()==1){
            count++;
            now=S.substr(i,1);
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize
    }
    let mut d = 0;
    let mut m = n;
    while m > 0 {
        d += m % 10;
        m /= 10;
    }
    if n % d == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main()
{
  int n;
  cin >> n;
  int ans(0);
  int xa(0), ba(0), bx(0);

  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    auto pos = s.find("AB");
    while (pos != string::npos) {
      ans++;
      pos = s.find("AB", pos + 2);
    }
    int m(0);
    if (s.front() == 'B') m += 1;
    if (s.back() == 'A') m += 2;
    switch (m) {
    case 1: bx++; break;
    case 2: xa++; break;
    case 3: ba++; break;
    }
  }
  ans += ba == 0 ? min(xa, bx) : xa + bx == 0 ? ba - 1 : ba + min(xa, bx);
  cout << ans << endl;
}


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



namespace Test1 {

    class ClassMain {




        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                string[] strs = line.Split(' ');
                int a = int.Parse(strs[0]), b = int.Parse(strs[1]);

                Console.WriteLine(a + b);


            }
        }

    }
}

Measured memory_bytes: 19980
/******************************\
*  Everyone has a different way of thinking, so God Created us
Hope You Respect My Way..,Thank You ):  *
*                            *
*   Created by : Murad   *
\******************************/
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
#include<bits/stdc++.h>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define MP make_pair
#define ff first
#define ss second
#define INF 2147483647
#define _INF -2147483647
#define pq priority_queue
#define MM multimap
#define PB push_back
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
LL MMIN(LL a, LL b)
{
	if (a <= b)
		return a;
	else
		return b;
}
LL MMAX(LL a, LL b) {
	if (a >= b)
		return a;
	else
		return b;
}
int main()
{
	El3zba;
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int ans = 0;
	for (int i = 1; i < n-1; i++)
	{
		if (a[i - 1] < a[i] && a[i] < a[i + 1])
			ans++;
		else if (a[i - 1] > a[i] && a[i] > a[i + 1])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,q; scanf("%d%d",&n,&q);
	static int c[300000];
	rep(i,n) scanf("%d",c+i);
	sort(c,c+n);

	rep(_,q){
		int m; scanf("%d",&m);
		int ans=0;
		for(int a=0;a<=300000+m;a+=m){
			int idx=lower_bound(c,c+n,a)-c-1;
			if(idx>=0) ans=max(ans,c[idx]%m);
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2212
from collections import Counter
N = int(input())
# 正数列A
A = list(map(int, input().split()))
Q = int(input())
# B_iである要素をC_iに置き換える
B_C = [list(map(int, input().split())) for _ in range(Q)]

all_count = Counter(A)
S = sum(A)

for B, C in B_C:

    count_B = all_count[B]
    all_count[B] = 0
    all_count[C] += count_B
    S = S + (C-B)*count_B

    print(S)

Measured memory_bytes: 40072
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;

vector<vector<ll>> multiply(vector<vector<ll>> A,vector<vector<ll>> B){
    int n = A.size();
    vector<vector<ll>> C(n,vector<ll>(n,0));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int x=0;x<n;x++){
                C[i][j] = (C[i][j] + A[i][x]*B[x][j]) % mod;    
            } 
        }
    }
    return C;
}

vector<vector<ll>> power(vector<vector<ll>>& matrix,ll exp){
    if(exp==1){
        return matrix;
    }
    vector<vector<ll>> result = power(matrix,exp/2);
    if(exp&1){
        return multiply(multiply(matrix,result),result);
    }
    else{
        return multiply(result,result);
    }
}

ll totalPaths(vector<vector<ll>>& adj,ll k,int n){
    vector<vector<ll> > ak = power(adj,k);
    ll ans = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            ans = (ans + ak[i][j]) % mod;
        }
    }
    return ans;
}

int main(){
    int n;
    ll k;
    cin>>n>>k;
    vector<vector<ll> > adj(n,vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>adj[i][j];
        }
    }
    cout<<totalPaths(adj,k,n);
    return 0;
}


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

const int INF = 1e9 + 5;

int main(){
	
	int n;
    scanf("%d", &n);
    vector<int> fill(n);
    for(int& x : fill) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
	dp[1] = abs(fill[1]-fill[0]);
	
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-2]+abs(fill[i-2]-fill[i]),dp[i-1]+abs(fill[i-1]-fill[i]));
	}
	
    printf("%d\n", dp[n-1]);
	
	return 0;
}


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

using namespace std;

int fib[1002];

int main(){
    fib[0] = 1;
    fib[1] = 2;

    for(int i=2;i<1002;i++){
        fib[i] = (fib[i-1] + fib[i-2]) % 1001;
    }

    int v,d;

    while(cin >> v >> d){
        if((v|d) == 0) break;
        vector<int> vec;
        int res = 1;
        for(int i=1;i<=v;i++){
            vec.push_back(fib[i]);
        }
        sort(vec.begin(), vec.end());

        for(int i=1;i<vec.size();i++){
            if(vec[i] - vec[i-1] >= d){
                res++;
            }
        }
        cout << res << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  int A[210];
  for (int i=0; i<N; i++){
    cin >> A[i];
  }
  int count=0;
  while(1){
    bool odd=false;
    for (int i=0; i<N; i++){
      if (A[i]%2==1){
        odd=true;
      }
    }
    if (odd){
      break;
    }
    for (int i=0; i<N; i++){
      A[i]/=2;
    }
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int first = 0;
    int second = 0;
    int maxindex = 0;

    for (int i = 0; i < n; i++) {
      int a = sc.nextInt();
      int ftmp = first;
      first = Math.max(ftmp, a);
      if (first > ftmp) {
        maxindex = i;
      }
      second = med(ftmp, second, a);
    }

    for (int i = 0; i < n; i++) {
      if (i == maxindex) {
        System.out.println(second);
      } else {
        System.out.println(first);
      }
    }

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

}

Measured memory_bytes: 59132
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
struct fish {
	int lx, ly, lz;
	int rx, ry, rz;
};
struct Compress {
	map<int, int>mp;
	map<int, int>revmp;

	Compress(vector<int>vs) {
		sort(vs.begin(), vs.end());
		vs.erase(unique(vs.begin(), vs.end()), vs.end());
		for (int i = 0; i < vs.size(); ++i) {
			mp[vs[i]] = i;
			revmp[i] = vs[i];
		}
	}
	Compress(const set<int>&vs) {
		int num = 0;
		for (auto v : vs) {
			mp[v] = num;
			revmp[num] = v;
			num++;
		}
	}
};
int pluss[101][101][101];
int num[102][102][102];
int main() {
	int N, K; cin >> N >> K;
	vector<fish>fs;
	vector<int>xs, ys, zs;
	for (int i = 0; i < N; ++i) {
		int lx, ly, ld, rx, ry, rd; cin >> lx >> ly >> ld >> rx >> ry >> rd;
		fs.push_back(fish{lx, ly, ld, rx, ry, rd});
		xs.push_back(lx); xs.push_back(rx);
		ys.push_back(ly); ys.push_back(ry);
		zs.push_back(ld); zs.push_back(rd);
	}
	Compress cx(xs), cy(ys), cz(zs);
	for (auto &f : fs) {
		f.lx = cx.mp[f.lx];
		f.rx = cx.mp[f.rx];
		f.ly = cy.mp[f.ly];
		f.ry = cy.mp[f.ry];
		f.lz = cz.mp[f.lz];
		f.rz = cz.mp[f.rz];
	}
	memset(pluss, 0, sizeof(pluss));
	for (auto f : fs) {
		pluss[f.lx][f.ly][f.lz]++;
		pluss[f.rx][f.ly][f.lz]--;
		pluss[f.lx][f.ry][f.lz]--;
		pluss[f.lx][f.ly][f.rz]--;
		pluss[f.rx][f.ry][f.lz]++;
		pluss[f.lx][f.ry][f.rz]++;
		pluss[f.rx][f.ly][f.rz]++;
		pluss[f.rx][f.ry][f.rz]--;
	}
	memset(num, 0, sizeof(num));
	long long int ans = 0;
	for (int x = 1; x < 102; ++x) {
		for (int y = 1; y < 102; ++y) {
			for (int z = 1; z < 102; ++z) {
				num[x][y][z] = pluss[x - 1][y - 1][z - 1]+ num[x][y][z - 1] + num[x][y - 1][z] +num[x - 1][y][z] - num[x - 1][y - 1][z] - num[x - 1][y][z - 1]- num[x][y - 1][z - 1] +num[x - 1][y - 1][z - 1];
				if (num[x][y][z] >= K) {
					if (cx.revmp.find(x) == cx.revmp.end())assert(false);
					if (cy.revmp.find(y) == cy.revmp.end())assert(false);

					if (cz.revmp.find(z) == cz.revmp.end())assert(false);

					long long int dx = cx.revmp[x] - cx.revmp[x - 1];
					long long int dy = cy.revmp[y] - cy. revmp[y - 1];
					long long int dz = cz.revmp[z] - cz.revmp[z - 1];
					ans += dx*dy*dz;
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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


int main(){
	int w;
	int n;
	int a[30];
	int b[30];
	int c[30];
	cin >> w;
	cin >> n;
	int x;
	int y;
	int z;
	for (int i = 1; i <= w; i++){
		c[i - 1] = i;
	}
	for (int i = 0; i < n; i++){
		char t;
		cin >> a[i] >> t >> b[i];

		x = a[i];
		y = b[i];
		z = c[x - 1];
		c[x - 1] = c[y - 1];
		c[y - 1] = z;
	}
	for (int i = 0; i < w; i++){
		cout << c[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
#include <stdio.h>

int main(void) {
  
  int x, n, k, j;
  scanf("%d", &n);
  for(k = 1; k <= n; k++) {
    j = k;
  int  fg = 0;
    while(j > 0) {
      if(j % 10 == 3) {
	fg = 1;
	break;
      }
      j/=10;
}

    if(k % 3 == 0 || fg == 1) {
      printf(" %d",k); 
    }  else {
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
import 'dart:io';

import 'dart:math';

List g1 = [1, 1];
List g2 = [1, 1];
List inverse = [0, 1];
void prev_cmb(N, mod) {
  for (var i = 2; i < N + 1; i++) {
    g1.add((g1.last * i) % mod);
    inverse.add((-inverse[mod % i] * (mod ~/ i)) % mod);
    g2.add((g2.last * inverse.last) % mod);
  }
}

int cmb(int n, int r, mod) {
  if (r < 0 || r > n) return (0);
  r = min(r, n - r);
  var ret = g1[n] * g2[r] % mod;
  ret *= g2[n - r];
  ret %= mod;
  return (ret);
}

void main(List<String> args) {
  List NM = stdin.readLineSync().split(" ").map((x) => int.parse(x)).toList();
  int N = NM[0];
  int M = NM[1];

  var mod = pow(10, 9) + 7;
  prev_cmb(M, mod);
  int ans = cmb(M, N, mod) * g1[N] % mod;
  var tmp = -1;
  var ans2 = 0;
  var tmp2 = 0;
  //print(g2);
  for (var i = 0; i <= N; i++) {
    tmp *= -1;
    tmp2 = cmb(N, i, mod) * g1[M - i] % mod;
    tmp2 *= g2[M - N];
    ans2 += tmp2 * tmp;

    //print("$i ${cmb(N, i, mod)}, ${(cmb(M - i, N - i, mod) * g1[N - i])}");
    //print(ans2);
    ans2 %= mod;
  }

  print(ans * ans2 % mod);
}


Measured memory_bytes: 35236
a,b,c=map(int,input().split())
l=int(input())

for i in range(l+1):
    a2=a*2**i
    for j in range(l+1):
        b2=b*2**j
        for k in range(l+1):
            c2=c*2**k
            if i+j+k==l and b2>a2 and c2>b2:
                print("Yes")
#                print(a2,b2,c2)
#                print(i,j,k)
                exit()
print("No")
#print(a2,b2,c2)
#print(i,j,k)


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

int main() {
	bool a = false, b = false;
	for (int i = 0; i < 3; i++) {
		char temp;	cin >> temp;
		if (temp == 'A')	a = true;
		if (temp == 'B')	b = true;
	}
	if (a && b) 	cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def find(x):
    if parents[x] < 0:
        return x
    else:
        parents[x] = find(parents[x])
        return parents[x]

def union(x, y):

    x = find(x)
    y = find(y)

    if x == y:
        return

    if parents[x] > parents[y]:
        x,y = y,x

    parents[x] += parents[y]
    parents[y] = x

def same(x,y):
    return find(x) == find(y)

N = int(input())

parents = [-1] * N
ver_x = []
ver_y = []
for i in range(N):
    x,y = map(int, input().split())
    ver_x.append((x,i))
    ver_y.append((y,i))

ver_x.sort()
ver_y.sort()

edge_list = []

for i in range(N-1):
    x_dist = ver_x[i+1][0]-ver_x[i][0]
    y_dist = ver_y[i+1][0]-ver_y[i][0]

    edge_list.append((x_dist, ver_x[i+1][1], ver_x[i][1]))
    edge_list.append((y_dist, ver_y[i+1][1], ver_y[i][1]))

ans = 0

edge_list.sort()

for w,s,t in edge_list:
    if not same(s,t):
        union(s,t)
        ans += w
print(ans)

Measured memory_bytes: 114268
#include<stdio.h>
int main(void){
	int N,x,a,b,c,i;
	scanf("%d", &N);
	x = N;
	for (i = 0; i < 999 - N; i++){
		
		if (x % 111 == 0){
			break;
		}
		x++;
	}
	printf("%d", x);

		return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

struct edge {
	int from,to;
	int cost;

	edge(int t,int c) : to(t),cost(c) {}
	edge(int f,int t,int c) : from(f),to(t),cost(c) {}

	bool operator<(const edge &e) const {
		return cost < e.cost;
	}
};

vector<edge> G[5005];
vector<int> g[5005];
int C[5005], R[5005], d[5005];
bool used[5005];

void dijkstra(int s,int n) {
	priority_queue<P,vector<P>,greater<P> > que;
	fill(d,d+n,INF);

	d[s] = 0;
	que.push(P(0,s));

	while(que.size()) {
		P p = que.top();
		que.pop();

		int v = p.second;
		if(d[v] < p.first) continue;

		rep(i,G[v].size()) {
			edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to],e.to));
			}
		}
	}
}

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

	memset(C, 0, sizeof(C));
	memset(R, 0, sizeof(R));
	rep(i, n) cin >> C[i] >> R[i];
	rep(i, m) {
		int s, t;
		cin >> s >> t;

		s--;
		t--;

		g[s].push_back(t);
		g[t].push_back(s);
	}

	rep(i, n) {
		fill(d, d + n, INF);

		priority_queue<P, vector<P>, greater<P> > que;
		que.push(mp(0, i));

		d[i] = 0;

		while(que.size()) {
			P p = que.top();
			que.pop();

			int v = p.second;

			if(d[v] < p.first) continue;

			rep(i, g[v].size()) {
				if(d[g[v][i]] > d[v] + 1) {
					d[g[v][i]] = d[v] + 1;
					que.push(mp(d[v] + 1, g[v][i]));
				}
			}
		}

		// cout << "i:" << i << endl;
		// rep(j, n) cout << j << " " << d[j] << endl;

		rep(j, n) {
			if(i == j) continue;
			if(d[j] <= R[i]) {
				G[i].push_back(edge(j, C[i]));
			}
		}
	}

	dijkstra(0, n);

	cout << d[n-1] << endl;

	return 0;
}

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

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

int main() {
	cout << fixed << setprecision(9);
	ios :: sync_with_stdio(0);

	for(int n, m, a; cin >> n >> m >> a && n; ) {
		vector <vi> v;
		while(m --) {
			int h, p, q; cin >> h >> p >> q;
			v.pb({h, p, q});
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		for(auto i : v) {
			int p = i[1], q = i[2];
			if(p == a) a = q;
			else if(q == a) a = p;
		}
		cout << a << '\n';
	}	

	return 0;
}

Measured memory_bytes: 3196
import math 
 
n = int(input())
if n <= 81:
  m = int(round(math.sqrt(n)))
  while True:
    if n % m == 0:
      print("Yes")
      break
    else:
      m += 1
      if m >= 10:
        print("No")
        break
else:
  print("No")


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

int main()
{
  ll a, b, n, x, i, ans;
  cin>>a>>b>>n;

  if(b>n)
  {
    ans=(a*n)/b;
  }
  else
  {
    ans=(a*(b-1))/b;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int H,W;
  cin>>H>>W;
  string s[H][W],a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>s[i][j];
      if(s[i][j]=="snuke"){
        cout<<a[j]<<i+1<<endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[200005],b[200005];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=n;i>=1;i--){
		if (i*2>n) b[i]=a[i];
		else{
			int sum=0;
			for (int j=i+i;j<=n;j+=i) sum=(sum+b[j])%2;
			b[i]=sum^a[i];
		}
	}
	int tot=0;
	for(int i=1;i<=n;++i) tot+=b[i];
	cout<<tot<<endl;
	for(int i=1;i<=n;++i) if(b[i]) printf("%d ",i);
	return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define  ren(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) ren(i,0,(n))
#define  all(a) begin(a),end(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;
 
int main()
{
    string o,e;
    cin>>o>>e;
    int a=o.size();
    e+='\n';
    rep(i,a) cout<<o[i]<<e[i];
    if(a-e.size())cout<<"\n";

    return 0;
}

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

inline bool ask( int x, int y ) {
    cout << "? " << x - 1 << " " << y - 1 << endl;
    
    char z;
    cin >> z;
    
    return (z == 'Y');
}

string str;
vector<int> stk;

int main( void ) {
    
    int a, b;
    cin >> a >> b;
    
    if( a <= b )
        cout << "Impossible" << endl;
    else {
        for( int i = 1; i <= a + b; i ++ ) {
            if( stk.empty() )
                stk.push_back( i );
            else {
                if( ask( stk.back(), i ) == true )
                    stk.push_back( i );
                else
                    stk.pop_back();
            }
        }
        
        for( int i = 1; i <= a + b; i ++ )
            str.push_back( '0' + ask( stk.back(), i ) );
        cout << "! " << str << endl;
    }
    
    return 0;
}

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

using namespace std;

int digit_sum(long n)
{
    if (n < 10)
        return n;
    return digit_sum(n / 10) + n % 10;
}

int main()
{
    int N, A, B, Sum = 0, Total = 0;
    cin >> N >> A >> B;
    vector<int> v;

    for (int i = 1; i <= N; i++)
    {
        Sum = digit_sum(i);

        if (Sum >= A && Sum <= B)
        {
            v.push_back(i);
        }
    }

    for (int i = 0; i < v.size(); i++)
    {
        Total += v[i];
    }

    cout << Total;
}

Measured memory_bytes: 384
s=input()
d=1
if not s[0]=='A':
    d=0
l=len(s)
t=0
for i in range(2,l-1):
    if s[i]=='C':
        t+=1
if not t==1:
    d=0
u=0
for i in range (l):
    if s[i]>='A' and s[i]<='Z':
        u+=1
if not u==2:
    d=0
if d:
    print('AC')
else:
    print('WA')

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

int main() {
    int64_t X;
    cin >> X;

    int i=0;
    int64_t money = 100;

    while(true){
        i++;
        money*= 1.01;
        if(money>=X)break;
    }

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main(void){
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n) cin >> v[i];

	int ans = 0;
	for (int i = 0; i <= n - 1; ++i){
		for (int j = n - 2; j >= i; --j){
			if(v[j] > v[j + 1]){
				swap(v[j], v[j + 1]);
				ans++;
			}
		}
	}
	rep(i, v.size() - 1){
		cout << v[i] << " ";
	}
	cout << v[n - 1] << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,k;
  cin>>n>>k;
  int x[n];
  rep(i,0,n) cin>>x[i];
  int ans=INT_MAX;
  rep(i,0,n-k+1){
    ans=min(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
    ans=min(ans,abs(x[i+k-1])+abs(x[i+k-1]-x[i]));
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 4024
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	
	cin>>n;
	
	cout<<(int)ceil((double)n/1000)*1000-n;
}


Measured memory_bytes: 3652
public class Main {
    static int x;
    public static void main(String[] args) throws Exception {
        // Here your code !
        for( int i = 1; i <= 9;i++ ){
            for( int r = 1; r <= 9; r++){
                int kei = i * r;
                System.out.println( i + "x" + r + "=" + kei);
            }
        }
    }
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    int64_t S = 0;
    vector<int64_t> x(N,0);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A.at(i);
        S += A.at(i);
    }
    
    int64_t r = 0;
    for ( int64_t i = 0; i < N/2; ++i){
        r += 2 * A.at(2*i+1);
    }
    x.at(0) = (S - r)/2;
    for ( int64_t i = 1; i < N; ++i){
        x.at(i) = A.at(i-1) - x.at(i-1);
    }
    
    for ( int64_t i = 0; i < N; ++i){
        cout << 2 * x.at(i) << " ";
    }
    cout << endl;
    
    
    return 0;
}



Measured memory_bytes: 2944
N = int(input())
Blue = [input() for i in range(N)]
M = int(input())
Red = [input() for i in range(M)]

maxX = 0
word = set(Blue+Red)
for w in word:
    x = Blue.count(w) - Red.count(w)
    if x > maxX:
        maxX = x

print(maxX)

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

using ll = long long;

map<ll, int> prime_factor(ll x) {
	map<ll, int> ret;
	for (ll i = 2; i * i <= x; ++i) {
		while (x % i == 0) {
			ret[i]++;
			x /= i;
		}
	}
	if (x > 1) ret[x]++;
	return ret;
}

int main() {
	ll N;
	cin >> N;
	auto factor = prime_factor(N);
	int ans = 0;
	for (auto p : factor) {
		ll f = p.second;
		ll c = 0;
		while (c * (c + 1) / 2 <= f) {
			c++;
		}
		ans += c - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3612
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int n, m;
  cin >> n >> m;
  if (n==1) n=14;
  if (m==1) m=14;
  if (n==m) cout << "Draw";
  else if (n > m) cout << "Alice";
  else cout << "Bob";
  cout << endl;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll n, m, r;
    cin >> n >> m >> r;
    vector<int> visit(r);
    REP(i, r) {
        cin >> visit[i];
        visit[i]--;
    }
    sort(ALL(visit));

    ll table[n][n];
    REP(i, n) REP(j, n) {
        table[i][j] = INF_LL;
        if(i == j) table[i][j] = 0;
    }

    REP(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        table[a][b] = min(table[a][b], c);
        table[b][a] = min(table[b][a], c);
    }
    REP(k, n) REP(i, n) REP(j, n) table[i][j] = min(table[i][j], table[i][k] + table[k][j]);

    ll ans = INF_LL;

    do {
        ll tmp = 0;
        REP(i, r-1) {
            tmp += table[visit[i]][visit[i+1]];
        }
        ans = min(ans, tmp);
    } while (next_permutation(ALL(visit)));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <iomanip>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;

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

  vector<long long> A(N + 1);
  for (int i = 0; i < N + 1; ++i) cin >> A[i];

  long long rest = 0, down_mon = 0;
  for (int i = 0; i < N+1; ++i)
  {
    long long B;
    if (i != N) cin >> B;
    else        B = 0;

    if (A[i] <= rest)
    {
      down_mon += A[i];
      A[i] = 0;
    }
    else
    {
      down_mon += rest;
      A[i] -= rest;
    }

    if (A[i] <= B)
    {
      down_mon += A[i];
      rest = B - A[i];
    }
    else
    {
      down_mon += B;
      rest = 0;
    }
  }
  cout << down_mon << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M, vector<int>(N, -1));
    vector<int> k(M);
    vector<int> p(M);
    REP(i, M) {
        cin >> k[i];
        REP(j, k[i]) { cin >> s[i][j]; }
    }
    REP(i, M) cin >> p[i];

    int ans = 0;

    REP(bit, (1 << N)) {
        vector<int> cnt(M);
        REP(i, N) {
            if (bit & (1 << i)) {
                REP(ki, M) {
                    REP(kj, k[ki]) {
                        if (i + 1 == s[ki][kj])
                            cnt[ki]++;
                    }
                }
            }
        }
        //計算
        bool f = true;
        REP(cn, M) {
            if (cnt[cn] % 2 != p[cn]) {

                f = false;
                break;
            }
        }
        if (f)
            ans++;
    }

    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){


	int nums[10];
	nums[0]=63;
	nums[1]=6;
	nums[2]=91;
	nums[3]=79;
	nums[4]=102;
	nums[5]=109;
	nums[6]=125;
	nums[7]=39;
	nums[8]=127;
	nums[9]=111;

	int n;
	while(cin>>n&&n!=-1){
		int s=0;
		for(int j = 0; j < n; j++){
			int t;
			cin>>t;
			int ret=nums[t]^s;
			for(int i = 6; i >= 0; i--){
				if((ret>>i)&1){
					cout<<1;
				}
				else
					cout<<0;
			}
			cout<<endl;
			s=nums[t];
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long
ll gcd(ll a,ll b)
{
    if(b == 0)
        return a;
    return gcd(b,a%b);
}
int main(){
	ll a,b;
	cin>>a>>b;
	cout<<a*b/gcd(a,b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string W,T;
    cin >> W;
    transform(W.begin(),W.end(),W.begin(),::tolower);
    int sum = 0;
    for (int i=0;i<i+1;i++) {
        cin >> T;
        if ( T !="END_OF_TEXT" ) {
            transform(T.begin(),T.end(),T.begin(),::tolower);
            if ( W==T ) {
                sum = sum +1;
            }
        } else {
            break;
        }
    }
    cout << sum << endl;
}



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

#define f(i,a,b) for( ll  i = a; i < (ll) b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter   ios::sync_with_stdio(false);cin.tie(0)

// policy-based



using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;



 
const ll MAX = 3e5+100;
const ll inf = 1e9;
const ll mod = 1e9+7;


int main(){
	fastio;
	ll a,b,c,d;
	cin >> a >> b >> c >> d;

	cout << max(max(a*c,b*d),max(a*d,b*c)) << endl;

	return 0;
}

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

typedef long long LL;

const int N=5000;

int mod;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n;

void into(){
  scanf("%d%d",&n,&mod);
}

int dp[N+9],ans;

void Get_dp(){
  int m=n-1>>1,now=0;
  dp[0]=1;
  for (int i=2;i<=n;++i){
	if (i<=m+2) ++now;
	for (int j=now;j<=n;++j) sadd(dp[j],dp[j-now]);
	if (i>=n-m+1) --now;
  }
  for (int i=0;i<=n;++i) sadd(ans,mul(n-i,dp[i]));
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

			System.out.println(a*a-b);

		

	}

}

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

A_str = input().split()

A = []

for Ai_str in A_str:
    Ai = int(Ai_str)

    if Ai == 0:
        print(0)
        exit()

    A.append(Ai)

product = 1

for Ai in A:
    product *= Ai

    if product > 1000000000000000000:
        print(-1)
        exit()

print(product)


Measured memory_bytes: 21476
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main()
{
  std::string S;
  std::cin >> S;
  long long K;
  scanf("%lld", &K);
  vector<pair<char, int>> v;
  int sum = 0;
  for (int i = 0; i < S.size() - 1; ++i)
  {
    if (S[i] == S[i + 1])
    {
      sum++;
    }
    else
    {
      v.emplace_back(S[i], sum + 1);
      sum = 0;
    }
  }
  if (sum > 0)
    v.emplace_back(S[S.size() - 1], sum + 1);
  ll ans = 0;
  if (v.empty())
    ans = K / 2;
  else if (v.size() == 1)
  {
    ans += v[0].second * K / 2;
  }
  else
  {
    for (int i = 1; i < v.size() - 1; ++i)
    {
      ans += v[i].second / 2 * K;
    }
    if (v[0].first == v[v.size() - 1].first)
    {
      ans += v[0].second / 2 + v[v.size() - 1].second / 2;
      ans += (v[0].second + v[v.size() - 1].second) / 2 * (K - 1);
    }
    else
    {
      ans += v[0].second / 2 * K + v[v.size() - 1].second / 2 * K;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <functional>
#include <string>
#include <array>
#include <vector>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#include <complex>
#define full(c) c.begin(), c.end()
#define vector2d(name,type,h,w,init) vector<vector<type>> name(h,vector<type>(w,init)) 
const int PRIME = 1000000007;
const int INF = 2147483647;
const double PI = acos(-1);
const double EPS = 0.000000001;
typedef unsigned long long int ull;
typedef long long int ll;
using namespace std;

int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	string s;
	ll i, k;
	cin >> s;
	cin >> k;
	i = 0;
	while (s[i] == '1') i++;
	if (i < k) cout << s[i] << endl;
	else cout << 1 << endl;
	return 0;
}


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

long gcd(long n, long m) {
	if (n == 0)return m;
	if (n < m)swap(n, m);
	return gcd(n % m, m);
}

int main() {
	long r, d; cin >> r >> d;
	long x; cin >> x;
	int c = 0;
	while (c < 10) {
		x = r * x - d;
		cout << x << endl;
		c++;
	}
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  vector<bool> z(N);
  for (ll i = 0; i < N; i++) {
    ll x, y; cin >> x >> y;
    if (x == y) z[i] = true;
  }
  ll cnt = 0;
  for (ll i = 0; i < N; i++) {
    if (z[i]) {
      cnt++;
      if (cnt == 3) {
	cout << "Yes\n";
	return 0;
      }
    }else {
      cnt = 0;
    }
  }
  cout << "No\n";

  return 0;
}



Measured memory_bytes: 3640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib> 
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

int main() {
	string x, y;
	cin >> x >> y;
	
	map<string, int> hexa;
	hexa["A"] = 11;
	hexa["B"] = 12;
	hexa["C"] = 13;
	hexa["D"] = 14;
	hexa["E"] = 15;
	hexa["F"] = 16;
	
	int a = hexa[x];
	int b = hexa[y];
	
	if (a > b) {
		cout << ">" << endl;
		return 0;
	}
	else if (a < b) {
		cout << "<" << endl;
		return 0;
	} 
	else {
		cout << "=" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc()) if(ch=='-') positive=0;
	for(;isdigit(ch);ch=gc()) x=x*10+ch-'0';
	return positive?x:-x;
}
inline void write(ll x){
	if(x<0){
		x=-x;putchar('-');
	}
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=1e5+5;
int fa[N];
set<int> s[N];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
map<pii,int> ma;
pii q[N];
int main(){
	int n=read(),top=0;
	For(i,1,2*n-2){
		int x=read(),y=read();
		ma[mp(x,y)]++;ma[mp(y,x)]++;
		s[x].insert(y);s[y].insert(x);
		if(ma[mp(x,y)]==2) q[++top]=mp(x,y);
	}
	For(i,1,n) fa[i]=i;
	For(o,1,top){
		int u=q[o].fi,v=q[o].se;
		u=find(u);v=find(v);
		if(s[u].size()<s[v].size()) swap(u,v);
		for(auto x:s[v]){
			if(x==u) continue;
			ma[mp(v,x)]=ma[mp(x,v)]=0;
			ma[mp(u,x)]++;ma[mp(x,u)]++;
			if(ma[mp(u,x)]==2) q[++top]=mp(u,x);
			s[u].insert(x);s[x].insert(u);s[x].erase(v);
		}
		s[v].clear();s[u].erase(v);
		fa[v]=u;
	}
	int sum=0;
	For(i,1,n) sum+=(find(i)==i);
	if(sum>1) puts("NO");
	else puts("YES");
}

Measured memory_bytes: 59428
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	lint N, K;
	cin >> N >> K;
	lint ans = 0;
	ans = abs(N % K);
	ans = min(ans, abs(abs(N % K) - K));
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef pair<int, int> P;

/** Problem2104 : Country Road **/
int main()
{
	int T, N, K;
	cin>>T;
	rep(z, T) {
		cin>>N>>K;
		K = min(N, K);
		
		vector<int> diff(N-1);
		int old;
		cin>>old;
		int sum=0;
		
		rep(i, N-1) {
			int a; cin>>a;
			diff[i] = a-old;
			sum+=diff[i];
			old = a;
		}
		
		sort(diff.begin(), diff.end(), greater<int>());
		
		rep(i, K-1) {
			sum -= diff[i];
		}
		
		cout << sum << endl;
	}
}

Measured memory_bytes: 1604
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

static const int N = 100;
static const int INFTY = ( 1 << 21 );


int n, M[N][N], d[N];

void bfs(int s) {
  queue<int> q;
  q.push(s);
  REP(i, n) d[i] = INFTY;
  d[s] = 0;
  int u;
  while ( !q.empty() ) {
    u = q.front();
    q.pop();
    REP(v, n) {
      if ( M[u][v] == 0 ) continue;
      if ( d[v] != INFTY ) continue;
      d[v] = d[u] + 1;
      q.push( v );
    }
  }
  REP(i, n) {
    cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
  }
}

int main() {
  int u, k, v;

  cin >> n;
  REP(i, n) {
    REP(j, n) M[i][j] = 0;
  }

  REP(i, n) {
    cin >> u >> k;
    u--;
    REP(j, k) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  bfs(0);
  return 0;
}

Measured memory_bytes: 3092