akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int k=sc.nextInt();
        int N=sc.nextInt();
        int[] arr=new int[N];
        int max=0;
        for (int i=0;i<N;i++){
            arr[i]=sc.nextInt();
            if (i>1){
                max = Math.max(arr[i] - arr[i - 1], max);
            }
        }
        max =  Math.max(k - arr[(N - 1)] + arr[0], max);
        System.out.println(k-max);
    }

}


Measured memory_bytes: 79224
package main

import "fmt"

func main() {
        var k, s, cnt int

        fmt.Scanf("%d %d", &k, &s)

        for x := 0; x <= k; x++ {
                for y := 0; y <= k; y++ {
                        z := s - x - y
                        if z >= 0 && z <= k {
                                cnt++
                        }
                }
        }

        fmt.Printf("%d", cnt)
}


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

int main() {
    int n, x, y;
    cin >> n;
    x = 800 * n;
    y = 200 * (int)(n / 15);
    cout << x - y << endl;

    return 0;
}


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

using namespace std;
const int MOD = 1000000007,MAX = 510000;
long int pow107 = (int)pow(10, 9) + 7,llimit = LONG_MAX,fac[MAX], finv[MAX], inv[MAX];
int ilimit = INT_MAX;

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long int COM(long int n,long int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool comp(pair<int, int> a, pair<int, int> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

long int Func2(long int n,long int m){
    long int s2 = 1,
        r = 1;
    for(long int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % (pow107);
    }
    return s2;
}

bool secsort(pair<int, int> a, pair<int, int> b){
    if(a.second == b.second)return a.first > b.first;
    else return a.second > b.second;
}

long int GCD(long int a,long int b){
    if(b == 0)return a;
    return GCD(b,a%b);
}

long int LCM(long int a,long int b){
    return a/GCD(a,b)*b;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2
//コンビネーションCOMinit(),COM(n,m)

int main(){
    int n,t = 0;
    cin >> n;
    for(int i = 0; i < n ; ++i){
        int a,b;
        cin >> a >> b;
        t += b-a+1;
    }
    cout << t << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			String qwright = "nmhjklyuiop" ;
			
			while(true) {
				int n = sc.nextInt();
				if(n == 0)	break;
				int[] a = new int[n];
				for(int i=0; i<n; i++) {
					a[i] = sc.nextInt();
				}
				Arrays.sort(a);
				int min = 1000000;
				for(int i=0; i<n-1; i++) {
					int sa = Math.abs(a[i] - a[i+1]);
					if(sa < min)	min = sa;
				}
				System.out.println(min);
			}
			
			
			
			
			
		}
	}
}




Measured memory_bytes: 46568
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def cnk(a, b):
    MOD = 10**9+7
    ret = 1
    for i in range(b):
        ret *= (a-i)
        ret %= MOD
        ret = ret * modinv(i+1, MOD) % MOD
    return ret


class UnionFind:
    def __init__(self, n):
        self.sz = [-1 for i in range(n)]

    # 検索
    def find(self, x):
        if self.sz[x] < 0:
            return x
        else:
            self.sz[x] = self.find(self.sz[x])
            return self.sz[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.sz[x] > self.sz[y]:
            x, y = y, x
        self.sz[x] += self.sz[y]
        self.sz[y] = x

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xが含まれている集合のサイズを求める
    def size(self, x):
        return -self.sz[self.find(x)]


def main():
    h = int(input())
    t = h
    k = 0
    while t > 1:
        t //= 2
        k += 1
    k+=1
    print(2**k - 1)




            


    




    


if __name__ == '__main__':
    main()


Measured memory_bytes: 5300
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int CardA = Integer.parseInt(sc.next());
		int CardB = Integer.parseInt(sc.next());
		String s = "";
		if(CardA == 1){
			CardA = 14;
		}

		if(CardB == 1){
			CardB = 14;
		}


		if(CardA > CardB){
			s="Alice";
		}else if(CardB > CardA){
			s="Bob";
		}else if(CardB == CardA){
			s="Draw";
		}
		System.out.println(s);
		sc.close();
	}
}

Measured memory_bytes: 22484
h, w = map(int, input().split())
a = [input() for i in range(h)]

memo = {}
for i in range(h):
    for j in range(w):
        if a[i][j] not in memo:
            memo[a[i][j]] = 1
        else:
            memo[a[i][j]] += 1

