akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    sys.setrecursionlimit(10**6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    sunuke = [0] * N
    for k in range(K):
        input()
        for a in [int(x) for x in input().strip().split()]:
            sunuke[a-1] += 1
    
    cnt = 0
    for n in range(N):
        if sunuke[n] == 0:
            cnt += 1
    
    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9212
num = int(input())

count = 0
is_ok = 0
for i in range(num):
    num1, num2 = map(int, input().split())
    if num1 == num2:
        count += 1
        if count >= 3:
            is_ok =1
    else:
        count = 0
        continue

if is_ok == 1:
    print('Yes')
else:
    print('No')

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

using namespace std;

using ll = long long;


ll arr[295785];

int main(){
    ll n; cin >> n;
    ll q; cin >> q;
    string s; cin >> s;
    for(ll i = 1; i < n; ++i){
        if(s[i] == 'C' && s[i - 1] == 'A')arr[i] = arr[i - 1] + 1;
        else arr[i] = arr[i - 1];
    }
    while(q--){
        ll l, r;
        cin >> l >> r;
        cout << arr[r - 1] - arr[l - 1] << endl;
    }
    return 0;

}


Measured memory_bytes: 4508
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int main() {
    int n; cin >> n;
    vector<int> a(n), idx(n);
    set<int> st;
    st.insert(-1);
    st.insert(n);
    REP(i, n) cin >> a[i];
    REP(i, n) idx[a[i] - 1] = i;
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        vector<int> r(2,n), l(2,-1);
        st.insert(idx[i]);
        auto itr = st.find(idx[i]);
        auto itl = itr;
        itr++;
        for (int j = 0; itr != st.end() && j < 2; j++) {
            r[j] = *itr;
            itr++;
        }
        itl--;
        for (int j = 0; itl != st.begin() && j < 2; j++) {
            l[j] = *itl;
            itl--;
        }
        ans += (ll)(i + 1)*(r[1] - r[0])*(idx[i] - l[0]);
        ans += (ll)(i + 1)*(l[0] - l[1])*(r[0] - idx[i]);
    }
    cout << ans << endl;
    getchar(); getchar();
}

Measured memory_bytes: 5760
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
using namespace std;

const int INF = 1e9;

struct RMinQ{
private:
  int n;
  vector<pair<int,int>> data;
public:
  RMinQ(vector<int> V){
    int sz = V.size();
    n = 1;
    while(n < sz) n *= 2;
    data.resize(2*n-1,{INF,-1});
    for(int i = 0; i < sz; ++i) data[n-1+i] = {V[i],i};
    for(int i = n-2; i >= 0; --i) data[i] = min(data[2*i+1],data[2*i+2]);
  }
  void update(int idx, long long val){//0-indexed
    idx += n-1;
    data[idx].first = val;
    while(idx > 0){
      idx = (idx-1)/2;
      data[idx] = min(data[2*idx+1],data[2*idx+2]);
    }
  }
  pair<int,int> get_min(int l, int r){//[l,r)の区間の最小値
    pair<int,int> ret = {INF,-1};
    l += n-1, r += n-1;
    while(l < r){
      if((l&1) == 0){
        ret = min(ret,data[l]);
      }
      if((r&1) == 0){
        ret = min(ret,data[r-1]);
      }
      l /= 2;
      r = (r-1)/2;
    }
    return ret;
  }
};

template<typename T>
struct BIT{//0-indexed
private:
  vector<T> data;
  const int n;
public:
  BIT(int sz) : data(sz+1,0), n(sz) {}
  BIT(vector<T> t) : data(t), n((int)t.size()) {}
  T sum(size_t i){//sum[0,i)
    //++i;
    T s = 0;
    while(i > 0){
      s += data[i];
      i -= i&(-i);
    }
    return s;
  }

  T sum(size_t i, size_t j){ return sum(j) - sum(i); }//sum[i,j)

  void add(int i, T x){
    ++i;
    assert(i > 0);
    while(i <= n){
      data[i] += x;
      i += i&(-i);
    }
  }
};

