akhauriyash/Code-Regression huggingface dataset:
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define finish(x) {cout<<x<<'\n'; return;}
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	int n;
	in(n);
	int num = 7, cnt = 1;
	vector<bool> mod(n, false);

	while(true) {
		if(mod[num%n]) finish(-1);
		mod[num%n] = true;
		if(num % n == 0) finish(cnt);
		num = (num * 10 + 7) % n;
		cnt++;
	}
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s;
	int n, i, j, k;
	bool valid = true;
	cin >> n >> s;

	if (n % 2 == 1) valid = false;
	else {
		for (i = 0; i < n / 2; i++) {
			if (s[i] != s[i + n / 2]) valid = false;
		}
	}
	
	if (valid) cout << "Yes\n";
	else cout << "No\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int N; cin >> N;
    int *B = new int[N-1];
    for (int i = 0; i < N-1; i++) cin >> B[i];
    int sum = B[0] + B[N-2];
    for (int i = 1; i < N-1; i++) {
        int tmp = min(B[i-1], B[i]);
        sum += tmp;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[200050],cn[200050],mx,mx2;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),cn[a[i]]++,mx=max(mx,a[i]);
	if(cn[mx]>1)mx2=mx;
	else
	{
		for(int i=1;i<=n;i++)if(a[i]!=mx)mx2=max(mx2,a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]<mx)printf("%d\n",mx);
		else printf("%d\n",mx2);
	}
}

