akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read(){
	int x=0,f=1;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0',ch=getchar();}while(ch>='0'&&ch<='9');
	return x*f;
}
const int N=1010,M=5010,INF=0x3f3f3f3f;
struct node{
	int v,nxt;
}edge[N];
int lst[N],le;
inline void add(int u,int v){
	edge[++le].v=v,edge[le].nxt=lst[u],lst[u]=le;
}
int dp[N],a[N],g[2][M],tans;
void dfs(int u){
	for (int i=lst[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		dfs(v);
	}
	for (int i=0;i<=a[u];++i) g[0][i]=g[1][i]=INF;
	int now=0;g[now][0]=0;
	for (int i=lst[u];i;i=edge[i].nxt){
		int v=edge[i].v;
		now^=1;
		for (int j=0;j<=a[u];++j) g[now][j]=INF;
		for (int j=min(a[v],dp[v]);j<=a[u];++j){
			if (j>=a[v]) g[now][j]=min(g[now][j],g[now^1][j-a[v]]+dp[v]);
			if (j>=dp[v]) g[now][j]=min(g[now][j],g[now^1][j-dp[v]]+a[v]);
		}
	}
	dp[u]=INF;
	for (int i=0;i<=a[u];++i) dp[u]=min(dp[u],g[now][i]);
	if (dp[u]==INF) tans=1;
}
int main(){
	int n=read();
	for (int i=2;i<=n;++i){
		int f=read();
		add(f,i);
	}
	for (int i=1;i<=n;++i) a[i]=read();
	dfs(1);
	puts(tans?"IMPOSSIBLE":"POSSIBLE");
	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
class Edge
  attr_accessor:to,:from
  def initialize(from,to)
      @to=to
      @from=from
  end
end
$ans=0
def bfs(g)
  color=array(N,-1)
  ret=Array.new(N){Hash.new}
  que=[0]
  until que==[]
    p=que.shift
    c=1
    g[p].each do|e|
        next unless color[e.to]==-1
        c+=1 if color[p]==c
        color[e.to]=c
        ret[e.from][e.to]=c
        #ret[e.to][e.from]=c
        $ans=max($ans,c)
        c+=1
        que.push(e.to)
    end
  end
  return ret
end
g=Array.new(N){[]}
ab=array(N-1)
(N-1).times do|i|
  ab[i]=get_i.map{|x| x-=1}
  g[ab[i][0]].push(Edge.new(ab[i][0],ab[i][1]))
  #g[ab[i][1]].push(Edge.new(ab[i][1],ab[i][0]))
end
color=bfs(g)
puts $ans
#p color
ab.each do|a,b|
    puts color[a][b]
end

Measured memory_bytes: 59364
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, K := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	var C [41]int
	for bit := 0; bit < 41; bit++ {
		count := 0
		d := 1 << uint(bit)
		for i := 0; i < N; i++ {
			if A[i]&d > 0 {
				count++
			}
		}
		C[bit] = count
	}
	var dp [42][2]int
	for i := 0; i < 41; i++ {
		ii := 40 - i
		nd := 1 << uint(ii)
		if K < nd {
			dp[i+1][0] = dp[i][0] + nd*C[ii]
			continue
		}
		if nd&K > 0 {
			// 未確定->確定
			dp[i+1][1] = dp[i][0] + nd*C[ii]
			dp[i+1][0] = dp[i][0] + nd*(N-C[ii])
		} else {
			dp[i+1][0] = dp[i][0] + nd*C[ii]
		}
		if dp[i][1] > 0 {
			dp[i+1][1] = max(dp[i+1][1], dp[i][1]+nd*max(C[ii], N-C[ii]))
		}
	}

	fmt.Fprintln(wtr, max(dp[41][0], dp[41][1]))
}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion


int main()
{
    int n, tmp;
    cin >> n;
    printf("%d:", tmp=n);
    for(int i=2; i*i<n; ++i) {
        while(!(tmp%i)) {
            tmp /= i;
            printf(" %d", i);
        }
    }
    if(tmp!=1) printf(" %d",tmp);
    printf("\n");
    return 0;
}

Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        long a = stdIn.nextLong();
        long b = stdIn.nextLong();
        long c = stdIn.nextLong();
        long k = stdIn.nextLong();

        if(k <= a){
            System.out.println(k);
        }else if(k <= a + b){
            System.out.println(a);
        }else{
            System.out.println(a - (k - a - b));
        }
    }
}