int main(){
  string s;
  int k;
  cin >> s >> k;
  vector<int> S(s.length());
  for(size_t i = 0; i < s.length(); ++i){
    S[i] = s[i]-'a';
  }
  BIT<int> erased(s.length());
  RMinQ rmq(S);
  int l = s.length();
  int idx = 0;
  string ans(l,'a');
  for(int i = 0; i < l; ++i){
    // cerr << i << " " << ans << endl;
    int ok = min(idx+k,l-1);
    int ng = l;
    while(ng-ok > 1){
      int m = (ok+ng)/2;
      int cnt = (m-idx)-erased.sum(idx,m);
      if(cnt <= k) ok = m;
      else ng = m;
    }
    int mi_val = rmq.get_min(idx,ok+1).first;
    int mi_idx = rmq.get_min(idx,ok+1).second;
    k -= mi_idx-idx-erased.sum(idx,mi_idx);
    ans[i] += mi_val;
    erased.add(mi_idx,1);
    rmq.update(mi_idx,INF);
    if(mi_idx == idx) ++idx;
  }
  cout << ans << endl;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> H(N);
  rep(i,N) cin >> H.at(i); 
  sort(H.begin(), H.end());
  
  K = min(N,K);
  ll sum = 0;
  rep(i,K) {
    H.pop_back();
  }
  rep(i,H.size()) sum += H.at(i);
  cout << sum << endl;
  return 0;
}

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



int aa[3001],f[3001],n,s,a;
int main()
{
    cin>>n>>s;
    f[0]=1;
    ref(i,n){
        cin>>a;
        ref(j,s+1) aa[j]=f[j];
        ref(j,s+1) if(j+a<=s) f[j+a]=(f[j+a]+aa[j])%mod;
        ref(j,s+1) f[j]=(f[j]+aa[j])%mod;

    }
    cout<<f[s]<<endl;

    return 0;
}