used = [[False]*w for i in range(h)]
cnt_4 = 0
cnt_2 = 0
cnt_1 = 0
for i in range(h):
    for j in range(w):
        if used[i][j]:
            continue
        cnt = 4
        if 2 * i + 1 == h:
            cnt = cnt // 2
        if 2 * j + 1 == w:
            cnt = cnt // 2
        if cnt == 4:
            cnt_4 += 1
        if cnt == 2:
            cnt_2 += 1
        if cnt == 1:
            cnt_1 += 1
        used[i][j] = True
        used[-i-1][j] = True
        used[i][-j-1] = True
        used[-i-1][-j-1] = True

for i in memo:
    tmp = memo[i] // 4
    if tmp < cnt_4:
        memo[i] -= tmp * 4
        cnt_4 -= tmp
    elif tmp >= cnt_4:
        memo[i] -= cnt_4 * 4
        cnt_4 = 0
        break

for i in memo:
    tmp = memo[i] // 2
    if tmp < cnt_2:
        memo[i] -= tmp * 2
        cnt_2 -= tmp
    elif tmp >= cnt_2:
        memo[i] -= cnt_2 * 2
        cnt_2 = 0
        break

for i in memo:
    tmp = memo[i]
    if tmp < cnt_1:
        memo[i] -= tmp * 1
        cnt_1 -= tmp
    elif tmp >= cnt_1:
        memo[i] -= cnt_1 * 1
        cnt_1 = 0
        break

if cnt_4 + cnt_2 + cnt_1 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 39664
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    if(
       abs(x-a)<abs(x-b)){
        printf("A\n");
    }
    else{
        printf("B\n");
    }
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int s = sc.nextInt();
    int w = sc.nextInt();
    
    if(s <= w){
      System.out.print("unsafe");
    }else{
      System.out.print("safe");
    }
    
  }
}

Measured memory_bytes: 35632
def p_c():
    N = int(input())
    H = list(map(int, input().split()))

    b = H[0] - 1
    now = 0
    m = 0

    for h in H:
        if b >= h:
            now += 1
            b = h
        else:
            if m < now:
                m = now
            now = 0
            b = h

    if m < now:
        m = now

    print(m)


if __name__ == '__main__':
    p_c()


Measured memory_bytes: 63856
import numpy as np

N = int(input())
#N,K,d= map(int,input().split())
#A = list(map(int,input().split()))
#S = str(input())
#T = str(input())

num=np.zeros(10**4+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            ans = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if ans < 10**4+1:
                num[ans]+=1


for i in range(N):
    print(int(num[i+1]))


Measured memory_bytes: 26544
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  int a, b; cin >> a >> b;
  cout << (b+a-3)/(a-1) << '\n';
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
left = 0

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break
    if flag:
        insert_index = max(insert_index, left)
    left += 1


if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s[:insert_index] + t + s[insert_index+len(t):]

    ans = next_word.replace("?", "a")
    print(ans)


Measured memory_bytes: 3064
if __name__ == "__main__":
    X,N = list(map(int,input().split()))
    p = list(map(int,input().split()))
    if not X in p: # pが空配列・pにXが含まれない
        print(X)
    else:
        i = 1
        while True:
            if not (X - i) in p:
                print(X-i)
                break
            if not (X + i) in p:
                print(X+i)
                break
            i += 1

Measured memory_bytes: 9112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int r, d, x;

    cin >> r >> d >> x;

    REP(i, 10)
    {
        x = r * x - d;
        cout << x << endl;
    }

    return 0;
}

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 ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int n, k;
    cin >> n >> k;

    int count = 1;
    while(1){
        int num = pow(k, count);
        if (num > n){
            break;
        }
        else{
            count++;
        }
    }
    cout << count << endl;
    return 0;
}  

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

int DP[1001][1001];

int main(){
    int T;
    cin >> T;
    for (int t = 0; t < T; t++) {
        char X[1002],Y[1002];
        scanf("%s%s",X,Y);
        
        int y = strlen(Y);
        int x = strlen(X);
        
        for (int i = 0; i <= y; i++) DP[i][0] = 0;
        for (int i = 0; i <= x; i++) DP[0][i] = 0;
        
        for (int r = 1; r <= y; r++) {
            for (int c = 1; c <= x; c++) {
                if (Y[r-1] == X[c-1]) DP[r][c] = DP[r-1][c-1]+1;
                else DP[r][c] = max(DP[r-1][c],DP[r][c-1]);
            }
        }
        cout << DP[y][x] << endl;
        
    }
    
    
    return 0;
}