Measured memory_bytes: 35748
N = int(input())
al = [chr(ord('a') + i) for i in range(26)]
out = dict(zip(al,[100]*26))
for i in range(N):
    S = list(input())
    tmp = dict(zip(al,[0]*26))
    for T in S:
        tmp[T] += 1
    for key in out.keys():
        out[key]=min(out[key],tmp[key])
outS = ""
for key in out.keys():
    outS += key*out[key]
print(outS)


Measured memory_bytes: 66200
#include <stdio.h>

int main(void) {
    int a, b, c, d, e, f;
    float x, y;
    while (scanf("%d", &a) != EOF) {
        scanf("%d", &b);
        scanf("%d", &c);
        scanf("%d", &d);
        scanf("%d", &e);
        scanf("%d", &f);

        x = (c * e - b * f) * 10000 / (a * e - d * b);                          
        y = (c * d - a * f) * 10000 / (b * d - a * e);                          
        printf("%.3f %.3f\n", x / 10000, y / 10000);                            
    }
    return 0;
}

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

all_sum = 0
for i in a:
    all_sum += i

ans = 0
for i in a:
    all_sum = all_sum - i
    ans = (ans + i * all_sum) % (pow(10, 9) + 7)
print(ans)

Measured memory_bytes: 31560
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(x);
  print(x < 1200 ? "ABC" : "ARC");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll; 
using namespace std;
ll n,m;
ll w[105],v[105];
ll dp[105][100005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			dp[i][j]=0;
		}
	}
	dp[0][0]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=m;j++){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+w[i+1]<=m)dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]],dp[i][j]+v[i+1]);
		}
	}
	ll ans=0;
	for(int i=0;i<=m;i++)ans=max(ans,dp[n][i]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 82460
#include<bits/stdc++.h>
using namespace std;
long long int way[1001][1001];
int main(){
int H,W;
  cin>>H>>W;
  char a[H][W];
  for(int i=0;i<H;i++)
    for(int j=0;j<W;j++)
      cin>>a[i][j];
  for(int i=1;i<=H;i++)
  {  
    if(a[i-1][0]=='#')
      break;
    way[i][1]=1;}
   for(int i=1;i<=W;i++)
  {  
    if(a[0][i-1]=='#')
      break;
    way[1][i]=1;}
  for(int i=2;i<=H;i++)
  {
		for(int j=2;j<=W;j++)
        {
            if(a[i-1][j-1]=='.')
			way[i][j]=(way[i-1][j]%1000000007+way[i][j-1]%1000000007)%1000000007;
        }
  }
  
  
  long long int ans=way[H][W]%1000000007;
  cout<<ans;
  return 0;
}
    
  
  


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  cout << max({A,B,C}) - min({A,B,C}) << endl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
int main(){
	fast;
	ll n;
	cin >> n;
	ll k;
	cin >> k;
	ll h[n];
	for(int i=0; i<n; i++){
		cin>>h[i];
	}
	vector<ll>dp(n, INF);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for(int i=2; i<n; i++){
		for(int j=1; j<=k && i-j >= 0; j++){
			dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
		}
	}	
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
import sys
A, B, C = map(int, input().split())

flag = [0] * (B+1)
i = 0

while True:
    i = (i + A) % B
    if i == C:
        break
    if flag[i] == 0:
        flag[i] = 1
    else:
        print('NO')
        sys.exit()

print('YES')

Measured memory_bytes: 3060
#include <iostream> 
#include <string> 
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ll long long

int main(){
    int s, w;
    cin >> s >> w;
    if (s > w) cout << "safe" << endl;
    else cout << "unsafe" << endl;
}



Measured memory_bytes: 3640
N, A, B, C=map(int, input().split())
l=[int(input()) for i in range(N)]

def ten2four(x, n):
  output=str()
  for i in range(n-1, 0, -1):
    output+=str(x//(4**i))
    x=x%(4**i)
    
  output+=str(x)
  return output

p=4**N
minmp=abs(A-l[0])+abs(B-l[1])+abs(C-l[2])
for i in range(p):
  tempa=0
  tempb=0
  tempc=0
  tempmp=0
  
  pat=ten2four(i, N)
  
  x=sum([pat[j]=='1' for j in range(N)])
  y=sum([pat[j]=='2' for j in range(N)])
  z=sum([pat[j]=='3' for j in range(N)])
  
  if x>0 and y>0 and z>0:
    for j in range(N):
      if pat[j]=='1':
        tempa+=l[j]
      elif pat[j]=='2':
        tempb+=l[j]
      elif pat[j]=='3':
        tempc+=l[j]
      else:
        pass
      
    tempmp=10*(x+y+z-3)+abs(A-tempa)+abs(B-tempb)+abs(C-tempc)

    if minmp>tempmp:
      minmp=tempmp
            
print(minmp)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    //   #ifndef ONLINE_JUDGE
    //        freopen("input.txt", "r", stdin);
    //        freopen("output.txt", "w", stdout);
    //    #endif
    int n,cap;
    cin>>n>>cap;
    int w[n+1],v[n+1];
    int i;
    for(i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    vector<vector<ll>> dp(n+1,vector<ll>(cap+1,0));
    int j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=cap;j++)
        {
            if(w[i]>j)
            dp[i][j]=dp[i-1][j];
            else 
            {
                dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
            }
        }
    }
    cout<<dp[n][cap]<<"\n";
}

Measured memory_bytes: 80256
#include<iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
   intmax_t x,y,sum;
   cin >> x >> y;
   if(x == 1 || y==1){
       cout << 1 << endl;
       return 0;
   }
   if(x*y % 2 != 0 ){
        cout << (x*y)/2 + 1 <<endl;
   }else{
         cout << (x*y)/2 <<endl;
   }
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){

  int m,h;
  string a,al,ar;
  
  while(1){

    cin >>a;
    
    if(a == "-")break;

    cin >>m;

    for(int i=0 ; i < m ; i++){
      cin >>h;
      al=a.substr(0,h);
      ar=a.substr(h);
      a=ar+al;
    }

    cout<<a<<endl;

  }

  return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if (a >= 1 && a <= 9 && b >= 1 && b <= 9){
    cout << a * b << '\n';
  }
  else{
    cout << "-1\n";
  }
  
  return 0; 
}