Measured memory_bytes: 3508
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	char n[5];
	int count = 0;
	cin >> n;

	for (int i = 0; i < 2; i++) {
		if (n[i] == n[i + 1] && n[i + 1] == n[i + 2]) {
			Yes; return 0;
		}
	}

	No;


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main()
{
	int n,m;
	int ans = 0;
	const int mod = 1e9+7;
	cin >> n >> m;
	if(n == m)
	{
		int fact[n+5];
		fact[0] = 1;
		for(int i = 1; i <= n; i++)
		fact[i] = ((i%mod)*(fact[i-1]%mod))%mod;
		ans += ((fact[n]%mod)*(fact[n]%mod))%mod;
		ans = ((ans%mod)+(ans%mod))%mod;
	}
	else if(abs(n-m) == 1)
	{
		if(m > n)
		n = m;
		int fact[n+5];
		fact[0] = 1;
		for(int i = 1; i <= n; i++)
		fact[i] = ((i%mod)*(fact[i-1]%mod))%mod;
		ans = ((fact[n]%mod)*(fact[n-1]%mod))%mod;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 1024
n = int(input())
a = list(map(int,input().split()))
ans = 10**19
sum_a = [0]
for x in a:
    sum_a.append(sum_a[-1]+x)

for q_r in range(2,n-1):
    pq = sum_a[q_r]
    rs = sum_a[n]-sum_a[q_r]
    #print(pq,rs)
    ok1 = 1
    ng1 = q_r
    while ng1-ok1 > 1:
        mid1 = (ng1+ok1)//2
        if pq > 2*sum_a[mid1]:
            ok1 = mid1
        else:
            ng1 = mid1
    p1 = sum_a[ok1]
    q1 = pq-p1
    p2 = sum_a[ok1+1]
    q2 = pq-p2
    if abs(p1-q1) > abs(p2-q2):
        p = p2
        q = q2
    else:
        p = p1
        q = q1
    ok2 = q_r+1
    ng2 = n
    while ng2-ok2>1:
        mid2 = (ng2+ok2)//2
        if rs > 2*(sum_a[mid2]-pq):
            ok2 = mid2
        else:
            ng2 = mid2
    r1 = sum_a[ok2]-pq
    s1 = rs-r1
    r2= sum_a[ok2+1]-pq
    s2 = rs-r2
    if abs(r1-s1) > abs(r2-s2):
        r = r2
        s = s2
    else:
        r = r1
        s = s1
    #print(p,q,r,s)
    ans = min(ans,max(p,q,r,s)-min(p,q,r,s))

print(ans)


Measured memory_bytes: 90616
#include <iostream>

using namespace std;

long long N;

int a[200] = {0};
int b[200] = {0};

int numa = 1;
int numb = 1;

int big = 100;

int main()
{
	cin >> N;
	
	N ++;
	while(N > 1)
	{
		if(N % 2)
		{
			a[numa ++] = big --;
			N --;
		}
		else
		{
			b[numb ++] = big --;
			N /= 2;
		}	
	}
	int len = numa + numb - 2;
	len *= 2;
	cout << len << endl;
	for(int i = 103 - numa - numb; i <= 100; i ++)
		cout << i << " ";
	for(int i = 1; i < numa; i ++)
		cout << a[i] << " ";
	for(int i = numb - 1; i >= 1; i --)
		cout << b[i] << " ";
	return 0;	
}

Measured memory_bytes: 256
N = int(input())
W = []
for i in range(N):
  W.append(str(input()))
  
ans="Yes"
for i in range(1,N):
  if W.count(W[i]) > 1 or W[i][0:1] != W[i-1][len(W[i-1])-1:len(W[i-1])]:
    ans = "No"
print(ans)

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

int n, m;
int a[1000];

int main()
{
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		int c, d;
		scanf("%d %d", &c, &d);
		--c, --d;
		for (int i = c; i < d; i++){
			a[i] = 1;
		}
	}
	
	int res = 0;
	for (int i = 0; i < n; i++){
		if (a[i]) res += 3;
		else res++;
	}
	
	printf("%d\n", ++res);
	
	return 0;
}

Measured memory_bytes: 1196
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;


fn main() {
  let x = read::<i64>();
  let mut dist: HashMap<char, i64> = HashMap::new();
  dist.insert('M', 0);
  dist.insert('A', 0);
  dist.insert('R', 0);
  dist.insert('C', 0);
  dist.insert('H', 0);
  for _ in 0..x {
    let y = read::<String>();
    let first = &y.chars().nth(0).unwrap();
    if *first == 'M' || *first == 'A' || *first == 'R' || *first == 'C' || *first == 'H' {
      let current = dist.entry(*first).or_insert(0);
      *current += 1;
    }
  }

  let mut total = 0;
  // MAR
  total += dist.get(&'M').unwrap() * dist.get(&'A').unwrap() * dist.get(&'R').unwrap();
  // MAC
  total += dist.get(&'M').unwrap() * dist.get(&'A').unwrap() * dist.get(&'C').unwrap();
  // MAH
  total += dist.get(&'M').unwrap() * dist.get(&'A').unwrap() * dist.get(&'H').unwrap();
  // MRC
  total += dist.get(&'M').unwrap() * dist.get(&'C').unwrap() * dist.get(&'R').unwrap();
  // MRH
  total += dist.get(&'M').unwrap() * dist.get(&'H').unwrap() * dist.get(&'R').unwrap();
  // MCH
  total += dist.get(&'M').unwrap() * dist.get(&'C').unwrap() * dist.get(&'H').unwrap();
  // ARC
  total += dist.get(&'R').unwrap() * dist.get(&'A').unwrap() * dist.get(&'C').unwrap();
  // ARH
  total += dist.get(&'H').unwrap() * dist.get(&'A').unwrap() * dist.get(&'R').unwrap();
  // ACH
  total += dist.get(&'C').unwrap() * dist.get(&'A').unwrap() * dist.get(&'H').unwrap();
  // RCH
  total += dist.get(&'C').unwrap() * dist.get(&'H').unwrap() * dist.get(&'R').unwrap();

  println!("{}", total);
}


Measured memory_bytes: 4352
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    char ch;
    cin>>ch;
    cout<<(char)(ch+1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 12032
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
res = 0
for d in range(1, N):
  s = set()
  t = 0
  for k in range(N):
    i = d * k
    if i + d >= N: break
    if i in s: break
    if N - 1 - i in s: break
    if i == N - 1 - i: break
    s.add(i)
    s.add(N - 1 - i)
    t += a[i]
    t += a[N - 1 - i]
    res = max(res, t)
print(res)


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

#define ll long long

int main(){
    ll K,A,B;scanf("%lld%lld%lld",&K,&A,&B);
    ll Ans=K+1;
    if (K>=A+1){
        ll base=B;K=K-A-1;
        ll cnt=K/2;base=base+cnt*(B-A);
        if (K%2==1) base++;
        Ans=max(Ans,base);
    }
    printf("%lld\n",Ans);
    return 0;
}

Measured memory_bytes: 256
def c_base_minus2_number(N):
    # 10進数を他の(正の)進数表記に変換するときと同様
    def negabinary(n):  # nを-2進数(文字列)で表現する
        if n == 0:
            return '0'
        digits = []
        while n != 0:
            # Pythonにおいて a % b の符号はbの符号に一致する
            n, remainder = divmod(n, -2)
            if remainder < 0:
                n, remainder = n + 1, remainder + 2  # 余りは非負とする
            digits.append(str(remainder))
        return ''.join(digits[::-1])

    ans = negabinary(N)
    return ans

N = int(input())
print(c_base_minus2_number(N))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    int n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    rep(i,n){
        if(c*(n-1-i)-d*i<=b-a and b-a<=-c*i+(n-1-i)*d){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

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

int main(){
	int64_t x;	cin >> x;
  	int64_t bk = 100;
  	int count = 0;
  	while(x > bk){
    	bk = bk*1.01;
      	count++;
    }
  	
  	cout << count << endl;
}

Measured memory_bytes: 3632
#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 RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
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, X;
    cin >> N >> X;
    vector<int> L(N);
    for (auto &i : L) {
        cin >> i;
    }

    int cnt = 0, ans = 1;
    for (auto &i : L) {
        cnt += i;
        if (X < cnt)
            break;
        ans++;
    }

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

    return 0;
}

Measured memory_bytes: 256
def main():
    N, K = [int(x) for x in input().split()]
    a = [int(x)-1 for x in input().split()]

    pos = 0
    while K > 0:
        if K&1:
            pos = a[pos]
        # doubling
        a = [a[a[i]] for i in range(N)]
        K >>= 1
    print(pos+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32308
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

string ans = "";
int cnt = 0;

void bfs(int K) {
	if (K <= 9) {
		ans = string() + (char)('0' + K);
		return;
	}

	queue<string> lunlun_que;

	for (int k=1; k<=9; k++) {
		lunlun_que.push(string() + (char)('0' + k));
	}

	while(!lunlun_que.empty()) {
		string n = lunlun_que.front();

		lunlun_que.pop();
		cnt++;
		if (cnt == K) {
			ans = n;
			return;
		}

		int right = n[n.size()-1] - '0';

		if (right - 1 >= 0) lunlun_que.push(n + (char)('0' + right - 1));
		lunlun_que.push(n + (char)('0' + right));
		if (right + 1 <= 9) lunlun_que.push(n + (char)('0' + right + 1));
	}
}

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

	bfs(K);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 13696
use std::io::prelude::*;
use std::str::FromStr;
pub struct Scanner<R: Read>(R);
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self(reader)
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| (b as char).is_whitespace())
            .take_while(|&b| !(b as char).is_whitespace())
            .collect::<Vec<u8>>();
        unsafe { std::str::from_utf8_unchecked(token.as_slice()) }
            .parse()
            .ok()
            .expect("Can't parse it.")
    }
    pub fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut sc = Scanner::new(stdin.lock());
    let mut out = std::io::BufWriter::new(stdout.lock());
    solve(&mut sc, &mut out);
    out.flush().ok().unwrap();
}
fn solve(sc: &mut Scanner<std::io::StdinLock>, out: &mut std::io::BufWriter<std::io::StdoutLock>) {
    use std::collections::BTreeSet;

    let n: usize = sc.read();
    let s: BTreeSet<u32> = (0..n).map(|_| sc.read()).collect();
    println!("{}", s.len());
}


Measured memory_bytes: 2164
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#define rep(i,n) for (int i= 0;i<(n);++i)
using namespace std;
typedef long long ll;
#define MOD 1000000007
int main()
{
    ll h;
    cin >> h;
 
    ll count = 0;
    ll base = 1;
    while(h > 0) {
         count += base;
         h = h / 2;
         base <<= 1;
    }
 
    cout << count << endl;


    return 0;
}

Measured memory_bytes: 3600
import sys
from collections import Counter
finput = sys.stdin.readline

N, M = [int(elem) for elem in finput().split(' ')]
A_list = [int(elem) % M for elem in finput().split(' ')]
assert len(A_list) == N

cuml_A_list = [0] * N
current_sum = 0
for i, A in enumerate(A_list):
    current_sum += A
    current_sum %= M
    cuml_A_list[i] = current_sum

counter = Counter(cuml_A_list)
total_count = 0
for key, value in counter.items():
    if key == 0:
        total_count += value * (value - 1) // 2 + value
    else:
        total_count += value * (value - 1) // 2

print(total_count)


Measured memory_bytes: 17280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll dp[2004][2004];
ll rui[2004][2004];
int s[2000];
int t[2000];
int main()
{
	int n,m;
	ll ans=0;
	cin>>n>>m;
	fill(dp[0],dp[2004],0);
	fill(rui[0],rui[2004],0);
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int j=0;j<m;j++)
		cin>>t[j];
	dp[0][0]=1;
	for(int i=1;i<m+1;i++)
		dp[0][i]=1;
	for(int i=1;i<n+1;i++)
		dp[i][0]=1;
	// start dp
	for(int i=1;i<n+1;i++)
	{
		for(int j=1;j<m+1;j++)
		{
			dp[i][j]=dp[i-1][j]+dp[i][j-1];
			if(s[i-1]!=t[j-1])
				dp[i][j]-=dp[i-1][j-1];
			dp[i][j]%=MOD;
		}
	}
	//end dp
	ans=dp[n][m];
	if(ans<0)
		ans+=MOD;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 63104
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DABS solver = new DABS();
        solver.solve(1, in, out);
        out.close();
    }

    static class DABS {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), z = in.nextInt(), w = in.nextInt();
            int[] a = IntStream.range(0, n).map(x -> in.nextInt()).toArray();
            out.println(Math.max(Math.abs(w - a[n - 1]), n == 1 ? 0 : Math.abs(a[n - 1] - a[n - 2])));
        }

    }
}