Measured memory_bytes: 3072
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
S = input()
T = S[:len(S)//2]
U = S[len(S)//2+1:]

for i in range (len(S)//2):
  if S[i] != S[-(i+1)]:
    print("No")
    exit()
for i in range (len(T)//2):
  if T[i] != T[-(i+1)]:
    print("No")
    exit()
for i in range (len(U)//2):
  if U[i] != U[-(i+1)]:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 6224
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int X, N; cin>>X>>N;
  map<int,int> V;
  REP(i,N) {
    int p; cin>>p; V[p]++;
  }
  int min_d = 100000, min_v = 0;
  for(int i = -200; i <= 200; i++) {
    if(V[i] == 0) {
      int d = abs(i - X);
      if(d < min_d) {
	min_v = i;
	min_d = d;
      }
    }
    
  }
  cout << min_v << endl;
  return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
 
const int INF = 1145141919;
const long long INFL = 1LL<<60;
 
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
 
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
 
int memo[110000];
int N, M;
vector<int> V[110000];
 
int rec(int x)
{
	if(memo[x] != 0)
	{
		return memo[x];
	}
	int fans = 0;
	for (auto v : V[x])
	{
		fans = max(fans, rec(v) + 1);
	}
	return memo[x] = fans;
}
 
int main()
{
	cin >> N >> M;
	int x, y;
	for (int i = 0; i < M; ++i)
	{
		cin >> x >> y;
		V[x].push_back(y);
	}
	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		ans = max(ans, rec(i));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
N = int(input()) 
W = list(map(int, input().split()))
x = sum(W)
 
for i in range(N):
	S_1 = sum(W[:i+1])
	S_2 = sum(W) - S_1
	x_current = abs(S_2 - S_1)
	if x_current < x:
		x = x_current

print(x)

Measured memory_bytes: 2940
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,length;
char buf[1000001];
bool used[1000001];


bool can_make(int tower_num){

	int tail_I_num = 0,mid_O_num = 0;
	for(int i = 0; i < length; i++)used[i] = false;

	for(int i = length-1; (i >= 0) && (tail_I_num < tower_num || mid_O_num < tower_num); i--){
		if(buf[i] == 'I'){
			if(tail_I_num < tower_num){
				tail_I_num++;
				used[i] = true;
			}
		}else if(buf[i] == 'O'){
			if(mid_O_num < tower_num && mid_O_num < tail_I_num){
				mid_O_num++;
				used[i] = true;
			}
		}
	}

	if(tail_I_num < tower_num || mid_O_num < tower_num)return false;

	int count = 0;
	mid_O_num = 0;

	for(int i = length-1; i >= 0 && count < tower_num; i--){
		if(buf[i] == 'I' || buf[i] == 'J'){
			if(used[i] == false && mid_O_num > 0){
				count++;
				mid_O_num--;
			}
		}else{ //buf[i] == 'O'
			if(used[i]){
				mid_O_num++;
			}
		}
	}

	return count == tower_num;
}


int main(){

	scanf("%d",&N);
	scanf("%s",buf);

	for(length = 0; buf[length] != '\0'; length++);

	int ans = 0;
	int left = 0, right = N,m = (left+right)/2;

	while(left <= right){

		if(can_make(m)){
			ans = m;
			left = m+1;
		}else{
			right = m-1;
		}
		m = (left+right)/2;
	}

	printf("%d\n",ans);

	return 0;
}



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

int main(){
     while(1){
	  int N,R;
	  cin>>N>>R;
	  if(N==0)break;
	  vector<int> cards;
	  for(int i=1;i<N+1;i++){
	       cards.push_back(i);
	  }
	  for(int i=0;i<R;i++){
	       int p,c;
	       cin>>p>>c;
	       vector<int>::iterator pos=cards.begin();
	       pos+=N-c-(p-1);
	       vector<int> temp;
	       temp.assign(cards.begin()+(N-p+1),cards.end());
	       cards.insert(pos,temp.begin(),temp.end());
	       cards.erase((cards.begin()+N),cards.end());
	  }
	  //for(int i=0;i<N;i++){
	  //     cout<<i<<":"<<cards[i]<<endl;
	  //}
	  cout<<cards.back()<<endl;
     }
}

Measured memory_bytes: 0
from collections import deque


def main():

    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for i in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    q = deque()
    score = [0] * N
    seen = [0] * N
    for _ in range(Q):
        a, s = map(int, input().split())
        score[a-1] += s

    q.append(0)
    while q:
        tmp = q.pop()
        seen[tmp] += 1
        for v in G[tmp]:
            if seen[v]:
                continue
            q.append(v)
            score[v] += score[tmp]

    print(*score)


if __name__ == '__main__':
    main()


Measured memory_bytes: 127812
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))


int main() {
    int k, t;
    cin >> k >> t;
    vi a(t);
    rep(i, t) scanf("%d", &a[i]);
    sort(a.begin(), a.end());

    ll r = k - a[t - 1];
    ll ans = max(0LL, a[t - 1] - r - 1);
    cout << ans << "\n";


    return 0;
}

Measured memory_bytes: 256
using System;

class program
{

    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine());

            if (n == 0) break;

            var str = Console.ReadLine().Split(' ');

            double m = 0.0;
            foreach (string s in str)
            {
                m += double.Parse(s);
            }
            m /= (double)str.Length;

            double sum = 0.0;
            foreach (string sm in str)
            {
                sum += Math.Pow(double.Parse(sm)-m,2);
            }
            sum /= (double)str.Length;

            double q = Math.Sqrt(sum);
            Console.WriteLine("{0:f5}", q);

        }
    }
}

Measured memory_bytes: 5888
from collections import defaultdict
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
q = int(input())
c = defaultdict(lambda: 0)
tmp = Counter(a)
for i, j in tmp.most_common():
	c[i] = j
s = sum(a)
for _ in range(q):
	mae, ato = map(int,input().split())
	kazu = c[mae]
	c[ato] += kazu
	c[mae] = 0
	s += (ato-mae)*kazu
	print(s)

Measured memory_bytes: 26420
import static java.lang.System.*;
import java.util.*;

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

        int n = sc.nextInt();
		int[] w = new int[n];
		
		int sum = 0;
		for(int i=0; i<n; i++) {
			w[i] = sc.nextInt();
			sum += w[i];
		}
		
		int ans = Integer.MAX_VALUE;
		int psum = 0;
		for(int i=0; i<n-1; i++) {
			psum += w[i];
			ans = Math.min(ans, Math.abs(psum - (sum - psum)));
		}
			
        out.println(ans);
    }
}


Measured memory_bytes: 21844
n = gets.to_i

A = gets.chomp.split(" ")

cards = {}

for value in A do
    idx = value.to_i
    if cards[idx].nil? || cards[idx] == 2
        cards[idx] = 1
    else
        cards[idx] = 2
    end
end

ans = cards.length

two = cards.select{|k, v| v > 1}.length

if two % 2 != 0
    ans = ans - 1
end

puts ans


Measured memory_bytes: 14348
n,m,k = gets.split(' ').map(&:to_i)
A=gets.split(' ').map(&:to_i)
B=gets.split(' ').map(&:to_i)
Sa=Array.new(n+1).fill(0)
Sb=Array.new(m+1).fill(0)
1.upto(n){|i| Sa[i]=Sa[i-1]+A[i-1] }
1.upto(m){|i| Sb[i]=Sb[i-1]+B[i-1] }
ans=0
0.upto(n) do |i|
  t = Sa[i] # Aのi冊目まで読んだ場合
  next if t > k
  bi=Sb.bsearch_index{|x| x+t>k}
  bi=m+1 if bi.nil?
  ans=[i+bi-1, ans].max