Measured memory_bytes: 5100
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
int main() {
    int n, q; cin >> n >> q;
    vector<bool> x(n), y(n);
    x[0] = true;
    y[1] = true;
    while (q --) {
        int a, b; cin >> a >> b; -- a; -- b;
        swap(x[a], x[b]);
        swap(y[a], y[b]);
        for (int i : { a-1, a, a+1, b-1, b, b+1 }) if (0 <= i and i < n and x[i]) {
            for (int j : { i-1, i+1 }) if (0 <= j and j < n) {
                y[j] = true;
            }
        }
    }
    int ans = 0;
    repeat (i,n) ans += x[i] or y[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
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;


int main(void)
{
	int N; cin >> N;
	vector<int> L(N);
	rep(i, 0, N)cin >> L[i];
	sort(L.begin(), L.end());

	lli ans = 0;
	for (int i = N - 1; i >= 2; i--) {
		for (int j = i - 1; j >= 1; j--) {
			for (int k = j - 1; k >= 0; k--) {
				if (L[i] < L[j] + L[k])ans++;
			}

		}

	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
if k==0:
    print(n**2)
    exit()
ans=0
for i in range(k+1,n+1):
    p=n//i
    q=n%i
    ans +=p*max(0,i-k)+max(0,q-k+1)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
	int A, B;
	int Max = 31;//2で割った一番少ない数
	cin >> A;
	for (int i = 0; i < A; i++){
    	int C = 0;
    	cin >> B;
		while (B % 2 == 0){
        		B /= 2;
            	C++;
        }
		if (C < Max){
        	Max = C;
        }
    }cout << Max << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 2020,mo=924844033;
int n,k,a[N],b[N],f[N],fac[N];
void add(int &x, int y){x=(x+y)%mo;}
void solve(int n, int f[N]){
	static int dp[N][2][2][N];memset(dp,0,sizeof(dp));
	dp[1][1][1][0]=1;
	rep(i,1,n-1)rep(x,0,1)rep(y,0,1)rep(j,0,i)if(dp[i][x][y][j]){
		rep(a,0,1)if(!a||y)rep(b,0,1)if(!b||x)
			add(dp[i+1][a^1][b^1][j+a+b],dp[i][x][y][j]);
	}
	rep(i,0,1)rep(j,0,1)rep(k,0,n)add(f[k],dp[n][i][j][k]);
}
void mul(int *f, int *g, int n1, int n2){
	static int a[N];memset(a,0,sizeof(a));
	rep(i,0,n1)if(f[i])rep(j,0,n2)add(a[i+j],1LL*f[i]*g[j]%mo);
	memcpy(f,a,sizeof(a));
}
int main() {
	read(n);read(k);
	fac[0]=1;rep(i,1,n)fac[i]=1LL*fac[i-1]*i%mo;
	solve(n/k,a);solve(n/k+1,b);f[0]=1;int tot=0;
	rep(i,1,k){
		int now=n/k+(i<=n%k);mul(f,now==n/k?a:b,tot,now);tot+=now;
	}
	int res=0;
	rep(i,0,n)add(res,1LL*f[i]*(i&1?mo-1:1)%mo*fac[n-i]%mo);
	cout<<res;
	return 0;
}


Measured memory_bytes: 64000
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class ATenki {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            char[] a = s.next().toCharArray(), b = s.next().toCharArray();
            int ans = 0;
            for (int i = 0; i < 3; i++) {
                if (a[i] == b[i]) ans++;
            }
            w.println(ans);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public String next() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            StringBuilder res = new StringBuilder();

            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define show(x) cout<<x<<'\n'
#define showh(x) cout<<x<<' '
#define go(i,a,n) for(ll i=a;i<n;i++)
#define gor(i,a,n) for(ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
bool prime[100001];
bool ispoweroftwo(ll x)
{
    return x && !(x & (x-1));
}
ll xorcal(ll n)
{
    if(n%4==0)
        return n;
    if(n%4==1)
        return 1;
    if(n%4==2)
        return n+1;
    if(n%4==3)
        return 0;
}
void sieve(ll n)
{
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(ll i=2;i*i<=n;i++)
    {
        if(prime[i]==true)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    show(prime[89]);
}
bool isprime(ll n)
{
    if (n<=1) return false;
    if (n<=3) return true;

    if(n%2==0 or n%3==0) return false;

    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0 or n%(i+2)==0) return false;
    }
    return true;
}

ll modinverse(ll a,ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m; a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    return(b%a,a);
}

ll power(ll A, ll B)
{
    if (A == 0)
        return 0;
    if (B == 0)
        return 1;

    ll y;
    if (B % 2 == 0) {
        y = power(A, B / 2);
        y = (y * y) % mod;
    }

    else {
        y = A % mod;
        y = (y * power(A, B - 1) % mod) % mod;
    }

    return (ll)((y + mod) % mod);
}

int main()
{
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    if((ll)s.size()==1)
    {
        show("0");
        exit(0);
    }
    ll count=0;
    go(i,0,(ll)s.size()-1)
    {
        if(s[i]==s[i+1])
        {
            if(s[i+1]=='0')
            {
                s[i+1]='1';
            }
            else
            {
                s[i+1]='0';
            }
            count++;
        }
        else
        {
            continue;
        }
    }
    show(count);
    return 0;

}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	int k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	sort(h.begin(), h.end());
	int min = h[k - 1] - h[0];
	for (int i = 1; i + k - 1 < n; ++i) {
		int sub = h[i + k - 1] - h[i];
		if (min > sub) min = sub;
	}
	cout << min;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct stnode
{
    int maxx,lz;
};
stnode st[200005];

int a[200005];
int d[5005][205];
int stk[205][5005];
int top[205];
int n,m,ans;

void update(int id, int l, int r, int u, int v, int val)
{
    if (l >= u && r <= v)
    {
        st[id].lz += val;
        return;
    }
    if (l > v || r < u) return;
    int mid = (l + r) >> 1;
    st[id * 2].lz += st[id].lz;
    st[id * 2 + 1].lz += st[id].lz;
    st[id].lz = 0;
    update(id * 2, l, mid, u, v, val);
    update(id * 2 + 1, mid + 1, r, u, v, val);
    st[id].maxx = max(st[id * 2].maxx + st[id * 2].lz, st[id * 2 + 1].maxx + st[id * 2 + 1].lz);
}

signed main()
{
    //freopen("file.inp","r",stdin);
    cin >> n >> m;
    for (int i = 2; i <= n; i++)
    {
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
    {
        cin >> d[i][j];
    }
    for (int r = 1; r <= n; r++)
    {
        if (r > 1) update(1, 1, n, 1, r - 1, -a[r]);
        for (int i = 1; i <= m; i++)
        {
            update(1, 1, n, r, r, d[r][i]);
            int ri = stk[i][top[i]];
            while (top[i] > 0 && d[ri][i] <= d[r][i])
            {
                int val = d[r][i] - d[ri][i];
                int le = stk[i][--top[i]] + 1;
                update(1, 1, n, le, ri, val);
                ri = le - 1;
            }
            stk[i][++top[i]] = r;
        }
        ans = max(ans, st[1].maxx + st[1].lz);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
const int N = 810;
int h, w, k, ans, sx, sy;
int d[N][N], q[N * N * 2];
char Map[N][N];
int main()
{
	scanf("%d%d%d", &h, &w, &k);
	for(int i = 0; i <= h + 1; ++i)
		for(int j = 0; j <= w + 1; ++j) Map[i][j] = '#';
	for(int i = 1; i <= h; ++i)
	{
		char s[N];
		scanf("%s", s + 1);
		for(int j = 1; j <= strlen(s + 1); ++j) 
		{
			if(s[j] == 'S')
			{
				sx = i;
				sy = j;
			}
			Map[i][j] = s[j];
		}
	}
	ans = 1 << 29;
	int l = 1, r = 0;
	q[++r] = sx;
	q[++r] = sy;
	while(l <= r)
	{
		int x = q[l++], y = q[l++];
		ans = min(ans, min(min(x - 1, h - x), min(y - 1, w - y)));
		if(d[x][y] == k) continue;
		for(int i = 0; i < 4; ++i)
		{
			int xx = x + dx[i], yy = y + dy[i];
			if(!d[xx][yy] && Map[xx][yy] == '.') 
			{
				q[++r] = xx;
				q[++r] = yy;
				d[xx][yy] = d[x][y] + 1;
			}
		}
	}
	ans = (ans + k - 1) / k + 1;
	printf("%d\n", ans);		
	return 0;
}

Measured memory_bytes: 8576
object Main extends App {
    val Array(n, m) = io.StdIn.readLine.split(" ").map(_.toInt)
    val xs = io.StdIn.readLine.split(" ").map(_.toInt)

    if (m <= n) println(0)
    else {
        val sorted = xs.sorted
        val ls = sorted.sliding(2).map(range => range.last - range.head).toArray.sorted.reverse
        val not_moved_section = ls.take(n-1).sum
        val all_section = sorted.last - sorted.head
        println(all_section-not_moved_section)
    }
}

Measured memory_bytes: 69536
package main

import "fmt"

func main(){
	var A, B int
	var S string
	var f int

	fmt.Scan(&A, &B, &S)
	for i := 0 ; i < A ; i++ {
		if !('0' <= S[i] && S[i] <= '9') {
			f = 1
		}
	}
	if (S[A] != '-'){
		f = 1
	}
	for i := A + 1 ; i <= A + B ; i++{
		if !('0' <= S[i] && S[i] <= '9') {
			f = 1
		}
	}
	if f == 1{
		fmt.Println("No")
	}else {
		fmt.Println("Yes")
	}
}

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

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int a[4];
	for(int i = 1; i <= 3; i ++)
		cin >> a[i];
	sort(a + 1, a + 3 + 1);
	int s = 0;
	for(int i = 2; i <= 3; i ++)
		s += abs(a[i] - a[i - 1]);
	cout << s;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

//    string s;
//    cin >> s;
//    reverse(all(s));
//    rep(i,0,s.size()){
//        if(s[i] )
//    }
    ll N;
    cin >> N;
    int ans = 0;
//    for (ll i = 0; pow(10LL, i) <= N; i++) {
////        N /= pow(10LL,i);
//        if (N >= 10) {
//            if (N % 10 != 9) {
//                N /= 10;
//                N--;
////            N *= 10;
////                N += 9;
//            }else{
//                N /= 10;
//            }
//            ans += 9;
//        }
//
////        N *= pow(10LL,i);
//    }
////    while(N > 0){
////        ans += (N % 10);
////        N /= 10;
////    }
    while(N >= 10){
        if(N % 10 == 9){
            N /= 10;
            ans += 9;
        }else{
            N /= 10;
            N--;
            ans += 9;
        }
    }
    ans += N;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define int long long
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(a) a.size()
#define re return 
#define MP make_pair
#define pb push_back
#define pii pair<int,int>
#define se second
#define fi first
using namespace std;
bool seen[105];
signed main(){
	ios_base::sync_with_stdio(0);
	int n,m,x;
	cin>>n>>m>>x;
	while(m--){
		int a;
		cin>>a;
		seen[a]=1;
	}
	int c1=0,c2=0;
	int cur=x;
	while(cur){
		cur--;
		if(seen[cur]) c1++;
	}
	cur=x;
	while(cur!=n){
		cur++;
		if(seen[cur]) c2++;
	}
	cout<<(c1<c2?c1:c2);
	re 0;
}

Measured memory_bytes: 3660
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10 ** 9 + 7

ans, frag = 1, 0
for i in range(n):
    if t[i] == a[i] == t[-1] == a[0]:
        frag = 1
    if 0 < i < n - 1 and t[i - 1] == t[i] and a[i] == a[i + 1]:
        ans = ans * min(t[i], a[i]) % mod
print(ans if frag == 1 else 0)


Measured memory_bytes: 97516
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define fill(a,val) memset(a,val,sizeof(a))
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first

#define M 315
using namespace std;
 

int main()
{
    std::ios::sync_with_stdio(false);
    int T = 1;
    //cin>>T;
    while(T--)
    {
       int x = 0;
       int y = 0;
       cin>>x>>y;
       int flag = 0;
       for(int  i = 0;i<=x;i++)
       {
            if(i*2+(x-i)*4 == y)
                flag = 1;
       }
       if(flag)
            cout<<"Yes";
        else
            cout<<"No";
    }   
    
    return 0;
}


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

int main() {
	int n;
	cin>>n;
	long long a[n];
	long long sum = 0;
	map<long long, long long> m;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		m[a[i]]++;
		sum+=a[i];
	}
	
	int q;
	cin>>q;
	while(q--) {
		long long u, v;
		cin>>u>>v;
		if(m.find(u) != m.end()) {
			sum -= (u * m[u]);
			sum += (v * m[u]);
			m[v] += m[u];
			m.erase(u);
		}
		
		cout << sum << "\n";
	}
	return 0;
}

Measured memory_bytes: 8360
/**************>>>JunSH's_Prefix<<<*************/
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rev(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
/***********************************************/
const int maxn=2e5+10;
int a[maxn];
int vis[maxn];
int main(){
    int n;
    cin>>n;
    rep(i,1,n)cin>>a[i];
    int mx=0;
    int sec=0;
    int pos;
    int res=0;
    for(int i=1;i<=n-1;i+=2){
        vis[a[i]]++;
        if(vis[a[i]]>mx){
            mx=vis[a[i]];
            pos=a[i];
        }
        else sec=max(sec,vis[a[i]]);
    }
    memset(vis,0,sizeof(vis));
    for(int i=2;i<=n;i+=2)
        vis[a[i]]++;
    int ans=-1;
    for(int i=1;i<=1e5;++i){
        ans=max(ans,vis[i]+(i==pos?sec:mx));
    }
    cout<<n-ans<<endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  if(a % 2 == 0 || b % 2 == 0)
  {
    cout << "Even" << endl;
  }
  else
  {
    cout << "Odd" << endl;
  }
}

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

typedef long long ll;

int MOD=1000000007;


int main(){
    int W,H,x,y;
    cin >> W >> H >> x >> y;
    cout << (double)(W)*(double)(H) / 2 << " " << (x+x == W && y+y == H) << endl;
}


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

typedef long long int ll;

using namespace std;
ll N, A, B;
string S;

int main()
{
  ll d;
  ll m;
  ll ret;

  cin >> N >> A >> B;
  d = N/(A+B);
  m = N%(A+B);
  ret = A*d;
  if (m>=A) ret+=A;
  else ret += m;

  printf("%lld\n", ret);

  return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer(8) :: n, m, i
  integer(8), allocatable :: edges(:, :)
  read *, n, m
  allocate (edges(3, m))
  do i = 1, m
    read *, edges(:, i)
  end do
  edges(3, :) = -1 * edges(3, :)
  call bellman_ford(n, m, edges)
  contains
  subroutine bellman_ford(n, m, edges)
    ! ベルマンフォードの変形
    ! https://ja.wikipedia.org/wiki/ベルマン–フォード法#アルゴリズム
    integer(8), intent(in) :: n, m, edges(3, m)
    integer(8) :: dist(n), predecessor(n), i, j, u, v, w, ptr
    logical :: used(n)

    ! Step1 グラフの初期化
    dist = 2 * 10_8 ** 18
    dist(1) = 0
    predecessor = -1

    ! Step2 辺の緩和を反復
    do i = 1, n - 1
      do j = 1, m
        u = edges(1, j)
        v = edges(2, j)
        w = edges(3, j)
        if (dist(v) > dist(u) + w) then
          dist(v) = dist(u) + w
          predecessor(v) = u
        end if
      end do
    end do

    used = .false.
    ptr = n
    do while (1 <= ptr)
      if (used(ptr)) exit
      used(ptr) = .true.
      ptr = predecessor(ptr)
    end do

    ! Step3 負の重みの閉路がないかチェック
    do j = 1, m
      u = edges(1, j)
      v = edges(2, j)
      w = edges(3, j)
      if (dist(u) + w < dist(v)) then
        if (used(u) .or. used(v)) then
          print "(a)", "inf"
          return
        end if
      end if
    end do
    print "(i0)", -1 * dist(n)
  end subroutine bellman_ford
end program main


Measured memory_bytes: 256
module DLinkedList = struct
  type 'a element =
    { value : 'a;
      mutable next : int;
      mutable prev : int
    }
  type 'a t = {
    mutable first : int;
    mutable last  : int;
    mutable index : int;
    elts : 'a element array
  }

  let create n = {first = -1; last = -1; index = 0;
                  elts = Array.make n {value=0;next=0;prev=0}}
  let is_empty t = t.first = -1

  let insert_first t value =
    let new_elt = {prev = -1; next = t.first; value} in
    let i = t.index in
    begin match t.first with
      | -1 -> ()
      |  old_first -> t.elts.(old_first).prev <- i
    end;
    t.first <- i; t.elts.(i) <- new_elt; t.index <- i + 1;
    begin match t.last with
      | -1 -> t.last <- t.first
      | _ -> ()
    end

  let remove t elt =
    let {prev; next; _} = elt in
    begin match prev with
      | -1 -> t.first <- next
      | pi -> t.elts.(pi).next <- next
    end;
    begin match next with
      | -1 -> t.last <- prev
      | ni -> t.elts.(ni).prev <- prev
    end
      
  let find t v =
    let rec loop = function
      | -1 -> ()
      |  i ->
        let elt = t.elts.(i) in
        if v = elt.value then remove t elt
        else loop elt.next
    in
    loop t.first

  let remove_first t =
    begin match t.first with
      | -1 -> ()
      |  i ->
        let first = t.elts.(i) in
        begin match first.next with
          | -1 -> t.first <- -1; t.last <- -1
          | j -> t.elts.(j).prev <- -1; t.first <- j
        end
    end

  let remove_last t =
    begin match t.last with
      | -1 -> ()
      | i ->
        let last = t.elts.(i) in
        begin match last.prev with
          | -1 -> t.first <- -1; t.last <- -1
          |  j -> t.elts.(j).next <- -1; t.last <- j
        end
    end

  let print t =
    let rec loop e = match e.next with
      | -1 -> Printf.printf "%d\n" e.value
      |  i -> Printf.printf "%d " e.value; loop t.elts.(i)
    in
    loop t.elts.(t.first)
end

let () =
  let open DLinkedList in
  let (n: int) = read_int () in
  let (dll: int t) = create n in
  for i=1 to n do
    begin match read_line () with
      | "deleteFirst" -> remove_first dll
      | "deleteLast" -> remove_last dll
      | s ->
        begin match String.sub s 0 6,
                    (String.sub s 7 (String.length s - 7)
                     |> int_of_string) with
        | "insert", n -> insert_first dll n
        | "delete", n -> find dll n
        | _ -> ()
        end
    end
  done;
  print dll

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, x, y = 0;
    cin >> n;

    x = n * 800;

    if (n > 15)
        y = (n / 15) * 200;

    cout << x - y << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define bug cout<<"--------------"<<endl
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
const double eps=1e-6;
const int inf=1e9;
const ll mod=1e9+7;
const int maxn=1e5+10;
int n,k;
char s[15];
int main(){
    ios::sync_with_stdio(false);
    //cout<<(1ll<<62)<<endl;
    cin>>n>>s+1>>k;
    char c=s[k];
    for(int i=1;i<=n;i++){
        if(s[i]==c) cout<<s[i];
        else cout<<"*";
    }
	return 0;
}


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

int main(){
                int a,b;
                cin >> a >> b;
                if (a<b){
                                cout << "a < b" << endl;
                }else if(a==b){
                                cout << "a == b" << endl;
                }else{
                                cout << "a > b" << endl;
                }
                return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

ll ds(ll N) {
  ll d = 0;
  while(N) {
    d += N % 10;
    N /= 10;
  }
  return d;
}


signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  ll dsum = ds(N);
  fin(N % dsum == 0 ? "Yes" : "No");
}

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

int main() {
    const long long mod = 1000000007;
    int N;
    cin >> N;

    long long ans = 1;
    for(int i = 1; i <= N; i++) {
        ans = (ans*i) % mod;
    }

    cout << ans % mod;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
using namespace std;
typedef pair<int, int>p;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	long long ans = 0;
	for (int i = 0; i <= n / r; i++) {
		for (int j = 0; j <= n/g; j++) {
			int tmp = n - i*r - j*g;
			if (tmp >= 0 && tmp%b == 0)ans += 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<set>
#define ll long long
using namespace std;
int main()
{
    int n,tmp,mm=0,k=0;
    int cnt[100005];
    memset(cnt,0,sizeof(cnt));
    cin>>n;
    while(n--)
    {
        scanf("%d",&tmp);
        cnt[tmp]++;
        cnt[tmp+1]++;
        cnt[tmp+2]++;
        for(int i=0;i<3;i++)
            if(cnt[tmp+i]>k)k=cnt[tmp+i];
    }
    cout<<k<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372085477807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, K;
	cin >> N >> K;
	VI P(N), C(N);
	REP(i, N) {
		cin >> P[i];
		P[i]--;
	}
	REP(i, N)cin >> C[i];


	VI cnt(N, -1), po(N);
	REP(i, N) {
		if (cnt[i] != -1)continue;
		int now = i, to;
		int res = 0;
		VI tmp;
		tmp.push_back(i);
		//res += C[i];
		while (to != i) {
			//cout << now << " " << to << endl;

			to = P[now];
			res += C[to];
			now = to;
			tmp.push_back(to);
		}
		fore(j, tmp) {
			cnt[j] = tmp.size() - 1;
			po[j] = res;
		}
	}


	int ans = -LLINF;
	REP(i, N) {
		int tmp = 0;
		int k;
		if (po[i] > 0) {
			if (K%cnt[i]) {
				tmp += (K / cnt[i]) * po[i];
				k = K % cnt[i];
			}
			else {
				tmp += ((K / cnt[i]) - 1) * po[i];
				k = K % cnt[i] + K;
			}
		}
		else k = K;

		int ttmp = -LLINF;
		int now = 0;
		int to = i;
		if (k == 0)ttmp = 0;
		while (k--) {
			//cout << to << endl;
			now += C[to];
			to = P[to];

			chmax(ttmp, now);
			if (to == i)break;
		}


		chmax(ans, tmp + ttmp);
	}

	cout << ans << endl;




	return 0;
}



Measured memory_bytes: 3856
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(ll i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = 1e17;
const ll NEGA=-INF; 

string W[200];
int main() 
{ 
int n;
cin>>n;
for(int i=0;i<n;i++) cin>>W[i];
for(int i=0;i<n;i++) for(int j=i+1;j<n;j++){
    if(W[i]==W[j]){
        cout<<"No"<<endl;
        return 0;
    }
}

for(int i=1;i<n;++i){
    if(W[i-1][W[i-1].length()-1]!=W[i][0]){
        cout<<"No"<<endl;
        return 0;
    }
}

cout<<"Yes"<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int d, n,ans=1;
	cin >> d >> n;
	if (n == 100) cout << (n+1) * (int)pow(100.0, (double)d);
	else cout << n * (int)pow(100.0, (double)d);
	return(0);
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

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

int main() {
    ll k; cin >> k;
    ll ans = 0;
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= k; j++) {
            for (int l = 1; l <= k; l++) {
                ans += GCD(i,GCD(j,l));
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include "iostream"
#include "cmath"
using namespace std;

const long double pi = 2 * acos(0);

int main() {
  long double a, b, h, m, theta, csq, c;
  cin >> a >> b >> h >> m;
  theta = fabs(11/2.0 * m - 30.0 * h);
  csq = a * a + b * b - 2 * a * b * cos(theta * pi / 180);
  c = sqrt(csq);
  cout.precision(15);
  cout << fixed << c << '\n';
}


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

const int N = 200000;

int n, m, k;
bool ok, visited[N];
long long mi, ma, delta[N];
std::vector<std::pair<int, int>> graph[N];

void dfs(int u) {
  visited[u] = true;
  if (u < n) {
    mi = std::max(mi, -delta[u]);
  } else {
    ma = std::min(ma, delta[u]);
  }
  for (auto &&iterator : graph[u]) {
    int v = iterator.first;
    int w = iterator.second;
    if (visited[v]) {
      ok &= delta[u] + delta[v] == w;
    } else {
      delta[v] = w - delta[u];
      dfs(v);
    }
  }
}

int main() {
  while (scanf("%d%d%d", &n, &m, &k) == 3) {
    for (int i = 0; i < n + m; ++i) {
      graph[i].clear();
    }
    for (int i = 0, a, b, c; i < k; ++i) {
      scanf("%d%d%d", &a, &b, &c);
      a--, b--;
      graph[a].emplace_back(n + b, c);
      graph[n + b].emplace_back(a, c);
    }
    ok = true;
    memset(visited, 0, sizeof(*visited) * (n + m));
    for (int i = 0; i < n; ++i) {
      if (!visited[i]) {
        mi = std::numeric_limits<long long>::min(),
        ma = std::numeric_limits<long long>::max(), delta[i] = 0;
        dfs(i);
        ok &= mi <= ma;
      }
    }
    puts(ok ? "Yes" : "No");
  }
}


Measured memory_bytes: 12928