Measured memory_bytes: 29780
floor = [[[0] * 10 for x in range(3)] for y in range(4)]

for c in range(int(input())):
    (b,f,r,v) = [int(x) for x in input().split()]
    if 1 > b > 5 or 1 > f > 4 or 1 > r > 10:
        break
    floor[b-1][f-1][r-1] += v

for x in range(3 * 4):
    if x % 3 == 0 and not x == 0:
        print('#' * 20)
    print('',' '.join(str(y) for y in floor[int(x / 3)][x % 3]))

Measured memory_bytes: 6732
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
signed main()
{
	int a, b, c, k, ans = 0;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	ans += min(a, k);
	k = max(0, k - a);
	k = max(0, k - b);
	ans -= min(c, k);
	printf("%d\n", ans);
}


Measured memory_bytes: 3828
# https://atcoder.jp/contests/abc138/tasks/abc138_d

def dfs(lst, start, ans):
    queue = [start]
    visited = [False] * len(ans)
    visited[start] = True

    while queue:
        parent = queue.pop()
        for child in lst[parent]:
            if visited[child]:
                continue
            visited[child] = True
            ans[child] += ans[parent]
            queue.append(child)

    print(*ans)

n,q = map(int, input().split())
start = 0

tree = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

ans = [0]*n
for _ in range(q):
    p, x = map(int,input().split())
    ans[p-1] += x