end
puts ans

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

int yvector(int d)
	{
	if(d==1)return -1;
	else if(d==3)return 1;
	else return 0;
	}
	
int xvector(int d)
	{
	if(d==0)return -1;
	else if(d==2)return 1;
	else return 0;
	}

int main()
{
	int N=1;
	while(true)
	{
		cin >> N;
		if(N==0)break;
		int top=0,bottom=0,left=0,right=0;
		int boxx[200],boxy[200];
		boxx[0]=0;boxy[0]=0;
		for(int i=1;i<=N-1;i++)
		{
			int n,d;
			cin >> n; cin >> d;
			boxx[i]=boxx[n]+xvector(d);
			boxy[i]=boxy[n]+yvector(d);
			if(boxx[i]<left)left = boxx[i];
			if(boxx[i]>right)right = boxx[i];
			if(boxy[i]>top)top=boxy[i];
			if(boxy[i]<bottom)bottom=boxy[i];
		}
		cout << right - left +1 << " " << top - bottom +1 << endl;
	
	
	}
	return 0;

}


	

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var inputs = readLine()!!.split(" ").map { it.toInt() }.toMutableList()

    // 0 を挟んでいれば b の値をいくつにしても結果は変わらない
    // 0 を挟めなくなるほど b の値の影響は大きくなる？
    // -> 0 を挟むケースが一番多くなる b を選択する？
    // 0 以上と0未満の数が等しくなるように b を設定する
    // -> 平均ではなく中央値の方針 が正しい （確かに実現したいことは中央値か）


    // 値を修正
    for (i in 0 until n) {
        inputs[i] = inputs[i] - (i + 1)
    }

    // 値を sort
    inputs.sort()

    // 中央値を取得 (無い場合はどちらか）

    val b = inputs[inputs.size/2]

//
//    // 平均値をもとめて，その平均値から一番近い修正後の値を b とする
//    // WA: ０より上 or 下どちらが多いか数え上げ，多い方で一番近い値に寄せる？
//    val mean = inputs.average()
//
//    var cnt = 0
//    for (i in 0 until n) {
//        if (inputs[i] - mean > 0) {
//            cnt += 1
//        }
//    }
//
//    val toPlus = cnt >= n.toDouble() / 2
//
//    var min = Double.MAX_VALUE
//    var index = 0
//    for (i in 0 until n) {
//        if (toPlus) {
//            if (inputs[i] - mean > 0) {
//                val now = Math.abs(inputs[i] - mean)
//                if (now < min) {
//                    min = now
//                    index = i
//                }
//            }
//        } else {
//            if (inputs[i] - mean <= 0) {
//                val now = Math.abs(inputs[i] - mean)
//                if (now < min) {
//                    min = now
//                    index = i
//                }
//            }
//        }
//    }
//
//    val b = inputs[index]
//
    var ans = 0L
    for (i in 0 until n) {
        ans += Math.abs(inputs[i] - b)
    }

    println(ans)
}

Measured memory_bytes: 80588
#include<bits/stdc++.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopb(i,a,b) for(int i=a;i>=b;i--)
#define loopm(i,a,b,step) for(int i=a;i<b;i+=step)
#define loopbm(i,a,b,step) for(int i=a;i>=b;i-=step)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define INF 1000000007
#define MOD 1000000007
#define BINF 1000000000000000001
#define int long long int
#define double long double

using namespace std;


#undef int
int main()
{
#define int long long int
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
  //  freopen("input.txt","r",stdin);
 int n;
 cin>>n;
 int a[n];
 loop(i,0,n) cin>>a[i];
 
 int cnt=0;
 
 loop(i,0,n)
 {
 	while(a[i]%2==0)
 	{
 		cnt++;
 		a[i]/=2;
 	}
 }
 
 cout<<cnt;
 
    return 0;
}

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