Measured memory_bytes: 256
S = [i for i in input()]
K = int(input())
ans = 0
s = S*2
for i in range(1,len(s)):
    if s[i-1] == s[i]:
        s[i] = "_"
        if i >= len(s)//2:
            ans += K-1
        else:
            ans += 1
kazu = set(S)
if len(kazu) == 1 and len(S) % 2 != 0:
  ans = len(S) * (K//2) + (K%2==1) * (len(S)//2)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  string prev = "";
  string tmp = "";
  int ans = 0;
  rep(i, N) {
    tmp += S[i];
    if(prev != tmp) {
      ans++;
      prev = tmp;
      tmp = "";
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define mpi map<int,int>
#define N 200005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define str stringstream
using namespace std;
int main() {
	ll n,a,Min=1e17;
	cin>>n;
	rep(i,0,5){
		cin>>a;
		Min=min(a,Min);
	}
	cout<<(n-1)/Min+4+1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<int>());
  if(t<=s){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define int long long int
#define MP make_pair
#define PB push_back
#define F first
#define S second
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, a[100010];
map<int, int> mp;
int kuwareru;
signed main()
{
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> a[i];

  for(int i = 0; i < n; i++){
    mp[a[i]]++;
  }
  
  if((n - mp.size()) % 2){
    kuwareru = n - mp.size() + 1;
  }
  else{
    kuwareru = n - mp.size();
  }
  
  cout << n - kuwareru << endl;
  return 0;
}


Measured memory_bytes: 7296
def minCandies(boxes,limit):
    out = 0
    for i in range(len(boxes) - 1):
        total = boxes[i] + boxes[i + 1]
        if total > limit:
            out += total - limit
            boxes[i + 1] = boxes[i + 1] - (total - limit)
            if boxes[i + 1] < 0:
                boxes[i + 1] = 0
    return out

num_of_boxes, limit = map(int,input().split())
boxes = list(map(int,input().split()))

if limit == 0:
    print(sum(boxes))
elif max([a + b for (a,b) in zip(boxes[:-1],boxes[1:])]) <= limit:
    print(0)
else:
    print(minCandies(boxes,limit))


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

a = [1]
p = [1]

for i in range(N):
  a.append(a[i]*2 + 3)
  p.append(p[i]*2 + 1)
  
def f(n, x):
  if n == 0:
    if x < 1:
      return 0
    else:
      return 1
  elif x <= a[n-1] + 1:
    return f(n-1, x-1)
  else:
    return p[n-1]+1+f(n-1, x-2-a[n-1])
  
print(f(N, X))

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = (1e9);

int main() {

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

  int cnt = 1;
  for(int i=0; i<n; i++){
    if( a[i] % 2 == 1 ){
      cnt *= 1;
    }else{
      cnt *= 2;
    }
  }
  cout << pow(3, n) - cnt << endl;

  return 0;
}


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

const long long m=1e9+7;

long long calc(long long k){
    if(k==1)return 1;
    return k%m*calc(k-1)%m;
}

int main(){
    long long N,M;
    cin>>N>>M;
    if(abs(N-M)>1){cout<<0<<endl;return 0;};
    long long ans=calc(N)*calc(M)%m;
    if(N==M)ans=2*ans%m;
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
bitset<20000> dpx;bitset<20000> dpy;
signed main(){
    string s;cin>>s;
    int x,y;cin>>x>>y;
    vector<int> dx,dy;
    int t=1;
    int cnt=0;
    rep(i,0,s.size()){
        if(s[i]=='F')cnt++;
        else {
            if(t)dx.push_back(cnt);
            else dy.push_back(cnt);
            cnt=0;
            t=t*-1+1;
        }
    }
    if(t)dx.push_back(cnt);
    else dy.push_back(cnt);
    dpx.set(10000+dx[0]);
    if(dx.size()>1)
    rep(i,1,dx.size()){
        dpx=(dpx<<dx[i])|(dpx>>dx[i]);
    }
    dpy.set(10000);
    if(dy.size())
    rep(i,0,dy.size()){
        dpy=(dpy<<dy[i])|(dpy>>dy[i]);
    }
    if(dpx[10000+x]&&dpy[10000+y])cout<<"Yes"<<endl;
    //else if(dpx[10000+x])cout<<"X"<<endl;
    //else if(dpy[10000+y])cout<<"Y"<<endl;
    else cout<<"No"<<endl;return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

template <class T>
struct fenwick {
    vector<T> node;
    int n;

    fenwick(int _n)
        : n(_n) {
        node.resize(n);
    }

    void add(int x, T v) {
        while (x < n) {
            node[x] += v;
            x |= (x + 1);
        }
    }

    T get(int x) {
        T v = 0;
        while (x >= 0) {
            v += node[x];
            x = (x & (x + 1)) - 1;
        }
        return v;
    }

    T get(int a, int b) {
        return get(b) - get(a - 1);
    }
};

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

    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), s(n + 1);
    rep(i, 0, n) {
        cin >> a[i];
        a[i] -= k;
        s[i + 1] = s[i] + a[i];
    }
    vector<ll> e = s;
    sort(e.begin(), e.end());
    e.erase(unique(e.begin(), e.end()), e.end());
    rep(i, 0, n + 1) {
        s[i] = lower_bound(e.begin(), e.end(), s[i]) - e.begin();
    }
    fenwick<ll> st(n + 5);
    ll ans = 0;
    rep(i, 0, n + 1) {
        ans += st.get(s[i]);
        st.add(s[i], 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6528
fun main(arr: Array<String>) {
    val x = readLine()!!.toInt()
    println(if(isValid(x)) 1 else 0)
}


fun isValid(num:Int):Boolean {
    val tmp = num % 100
    val c100 = num/100

    var div = tmp / 5
    if(tmp%5 != 0) {
        div++
    }
    return c100 >= div
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll N;
  cin >> N;

  ll ans = 0;

  FOR(i,1,N+1){
    //DEBUG(i);
    ll n = i;
    ll b = n%10;
    while(n>=10) n /=10;
    ll a = n;
    //cout << "a:" << a << "b:" << b << endl;
    if(a==0 || b==0) continue;
    //a
    if(a==b && a<=N) ans++;
    //DEBUG(ans);
    //ba
    if(b*10+a<=N) ans++;
    //DEBUG(ans);
    {
      ll m = N-(b*100+a);
      //b0a
      if(m>=0) {
        ans++;

        m = min(90ll,m);
        //bxa
        ans += m/10;
      }
    }
    //DEBUG(ans);
    {
      ll m = N-(b*1000+a);
      //b00a
      if(m>=0) {
        ans++;

      m = min(990ll,m);
      //bxa
      ans += m/10;
      }
    }
    //DEBUG(ans);
    {
      ll m = N-(b*10000+a);
      //b000a
      if(m>=0){
        ans++;

        m = min(9990ll,m);
        //bxa
        ans += m/10;
      }
    }
    //DEBUG(ans);
    {
      ll m = N-(b*100000+a);
      //b0000a
      if(m>=0){
        ans++;

        m = min(99990ll,m);
        //bxa
        ans += m/10;
      }
    }
    //DEBUG(ans);
  }
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(700000)

def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

n=n_in()
A=l_in()
B=[i-A[i] for i in range(n)]

from collections import Counter
c= Counter(B)

res = 0
for i in range(n):
    res += c[A[i]+i]

print(res)


Measured memory_bytes: 127028
#include <bits/stdc++.h>
 
#define all(v) (v).begin(), (v).end()
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vl;
 
const ll N = 1e4 + 3;
const ll A[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
 
ll n, m, a[N], cnt[N];
vl res[N];
 
bool cmp_vector(vl x, vl y) {
	if (x.size() == y.size()) {
		for (size_t i = 0; i < x.size(); ++i) {
			if (x[i] < y[i]) return true;
			if (x[i] > y[i]) return false;
		}
		return true;
	}
	return x.size() < y.size();
}
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n >> m;
	for (ll i = 1; i <= m; ++i) cin >> a[i];
	
	for (ll i = 1; i <= n; ++i) {
		for (ll j = 1; j <= m; ++j) {
			if ((i - a[j] > 0 && cnt[i - A[a[j]]]) || i == A[a[j]]) {
				if (cnt[i] <= cnt[i - A[a[j]]] + 1) {
					vl tmp = res[i - A[a[j]]];
					tmp.push_back(a[j]);
					sort(all(tmp), greater<ll>());
 
					if (cmp_vector(res[i], tmp)) {
						res[i] = tmp;
						cnt[i] = cnt[i - A[a[j]]] + 1;
					}
				}
			}
		}
	}
	
	for (ll& v: res[n]) cout << v;
	
	return 0;
}


Measured memory_bytes: 235032
H,W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]
B = [list(map(int,input().split())) for i in range(H)]
C = []
for arow,brow in zip(A,B):
    C.append([abs(a-b) for a,b in zip(arow,brow)])

ofs = 80*(H+W)
dp = [0] * W
dp[0] = (1<<(ofs+C[0][0])) | (1<<(ofs-C[0][0]))
for j in range(W-1):
    dp[j+1] = (dp[j] << C[0][j+1]) | (dp[j] >> C[0][j+1])

for i in range(1,H):
    dp2 = [0] * W
    for j in range(W):
        dp2[j] = (dp[j] << C[i][j]) | (dp[j] >> C[i][j])
        if j:
            dp2[j] |= (dp2[j-1] << C[i][j]) | (dp2[j-1] >> C[i][j])
    dp = dp2

ans = ofs*2
for i in range(ofs*2):
    if dp[-1] & (1<<i):
        ans = min(ans, abs(ofs - i))
print(ans)

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

int main(){
  int n,negative = 0;
  cin >> n;
  long a[n],result = 0,x = 1000000000000000;
  for(int i = 0;i < n;i++){
    cin >> a[i];
    result += abs(a[i]);
    x = min(x,abs(a[i]));
    if(a[i] <= 0){
      negative++;
    }
  }
  if(negative % 2 == 1){
    result -= 2*x;
  }
  cout << result << endl;
}

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

using namespace std;

typedef unsigned long long ull;
ull A;
string B;

int main(){
    cin >> A >> B;
    string B_ = B.substr(0, B.size()-3) + B.substr(B.size()-2, 2);
    // cout << B_ << endl;
    ull ans = A * stoi(B_);
    // cout << ans << endl;
    cout << ans/100 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <stack>

using namespace std;
int main(int argc, const char * argv[]) {
    
    string s;
    cin >> s;

    if (s[0] != 'A') {
        cout << "WA" << endl;
        return 0;
    }

    int c=0;
    for (int i=2; i<s.size()-1; i++) {
        if (s[i]=='C') c++;
    }

    if (c!=1) {
        cout << "WA" << endl;
        return 0;
    }

    for (int i=0; i<s.size(); i++) {
        if (s[i]=='C' || s[i] == 'A') continue;

        if (!islower(s[i])) {
            cout << "WA" << endl;
            return 0;
        }
    }
   
    cout << "AC" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if(a+b<=16&&a<=8&&b<=8)
		cout<<"Yay!";
	else
		cout<<":(";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define ff          first
#define ss          second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    string s,t;
    int ans = 0;
    cin >> s >> t;
    for(int i = 0; i <(int)s.size(); i++){
        if(s[i]!=t[i])
        ans++;
    }
    cout << ans;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3800
# -*- coding: utf-8 -*-
moji=[]
moji.append("eraser")
moji.append("erase")
moji.append("dreamer")
moji.append("dream")
user = "erasedream"
user = int(input())
result = user
count = 1

while result != 0:
    result += user
    result %= 360
    count += 1
print(count,end="")


Measured memory_bytes: 9088
def AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p):
    # print(SwitchPattern)
    Light=0
    for m in range(M):
        OnSwitch=0
        for l in range(LineVolume[m]):
            a=Destinations[m][l]-1
            if SwitchPattern[a]==1:
                OnSwitch += 1
            else:
                pass
        if OnSwitch%2==p[m]:
            Light+=1
    # print (Light)
    if Light==M:
        return True


N,M=map(int,input().split())
K=[]
for _a in range (M):
    arr=list(map(int,input().split()))
    K.append(arr)
LineVolume=[] #m番目の電球がスイッチとつながっている線の数
Destinations=[] #m番目の電球がつながっているスイッチの番号(1スタート)
for _b in range (M):
    LineVolume.append(K[_b][0])
    Destinations.append(K[_b][1:])
p=list(map(int,input().split()))
# print (LineVolume)
# print (Destinations)
# print(p)

LightOnPattern=0

for Pattern in range (2**N):
    SwitchPattern=[]
    for ONOFF in range(N):
        if(Pattern>>ONOFF)&1==1:
            SwitchPattern.append(1)
        else:
            SwitchPattern.append(0)
    # print(SwitchPattern)
    if AreAllTheLightsOn(SwitchPattern,M,LineVolume,Destinations,p)==True:
        LightOnPattern += 1

print(LightOnPattern)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define len(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>

signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  int res = 0;
  repz(i,1, n + 1) {
    int a;
    cin >> a;
    if (i % 2 == 1 and a % 2 == 1) res++;
  }
  cout << res << endl;
  ret;
}


Measured memory_bytes: 3620
# ALDS1_2_D
n = int(input())
A = [int(input()) for _ in range(n)]


def insertionSort(A, n, g):
    global cnt
    for i in range(g, n, 1):
        v = A[i]
        j = i - g
        while (j >= 0) & (A[j] > v):
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v


def trace(A):
    for i in range(len(A)):
        if i != len(A) - 1:
            print(A[i], end='\n')
        else:
            print(A[i], end='')


G = []
h = 1
G.append(h)
while h < n:
    G.append(h)
    h = 5 * h + 1
m = len(G)
G.reverse()

cnt = 0
for i in G:
    insertionSort(A, n, i)

print(m)
for i in range(len(G)):
    print(G[i], end=' ')
    if i == len(G) - 1:
        print('')
print(cnt)
trace(A)



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

int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
mod = 10**9 + 7
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]

for i in range(2, 10 ** 6 + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)


def comb(n, r, mod):
    if r < 0 or r > n:
        return 0
    r = min(r, n - r)
    return g1[n] * g2[r] * g2[n-r] % mod

N, K = map(int, input().split())
R = N - K
for i in range(1, K+1):
  print(comb(K-1, i-1, mod)*comb(R+1, i, mod) % mod)

Measured memory_bytes: 122156
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    //2つを関連付けてソートする例
    class ProgramA
    {
        static void Main(string[] args)
        {
            long x = long.Parse(Console.ReadLine());
            long yen = 100;
            long count = 0;
            

            while(x > yen)
            {
                yen = (long)(yen * 1.01);
                count++;
            }

            Console.WriteLine(count);

        }
    }



}


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

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

  string w;
  cin >> w;
  map<char, int> dic;
  for (auto i : w) {
    dic[i]++;
  }

  rep(i, 26) {
    if (dic['a'+i]%2 == 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}

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

int main() {
  string s;
  cin >> s;
  
  while (true) {
    string a, b;
    s.erase(s.begin() + s.size() - 1);

    if (s.size() % 2 != 0) continue;
    a = s.substr(0, s.size() / 2);
    b = s.substr(s.size() / 2, s.size());
    if (a == b) {
      break;
    }
  }
  printf("%d\n",s.size());

  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,d;
    cin >> n >> d;
    int range = 2 * d + 1;
    int monitor;
    if(n%range==0){
        monitor = n / range;
    } else {
        monitor = n / range + 1;
    }
    cout << monitor << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for (int i = l; i <=r; i++)
    {
        if(i%d==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int n;
	cin >> n;
	int h[n], dp[n];
	for(int i=0; i<n; ++i) {
		cin >> h[i];
	}
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2; i<n; ++i)
		dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	cout << dp[n-1];
}

Measured memory_bytes: 4344
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		
		System.out.println(Math.max(a+b, Math.max(a-b, a*b)));
		in.close();
	}
}

Measured memory_bytes: 22228
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn solve(a: &[i64]) -> usize {
    let mut min = a[0];
    let mut ms = Vec::new();
    ms.push(0);
    for i in 1..a.len() {
        if a[i] < min {
            min = a[i];
        }
        ms.push(a[i] - min);
    }
    let max = ms.iter().max().unwrap();
    ms.iter().filter(|&elem| elem == max).count()
}


fn main() {
    input! {
    n: usize,
    _t: usize,
    a: [i64; n],
    };

    println!("{}", solve(&a));
}


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

void solve(){
    int n;
    cin >> n;
    int a[n+10];
    rep(i,n){
        cin >> a[i];
    }
    /*
    a[0], a[1], ..., a[n-1]
    a[0], a[1], ..., a[i]までの数の最大値をb[i]とする。要素数はn-1で、b[n-1]が最大。なお、使わない
    a[i], ..., a[n-2], a[n-1]の最大値をc[i]とする。要素数はn-1で、c[n-1]が最大。なお、a[0]は使わない
    */
    int b[n+10];
    int c[n+10];
    b[0]=a[0];
    c[n-1]=a[n-1];
    for(int i=1; i<n; i++){
        b[i]=max(b[i-1], a[i]);
    }
    for(int i=n-2; i>=0; i--){
        c[i]=max(c[i+1], a[i]);
    }
    /*
    c[1], max(b[0], c[2]), max(b[1], c[3]), ..., max(b[n-3], c[n-1]), b[n-2]
    */
    cout << c[1] << endl;
    for(int i=1; i<=n-2; i++){
        cout << max(b[i-1], c[i+1]) << endl;
    }
    cout << b[n-2] << endl;
    
}

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

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

#define ll long long
#define fi first
#define se second
#define mp make_pair

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;

int main(){
	fastio();
	string a,b;cin>>a>>b;
	int ans = 1e9,temp=0;
	for(int i=0;i<a.size()-b.size()+1;i++){
	    for(int j=0;j<b.size();j++){
	        
	        if(a[i+j]!=b[j])temp ++;
	    }
	    ans = min(ans,temp);
	    temp =0 ;
	}
	cout<<ans<<endl;
	
	
	return 0;
}

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

const int MOD = 1e9+7;
const int MAXN = 123;

typedef struct def{
	int a,b,c;

	def(){}
	def(int a2, int b2, int c2){
		a = a2; b = b2; c = c2;
	}
	bool operator < (def comp) const{
		if(a!=comp.a) return a < comp.a;
		else return b < comp.b;
	}
} generico;

typedef pair<int,int> pii;
typedef long long int ll;

#define INF 0x3f3f3f3f
#define pb push_back
#define mp make_pair
#define x first
#define y second

int n, w;
int pes[MAXN];
int val[MAXN];

int main(){
	
	scanf("%d %d",&n,&w);
	
	for(int i = 0 ; i < n ; i ++)
		scanf("%d %d", &pes[i], &val[i]);
	
	ll memo[n+1][w+1];
	
	memset(memo,0,sizeof memo);
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=w;j++){
			if(pes[i] > j) memo[i+1][j] = memo[i][j];
			
			else if(memo[i][j-pes[i]] + val[i] > memo[i][j]){
				memo[i+1][j] = memo[i][j-pes[i]] + val[i];
			}
			else memo[i+1][j] = memo[i][j];
		}
	}
	
	printf("%lld\n",memo[n][w]);
	
	return 0;
}

Measured memory_bytes: 79104
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    if(a<=8&&b<=8){
        cout << "Yay!";
    }
    else{
        cout << ":(";
    }

    return 0;
}

Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    X = int(input())
    A = int(input())
    B = int(input())
    print((X-A)%B)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
n = int(input())
for i in range(0, n):
    a, b, c = sorted(map(int, input().strip("\n").split(" ")))
    # a,b,c = sorted(input().strip("\n").split(" "))
    #print(a, b, c)
    if c*c - (a*a + b*b) == 0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 6720
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

H,W = map(int,S().split())
a = [LI() for _ in range(H)]

ANS = []
for i in range(H):
    for j in range(W):
        if j != W-1:
            if a[i][j] % 2 == 1:
                a[i][j+1] += 1
                ANS.append([i+1,j+1,i+1,j+2])
        else:
            if i != H-1:
                if a[i][j] % 2 == 1:
                    a[i+1][j] += 1
                    ANS.append([i+1,j+1,i+2,j+1])

print(len(ANS))

for i in range(len(ANS)):
    print(*ANS[i])

Measured memory_bytes: 70236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

typedef pair<int, int> P;
typedef unsigned long long ll;

int main()
{
	int n, k, c;
	cin >> n >> k >> c;

	string s;
	cin >> s;

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}

	vector<int> l(k, -1), r(k, -1);

	for (int i = 0, j = 0; j < k;) {
		if (s[i] == 'o') {
			//cout << i << endl;
			l[j++] = i;
			i += c + 1;
		}
		else {
			i++;
		}
	}

	for (int i = n - 1, j = 0; j < k;) {
		if (s[i] == 'o') {
			//cout << i << endl;
			r[j++] = i;
			i -= c + 1;
		}
		else {
			i--;
		}
	}

	for (int j = 0; j < k; j++) {
		if (l[j] == r[k - j - 1]) {
			cout << l[j] + 1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3332
S = input()
prev = ">"
terrain = []
curr = 0
for c in S:
    if c == prev:
        curr += 1
    else:
        prev = c
        terrain.append(curr)
        curr = 1
terrain += [curr]
ans = (terrain[0] * (terrain[0] + 1)) // 2
for up, down in zip(terrain[1::2], terrain[2::2]):
    if up < down:
        up, down = down, up
    down -= 1
    ans += (up * (up + 1)) // 2
    ans += (down * (down + 1)) // 2
if len(terrain) % 2 == 0:
    ans += terrain[-1] * (terrain[-1] + 1) // 2
print(ans)


Measured memory_bytes: 8220
#include<cstdio>
#include<algorithm>
#include<functional>
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
using namespace std;
typedef pair<int,int> P1;
typedef pair<P1,P1> P3;
P3 pp[100000];
int main(void)
{
	int n,m,p,y,i,nn;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)	{
		scanf("%d %d",&pp[i].FF,&pp[i].FS);
		pp[i].SF=i;
	}
	sort(pp,pp+m);
	p=1;
	pp[0].SS=p;
	p++;
	for(i=1;i<m;i++)	{
		if(pp[i].FF==pp[i-1].FF)	{
			pp[i].SS=p;
		}
		else {
			p=1;
			pp[i].SS=p;
		}
		p++;
	}
	for(i=0;i<m;i++)	{
		swap(pp[i].SF,pp[i].FF);
	}
	sort(pp,pp+m);
	for(i=0;i<m;i++)	{
		printf("%06d%06d\n",pp[i].SF,pp[i].SS);
	}
	return 0;
}


Measured memory_bytes: 2944