akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int m,d ;
    cin >> m >> d ;
    int ans = 0 ;
    int d1 ,d10 ;
    for (size_t i = 1; i < m+1; i++)
    {
        for (size_t j = 1; j < d+1; j++)
        {
            d1 = j % 10 ;
            d10 = j / 10 ;
            if (d1 > 1 && d10 > 1)
            {
                if (d1*d10 == i)
                    {
                        ans ++ ;
                    }
            }
            
            
        }
        
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()
if ("##" in S[A:C+1]) or ("##" in S[B:D+1]):
    print("No")
else:
    if C < D:
        print("Yes")
    else:
        if "..." in S[B-2:D+1]:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 3572
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

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

	int N;
	cin >> N;

	map<int, int> m;
	for( int i = 0; i < N; ++i ) {
		int a;
		cin >> a;
		m[a] += 1;
	}

	string ans = "YES";
	for( auto& v: m ) {
		if( v.second > 1 ) {
			ans = "NO";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define N (int)1e6+5
using namespace std;
int n, a, b;
int h[N];
bool check(int x) {
	int dis = a - b;
	int mns = b * x;
	int cnt = 0;
	for (int i = 1; i <= n; i ++) {
		int tmp = h[i] - mns;
		if (tmp <= 0) continue;
		cnt += (tmp + dis - 1) / dis;
		if (cnt > x) return false;
//		cout << i << " " << tmp << " " << cnt << endl;
	}
	return cnt <= x;
}
int main() {
	scanf("%d%d%d", &n, &a, &b);
	int mx = 0;
	for (int i = 1; i <= n; i ++) {
		scanf("%d", &h[i]);
		mx = max(mx, h[i]);
	}
	int l = 1, r = (mx+b-1) / b, ans;
	while (l <= r) {
		int mid = ((l - r) >> 1) + r;
		if (check(mid)) {
			r = mid - 1;
			ans = mid;
		} else {
			l = mid + 1;
		}
//		cout << mid << " " << ans << " " << check(mid) << endl;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <algorithm>
using namespace std;
 
int N, D[100100][3];
int main()
{
	scanf("%d", &N);
 
	for (int i=1;i<=N;i++){
		int a,b,c; scanf ("%d %d %d",&a,&b,&c);
		int p = a + max(D[i-1][1], D[i-1][2]);
		int q = b + max(D[i-1][0], D[i-1][2]);
		int r = c + max(D[i-1][1], D[i-1][0]);
		D[i][0] = p;
		D[i][1] = q;
		D[i][2] = r;
	}
	printf ("%d\n",max({D[N][0],D[N][1],D[N][2]}));
 
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define RFOR(i, a, b) for(int i = a; i >= b; --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
const int INF = 1e9;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int gcd(int a, int b) {
    if(a < b) swap(a, b);
    if(b == 0) return a;
    return gcd(a%b, b);
}

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    int ans = 0;
    int g = gcd(A, B);
    for(int i=g;;i--) {
        if((A%i == 0) && (B%i == 0)) K--;
        if(K==0) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n, d;
    cin >> n >> d;
    cout << Div(n, 2*d + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
const int N = 100010;
int f[N];
int v[N];
int n;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> 	v[i];
	for(int i = 2; i <= n; i++)
	{
		f[i] = f[i-1] + abs(v[i]-v[i-1]);
		if(i >= 3) f[i] = min(f[i],f[i-2]+abs(v[i]-v[i-2]));
	}
	cout << f[n] << endl;
} 


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#define rep(i,a,b) for(int i=(a);i<b;i++)
#define INF 1000000000
using namespace std;
bool debug=false;

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

  //プラススタート
  cnt=0;
  long long sum=a[0];
  if(sum<=0){
    cnt+=abs(sum)+1;
    sum=1;
  }
  bool plus=true;
  
  for(int i=1;i<n;i++){
    sum+=a[i];
    if(debug)cout<<"sum:"<<sum<<endl;
    if(plus){
      if(sum>=0){
	cnt+=sum+1;
	sum=-1;
      }
      plus=false;
    }else{
      if(sum<=0){
	cnt+=abs(sum)+1;
	sum=1;
      }
      plus=true;
    }
  }
  if(sum==0)cnt+=1;
  long long tmp=cnt;

  
  //マイナススタート
  cnt=0;
  sum=a[0];
  
  if(sum>=0){
    cnt+=sum+1;
    sum=-1;
  }
  plus=false;
  
  for(int i=1;i<n;i++){
    sum+=a[i];
    if(debug)cout<<"sum:"<<sum<<endl;
    if(plus){
      if(sum>=0){
	cnt+=sum+1;
	sum=-1;
      }
      plus=false;
    }else{
      if(sum<=0){
	cnt+=abs(sum)+1;
	sum=1;
      }
      plus=true;
    }
  }
  if(sum==0)cnt+=1;
  
  if(tmp<cnt)cout<<tmp<<endl;
  else cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int>a(n + 2);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);

	vector<bool> dp(k + 3);
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j  < n; j++) {
			if (i >= a[j] && !dp[i - a[j]]) {
				dp[i] = true;
			}
		}
	}
	puts(dp[k] ? "First" : "Second");


	return 0;
}


Measured memory_bytes: 256
import numpy as np
S = raw_input()
K = input()
DAYS = 60
sum_count_list = []
for i in range(len(S)):
	sc = 0
	if len(sum_count_list) > 0:
		sc = sum_count_list[-1]
	sc += int(S[i]) ** DAYS
	sum_count_list.append(sc)
	
for i in range(len(S)):
	if K <= sum_count_list[i]:
		print(S[i])
		break


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

int main(){
    int n,m;
    cin >> n >> m;
    int x;
    cin >> x;
    vector<vector<int>> ca(n,vector<int>(m+1));
    for(auto& v:ca){
        for(auto& e: v){
            cin >> e;
        }
    }

    int ans = 100000007;
    bool flag2 = true;
    for(int bit = 0;bit < (1<<n); ++bit){
        vector<int> ca_hoge(m+1,0);
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                for(int j = 0;j<m+1;j++){
                    ca_hoge.at(j) += ca[i].at(j);
                }
            }
        }

        bool flag = true;
        for(int i=1;i<m+1;i++){
            if(ca_hoge.at(i)<x){
                flag = false;
            }
        }
        if(flag){
            flag2 = false;
            ans = min(ans,ca_hoge.at(0));
        }
    }
    if(flag2){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N;
    vec a(N);
    rep(i,N) cin>>a[i];
    sort(a.begin(), a.end());
    cout<<a[N-1] - a[0]<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+4;
ll n;
ll cur=1;
ll ans;
inline int read() {
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
inline void smax(int &x,int y) {
	x=x<y?y:x;
}
inline void smin(int &x,int y) {
	x=x>y?y:x;
}
int main() {
//	freopen("in.txt","r",stdin);
	scanf("%lld",&n);
	while (n) {
		ans+=cur;
		cur<<=1;
		n>>=1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3768
N, X, Y = map(int, input().split())

ans = [0] * (N + 1)

for i in range(1, N+1):
    for j in range(i+1, N+1):
        # print(i, j)
        tmp = abs(i-X) + abs(j - Y) + 1
        minV = min( abs(i-j) ,tmp)
        ans[minV] += 1

for i in range(1, N):
    print(ans[i])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
void bulk(){}template<class H,class...T>void bulk(H&h,T&...t){cin>>h;bulk(t...);}
#define rep(i,n) for(int i=0;i<n;i++)
#define all(i) i.begin(),i.end()
int main(void){
    // Your code here!
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  string o;
  int ef=0;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if((i+1)%2==1){
      if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
        ef=1;
        break;
      }
    }else{
      if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
        ef=1;
        break;
      }
    }
  }
  if(ef==0){
    o="Yes";
  }else{
    o="No";
  }
  cout << o << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    string A, B;
    cin >> A >> B;
    int N = sz(A);
    bool flag1 = true, flag2 = true;
    rep(i, N){
        if(A[i] == '1') flag1 = false;
        if(B[i] == '1') flag2 = false;
    }
    if(flag2){
        if(flag1) cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }
    int l[N], r[N];
    rep(i, N){
        rep(j, N) if(B[(i+j)%N] == '1') {r[i] = j; break;}
        rep(j, N) if(B[(N+i-j)%N] == '1') {l[i] = j; break;}
    }
    int ans = inf;
    vector<pii> v[2];
    rep(i, N){
        rep(j, N){
            int k = (i+j)%N;
            if(A[k] == B[j]) continue;
            v[0].pb(pii(max(l[k]-i, 0), r[k]));
            v[1].pb(pii(l[k], max(r[k]-(N-i), 0)));
        }
        rep(j, 2) sort(all(v[j]));
        int n = sz(v[0]);
        rep(j, 2){
            int M = 0, m = inf;
            rep3(k, n-1, 0){
                chmin(m, M+v[j][k].first);
                chmax(M, v[j][k].second);
            }
            chmin(m, M);
            int tmp = (j == 0)? i:(N-i);
            tmp += n+2*m;
            chmin(ans, tmp);
        }
        rep(j, 2) v[j].clear();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3708
//38
#include<vector>
#include<iostream>
#include<complex>
#include<algorithm>
#include<cmath>

using namespace std;

typedef complex<double> P;

struct C{
  P p;
  int o,l;
  bool operator<(C a)const{
    return p.real()<a.p.real();
  }
};

double cr(P a,P b){
  return a.real()*b.imag()-a.imag()*b.real();
}

int main(){
  int t;
  cin>>t;
  while(t--){
    double xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    P a=P(xa,ya),b=P(xb,yb);
    int n;
    cin>>n;
    vector<C> c;
    while(n--){
      double xs,ys,xt,yt;
      int o,l;
      cin>>xs>>ys>>xt>>yt>>o>>l;
      P s=P(xs,ys),t=P(xt,yt);
      if(cr(a-s,t-s)*cr(b-s,t-s)<0&&cr(s-a,b-a)*cr(t-a,b-a)<0){
	double d1=fabs(cr(t-s,a-s));
	double d2=fabs(cr(t-s,b-s));
	P cp=(b-a)*d1/(d1+d2)+a;
	C cc={cp,o,l};
	c.push_back(cc);
      }
    }
    sort(c.begin(),c.end());
    int p=-1;
    int cn=0;
    for(int i=0;i<c.size();i++){
      int cp=c[i].o==c[i].l;
      cn+=p!=cp;
      p=cp;
    }
    cout<<(c.empty()?0:cn-1)<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        
        long remainder = n % k;
        long smallest = remainder;
        while (Math.abs(k - remainder) < smallest) {
        	smallest = Math.abs(k - remainder);
        }
        System.out.println(smallest);
        sc.close();
    }
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <queue>
#include <climits>
using edge_to = std::pair<long long, long long>; // {weight, to}
using edge = std::vector<long long>; // {weight, from, to}

// return set of edges
std::vector<edge> prim(
	long long V,
	long long E,
	std::vector<std::vector<edge_to>>& adj_list
) {
	std::vector<edge> ret(0);
	std::priority_queue<edge, std::vector<edge>, std::greater<edge>> pq;
	for (auto i : adj_list[0]) {
		pq.push({i.first, 0, i.second});
	}
	std::vector<bool> connected(V, false);
	connected[0] = true;
	while (--V) {
		while (connected[pq.top()[2]]) pq.pop();
		edge e = pq.top(); pq.pop();
		ret.push_back(e);
		connected[e[2]] = true;
		for (auto i : adj_list[e[2]]) {
			if (connected[i.second]) continue;
			pq.push({i.first, e[2], i.second});
		}
	}
	return ret;
}

int main() {
	long long V, E;
	std::cin >> V >> E;
	std::vector<std::vector<edge_to>> adj_list(V);
	for (long long i = 0; i < E; i++) {
		long long s, t, w;
		std::cin >> s >> t >> w;
		adj_list[s].push_back({w, t});
		adj_list[t].push_back({w, s});
	}
	std::vector<edge> edges = prim(V, E, adj_list);
	long long ans = 0;
	for (auto i : edges) ans += i[0];
	std::cout << ans << std::endl;
}


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


using namespace std;

int main() {
    int n;
    cin >> n;
    int w[n], sum=0;
    for (auto &wi:w) {
        cin >> wi;
        sum += wi;
    }
    int s1=0, s2=sum, dif = sum;
    for (int i=0; i<n; i++) {
        s1 += w[i];
        s2 -= w[i];
        dif = min(dif, abs(s1-s2));
        //cerr << s1 << ' ' <<  s2 << '\n';
    }
    cout << dif << '\n';
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	N, M, _ := sc.NextInt(), sc.NextInt(), sc.NextInt()
	r := sc.NextIntArray()
	sort.Ints(r)
	edge := make([][]int, N+1)

	for i := 0; i < len(edge); i++ {
		edge[i] = make([]int, N+1)
		for j := 0; j < len(edge[i]); j++ {
			edge[i][j] = 1e8
		}
		edge[i][i] = 0
	}

	for i := 0; i < M; i++ {
		A, B, C := sc.NextInt(), sc.NextInt(), sc.NextInt()
		edge[A][B] = min(edge[A][B], C)
		edge[B][A] = min(edge[B][A], C)
	}

	for k := 1; k <= N; k++ {
		for i := 1; i <= N; i++ {
			for j := 1; j <= N; j++ {
				if edge[i][j] > edge[i][k]+edge[k][j] {
					edge[i][j] = edge[i][k] + edge[k][j]
				}
			}
		}
	}

	//	fmt.Printf("%+v", edge)

	min_res := 1000000000

	for true {
		res := 0
		for i := 0; i < len(r)-1; i++ {
			res += edge[r[i]][r[i+1]]
		}
		if res < min_res {
			min_res = res
		}
		if !next_perm(r) {
			break
		}
	}
	fmt.Println(min_res)

}

func next_perm(p []int) bool {
	i := len(p) - 1
	for i > 0 && p[i-1] > p[i] {
		i--
	}
	if i == 0 {
		return false
	}
	i--
	j := len(p) - 1
	for p[j] < p[i] {
		j--
	}
	p[i], p[j] = p[j], p[i]
	i, j = i+1, len(p)-1
	for i < j {
		p[i], p[j] = p[j], p[i]
		i, j = i+1, j-1
	}
	return true
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <deque>
#include <bits/stdc++.h>
//#include "D:\C++\test_lib_projects\testlib.h"
using namespace std;
#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)

bool debug=true;

/*    *************************************
	  * Written in New Computer           *
	  * The following code belongs to     *
	  * XiaoGeNintendo of HellHoleStudios *
	  *************************************
*/
template<typename T1,typename T2>ostream& operator<<(ostream& os,pair<T1,T2> ptt){
	os<<ptt.first<<","<<ptt.second;
	return os;
}
template<typename T>ostream& operator<<(ostream& os,vector<T> vt){
	os<<"{";
	for(int i=0;i<vt.size();i++){
		os<<vt[i]<<" ";
	}
	os<<"}";
	return os;
}

int a,b;
int main(int argc,char* argv[]){
	cin>>a>>b;
	if(b==1){
		cout<<'0';
		return 0;
	}
	int left=a-b;
	cout<<left<<endl;
	return 0;
}



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

int main()
{
int N, K, x[101], total = 0;
cin >> N >> K;
for(int i = 1; i <= N; i++) cin >> x[i], total += 2 * min(abs(K - x[i]), x[i]);
cout << total << endl;
return 0;
}

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

int main()
{
    string a;
    int c=0;
    cin>>a;
    for(int i=0; i<a.size(); i++)
    {
        if(a[2]==a[3] && a[4]==a[5])
            c=1;
    }
    if(c==1)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
minf = 11
for i in range(1,N+1):
    if i**2 > N:
        break
    if N%i == 0:
        j = N/i ## j > i
    for k in range(1,12):
        if 10**k > j:
            if k < minf:
                minf = k
            else:
                break
print(minf)


Measured memory_bytes: 2940
//#define NDEBUG
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>
#include <cassert>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
// closed interval, inverse repeat
#define CIREP(i,start,fin) for(int i=(start);i>=(fin);i--)
#define CREP(i,start,fin) for(int i=(start);i<=(fin);i++)
#define RNG(i,start,fin) for(int i=(start);i<(fin);i++)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back
#define SZ(x) (int)(x).size()

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VVI = vector<VI>;
const LL LINF = 1001002003004005006ll;
/* 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,SZ(v))i>>v[j];return i;}

template<typename T>string join(const vector<T>&v)
{stringstream s;REP(i,SZ(v))s<<' '<<v[i];return s.str().substr(1);}

template<typename T>inline ostream& operator<<(ostream&o,const vector<T>&v)
{if(SZ(v))o<<join(v);return o;}
*/

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;
}




/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9


// Main program
void solve(){
    int a,b,c;cin >> a >> b >> c;
    cout << max(0,c- (a-b)) << endl;
    return;
}



// ----------------------------------------------
int main(){

    int T=1; 

    for (int i = 0; i < T; ++i) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np
from heapq import heappop, heappush


def solve(h, w, s, t, field):
    WARP = (-(w * 2 + 10), -(w * 2 + 9), -(w * 2 + 8), -(w * 2 + 7), -(w * 2 + 6),
            -(w + 6), -(w + 5), -(w + 3), -(w + 2),
            -2, 2,
            w + 2, w + 3, w + 5, w + 6,
            w * 2 + 6, w * 2 + 7, w * 2 + 8, w * 2 + 9, w * 2 + 10)
    WALK = (-(w + 4), -1, 1, w + 4)

    qc = np.zeros(2000000, dtype=np.int32)
    qv = np.zeros(2000000, dtype=np.int32)
    qv[0] = s
    l, r = 0, 1
    visited = np.zeros((h + 4) * (w + 4), np.int8)
    queued = np.zeros((h + 4) * (w + 4), np.int8)
    queued[s] = 1
    while l < r:
        cost = qc[l]
        v = qv[l]
        l += 1
        if v == t:
            return cost
        if visited[v]:
            continue
        visited[v] = 1
        for d in WALK:
            u = v + d
            if field[u] or visited[u] or queued[u]:
                continue
            queued[u] = 1
            l -= 1
            qc[l] = cost
            qv[l] = u
        for d in WARP:
            u = v + d
            if field[u] or visited[u] or queued[u]:
                continue
            qc[r] = cost + 1
            qv[r] = u
            r += 1

    return -1


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8,i8,i8,i8,i1[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8,i8,i8,i8,i1[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

h, w = map(int, sys.stdin.readline().split())
ch, cw = map(int, sys.stdin.readline().split())
dh, dw = map(int, sys.stdin.readline().split())
field = np.ones((h + 4) * (w + 4), dtype=np.int8)
for i in range(h):
    line = sys.stdin.readline().strip()
    field[(i + 2) * (w + 4) + 2:(i + 2) * (w + 4) + w + 2] = list(map('.#'.index, line))
s = (ch + 1) * (w + 4) + cw + 1
t = (dh + 1) * (w + 4) + dw + 1
ans = solve(h, w, s, t, field)
print(ans)


Measured memory_bytes: 45432
#include <stdio.h>
int main(){
    int a,b,x;
    while(1){
        scanf("%d %d",&a,&b);
        if(a == 0 && b == 0) break;
        if(a > b){
            x = a;
            a = b;
            b = x;
        }
        printf("%d %d\n",a,b);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
	int n; cin>>n;
	long worstRank=0,worstPt=INF;
	rep(i,n){
		int a,b; cin>>a>>b;
		if(worstRank<a){
			worstRank=a; worstPt=b;
		}
	}
	cout<<worstRank+worstPt<<endl;
	return 0;
}


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

int main(){
    double x1,x2,y1,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(5);
    cout << sqrt(pow(x1-x2,2)+pow(y1-y2,2)) << endl;
    return 0;
}


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

int cnt[100005];

const long long MOD = 1e9+7;

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

    memset(cnt, 0, sizeof(cnt));

    long long ans = 1;
    int temp;
    for(int i = 0; i < N; i ++){
        scanf("%d", &temp);
        if(temp == 0){
            ans = ans*(3-cnt[temp])%MOD;
        }else{
            if(cnt[temp-1]-cnt[temp] < 0){
                printf("0");
                return 0;
            }
            ans = ans*(cnt[temp-1]-cnt[temp])%MOD;
        }
        if(ans == 0){printf("0");return 0;}
        cnt[temp]++;
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 640
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    string S;
    cin >> S;
    bool is_easy = true;
    
    for (int i = 0; i < S.length(); i++) {
        if (i % 2 == 0) {
            is_easy = is_easy && (S[i] == 'R' || S[i] == 'U' || S[i] == 'D');
        } else {
            is_easy = is_easy && (S[i] == 'L' || S[i] == 'U' || S[i] == 'D');
        }
    }
    
    if (is_easy) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import heapq
from collections import defaultdict
input = sys.stdin.readline
inf = 10**18 #つまずきポイントその２（10 ** 10にしてた）



def dijkstra(repn, start, goal):
    dist = [inf for i in range(N + 1)] # 始点から各頂点までの最短距離を格納する
    
    dist[start] = 0
    q = []                  # プライオリティキュー．各要素は，(startからある頂点vまでの仮の距離, 頂点vのID)からなるタプル
    heapq.heappush(q, (0, start)) # 始点をpush

    while q:
        prov_cost, src = heapq.heappop(q) # pop
        
        # プライオリティキューに格納されている最短距離が，現在計算できている最短距離より大きければ，distの更新をする必要はない
        if dist[src] < prov_cost:
            continue

        # 他の頂点の探索
        for dest in repn[src]:
            cost = repn[src][dest]
            if dist[dest] > dist[src] + cost:
                dist[dest] = dist[src] + cost # distの更新
                heapq.heappush(q, (dist[dest], dest)) # キューに新たな仮の距離の情報をpush
                
    return dist[goal]
        



N, M = map(int, input().split())
repn = [defaultdict(list) for _ in range(N + 1)]
for i in range(2, N + 1):
    repn[i][i - 1] = 0
for _ in range(M):
    l, r, c = map(int, input().split())
    if repn[l][r] == [] or repn[l][r] > c: #つまずきポイントその１
        repn[l][r] = c

d = dijkstra(repn, 1, N)

if d == inf:
    print(-1)
else:
    print(d)


Measured memory_bytes: 90972
# -*- encoding:utf-8 -*-

arr = map(int,  raw_input().split(" "))

def exchange(arr):
    result=[]
    harf=[i/2 for i in arr]
    for i in range(len(arr)):
        result.append(sum(harf)-harf[i])
        
    return result

def odd_check(arr):
    result=True
    for i in arr:
        if i%2==1:
            result=False
    return result


ans=0
loop=[]
while odd_check(arr):
    loop.append(arr[:])
    arr = exchange(arr)
    ans += 1
    if arr in loop:
        ans = -1
        break
        
print(ans)


Measured memory_bytes: 2568
#!/usr/bin/env python3
import sys
INF = float("inf")
from collections import deque
import heapq


def argmost(a, comp, ini):
    m, n = ini, -1
    for i, v in enumerate(a):
        if comp(m, v):
            m, n = v, i
    return m, n


def solve(N: int, K: int, V: "List[int]"):
    M = min(N, K)
    m = -INF
    for A in range(M+1):
        for B in range(M-A+1):
            jueries = V[:A] + V[N-B:]
            # print("before:", jueries)
            heapq.heapify(jueries)
            for i in range(K-A-B):
                if len(jueries) > 0:
                    sute = heapq.heappop(jueries)
                    if sute >= 0:
                        heapq.heappush(jueries, sute)
                        break
            s = sum(jueries)
            # print("after:", jueries, s)
            if m < s:
                m = s
    print(m)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, V)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int dp[100001];

int main () {
  int h, n;
  cin >> h >> n;
  vi a(n), b(n);
  rep(i,n) {
    cin >> a[i] >> b[i];
  }

  rep(i,100000) dp[i] = INF;
  dp[0] = 0;
  rep(i,h+1) {
    rep(j,n) {
      if (dp[i] == INF) continue;
      chmin(dp[i+a[j]], dp[i]+b[j]); 
    }
  }

  int ans = INF;
  for (int i = h; i < h+*max_element(rng(a)); ++i) {
    chmin(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 1e5;
int n, k, h[N], c[N];

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> h[i];
  memset(c, INF, sizeof c);
  c[0] = 0;
  for (int i = 1; i < n; ++i) {
    for (int b = 1; b <= k; ++b) {
      const int f = i-b;
      if (f < 0) break;
      c[i] = min(c[i], c[f] + (abs(h[i] - h[f])));
    }
  }
  cout << c[n-1] << nl;

  return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<numeric>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<ctype.h>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<utility>
#define For(a,b) for(int i=(a);i<(b);i++)
#define Rep(n) for(int i=0; i<(n); ++i)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
//----------program from here----------

int main(){
    int A=0,B=0;
    cin >> A >> B;
    int n[3]={A+B,A-B,A*B};
    sort(n, n+3);
    cout << n[2] << endl;
}

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

using lint = long long;

lint pow5(lint x) {
    return x * x * x * x * x;
}

void solve() {
    lint x;
    std::cin >> x;

    std::vector<lint> xs;
    for (lint a = 0;; ++a) {
        if (pow5(a) - pow5(a - 1) > x) break;
        xs.push_back(a);
    }

    for (auto a : xs) {
        for (auto b : xs) {
            if (pow5(a) - pow5(b) == x) {
                std::cout << a << " " << b << std::endl;
                return;
            }
            if (pow5(a) + pow5(b) == x) {
                std::cout << a << " " << -b << std::endl;
                return;
            }
        }
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3664
n=int(input())
s=input()

ws=sum([1 for i in s if i=="E"])
s="E"+s
count=[0]*n

for i in range(n):
    now=s[i+1]
    before=s[i]
    
    if now=="E":
        ws-=1
    if before=="W":
        ws+=1
    count[i]=ws
print(min(count))
        
        


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

ll a[1000];
char s[40], b[2000];
int main() {
	int n, m, q;
	while (scanf("%d%d%d", &n, &m, &q), n) {
		rep(i, m)a[i] = (1LL << n) - 1;
		ll k = 0;
		rep(i, q) {
			scanf("%s%s", s, b);
			ll t = 0;
			rep(j, n)t = ((t << 1) | (s[j] - '0'));
			k ^= t;
			rep(j, m) {
				if (b[j] == '1')a[j] &= k;
				else a[j] &= ~k;
			}
		}
		rep(i, m) {
			int t = -1;
			rep(j, n) {
				if (a[i] >> j & 1) {
					if (~t) { t = -1; break; }
					t = n - j - 1;
				}
			}
			if (t == -1)printf("?");
			else printf("%c", t < 10 ? '0' + t : 'A' - 10 + t);
		}
		puts("");
	}
}

Measured memory_bytes: 3140
#include<stdio.h>
int main(void)
{
	char b;
	scanf("%c",&b);
	if(b=='A'){
		printf("T\n");
	}
	if(b=='T'){
		printf("A\n");
	}
	if(b=='G'){
		printf("C\n");
	}
	if(b=='C'){
		printf("G\n");
	}
	return 0;
}

Measured memory_bytes: 128
import sys




def solve(a, b, n):
    result = 0
    a = a % b
    for i in range(n):
        a *= 10
        result += a // b
        a = a % b
    return result




if __name__ == '__main__':
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        a, b, n = [int(x) for x in line.strip().split(' ')]
        result = solve(a, b, n)
        print(result)

Measured memory_bytes: 7636
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n, c, k = map(int, input().split())
    ti = []
    for i in range(n):
        t = int(input())
        ti.append(t)
    ti = sorted(ti)
    next_time = -HUGE
    next_capacity = 0
    count_bus = 0
    for t in ti:
        if (next_capacity) == 0 or (next_time < t) or (next_time > t + k):
            next_time = t + k
            next_capacity = c - 1
            count_bus += 1
        else:
            next_capacity -= 1
    print(count_bus)

main()


Measured memory_bytes: 8792
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  ll ans = 0;
  FOR(i, 1, n + 1) {
    if(i % 3 != 0 && i % 5 != 0) ans += i;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3652
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        int[] ans = solve2(N, K, A);
        for (int i=0; i<N; i++) {
            if (i != 0) System.out.print(" ");
            System.out.print(ans[i]);
        }
        System.out.println();
    }

    private static int[] solve2(int N, int K, int[] A) {
        int[] ans = A.clone();
        int[] next = null;

        for (int i=0; i<Math.min(K, 200); i++) {
            next = new int[N];
            int[] up = new int[N];
            int[] down = new int[N];

            for (int j=0; j<N; j++) {
                up[Math.max(0, j-ans[j])]++;
                down[Math.min(N-1, j+ans[j])]++;
            }

            int on = 0;
            for (int j=0; j<N; j++) {
                on += up[j];
                next[j] = on;
                on -= down[j];
            }

            ans = next;

            // System.err.println(Arrays.toString(next));
        }

        return next;

    }
}

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

int main() {
  string a, s;
  cin >> a >> s >> a;
  
  string x = "ABC";
  x.at(1) = s.at(0);

  cout << x << endl;
}

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

int R, C, r, c;
int main () {
	cin >> R >> C >> r >> c;
	
	if (r==R-1 && c==C-1)
		cout << 1;
		
	else if (R>r && C>c)
		cout << (R-r)*(C-c);
		
	else
		cout << 0;
	
	
return 0;
}

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

int dfs(int n,int k,int s,int i,int pre,int sum){
    if(i==k){
        if(sum==s)
            return 1;
        else
            return 0;

    }
    int cnt=0;
    for(int j=pre+1;j+sum<=s && j<=n;j++){
        if((k-i)*j+(k-i)*(k-i-1)/2+sum<=s){
            cnt+=dfs(n,k,s,i+1,j,sum+j);
            }


    }
    return cnt;


}

int main(){
    int n,k,s;
    while(cin>>n>>k>>s,n){
        cout<<dfs(n,k,s,0,0,0)<<endl;;



    }
    return 0;
}

Measured memory_bytes: 3008
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<int MOD>
struct ModInt{
	int x;
	ModInt(): x(0){}
	ModInt(ll y): x(y>=0 ? y%MOD : (MOD-(-y)%MOD)%MOD){}

	ModInt &operator+=(const ModInt &p){
		if((x+=p.x)>=MOD) x-=MOD;
		return *this;
	}
	ModInt &operator-=(const ModInt &p){
		if((x+=MOD-p.x)>=MOD) x-=MOD;
		return *this;
	}
	ModInt &operator*=(const ModInt &p){
		x=(int)(1ll*x*p.x%MOD);
		return *this;
	}
	ModInt &operator/=(const ModInt &p){
		*this*=p.inv();
		return *this;
	}

	ModInt operator-() const{ return ModInt(-x);}
	ModInt operator+(const ModInt &p) const{ return ModInt(*this)+=p;}
	ModInt operator-(const ModInt &p) const{ return ModInt(*this)-=p;}
	ModInt operator*(const ModInt &p) const{ return ModInt(*this)*=p;}
	ModInt operator/(const ModInt &p) const{ return ModInt(*this)/=p;}
	bool operator==(const ModInt &p) const{ return x==p.x;}
	bool operator!=(const ModInt &p) const{ return x!=p.x;}

	ModInt pow(ll n) const{
		ModInt ret(1), p(x);
		while(n){
			if(n&1) ret*=p;
			p*=p;
			n>>=1;
		}
		return ret;
	}
	ModInt inv() const{
		return pow(MOD-2);
	}
};
const int MOD=1e9+7;
using mint=ModInt<MOD>;
string s;
int n;
mint dp[2][2][300030];
bool ok[2][2][300030];
mint solve(int p, int c, int i){
    if(c>=2) return 0;
    if(ok[p][c][i]) return dp[p][c][i];
    ok[p][c][i]=1;
    if(i==n-1){
        if(c==0 && p==0) return dp[p][c][i]=1;
        else return 0;
    }
    if(i==n-2){
        int c1=c;
        if(p==0) c1--;
        else c1++;
        mint ret=0;
        if(s[n-1]=='?' || s[n-1]=='1'){
            if(c1+1<0) ret+=1;
        }
        if(s[n-1]=='?' || s[n-1]=='0'){
            if(c1-1<0) ret+=1;
        }
        return dp[p][c][i]=ret;
    }
    mint ret=0;
    if(p==1){
        if(s[i+1]=='?' || s[i+1]=='1') ret+=solve(1, c+1, i+1);
        if(s[i+1]=='?' || s[i+1]=='0') ret+=solve(0, c+1, i+1);
        return dp[p][c][i]=ret;
    }
    if((s[i+1]=='?' || s[i+1]=='0') && (s[i+2]=='?' || s[i+2]=='0')){
        ret+=solve(0, c, i+2);
    }
    if((s[i+1]=='?' || s[i+1]=='0') && (s[i+2]=='?' || s[i+2]=='1')){
        ret+=solve(0, c, i+2);
    }
    if((s[i+1]=='?' || s[i+1]=='1') && (s[i+2]=='?' || s[i+2]=='0')){
        ret+=solve(0, c, i+2);
    }
    if((s[i+1]=='?' || s[i+1]=='1') && (s[i+2]=='?' || s[i+2]=='1')){
        ret+=solve(1, c, i+2);
    }
    return dp[p][c][i]=ret;
}
int main()
{
    cin>>s;
    n=s.size();
    mint ans=0;
    if(s[0]=='?' || s[0]=='1') ans+=solve(1, 0, 0);
    if(s[0]=='?' || s[0]=='0') ans+=solve(0, 0, 0);
    mint p=1;
    for(int i=0; i<n; i++) if(s[i]=='?') p*=2;
    ans=p-ans;
    cout<<ans.x<<endl;
	return 0;
}

Measured memory_bytes: 22916
package main

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

var scanner = bufio.NewScanner(os.Stdin)

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

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

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	d := nextInt()

	r := 2*d + 1

	if n%r == 0 {
		fmt.Println(n / r)
	} else {
		fmt.Println(n/r + 1)
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



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

    int count=INF;
    if(a+c<count) count=a+c;
    if(a+d<count) count=a+d;
    if(b+c<count) count=b+c;
    if(b+d<count) count=b+d;
    out(count);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  string S = "";
  cin >> H >> W;
  for(int i=0; i<H; i++){
    string s;
    cin >> s;
    S += s;
  }
  
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      
      int n = 0;
      int l = h * W + w;
      int top = l - W;
      int topleft = top - 1;
      int topright = top + 1;
      int left = l - 1;
      int right = l + 1;
      int bottom = l + W;
      int bottomleft = bottom - 1;
      int bottomright = bottom + 1;


      
      if(S.at(l) == '#'){
        cout << '#';
       continue;
      }
      
      if(top >= 0){
        if(topleft >= 0 && top % W != 0){
          if(S.at(topleft) == '#'){
//            cout << "topleft" << endl;
          n++;
          }
        }
        if(S.at(top) == '#'){
          
//            cout << "top" << endl;
          n++;
        }
        if(topright % W != 0){
 //         cout << '*' << topright << '*' << endl;
          if(S.at(topright) == '#'){
            
//            cout << "topright" << endl;
          n++;
          }
        }
      }
        if(left >= 0 && l % W != 0){
          if(S.at(left) == '#'){
            
//            cout << "left" << endl;
          n++;
          }
        }
        if(right < W * H && right % W != 0){
          if(S.at(right) == '#'){
            
//            cout << "right" << endl;
          n++;
          }
        }
      if(bottom < W * H){ 
        if(bottom % W != 0){
          if(S.at(bottomleft) == '#'){
//            cout << "bottomleft" << endl;
          n++;
          }
        }
//        if(bottom < W * H){
        if(S.at(bottom) == '#'){
          
//            cout << "bottom" << endl;
          n++;
        }
//        }

        if(bottomright < W * H && bottomright % W != 0){
          if(S.at(bottomright) == '#'){
            
//            cout << "bottomright" << endl;
          n++;
          }
        }
      }
      cout << n;
/*      cout << endl;
      cout << topleft << " " << top << " " << topright <<endl;
      cout << left << " " << l << " " << right <<endl;
      cout << bottomleft << " " << bottom << " " << bottomright <<endl;*/
    }
    cout << endl;
  }
  // ここにプログラムを追記
}

Measured memory_bytes: 3640