dfs(tree, start, ans)


Measured memory_bytes: 55856
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    if(c-a-b <= 0){
            System.out.println("No");
      return;
    }
    if((c-a-b)*(c-a-b)>4*a*b){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
  

  
}


Measured memory_bytes: 22996
# 空白区切の入力を数値(整数)の配列で返す
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

A, B = gets_i_list

if B == 1
  puts 0
else
  count = 1
  total = A
  while true
    break if total >= B
    count += 1
    total = (A * count) - (count - 1)
  end
  puts count
end


Measured memory_bytes: 14148
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<long long,long long> pll;

int main() {
    fastIO;
    int n, m, k, aux, rta = 0;
    cin >> n >> m;
    bool lista[n][m];
    memset(lista, 0,  sizeof(lista));
    for(int i = 0; i < n; i++){
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> aux;
            lista[i][aux-1] = true;
        }
    }
    for(int i = 0; i < m; i++){
        aux = 0;
        for(int j = 0; j < n; j++){
            if(lista[j][i]) aux++;
        }
        if(aux == n) rta++;
    }
    cout << rta << endl;
    return 0;
}



Measured memory_bytes: 3580
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    Yes(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

bool seen[1005];

int f(int n, int k) {
  int r = 1;
  while(n) {
    r += n /= k;
  }
  return r;
}

int main() {
  int n;
  scanf("%d", &n);
  ll ret = 1;
  for(int i = 2; i <= n; i++) {
    if(seen[i]) continue;
    for(int j = i; j <= n; j += i) {
      seen[j] = true;
    }
    ret *= f(n, i);
    ret %= 1000000007;
  }
  printf("%lld\n", ret);
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();
        int j = sc.nextInt();
        int k = 0;
        for(int l = i;l <= j;l++){
            if(l/1000==l%10*10+l%100/10) k++;
        }
        System.out.println(k);
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
int n;
ll a[maxx];

int main() {
	ll ans;
	while(cin >> n && n) {
		memset(a, 0, sizeof(a));
		for(int i = 1; i <= n; i++) cin >> a[i];
		sort(a + 1, a + 1 + n);
		int l = 1, r = n;
		ans = abs(a[1] - a[n]);
		for(int i = 2; i <= n / 2; i++) {
			int dd = abs(a[l] - a[n - i + 1]);
			int pp = abs(a[r] - a[i]);
			ans += dd + pp;
			l++;
			r--;
		}
		if(n & 1) {
			int x = abs(a[n / 2 + 1] - a[r]);
			int y = abs(a[n / 2 + 1] - a[l]);
			ans += max(x, y);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1024
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def dd(al,n):
	imos=[0]*(n+1)
	for i, v in enumerate(al):
		imos[max(0, i-v)]+=1
		imos[min(n, i+v+1)]-=1
	ret = [0]*(n)
	ret[0]=imos[0]
	mmm=0
	for i, v in enumerate(imos[1:-1],1):
		ret[i]=ret[i-1]+imos[i]
	return ret, min(ret)



def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	al=lin()
	for _ in range(k):
		nal, min_al = dd(al,n)
		if min_al == n:
			print(*nal)
			return
		al=nal
	print(*nal)
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 171912
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

count = 1
num_count = 1
num_count_list = list()
for i in range(1, n):
    if(a[i] == a[i - 1]):
        num_count += 1
    else:
        num_count_list.append(num_count)
        num_count = 1
        count += 1

num_count_list.append(num_count)

num_count_list.sort()
result = 0
if(count > k):
    loop = count - k

    for i in range(loop):
        result += num_count_list[i]

print(result)

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

using namespace std;

int main() {
    //freopen("sample-8.in", "r", stdin);
    //freopen("output8.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    string s;
    cin>>n>>k>>s;
    s[k-1]=tolower(s[k-1]);
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
#define CEIL(A,B) ((A)+(B)-1)/(B)
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, K, ans, A, B;
ll X[100], Y[100];

bool judge(ll xl, ll xr, ll yl, ll yr) {
    int cnt = 0;
    if(xl > xr || yl > yr) return false;
    REP(i, N) {
        if(xl <= X[i] && X[i] <= xr && yl <= Y[i] && Y[i] <= yr) cnt++;
        if(cnt >= K) return true;
    }
    return false;
}

int main() {
    fastio();
    cin >> N >> K;
    REP(i, N) cin >> X[i] >> Y[i];
    ans = LLINF;
    REP(i, N) REP(j, N) REP(k, N) REP(l, N) {
        if(judge(X[i], X[j], Y[k], Y[l])) ans = min(ans, (X[j] - X[i]) * (Y[l] - Y[k]));
    }
    cout << ans << endl;
	return 0;
}

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

int main(){
  long X, K, D;
  cin >> X >> K >> D;  

  long absx = abs(X);
  
  if(absx/D > K)
  {
    cout << absx-K*D;
    return 0;
  }
  else
  {
    // 負値とならないギリギリまで減らす
    long k = absx/D;
    absx -= k*D;
    K -= k;
    
    if(K%2==0)
    {
      cout << absx;
    }
    else
    {
      cout << abs(absx-D);
    }
    return 0;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    lint r, d, x; cin >> r >> d >> x;
    for(int i=0;i<10;i++){
        cout << r * x - d << endl;
        x = r * x - d;
    }
    return 0;
}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)
ll a[1000005],vis[1000005];
int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n;
        cin>>n;
        if(n%1000==0) cout<<0;
        else cout<<1000-(n%1000);

    }
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000001;
const ll MOD = 1000000007;
 
int dp[1001][1001];
int ways(int h,int w){
    //int dp[1001][1001]={0};
    if(dp[0][0]==-1){
        return 0;
    }
    
    for(int j=0;j<w;j++){
        if(dp[0][j]==-1){
            break;
        }
        dp[0][j]=1;
    }
    for(int i=0;i<h;i++){
        if(dp[i][0]==-1){
            break;
        }
        dp[i][0]=1;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(dp[i][j]==-1)
            continue;
            dp[i][j]=0;
            if(dp[i][j-1]!=-1)
            dp[i][j]=dp[i][j-1] % 1000000007;
            if(dp[i-1][j]!=-1){
                dp[i][j]=(dp[i][j]+dp[i-1][j])%1000000007;
            }
        }
    }
    if(dp[h-1][w-1]==-1){
      return 0;}
    //for(int i=0;i<h;i++){
        //for(int j=0;j<w;j++){
            //cout<<dp[i][j]<<" ";
        //}
       // cout<<endl;
    

    return dp[h-1][w-1];

    
}
int main() {
    int h,w;
    cin>>h>>w;
    memset(dp,0,sizeof dp);
    //char grid[N][N];
    char x;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            //cin>>grid[i][j];
            cin>>x;
            if(x=='#'){
                dp[i][j]=-1;
            }
        }
        
    }
   cout<<ways(h,w);

}


Measured memory_bytes: 7512
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

S = input()

sa = float('inf')

for i in range(len(S)-2):
    if abs(int(S[i:i+3]) - 753) < sa:
        sa = abs(int(S[i:i+3]) - 753)

print(sa)

Measured memory_bytes: 9124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	rep(i, n - 1) if (s[i] == s[i + 1]) ans++;
	int j_ans = min(ans + 2 * k, n - 1);
	cout << j_ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n + 1, 0);
    vector<int> index(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
        index[v[i]] = i;
    }
    vector<int> res(n + 1, 1);
    for (int i = 2; i <= n; i++) {
        if (index[i] > index[i - 1]) {
            res[i] = res[i - 1] + 1;
        } else {
            res[i] = 1;
        }
    }
    cout << n - *max_element(res.begin() + 1, res.end()) << endl;
}