int main()
{
  int r, D;
  long long int X;
  //Xが計算のたびに変化していく
  cin >> r >> D >> X;
  
  for(int i=0; i<10; i++)
  {
    cout << r*X-D << endl;
    X = r * X - D;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,k;
int pw[4010];
const int md=1e9+7;
int qmul(int x,int p)
{
	if(p<=0)return 1;
	if(p==1)return x;
	int res=qmul(x,p>>1);
	res=1LL*res*res%md;
	if(p&1)res=1LL*res*x%md;
	return res;
}
int C(int x,int y)
{
	if(x<y || x<0 || y<0)return 0;
	return 1LL*pw[x]*qmul(pw[x-y],md-2)%md*qmul(pw[y],md-2)%md;
}
int main()
{
	scanf("%d%d",&n,&k);
	pw[0]=1;
	for(int i=1;i<=4000;i++)pw[i]=1LL*pw[i-1]*i%md;
	printf("%d",1LL*(C(n+k-2,n-1)+md-C(n+k-2,n))*qmul(2,n-k-1)%md);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int num = in.nextInt();
		for(int i = 0;i < num;i++){
			int c = in.nextInt();
			int a = in.nextInt();
			int n = in.nextInt();
			int cnt = 0;
			while(true){
				if(c > 0 && a > 0 && n > 0){
					c--;a--;n--;cnt++;
				}else if(c > 1 && a > 0){
					c-=2;a--;cnt++;
				}else if(c > 2){
					c-=3;cnt++;
				}else break;
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 20652
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005,mod=998244353;
int n,q,p[N],tr[N<<2],s[N<<2],tag[N<<2];
void build(int k,int l,int r)
{
	if(l==r)
	{
		s[k]=p[l];
		tr[k]=p[l];
		return;
	}
	int mid=l+r>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	s[k]=(s[k<<1]+s[k<<1|1])%mod;
	tr[k]=(tr[k<<1]+tr[k<<1|1])%mod;
}
void pushdown(int k)
{
	if(tag[k])
	{
		tag[k<<1]=tag[k];
		tr[k<<1]=tag[k]*s[k<<1]%mod;
		tag[k<<1|1]=tag[k];
		tr[k<<1|1]=tag[k]*s[k<<1|1]%mod;
		tag[k]=0;
	}
}
void update(int k,int l,int r,int a,int b,int v)
{
	if(l==a&&r==b)
	{
		tr[k]=s[k]*v%mod;
		tag[k]=v;
		return;
	}
	pushdown(k);
	int mid=l+r>>1;
	if(b<=mid) update(k<<1,l,mid,a,b,v);
	else if(a>mid) update(k<<1|1,mid+1,r,a,b,v);
	else update(k<<1,l,mid,a,mid,v),update(k<<1|1,mid+1,r,mid+1,b,v);
	tr[k]=(tr[k<<1]+tr[k<<1|1])%mod;
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	p[n]=1;
	for(int i=n-1;i>=1;i--)
		p[i]=p[i+1]*10%mod;
	build(1,1,n);	
	while(q--)
	{
		int l,r,v;
		cin>>l>>r>>v;
		update(1,1,n,l,r,v);
		cout<<tr[1]<<endl;
	}
	return 0;
}


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

int main(){
  ll a,b;
  cin >>a >>b;
  for(int i = 1; i<=b; i++){
    if((a*i)%b == 0){
      cout << a*i << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class DGridColoring {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt(), w = in.nextInt();
            int n = in.nextInt();

            int[][] grid = new int[h][w];
            int dir = 1;
            int row = 0, col = 0;
            for (int color = 1; color <= n; color++) {
                int a = in.nextInt();
                for (int i = 0; i < a; i++) {
                    grid[row][col] = color;
                    col += dir;
                    if (col >= w) {
                        dir = -1;
                        row++;
                        col--;
                    }
                    if (col < 0) {
                        dir = 1;
                        row++;
                        col++;
                    }
                }
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    out.print(grid[i][j]);
                    if (j + 1 < w)
                        out.print(" ");
                }
                out.println();
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

import sys
sys.setrecursionlimit(300000)


def solve(S: str):
    d = ['SUN','MON','TUE','WED','THU','FRI','SAT']
    for i, v in enumerate(d):
        if S == v:
            ret = 7 - i
            break
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define min(a,b) ((a)<(b) ? (a):(b))
#define max(a,b) ((a)>(b) ? (a):(b))

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

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

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //第1条件
        if(riLeft.z != riRight.z){
            return riLeft.z > riRight.z;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.y < riRight.y;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    int N;
    cin >> N;

    double ans=N*(1+N)/2;

    cout << ans << endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        n: usize,
        s: String,
    }

    let x = s
        .chars()
        .map(|e| e.to_digit(2).unwrap() as i64)
        .collect::<Vec<_>>();
    let pc: i64 = x.iter().sum();
    let mut ans = vec![0; n];

    for b in 0..=1 {
        let mut pc = pc;
        if b == 0 {
            pc += 1;
        } else {
            if pc == 1 {
                continue;
            }

            pc -= 1;
        }

        let mut r0 = 0;
        for &e in &x {
            r0 = (e + (r0 << 1)).rem_euclid(pc);
        }

        let mut k = 1;
        for (i, &e) in x.iter().enumerate().rev() {
            if e == b {
                if b == 0 {
                    ans[i] = f((r0 + k).rem_euclid(pc)) + 1;
                } else {
                    ans[i] = f((r0 - k).rem_euclid(pc)) + 1;
                }
            }

            k = (k << 1).rem_euclid(pc);
        }
    }

    for e in &ans {
        println!("{}", e);
    }
}

fn f(n: i64) -> i64 {
    if n == 0 {
        return 0;
    }

    1 + f(n.rem_euclid(n.count_ones() as i64))
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int n, t;
    cin >> n >> t;
    int ans = 1e5;
    int path = 1e5;
    rep(i, n)
    {
        int c, s;
        cin >> c >> s;
        if (s <= t)
        {
            path = min(path, c);
        }
    }
    if (path == 1e5)
    {
        OP("TLE");
    }
    else
    {
        OP(path);
    }
    return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

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> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

ll n, r;
string s;
ll m[5];
map<char,int> c;

signed main() {
	cin >> n;
	c['M'] = 0, c['A'] = 1, c['R'] = 2, c['C'] = 3, c['H'] = 4;
	rep(i,n) {
		cin >> s;
		if (!(s[0]=='M' || s[0]=='A' || s[0]=='R' || s[0]=='C' || s[0]=='H')) continue;
		int tmp = c[s[0]];
		ll sum = 0, ms = 0;
		rep(j,5) {
			if (tmp==j) continue;
			sum += m[j];
			ms += m[j]*(m[j]-1)/2;
		}
		r += sum*(sum-1)/2 - ms;
		m[tmp]++;
	}
	cout << r << ln;
}

Measured memory_bytes: 256
//https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5/DPL_5_If

#include <bits/stdc++.h>

using namespace std;

long long MOD = 1e9 + 7;

long long f[1010][1010];

int main() {
    long long n;//ボール
    long long k;//箱
    cin >> n >> k;

    f[0][0] = 1;
    for (int i = 1; i <= 1000; ++i) {
        f[i][0] = 0;
        f[i][i] = 1;
    }

    for (long long i = 1; i <= 1000; ++i) {
        for (long long j = 1; j <= 1000; ++j) {
            f[i][j] = (f[i - 1][j - 1] + j * f[i - 1][j] + MOD) % MOD;
        }
    }

    cout << f[n][k] << endl;
    return 0;
}

/*
 * 第2種スターリング数を使う。
 * 区別できるn個のボールを区別できないi個の箱（空箱なし）
 * に入れる方法をf[n][i]とする。
 * f[n][k]=f[n-1][k-1]+k*f[n-1][k]
 *
 */


Measured memory_bytes: 11012
using System;
using System.Linq;
class hello
{
    public static void Main()
    {
        int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(n[0] == n[1] ? n[2] : (n[1] == n[2] ? n[0] : n[1]));
    }
}

Measured memory_bytes: 11348
#include<stdio.h>
int main(void)
{
	int N,p[10000],max,T,i,j,k;

	scanf("%d",&N);

	for(i=0;i<N;i++)
		scanf("%d\n",&p[i]);
               
	max=p[0];
	for (i=1;i<N;i++)
		if(max<p[i])
			max=p[i];

	T=0;
       for(i=0;i<N;i++)
	        T=T+p[i];
		
       T=T-0.5*max;

       printf("%d\n",T);
       return  0;

}

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

int main() {
    int n, m;
    cin >> n >> m;
    
    int numOfAC = 0, numOfPenalty = 0;
    vector<int> Accepted(n + 10, 0);
    vector<int> Wrong(n + 10, 0);
    for (int i = 0; i < m; i++)
    {
        int p; string s;
        cin >> p >> s;
        if (s == "AC")  {
            Accepted[p]++;
            if (Accepted[p] == 1)  numOfPenalty += Wrong[p];
        }
        else  Wrong[p]++;
    }
    for (int i = 0; i <= n; i++)  {
        //cout << Accepted[i] <<endl;
        if (Accepted[i])  numOfAC++;
    }      
    cout << numOfAC << " " << numOfPenalty;
    return 0;
    
    
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,ans=0,a;
    vector<ll> v;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a==0){
            v.pb(ans);
            ans=0;
        }
        else if(i==n-1){
            ans+=a;
            v.pb(ans);
            ans=0;
        }
        else{
            ans+=a;
        }
    }
    for(int i=0;i<v.size();i++){
        ans+=v[i]/2;
    }
    cout << ans<<endl;
    return 0;
}




Measured memory_bytes: 1400
n = int(input())
List = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
  num_evidence = int(input())
  for j in range(num_evidence):
    darega, doushita = map(int,input().split())
    List[i][darega - 1] = doushita * 2 - 1

def is_inconsistent(all_evidence, honest_or_unkind):
  for i in range(n):
    if honest_or_unkind[i] == 1:
      for j in range(n):
        if honest_or_unkind[j] * all_evidence[i][j] == -1:
          return True
  return False

max_honest = 0
for i in range(2**n):
  temp = format(i, '0'+str(n)+'b')
  honest_or_unkind = [int(temp[i]) * 2 - 1 for i in range(n)]
  if not is_inconsistent(List, honest_or_unkind):
    max_honest = max(max_honest, honest_or_unkind.count(1))

print(max_honest)

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.Map;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int K2 = 10-K;
        int[] D = new int[K];
        int[] E = new int[K2];
        for(int i=0;i<K;i++){
            D[i] = sc.nextInt();
        }
        /*for(int i=0;i<=9;i++){
            int count = 0;
            boolean a = true;
            for(int j=0;j<K;j++){
                if(i==D[j]){
                    a = false;
                    break;
                }
            }
            if(a){
                E[count] = i;
                count ++;
            }
        }
        */
        x:while(true){
            String a = String.valueOf(N);
            int size = a.length();
            y:for(int i=0;i<size;i++){
                int x = Integer.parseInt(a.substring(i,i+1));
                for(int j=0;j<K;j++){
                    if(x==D[j]){
                        break y;
                    }
                }
                if(i==size-1){
                    break x;
                }
            }
        
            N++;
        }
        
        
        System.out.println(N);
        
    }
}


Measured memory_bytes: 19740
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int N;
  cin >> N;
  vector <int> H(N);
  rep(i,N) cin >> H[i];
  int ans = 0;
  int cnt = 0;
  for (int i = 1; i < N; i++){
    if (H[i - 1] >= H[i]){
      cnt ++;
      ans = max(ans, cnt);
    }else{
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

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

    int N, K;
    vector<int> H;
    cin >> N >> K;
    H.resize(N);
    int ans = 0;
    REP(i, N) {
        cin >> H[i];
        if(K <= H[i]) { ans++; }
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1024
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
Lb = L[::-1]
ans = 0
for i, l1 in enumerate(L):
    for j, l2 in enumerate(L[i + 1:]):
        c = l1 - l2
        p = max(0, len(L) - (i + j + 2) - bisect.bisect_right(Lb, c))
        ans += p
print(ans)

Measured memory_bytes: 47324
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;


int main(){


    int k,x;
    cin >> k >> x;

    int minx = max(x - (k - 1), -1000000);
    int maxx = min(x + (k - 1), 1000000);

    for(int i = minx; i <= maxx; i++){
        cout << i << " ";
    }

    cout << endl;

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
vector<int> decToBinary(int n) 
{ 
    // array to store binary number 
    int binaryNum[32]; 
    vector<int> p(32,0);
    // counter for binary array 
    int i = 0; 
    while (n > 0) { 
  
        // storing remainder in binary array 
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = i - 1; j >= 0; j--) 
        {
            //cout << binaryNum[j];
            p[j]=binaryNum[j];
        }
        return p;
}  
int main() {
    fast();
    /*ll t;
    cin>>t;
    while(t--)			
    {
       
    }*/
    ll n,m,x;
    cin>>n>>m>>x;
    ll c[n],a[n][m];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
        for(int j=0;j<m;j++)
        cin>>a[i][j];
    }
    ll ans=1e18;
    ll du=pow(2,n)-1;
    for(int i=1;i<=du;i++)
    {
        //cout<<i<<"sadf ";
        vector<int>k=decToBinary(i);
        ll sum=0,s[m]={0};
       // if(i==du)
       // for(int j=0;j<k.size();j++)
        //cout<<k[j]<<" ";
        //cout<<endl;
        for(int j=0;j<k.size()&&j<n;j++)
        {
            if(k[j]==1)
            {
                for(int y=0;y<m;y++)
                {
                    s[y]+=a[j][y];
                }
                sum+=c[j];
            }
           
        }
        int flag=1;
        for(int y=0;y<m;y++)
        {
            if(s[y]<x)
            flag=0;
        }
       //cout<<flag<<" "<<sum<<endl;
        if(flag)
        ans=min(sum,ans);
    }
    if(ans==1e18)
    cout<<-1;
    else
    cout<<ans;
}


Measured memory_bytes: 4120
from itertools import permutations

n = int(input())
a = tuple(map(int, input().split()))
p = list(permutations(sorted(a), n))

for i in p:
    if a == i:
        j = p.index(i)
        if j != 0:print(*p[j-1])
        print(*i)
        if j+1 < len(p):print(*p[j+1])


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int r; cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[4],t;
    int i,j;
    scanf("%s",s);
    for(i=0;i<2;i++){
        for(j=2;j>i;j--){
            if(s[j-1]>s[j]){
                t=s[j-1];
                s[j-1]=s[j];
                s[j]=t;
            }
        }
    }
    puts(strcmp(s,"abc")?"No":"Yes");
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 20
#define maxq 60
#define int ll
int A[maxq],B[maxq],C[maxq],D[maxq];

int N,M,Q;
int ans = 0;

vi vect;
void gen(int idx){
	
	if (idx == N + 1){
		int res = 0;
		
		FOR(i,1,Q){
			if (vect[B[i] - 1] - vect[A[i] - 1] == C[i]) res += D[i];
		}
		
		ans = max(ans,res);
		return;
	}
	
	int lim = 1;
	if (!vect.empty()) lim = max(lim,vect.back());
	
	FOR(i,lim,M){
		vect.pb(i);
		gen(idx+1);
		vect.pop_back();
	}
}
int32_t main(){
	fast;
	
	cin>>N>>M>>Q;
	
	FOR(i,1,Q) cin>>A[i]>>B[i]>>C[i]>>D[i];
	
	
	gen(1);
	
	cout<<ans;
	
}



Measured memory_bytes: 3660
# dp[i] 足場iまでいくコストの最小値

n = int(input())
h = [0] + list(map(int,input().split()))

# dp[2]までは初期条件で確定
dp = [0 for i in range(n+1)]
dp[2] = abs(h[2]-h[1])

for i in range(3,n+1):
    dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))


ans = dp[n]
print(ans)


Measured memory_bytes: 53640
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define lll pair<ll,ll>
#define ii pair<int, int>
#define vii vector<ii>
#define vi vector<int>
#define ff first
#define ss second
#define pb(a) push_back(a)
#define ppb() pop_back()
#define mkp(a,b) make_pair(a,b)
#define vs vector<string>
#define vc vector<char>
#define deb1(a) cout<<#a<<" "<<a<<"\n"
#define deb2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n";
#define deb3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n"
#define mms0(a) memset(a,0,sizeof(a))
#define mms1(a) memset(a,-1,sizeof(a))
#define FOR(a,b,c) for(int i=(a);i<(b);i+=(c))
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define _ 0
using namespace std;




void solve(){
   int N;
   cin>>N;
   int arr[N+1];
   FOR(1,N+1,1) cin>>arr[i];
   ll dp[N+1];
   mms0(dp);
   dp[2] = abs(arr[2] - arr[1]);
   for(int i=3;i<=N;i++){
      ll a = dp[i-2] + abs(arr[i] - arr[i-2]);
      ll b = dp[i-1] + abs(arr[i] - arr[i-1]);
      dp[i] = min(a,b); 
   }

  // for(int i=0;i<=N;i++) cout<<dp[i]<<" ";cout<<"\n";
   cout<<dp[N];
}




int main(){
   int t = 1;
   //cin>>t;
   while(t--){
      solve();
   }
   return 0;
}

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

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

  vector<int> Ai;
  rep(i,N){
    int tmpAi = 0;
    cin >> tmpAi;
    Ai.push_back(tmpAi);
  }

  int Search_i = 1;
  rep(i,N){
    if(Ai.at(i) == Search_i) Search_i++;
  }
  
  int ans;
  if(Search_i == 1){
    ans = -1;
  }else{
    ans = N - Search_i + 1;
  }

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


Measured memory_bytes: 1400
package main

import (
	"fmt"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)

	ans := 0
	for i := 0; i < n-2; i++ {
		if s[i:i+3] == "ABC" {
			ans++
		}
	}
	fmt.Println(ans)
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    int32 cnt = 0;
    REP(i,n){
        int32 p;
        cin >> p;
        if(p != i+1)cnt++;
    }
    YES(cnt <= 2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

int a,b[110];
  double c,d,e,f;
  cin >> a;
  for(int i=0;i<a;i++)
  cin >>b[i];
  
  c=0,e=0;
  for(int i=0;i<a;i++){
    d =1;
       d /= b[i];
     c += d;
  }
  
  
  
  cout << 1/c <<endl;
}

 


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

long double XS,YS,XT,YT;
int N;
struct barrier{
	long double x,y,r;
};
long double min_cost [1000];
const long double INF = 1e30;

long double distance(long double x1,long double y1,long double x2,long double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

void dijkstra(vector<barrier>& B)
{
	priority_queue< pair<long double,int>,vector< pair<long double,int> >,greater< pair<long double,int> > > pq;
	FOR(i,0,N){
		pq.push({max(0.0l,distance(XS,YS,B [i].x,B [i].y) - B [i].r),i});
	}

	while(pq.empty() == false){
		long double cost = pq.top().first;
		int curr = pq.top().second;
		pq.pop();

		if(min_cost [curr] <= cost) continue;
		min_cost [curr] = cost;

		FOR(i,0,N) if(i != curr){
			pq.push({cost + max(0.0l,distance(B [curr].x,B [curr].y,B [i].x,B [i].y) - B [curr].r - B [i].r),i});
		}
	}
}

int main()
{
	scanf("%Lf%Lf%Lf%Lf",&XS,&YS,&XT,&YT);
	scanf("%d",&N);

	vector<barrier> B(N);
	FOR(i,0,N){
		scanf("%Lf%Lf%Lf",&B [i].x,&B [i].y,&B [i].r);
	}

	fill_n(min_cost,N,INF);
	dijkstra(B);

	long double ans = distance(XS,YS,XT,YT);
	FOR(i,0,N){
		chmin(ans,min_cost [i] + max(0.0l,distance(B [i].x,B [i].y,XT,YT) - B [i].r));
	}

	printf("%.10Lf\n",ans);

	return 0;
}


Measured memory_bytes: 33384
n, k = map(int, input().split( ))
mod = 10**9+7

def chs(s,t,mod):
    nume =  1
    for i in range(s-t+1,s+1):
        nume *= i
        nume %= mod
    deno = 1
    for i in range(1,t+1):
        deno *= i
        deno %= mod
    deno = pow(deno,mod-2,mod)
    
    return (nume*deno%mod)

ans = chs(k,n,mod)
print(ans)


Measured memory_bytes: 5600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct State
    {
        internal int x, y, cnt;

        public State(int x, int y, int cnt)
        {
            this.x = x;
            this.y = y;
            this.cnt = cnt;
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };
        readonly int INF = 1 << 20;
        readonly int w, h;

        int[,] map, counts;
        int sx, sy, minCnt;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            counts = new int[h, w];
        }

        public int Solve()
        {
            MakeMap();
            minCnt = INF;

            Stack<State> stk = new Stack<State>();
            stk.Push(new State(sx, sy, 0));

            while (stk.Count > 0)
            {
                State cur = stk.Pop();
                counts[cur.y, cur.x] = cur.cnt;

                for (int i = 0; i < 4; i++)
                {
                    int nextX = cur.x + moveX[i];
                    int nextY = cur.y + moveY[i];

                    if (IsValid(nextX, nextY))
                    {
                        int tempCnt = cur.cnt + (map[cur.y, cur.x] == 1 ? 0 : map[nextY, nextX]);

                        if (counts[nextY, nextX] <= tempCnt) continue;

                        if (tempCnt < minCnt) stk.Push(new State(nextX, nextY, tempCnt));
                    }
                    else minCnt = Math.Min(minCnt, cur.cnt);
                }
            }
            return minCnt;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0 || x >= w) return false;
            if (y < 0 || y >= h) return false;
            return true;
        }

        private void MakeMap()
        {
            for (int i = 0; i < h; i++)
            {
                string input = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    switch (input[j])
                    {
                        case '#':
                            map[i, j] = 1;
                            break;
                        case '&':
                            sx = j;
                            sy = i;
                            break;
                    }
                    counts[i, j] = INF;
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int w = int.Parse(input[0]);
                int h = int.Parse(input[1]);

                if (w == 0 && h == 0) break;

                Problem pb = new Problem(w, h);
                sb.AppendLine(pb.Solve().ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10524