akhauriyash/Code-Regression huggingface dataset:
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)*} }; }
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")
    };
}
#[warn(dead_code)]
fn sieve_of_eratosthenes(n: usize) -> Vec<usize> {
    // spf:
    // store smallest prime factor of number
    // 最小の素因数を格納
    // is_prime:
    // 配列番号が素数であるかどうかを示す
    let mut spf = vec![None; n + 1];
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();

    // 0 と 1 は素数ではない
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        // is_prime[i]:
        // それ以下の素数で割り切られていなければ True となる
        if is_prime[i] {
            // この if 文より i は素数なので
            primes.push(i);

            // 素数はそれ自身の最も小さい素因数であるから
            spf[i] = Some(i);
        }

        // 全ての prime の倍数(prime * i)を取り除く
        for prime in &primes {
            // prime が i の最も小さい因数よりも大きくなってしまったら探索終了
            if i * prime >= n + 1 || prime > &spf[i].unwrap() {
                break;
            }

            is_prime[i * prime] = false;

            // i * primes[j] の最も小さい素数は primes[j] 自身
            spf[i * prime] = Some(*prime);
        }
    }
    primes
}
use std::cmp::Ordering;
#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}
fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

#[warn(unused_mut)]
#[warn(unused_imports)]

fn main() {
    input! {
        n: usize,
        s:chars,
    };
    if n % 2 == 0 {
        for i in 0..(n / 2) {
            if s[i] != s[i + n / 2] {
                println!("No",);
                return ();
            }
        }
        println!("Yes",);
    } else {
        println!("No",);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

vector<bool> era(1000010, true);
void makePrimeTable(int n)
{
	era[0] = false; era[1] = false;
	for (int i = 2; i <= n; i++)
	{
		if (era[i]) { for (int j = i * 2; j <= n; j += i) { era[j] = 0; } }
	}
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	makePrimeTable(1000000);
	while(1)
	{
		int a = 0, d = 0, n = 0; cin >> a >> d >> n;
		if (a == 0 && d == 0 && n == 0) { break; }
		int tmp = a, tmp1 = 0;
		while (1)
		{
			if (era[tmp])
			{
				tmp1 += 1;
				if (tmp1 == n) { printf("%d\n", tmp); break; }
			}
			tmp += d;
		}
	}
	return 0;
}

Measured memory_bytes: 1320
/*安定なソート*/
#include <stdio.h>
#include <stdlib.h>

#define N 37

typedef struct{
  char mark;
  int value;
} Card;

int isStable(Card *, Card *, int);
int ctoi(char);

int main(){
  Card c[N], s[N], b[N], tmp;
  char data[2];
  int i, j, n, min;

  /*入力*/
  scanf("%d", &n);
  for (i=0; i<n; i++){
    scanf("%s", data);
    c[i].mark = data[0];
    c[i].value = ctoi(data[1]);
    s[i] = c[i];
    b[i] = c[i];
  }
  
  /*バブルソートについて*/
  for (i=0; i<n; i++){
    for (j=n-1; j>i; j--){
      if (b[j].value < b[j-1].value){
	tmp = b[j];
	b[j] = b[j-1];
	b[j-1] = tmp;
      }
    }
  }
  for (i=0; i<n-1; i++){
    printf("%c%d ",b[i].mark, b[i].value);
  }
  printf("%c%d\n",b[n-1].mark, b[n-1].value);
  if (isStable(c,b,n))
    printf("Stable\n");
  else
    printf("Not stable\n");
  
  
   /*選択ソートについて*/
  for (i=0; i<n; i++){
    min = i;
    for (j=i; j<n; j++){
      if (s[j].value < s[min].value)
	min = j;
    }
    tmp = s[i];
    s[i] = s[min];
    s[min] = tmp;
  }
  
  for (i=0; i<n-1; i++){
    printf("%c%d ",s[i].mark, s[i].value);
  }
  printf("%c%d\n",s[n-1].mark, s[n-1].value);
  if (isStable(s,b,n))
    printf("Stable\n");
  else
    printf("Not stable\n");

  return 0;
}

int isStable(Card *in, Card *out, int n){
  int i, j, k, l;
  
  for (i=0; i<n; i++){
    for (j=i+1; j<n; j++){
      for (k=0; k<n; k++){
	for (l=k+1; l<n; l++){
	  if (in[i].value == in[j].value &&
	      in[i].value == out[l].value &&
	      in[j].value == out[k].value &&
	      in[i].mark == out[l].mark &&
	      in[j].mark == out[k].mark)
	    return 0;
	}
      }
    }
  }

  return 1;
}

int ctoi(char c) {
  switch (c) {
  case '0': return 0;
  case '1': return 1;
  case '2': return 2;
  case '3': return 3;
  case '4': return 4;
  case '5': return 5;
  case '6': return 6;
  case '7': return 7;
  case '8': return 8;
  case '9': return 9;
  default: return 0;
  }
}



Measured memory_bytes: 2100
/*  -*- coding: utf-8 -*-
 *
 * 2883.cc: Proof of Knowledge
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 4;
const char opcs[] = "abcd+*^";

/* typedef */

enum { OP_A, OP_B, OP_C, OP_D, OP_OR, OP_AND, OP_XOR };

struct Node {
  int op;
  Node *lpt, *rpt;
  Node() {}

  int calc(int ps[]) {
    if (op >= OP_A && op <= OP_D) return ps[op];
    int c0 = lpt->calc(ps), c1 = rpt->calc(ps), r;
    switch (op) {
    case OP_OR:  r = (c0 | c1); break;
    case OP_AND: r = (c0 & c1); break;
    case OP_XOR: r = (c0 ^ c1); break;
    }
    return r;
  }

  void print(int *ps = NULL) {
    if (op >= OP_A && op <= OP_D) {
      if (ps != NULL) printf("%d", ps[op]);
      else putchar('a' + op);
    }
    else {
      putchar('(');
      lpt->print(ps);
      putchar(opcs[op]);
      rpt->print(ps);
      putchar(')');
    }
  }
};

/* global variables */

char cmap[256];
char se[84], sp[6];
int ps[N], qs[N];
Node buf[80], *bpt;

/* subroutines */

Node *parse(char *(&cpt)) {
  Node *npt = bpt++;
  char c = *(cpt++);
  if (c == '[') {
    npt->op = cmap[*(cpt++)];
    npt->lpt = parse(cpt);
    npt->rpt = parse(cpt);
    cpt++; // ']'
  }
  else
    npt->op = cmap[c], npt->lpt = npt->rpt = NULL;
  return npt;
}

/* main */

int main() {
  for (int i = 0; opcs[i]; i++) cmap[opcs[i]] = i;

  while (scanf("%s", se) == 1 && se[0] != '.') {
    scanf("%s", sp);
    for (int i = 0; i < N; i++) qs[i] = sp[i] - '0';

    bpt = buf;
    char *cpt = se;
    Node *exp = parse(cpt);
    //exp->print(); putchar('\n');

    int qh = exp->calc(qs);
    //exp->print(qs); printf("=%d\n", qh);

    memset(ps, 0, sizeof(ps));
    int cnt = 0;

    for (;;) {
      int ph = exp->calc(ps);
      if (ph == qh) cnt++;

      int k = 0;
      while (k < N) {
	if (++ps[k] < 10) break;
	ps[k++] = 0;
      }
      if (k >= N) break;
    }

    printf("%d %d\n", qh, cnt);
  }
  return 0;
}



Measured memory_bytes: 3244
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int A[2][100];

int D[2][100];
void solve(){
	D[0][0] = A[0][0];
	D[1][0] = A[1][0];
	rep(i, 2){
		reps(j, N - 1){
			D[i][j] = A[i][j] + D[i][j - 1];
		}
	}
	int ans = A[0][0] + D[1][N - 1];
	reps(i, N - 1){
		chmax(ans, D[0][i] + D[1][N - 1] - D[1][i - 1]);
	}
	cout << ans << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N)
		cin >> A[0][i];
	rep(i, N)
		cin >> A[1][i];
		solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	string S, T;
	cin >> S >> T;

	auto ans = "Yes";
	for (auto i = 0; i < S.length(); ++i)
	{
		if (S[i] != T[i])
		{
			ans = "No";
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int A[510][510], B[510][510];

int main(){
    int N, M, Q;
    cin >> N >> M >> Q;
    for(int i=0; i<M; i++){
        int l, r;
        cin >> l >> r;
        A[l][r]++;
    }
    //処理
    for(int i=1; i<=N; i++){
        for(int j=i; j<=N; j++){
            for(int k=i; k<=j; k++){
                B[i][j] += A[k][j];
            }
        }
    }
    //クエリに応える
    for(int i=0; i<Q; i++){
        int l, r;
        cin >> l >> r;
        int ans=0;
        for(int i=l; i<=r; i++){
            ans += B[l][i];
        }
        cout << ans << endl;
    }
}

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

int main() {
    using namespace std;
    array<long, 5> v{};
    for(auto &i : v)cin >> i;
    
    long a((*min_element(v.begin(), v.end(), [](auto a, auto b){return (a - 1) % 10 < (b - 1) % 10;}) - 1) % 10 - 9);
    for(auto &i : v)i = (i + 9) / 10 * 10;
    
    cout << a + accumulate(v.begin(), v.end(), 0L) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
//***********//
int main() {
	cin >> N;
	vl A(N);
	for (i = 0; i < N; i++) cin >> A[i];
	ans = INF;
	for (i = -100; i <= 100; i++) {
		ll pre = 0;
		for (j = 0; j < N; j++) {
			pre += (i - A[j]) * (i - A[j]);
		}
		ans = min(ans, pre);
	}
	cout << ans;
}

Measured memory_bytes: 256
N, A, B = input().split(' ')
N = int(N)
A = int(A)
B = int(B)
Num = []
Num = list(range(1, N+1))
checkbox = [0]
all = []
for i in range(N):
  cn = str(Num[i])
  for j in range(len(cn)):
    cnk = int(cn[j])
    checkbox.append(cnk)
  check = sum(checkbox)
  if A<= check <= B:
    all.append(Num[i])
  checkbox = [0]
print(sum(all))


Measured memory_bytes: 9272
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

bool ok(const vecint& a, const int th) {
  ll n = a.size();
  vecint v(n*4);
  int offset = n*2;
  ll cnt = 0;
  ll sum = 0;
  REP(i,n) {
    v[offset] += 1;
    if (a[i] >= th) {
      offset -= 1;
      sum -= v[offset];
    } else {
      sum += v[offset];
      offset += 1;
    }
    cnt += sum;
  }
  ll m = n * (n+1) / 2;
  ll mid = m/2 + 1;
  return cnt >= mid;
}

int main()
{
  int n;
  scanf("%d", &n);
  vecint a(n);
  REP(i,n) scanf("%d", &a[i]);
  vecint b = a;
  b.push_back(0);
  b.push_back(1000000007);
  sort(ALL(b));
  b.erase(unique(ALL(b)), end(b));
  int hi = b.size()-1;
  int lo = 0;
  while ((hi - lo) > 1) {
    int mid = (hi + lo) / 2;
    if (ok(a, b[mid])) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  printf("%d\n", b[lo]);
  return 0;
}


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

int main(){
    ll x;cin>>x;                                                                 ll okane =100;                                                               for(int i=0;i<1000000;i++){                                                      if(okane>=x){
            cout << i << endl;
            return 0;;                                                               }
        okane*=1.01;                                                             }

    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)

int main() {
  int n;cin>>n;
  map<string,int> mp;
  for(int i=0;i<n;++i){
    string s;cin>>s;
    if (mp.find(s)==mp.end()){
      mp[s] =1;
    } else {
      mp[s] +=1;
    }
  }
  vector<pair<string, int>> v;
  for (auto const& ele: mp) v.push_back(make_pair(ele.first,ele.second));
  sort(all(v),[](pair<string, int>& a,pair<string, int>& b){return a.second>b.second;});
  int cnt = v[0].second;
  vector<string> out;
  for (auto const& ele: v) {
    if(ele.second==cnt){
      out.push_back(ele.first);
    } else {
      break;
    }
  }
  sort(all(out));
  for (auto const& ele: out) cout << ele <<endl;
  return 0;
}


Measured memory_bytes: 33260
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vector<vector<int>> dp(H, vector<int>(W, INF));
    if(s[0][0] == '#')
        dp[0][0] = 1;
    else
        dp[0][0] = 0;
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            if(i - 1 >= 0) {
                if(s[i][j] == '#') {
                    if(s[i - 1][j] == '#' && dp[i - 1][j] <= dp[i][j]) {
                        dp[i][j] = dp[i - 1][j];
                    } else if(s[i - 1][j] == '.' &&
                              dp[i - 1][j] + 1 <= dp[i][j]) {
                        dp[i][j] = dp[i - 1][j] + 1;
                    }
                } else {
                    dp[i][j] = min(dp[i - 1][j], dp[i][j]);
                }
            }
            if(j - 1 >= 0) {
                if(s[i][j] == '#') {
                    if(s[i][j - 1] == '#' && dp[i][j - 1] <= dp[i][j]) {
                        dp[i][j] = dp[i][j - 1];
                    } else if(s[i][j - 1] == '.' &&
                              dp[i][j - 1] + 1 <= dp[i][j]) {
                        dp[i][j] = dp[i][j - 1] + 1;
                    }
                } else {
                    dp[i][j] = min(dp[i][j - 1], dp[i][j]);
                }
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <atcoder/all>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using namespace atcoder;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll op(ll a, ll b) { return max(a, b); }

ll e() { return 0; }

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

    vector<ll> a(n);
    ll ma = 0;

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

        ma = max(ma, a[i]);
    }

    segtree<ll, op, e> s(ma + 1);

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ll l, r;

        l = max(a[i] - k, 0ll);
        r = min(a[i] + k + 1, ma + 1);

        s.set(a[i], s.prod(l, r) + 1);
    }

    for (int i = 0; i <= ma; i++)
    {
        ans = max(ans, s.get(i));
    }

    cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;

  int n = S.length() - 1;
  long long total = 0;

  for (int bit = 0; bit < (1 << n); bit++) {
    long long number = 0;

    for (int i = 0; i < n; i++) {
      number = (number * 10 + (S[i] - '0'));

      if (bit & (1 << i)) {
        total += number;
        number = 0;
      }
    }

    total += (number * 10 + (S[n] - '0'));
  }

  cout << total << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

string S;
ll K;

bool allSame(string s) {
    REP (i, s.size()-1) if (s[i] != s[i+1]) return false;
    return true;
}

ll countChange(string s) {
    int res = 0;
    FOR (i, 1, s.size()) {
        if (s[i] == s[i-1]) {
            res++;
            i++;
        }
    }
    return res;
}

ll solve() {
    if (allSame(S)) {
        return K*S.size()/2;
    }
    if (S[0] != S[S.size()-1]) {
        return countChange(S) * K;
    } else {
        int head = 1;
        int tail = 1;
        while (S[head-1] == S[head]) head++;
        while (S[S.size()-tail-1] == S[S.size()-tail]) tail++;
        return K*countChange(S) - (K-1) * (head/2+tail/2-(head+tail)/2);
    }
}

int main() {
    cin >> S >> K;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
int64_t INF = 1000000007;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vi h(n);
    rep(i,n) cin >> h.at(i);
    vi flower(n,0);
    // 左端から順番に水を上げていく
    // i番目の花の長さがhと同じかどうかで分類
    int64_t res = 0;
    bool complete = false;
    while(!complete){
        bool cluster = false;
        complete = true;
        rep(i,n){
            if(flower.at(i) != h.at(i)){
                if(!cluster) res++;
                cluster = true;
                flower.at(i)++;
                complete = false;
            }else{
                cluster = false;
            }
        }
    }
    cout << res << endl;
}

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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int a,b,c,d;

int main(){
  cin >> a >> b >> c >> d;
  while(a && c){
    c-=b;
    if(c<=0){cout << "Yes";break;}
    a-=d;
    if(a<=0){cout << "No";break;}
  }
  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int N, K; cin >> N >> K;

    Int maxK = (N-1)*(N-2)/2;

    if (K > maxK) {
        cout << -1 << endl;
        return 0;
    }

    vector<pair<Int, Int>> edges;
    Int curK = maxK;

    rep(i, 1, N) {
        edges.emplace_back(make_pair(i, N));
        //printf("edge (%lld, %lld)\n", i, N);
    }

    rep(i, 1, N-1) {
        rep(j, i+1, N) {
            if (K == curK) break;
            edges.emplace_back(make_pair(i, j));
            //printf("edge (%lld, %lld)\n", i, j);
            //printf("curK %lld\n", curK);
            
            --curK;
        }
    }

    printf("%lld\n", (Int)edges.size());
    rep(i, 0, edges.size()) printf("%lld %lld\n", edges[i].first, edges[i].second);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin >> a >> b >> c;
  int min=(a+b);
  if((a+c)<min)
    min=a+c;
  if((b+c)<min)
    min=b+c;
  cout << min << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	char arr[a][b];
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++)
			cin>>arr[i][j];
	}
	for(int i=0;i<=b+1;i++)
		cout<<"#";
	cout<<endl;
	for(int i=0;i<a;i++){
		cout<<"#";
		for(int j=0;j<b;j++)
			cout<<arr[i][j];
		cout<<"#"<<endl;
	}
	for(int i=0;i<=b+1;i++)
		cout<<"#";
	cout<<endl;
}

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

#define MAX 200000

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

  int N,M,Q;
  cin >> N >> M >> Q;
  bool students[N];
  int next[N];
  int prev[N];
  for(int i=0;i<N;i++) {
    next[i] = (i + 1 + N) % N;
    prev[i] = (i - 1 + N) % N;
    students[i] = true;
  }
  int pos = 0;
  while(M--) {
    int a; cin >> a;
    if(a & 1) {
      for(int i=0;i<a;i++) {
        pos = prev[pos];
      }
    }
    else {
      for(int i=0;i<a;i++) {
        pos = next[pos];
      }
    }
    students[pos] = false;
    next[prev[pos]] = next[pos];
    prev[next[pos]] = prev[pos];
    pos = next[pos];
  }
  while(Q--) {
    int pos; cin >> pos;
    if(students[pos]) cout << 1 << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 2956
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    if(2 <= N && 2 <= M) {
        cout << (ll)(N-2)*(M-2);
    }
    else if(N == 1 && 2 <= M) {
        cout << M-2;
    }
    else if(M == 1 && 2 <= N) {
        cout << N-2;
    }
    else {
        cout << 1;
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
 
int main() {
    // エラトステネスのふるい
    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i<MAX; i++) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
    
    // 2017likeかどうか
    vector<int> a(MAX, 0);
    for (int i = 0; i < MAX; i++) {
        if (i%2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    
    // 累積和
    vector<int> s(MAX, 0);
    for (int i = 0; i < MAX; i++) s[i+1] = s[i] + a[i];
    
    ll Q;
    cin >> Q;
    //for (int i = 0; i<Q; i++) {
    REP(i,Q) {
        int l, r;
        cin >> l >> r;
        r++;
        
        cout << s[r] - s[l] << endl;
    }
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C102
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<long> A = Console.ReadLine().Split(' ')
                .Select((x, i) => long.Parse(x) - i).ToList();
            A.Sort();
            //double aved = A.Average();
            //int ave = (int)Math.Round(aved);
            //int abs = A.Sum(x => Math.Abs(x - ave));
            //Console.WriteLine(abs);

            long sumR = 0, sumL = 0, minSum = 0;
            long b = A[0];
            foreach (int a in A)
            {
                sumR += a - b;
            }
            minSum = sumR;

            for(int i = 1; i < N; i++)
            {
                long d = A[i] - A[i - 1];
                sumR -= (N - i) * d;
                sumL += i * d;
                long sum = sumL + sumR;
                if (sum < minSum) minSum = sum;
            }

            Console.WriteLine(minSum);
        }

    }
}


Measured memory_bytes: 35204
import sys
input = sys.stdin.readline
s=list(input().strip())
n=len(s)
ans=0
for i in range(1<<(n-1)):
    sum=0
    for j in range(n):
        sum*=10
        sum+=int(s[j])
        if 1&i>>j:
            ans+=sum
            sum=0
    ans+=sum
print(ans)


Measured memory_bytes: 39664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace std;
using namespace __gnu_pbds; 
#define     mod             1e9+7
#define     MOD             998244353
#define     ll              long long
#define     mp              make_pair
#define     F               first
#define     S               second
#define     t()             int test;cin>>test;while(test--)
#define     ii              pair<int,int>
#define     que_max         priority_queue <int>
#define     IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define     endl            "\n"
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif




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

    IOS;
   
    ll int a, b;
    cin>>a>>b;

    cout<<a*b<<endl;
    
    

}

Measured memory_bytes: 3644
package main

import "fmt"

func main() {
	var m, n int
	fmt.Scan(&m, &n)
	a := make([][]rune, m+2)
	a[0] = make([]rune, n+2)
	a[m+1] = make([]rune, n+2)
	for i := 1; i <= m; i++ {
		a[i] = make([]rune, n+2)
		var tmp string
		fmt.Scan(&tmp)
		for j, r := range tmp {
			a[i][j+1] = r
		}
	}
	for i := 1; i <= m; i++ {
		for j := 1; j <= n; j++ {
			if a[i][j] == '#' {
				continue
			} else {
				cnt := 0
				for k := i - 1; k <= i+1; k++ {
					for l := j - 1; l <= j+1; l++ {
						if a[k][l] == '#' {
							cnt++
						}
					}
				}
				a[i][j] = rune(cnt)
			}
		}
	}
	for i := 1; i < m+1; i++ {
		for j := 1; j < n+1; j++ {
			switch {
			case a[i][j] == '#':
				fmt.Printf("#")
			default:
				fmt.Printf("%d", a[i][j])
			}
		}
		fmt.Printf("\n")
	}
}


Measured memory_bytes: 512
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 100001
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
queue<pair<int,int>> que;
int n;
map<int,int> edge[N],test;
int main()
{
	re(n);
	for(int i=1,u,v;i<n;++i)
	{
		re(u),re(v);
		++edge[u][v];
		++edge[v][u];
	}
	for(int i=1,u,v;i<n;++i)
	{
		re(u),re(v);
		++edge[u][v];
		++edge[v][u];
		if(edge[u][v]==2)
			que.push(make_pair(u,v));
	}
	while(!que.empty())
	{
		int u=que.front().first,v=que.front().second;
		que.pop();
		if(edge[u][v]!=2)continue;
		--n;
		if(edge[u].size() < edge[v].size())swap(u,v);
		edge[u].erase(v);
		edge[v].erase(u);
		for(auto i:edge[v])
		{
			edge[u][i.first]+=i.second;
			edge[i.first][u]+=i.second;
			if(edge[u][i.first]==2)
				que.push(make_pair(u,i.first));
			edge[i.first].erase(v);
		}
		edge[v].clear();
	}
	puts(n==1?"YES":"NO");
}


Measured memory_bytes: 23680
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
vector<string> bit;


void subBin(string str, int n)
{
    if (n == 0){
        bit.push_back(str);
    }
    if (n > 0) {
        subBin(str + "0", n - 1);
        subBin(str + "1", n - 1);
    }
}

string toBin(int n){
    if(n == 1)return "1";
    else if(n == 0)return "0";

    return toBin(n/2)  + to_string(n%2);
}
int main(){
    int n;
    cin >> n;

    vector<long long> a(n);
    int count = 0;
    long long ans = 0;
    rep(i, n){
        scanf("%lld", &a[i]);
        if(a[i] < 0)count++;
        a[i] = abs(a[i]);
        ans += a[i];
    }
    sort(a.begin(), a.end());
    if(count %2 == 1)ans -= a[0]*2;
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;


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

    vector<pair< int, int > > p(n);
    int x, y;
    for (int i = 0; i<n; i++) {
        scanf("%d", &x);
        scanf("%d", &y);
        p[i].first = x; p[i].second = y;
    }
    int ans = 100;
    if(n == 2 || n == 1) {
        printf("1\n");
        return 0;
    }

    //for(int i=0; i<n; i++) {
        //printf("%d: %d %d\n",i, p[i].first, p[i].second);
    //}
    for (int i=0; i<n; i++) {
        int zerocost = 1;
        for(int j = 0; j<n; j++) {
            if (j == i) {continue;}
            long long x, y;
            x = p[i].first - p[j].first;
            y = p[i].second - p[j].second;
            if (x==0 && y == 0) { continue; }
            //printf("i, j = %d, %d\n", i, j);
            //printf("x,y: %d, %d\n",x, y);
            for(int k=0; k<n; k++) {
                for(int l=0; l<n; l++) {
                    if(k == i && l == j) {continue;}
                    if((p[k].first - p[l].first) == x && (p[k].second - p[l].second) == y) {
                        zerocost++;    
                    }
                }
                //printf("x * (p[k].second - p[j].second): %d\n", x * (p[k].second - p[j].second));

                //printf("y * (p[k].first - p[j].first): %d", y * (p[k].first - p[j].first));
            }
            if (ans >= n-zerocost) { ans = n - zerocost; }
            zerocost = 1;
            //printf("\n");
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
/*
 * いろはちゃんはこだわりもので、嫌いな数字が K 個あり、それぞれ D1,D2,...,DKです。
 * 
 * いろはちゃんはお店でお買い物をしていて、 N円の品物を買おうとしています。 もちろん、この品物は N 円以上のお金を支払えば買うことができます。 
 * しかし、先ほど述べたようにいろはちゃんは強いこだわりがあるので、自分がお店に支払う金額の 10進表記にいろはちゃんの嫌いな数字が出現しないような最も少ない金額を支払おうとします。
 * 
 * いろはちゃんが支払う金額を求めてください。
 */

import java.util.*;
	public class Main{
		public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            // 入力
            int n = Integer.parseInt(sc.next());
            int nLen = String.valueOf(n).length();
            int k = Integer.parseInt(sc.next());
            int[] nums = new int[10];
            
            for(int i=0; i<10; i++){
            	nums[i] = i;
            }

            for(int i=0; i<k; i++){
            	int a = Integer.parseInt(sc.next());
            	nums[a] = a+1;
            }
            for(int i=8; i>=0; i--){
            	nums[i] = nums[nums[i]];
            }
            
            // 出力
            System.out.println(minObsession(nums, n, nLen-1));

            sc.close();
		}
		
		public static int minObsession(int[] a, int n, int k){
			int kNum = (n/(int)(Math.pow(10, k)))%10;
			int ret = 0;
			int minnext = a[kNum];
			if(kNum == minnext){
				if(k==0){
					ret = n;
				}else{
					ret = minObsession(a, n, k-1);
				}
            }else if(minnext == 10){
            	ret = minObsession(a, (n/(int)(Math.pow(10, k)) + 1) * (int)(Math.pow(10, k)), k+1);
            }else{
            	ret = n - n%((int)(Math.pow(10, k+1))) + minnext * ((int)(Math.pow(10, k)));
            	int min = a[0];
            	for(int i = 0; i<k; i++){
            		ret += ((int)(Math.pow(10, i))) * min;
            	}
            }
            
			return ret;
        }
    }
	

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
 
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
   	ll n,x,m;
	cin>>n>>x>>m;
	map<ll,ll> ma;
	ll idx=0;
	vector<ll> path;
	do
	{
		ma[x]=idx++;
		path.push_back(x);
		x=(x*x)%m;
	}while(ma.count(x)==0);
	ll start=0;
	start=ma[x];
	ll len=(idx-start);
	ll sum=0;
	for(ll i=start;i<idx;i++) sum+=path[i];
	ll ans=0;
	if(n<start) 
	{
		rep(i,n) ans+=path[i];

	}
	else
	{
		for(ll i=0;i<start;i++) ans+=path[i];
		ans+=(((n-start)/len)*sum);
		ll rem=(n-start)%len;
		for(ll i=0;i<rem;i++) ans+=path[start+i];
	}
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 6720
import copy
import sys
class Dice():
    def __init__(self, t, s, e, w, n, b):
        self.a = [t, s, e, w, n, b]
        self.a_org = copy.deepcopy(self.a)

    def reset(self):
        self.a = copy.deepcopy(self.a_org)
    
    def shake(self, me):
        if me == 'S':
            self.b = [self.a[int(i)] for i in '402351']
            self.a = self.b
        elif me == 'N':
            self.b = [self.a[int(i)] for i in '152304']
            self.a = self.b
        if me == 'W':
            self.b = [self.a[int(i)] for i in '215043']
            self.a = self.b
        if me == 'E':
            self.b = [self.a[int(i)] for i in '310542']
            self.a = self.b  
    def get(self, dir):
        if dir == 't': return self.a[0]
        elif dir == 's': return self.a[1]
        elif dir == 'e': return self.a[2]
        elif dir == 'w': return self.a[3]
        else: print('input err', dir)
    def front(self, f):
        self.reset()
        if f == 0:self.shake('S')
        elif f == 4:self.shake('S');self.shake('S')
        elif f == 3:self.shake('E');self.shake('S')
        elif f == 2:self.shake('W');self.shake('S')
        elif f == 5:self.shake('N')

n = int(input())
n1 = list(map(int, input().split()))
nn = [list(map(int, input().split())) for _ in range(n-1)]
d1 = Dice(*n1)

for k in range(n-1):
    n2 = nn[k]
    d2 = Dice(*n2)

    for i in range(6):
        if d1.a == d2.a:
            print('No')
            sys.exit()
        else:
            d2.front(i)
        for j in range(4):
            if j != 0:d2.shake('W')
            if d1.a == d2.a:
                print('No')
                sys.exit()

print('Yes')



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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n, k; read(n, k);

    int v[n];

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

    sort(v, v+n);

    int ans = MOD;

    for(int i=k-1; i<n; i++){
        ans = min(ans, v[i]-v[i-(k-1)]);
    }

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

Measured memory_bytes: 4008
#include<cstdio>
#include<vector>
using namespace std;
typedef pair<int, int> P;

int k, q, d[5000];
int a[5000], b[5000], c[5000];

int main() {
    scanf("%d %d", &k, &q);
    for (int i = 0; i < k; i++) scanf("%d", &d[i]);
    for (int i = 0; i < q; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
    for (int j = 0; j < q; j++) {
        int n = a[j], x = b[j] % c[j], m = c[j];
        int y = 0, cnt = 0;
        for (int i = 0; i < k - 1; i++) {
            if (y + d[i] % m >= m || d[i] % m == 0) cnt++;
            y = (y + d[i]) % m;
        }
        int ans = 0;
        if (y + d[k - 1] % m >= m || d[k - 1] % m == 0) {
            cnt++;
            ans = -1;
        }
        int e = (y + d[k - 1]) % m;
        ans += n / k * cnt + (static_cast<long>(e) * (n / k - 1) + x + y) / m;
        y = (static_cast<long>(e) * (n / k - 1) + x + y) % m;
        if (n % k > 0 && (y + d[k - 1] % m >= m || d[k - 1] % m == 0)) ans++;
        y = (y + d[k - 1]) % m;
        for (int i = 0; i < n % k - 1; i++) {
            if (y + d[i] % m >= m || d[i] % m == 0) ans++;
            y = (y + d[i]) % m;
        }
        ans = n - 1 - ans;
        printf("%d\n", ans);
    }
    return 0;
} 


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin>>n;
	if((n/100)*111<n){
		 cout<<(n/100+1)*111<<endl;
	}
	
	else if((n/100)*111>n){
		cout<<(n/100)*111<<endl;
	}
	
	else if((n/100)*111==n){
		cout<<n<<endl;
	}
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-f; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

template< typename T >
inline void Max(T &a,T &b){if(a<b) a=b;}
template< typename T>
inline void Min(T &a,T &b){if(a>b) a=b;}

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 998244353;
const int MAXN =(int) 3e3+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
int N,S;
int a[MAXN];
LL dp[MAXN];

void work(){
    scanf("%d%d",&N,&S);
    for(int i=1;i<=N;i++) scanf("%d",&a[i]);
    LL ans=0;
    for(int i=1;i<=N;i++){
        for(int j=S;j>=a[i];j--){
            dp[j]=(dp[j]+dp[j-a[i]])%MOD;
        }
        if(a[i]<=S) dp[a[i]]=(dp[a[i]]+i)%MOD;
//        printf("i = %d: ",i);
//        for(int k=1;k<=S;k++) printf("%lld ",dp[k]);
//        printf("\n");
//        printf("sumL = %lld, add = %lld\n",dp[S],dp[S]*(N-i+1));
        ans=(ans+dp[S])%MOD;
    }
    printf("%lld\n",ans);
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}





Measured memory_bytes: 256
s = input()

if s.count(s[0]) != 2:
    p = "No"
elif s.count(s[1]) != 2:
    p = "No"
elif s.count(s[2]) != 2:
    p = "No"
elif s.count(s[3]) != 2:
    p = "No"
else:
    p = "Yes"
print(p)


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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    string t[] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
    string s;
    cin >> s;
    rep(i, 7) {
        if (t[i] == s) {
            cout << 7-i << 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++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)

const long long MOD = 998244353;
struct mint {
  long long x;
  mint(long long x = 0) noexcept : x((x + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x -= a.x) < 0) x += MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (t == 0) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};

mint dp[305][305][305];

int main(){
  string S; cin >> S;
  int K; cin >> K;
  vector<int> vec(1);
  int cnt = 0;
  rep(i, S.size()) {
    if (S[i] == '0') {
      cnt++;
      vec.push_back(0);
    } else {
      vec[cnt]++;
    }
  }
  int N = vec.size(), M = S.size() - vec.size() + 1;
  K = min(K, M);
  reverse(vec.begin(), vec.end());
  vector<int> sum_vec(N + 1);
  rep(i, N) sum_vec[i + 1] = sum_vec[i] + vec[i];

  dp[0][0][0] = 1;

  rep(a, N) {
    vector<vector<mint>> sum_a(sum_vec[a + 1] + 1, vector<mint>(K + 1));
    vector<vector<mint>> sum_b(sum_vec[a + 1] + 1, vector<mint>(K + 1));
    rep(b, sum_vec[a + 1] + 1) rep(k, K + 1) {
      sum_a[b][k] = dp[a][b][k];
      if (b > 0) sum_a[b][k] += sum_a[b - 1][k];
      if (b >= vec[a]) sum_a[b][k] -= dp[a][b - vec[a]][k];

      if (b == 0 || k == 0) sum_b[b][k] = dp[a][b][k];
      else sum_b[b][k] = sum_b[b - 1][k - 1] + dp[a][b][k];
    }

    rep(b, sum_vec[a + 1] + 1) rep(k, K + 1) {
      dp[a + 1][b][k] += sum_a[b][k];
      if (b - vec[a] >= 0) dp[a + 1][b][k] += sum_b[b - vec[a]][k];
    }
  }

  mint ans;
  rep(k, K + 1) ans += dp[N][M][k];
  cout << ans.x << endl;
}


Measured memory_bytes: 226060