Measured memory_bytes: 5628
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define all(v) v.begin(),v.end()
using namespace std;

signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n)cin>>a[i];
    int q;
    cin>>q;
    rep(i,q){
        int b,e,t;
        cin>>b>>e>>t;
        swap_ranges(a+b,a+e,a+t);
    }
    rep(i,n){
        cout<<(i?" ":"")<<a[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int N; cin >> N;

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

    vector<int> dp(N, numeric_limits<int>::max());
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        if (i + 1 < N)
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(H[i] - H[i + 1]));
        if (i + 2 < N)
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(H[i] - H[i + 2]));
    }

    cout << dp.back() << "\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  string s;
  cin >> n >> s;
  string s1,s2;
  int result = 0;
  for(int i = 1; i < n; i++){
    vector<int> map1(26,0);
    vector<int> map2(26,0);
    int count = 0;
    s1 = s.substr(0,i+1);
    s2 = s.substr(i+1,s.size()-1);
    //cout << s1 << " "<< s2 << endl;
    for(int j = 0; j < s1.size(); j++){
      map1.at(s1.at(j) - 'a')=1;
    }
    for(int j = 0; j < s2.size(); j++){
      map2.at(s2.at(j) - 'a')=1;
    }
    for(int j = 0; j < 26; j++){
      if(map1.at(j) == 1 && map2.at(j) == 1){
        count++;
      };
    }
    result = max(result, count);
  }
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=0,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b});
	





	cout<<endl;
} 


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxNum = 1;
		int count = 0;
		for (int i = 0; i < N; i++) {
			int targetNum = i + 1;
			int tmpCount = 0;
			while (targetNum % 2 == 0) {
				targetNum = targetNum / 2;
				tmpCount++;
			}
			if (tmpCount > count) {
				count = tmpCount;
				maxNum = i + 1;
			}
		}
		System.out.println(maxNum);
		sc.close();
	}
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    ll n, k;
    cin >> n >> k;

    if ( n <= k ) cout << min(n, abs(n - k)) << endl;
    else {
        n -= k * (n / k);
        cout << min(n, abs(n - k)) << endl;
    }

    return 0;
}

Measured memory_bytes: 3616
N = int(input())
A, B = map(int, input().split())
P = list(map(int, input().split()))

c1, c2, c3 = 0,0,0
for p in P:
  if p <= A:
    c1 += 1
  elif p <= B:
    c2 += 1
  else:
    c3 += 1

print(min(c1,c2,c3))

Measured memory_bytes: 3316
H, W = map(int, input().split())

# コーナーケースに注意！1行 or 1列の時は動けないよ！
if H == 1 or W == 1:
    print(1)
    exit()

if H % 2 == 0:
    ans = (H / 2) * W
else:
    ans = (H // 2) * W + W // 2
    if W % 2 != 0:
        ans += 1

print(int(ans))

Measured memory_bytes: 3060
a,b,c,x,y=map(int, input().split())

if c<=min(a,b)/2:
    print(2*c*max(x,y))
elif c>(a+b)/2:
    print(x*a+y*b)
else:
    if x>=y:
        if c<a/2:
            print(2*c*max(x,y))
            
        else:
            print(2*c*y+(x-y)*a)
    else:
        if c<b/2:
            print(2*c*max(x,y))
        else:    
            print(2*c*x+(y-x)*b)

Measured memory_bytes: 3064
h,w=map(int,input().split())
x=[[0]*w for _ in range(h)]
s=[input() for _ in range(h)]

if s[0][0]=="#": x[0][0]=1

for j in range(1,w):
    x[0][j]=x[0][j-1]
    if s[0][j]=="#" and s[0][j-1]==".": x[0][j]+=1

for i in range(1,h):
    x[i][0]=x[i-1][0]
    if s[i][0]=="#" and s[i-1][0]==".": x[i][0]+=1

for i in range(1,h):
    for j in range(1,w):
        if s[i][j]==".": x[i][j]=min(x[i][j-1],x[i-1][j])
        else:
            p=x[i][j-1];q=x[i-1][j]
            if s[i][j-1]==".": p+=1
            if s[i-1][j]==".": q+=1
            x[i][j]=min(p,q)


print(x[h-1][w-1])

Measured memory_bytes: 41712
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans= 0;
    ll frac = n / (a + b);
    ll frac2 = n % (a + b);
    ans = frac*a;
    if(frac2 > 0){
        if(frac2 < a){
            ans += frac2;
        }
        if(frac2 >= a){
            ans += a;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    long long int a,b,c,d;
    cin>>a>>b>>c>>d;
    long long int num[4]={a*c,a*d,b*c,b*d};
    sort(num,num+4);
    cout<<num[3];
    

    return 0;
}

Measured memory_bytes: 3616
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
      #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
       ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
           # #  # # #                   # #      ###### #    # #    # #      #####
      #    # #   #  #              #    # #      #    # #    # #    # #      #   #
       ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<long long> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LLi i = 0; i < (n); i++)
#define FOR(in) for(LLi i=1; i <= (n); i++)
#define pb push_back
#define sr(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 

 
 
int main()
{
	
	long long a,b,c,d;
	cin>>a;
	string s;
	if(a<1200)cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
		
			
	
			
    exit()
 
 
}


Measured memory_bytes: 3548
N = int(input())
price = int(N // 1.08)
if int((price - 1) * 1.08) == N:
    print(int(price - 1))
elif int(price * 1.08) == N:
    print(int(price))
elif int((price + 1) * 1.08) == N:
    print(int(price + 1))
else:
    print(":(")

Measured memory_bytes: 3060
#include <iostream>
static const int N = 1000;
using namespace std;

void trace(int A[], int n){
    for(int i=1; i<=n; i++){
        if(i>1)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[]){
    int n;
    int A[N+1];
    cin >> n;
    for(int i=1;i<=n;i++)
        cin >> A[i];
    trace(A,n);
    for(int j=2; j<=n; j++){
        int key = A[j];
        int i = j - 1;
        while (i>0 && A[i]>key) {
          A[i+1] = A[i];
          i--;
        }
        A[i+1] = key;
        trace(A,n);
    }
    return 0;
}

Measured memory_bytes: 3080
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  int OK = 1000;
  for (int k = 0; k < N; ++k) {
    cin >> b[k];
    for (int i = 0; i < 3; ++i) {
      for (int j = 0; j < 3; ++j) {
        if (b[k] == A[i][j]) {
          A[i][j] = OK;
        }
      }
    }
  }

  if ((A[0][0] == OK && A[0][1] == OK && A[0][2] == OK) ||
      (A[1][0] == OK && A[1][1] == OK && A[1][2] == OK) ||
      (A[2][0] == OK && A[2][1] == OK && A[2][2] == OK) ||
      (A[0][0] == OK && A[1][0] == OK && A[2][0] == OK) ||
      (A[0][1] == OK && A[1][1] == OK && A[2][1] == OK) ||
      (A[0][2] == OK && A[1][2] == OK && A[2][2] == OK) ||
      (A[0][0] == OK && A[1][1] == OK && A[2][2] == OK) ||
      (A[0][2] == OK && A[1][1] == OK && A[2][0] == OK) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }



  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
SUM = 0
for i in range(N):
    SUM += B[A[i]-1]
    if i >= 1 and A[i] == (A[i-1]+1):
        SUM += C[A[i-1]-1]
print(SUM)


Measured memory_bytes: 3060