akhauriyash/Code-Regression huggingface dataset:
package main

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

func solve(sc *scanner, wr *bufio.Writer) {
	m := sc.getInt()
	ans := 48 - m
	fmt.Fprintln(wr, ans)
}

func main() {
	sc := newScanner()
	wr := bufio.NewWriter(os.Stdout)
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)

	solve(sc, wr)
	wr.Flush()
}

// input ------------------------
type scanner struct {
	*bufio.Scanner
}

func newScanner() *scanner {
	sc := bufio.NewScanner(os.Stdin)
	return &scanner{sc}
}
func (sc *scanner) getInt() int {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getInt2() (int, int) {
	return sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt3() (int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInt4() (int, int, int, int) {
	return sc.getInt(), sc.getInt(), sc.getInt(), sc.getInt()
}
func (sc *scanner) getInts(n int) []int {
	ret := make([]int, n)
	for i := range ret {
		ret[i] = sc.getInt()
	}
	return ret
}
func (sc *scanner) getString() string {
	sc.Scan()
	return sc.Text()
}
func (sc *scanner) getRunes() []rune {
	return []rune(sc.getString())
}
func (sc *scanner) getFloat() float64 {
	sc.Scan()
	ret, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return ret
}
func (sc *scanner) getFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := range ret {
		ret[i] = sc.getFloat()
	}
	return ret
}

// math ----------------------------
func sum(ns ...int) int {
	var sum int
	for _, n := range ns {
		sum += n
	}
	return sum
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func pow(a, b int) int {
	ret := 1
	for b > 0 {
		if b&1 > 0 {
			ret = ret * a
		}
		a = a * a
		b >>= 1
	}
	return ret
}


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

/* type defnition */
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using Graph = vector<vi>;


//macros
#define __all(v) v.begin(),v.end()


/*  Util Function defnition                  */

inline int ctoi(char c){
    return c - '0';
}

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

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

/*  End Util Function defnition              */



/*  Global Variable defnition                 */

/*  End Global Variable defnition              */



/**/


/**/

void calclation(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC\n";
    else cout << "ABC\n";
    return;


}

//main function
int main(int, char**) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    calclation();
    return 0;
}


Measured memory_bytes: 3640
S = input()
d = {}

for s in S:
  d[s] = True

if 'N' in d:
  if 'S' not in d:
    print("No")
    exit()
    
if "S" in d:
  if 'N' not in d:
    print("No")
    exit()

if "E" in d:
  if "W" not in d:
    print("No")
    exit()
    
if "W" in d:
  if "E" not in d:
    print("No")
    exit()  
    
print("Yes")


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define test int t; cin >> t; while (t--)
#define fast ios::sync_with_stdio(NULL); cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/GCD(m,n))
#define all(v) v.begin(),v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC


int main(){
    fast;
    // test{
    //     ll n,s=0;cin>>n;
    //     vecll a(n);
    //     set <ll> se;
    //     for(auto &x:a){cin>>x;s+=x;se.insert(x);}
    //     vecll pra,prb;
    //     pra.pb(a[0]),prb.pb(s);
    //     for(int i=1;i<n;i++){
    //         pra.pb(a[i]+pra[i-1]);
    //         prb.pb(prb[i-1]-a[i-1]);
    //     }
    //     ll c=0,z=1;
    //     for(auto x:se){
    //         if(x!=z){c=1;break;}
    //         z++;
    //     }
    //     if(c)cout<<0<<endl;
    //     else{
    //         vecll ans;
    //         for(int i=0;i<n-1;i++){
    //             if(s-pra[i] == ((n-i)*(n-i-1))/2 and pra[i]==((i+1)*(i+2))/2){ans.pb(i+1);}
    //         }   
    //         for(int i=n-1;i>=0;i--){
    //             if(s-prb[i] == ((n-i)*(n-i-1))/2 and prb[i]==((i+1)*(i+2))/2){ans.pb(i+1);}
    //         }
    //         cout<<ans.size()<<endl;
    //         for(auto x:ans)cout<<x<<" "<<n-x<<endl;
    //     }


    // }
    string s;
    cin>>s;
    if(s[1]== '7' or s[0]== '7' or s[2]== '7')cout<<"Yes";
    else cout<<"No";
    //cout<<s[0];
    return 0;
}


Measured memory_bytes: 3644
import java.util.*;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    String ans = "No";

    if(a < b && b < c && a < c){
      ans = "Yes";
    }

    System.out.println(ans);
  }
}



Measured memory_bytes: 26276
#include <bits/stdc++.h>
#include<cmath>
#define _GLIBCXX_DEBUG
using namespace std;

int main()
{
    int K;
    int A,B;
    cin>>K;
    cin>>A>>B;
    int ans=0;

    for(int i=A;i<=B;i++){
        if(i%K==0){
            ans=1;
            break;
        }
    }
    if(ans==0){
        cout<<"NG";
    }
    else{
        cout<<"OK";
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y=0,sum;
    string s = "No";
    cin >> x >> sum;
    for(int i=0;i<=x;i++){
        y=2*i+4*(x-i);
        if(y==sum){
            s = "Yes";
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <deque>
#include <string>
using namespace std;

int main(){
	int n;
	string s,t;
	char c,d;
	deque<char> de,sub;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> s >> t;
		de.clear();
		for(int j = 0;j < t.size();j++){
			de.push_back(t[j]);
		}
		for(int j = s.size()-1;j >= 0;j--){
			//cout << s[j] <<endl;
			if(s[j] == 'C'){
				c = de.front();
				de.pop_front();
				de.push_back(c);
			}
			else if(s[j] == 'J'){
				c = de.back();
				de.pop_back();
				de.push_front(c);
			}
			else if(s[j] == 'A'){
				for(int k = 0;k < de.size()/2;k++){
					swap(de[k],de[de.size()-k-1]);
				}
			}
			else if(s[j] == 'E'){
				if(de.size()%2 == 1){
					for(int k = 0;k < t.size()/2;k++){
						c = de.back();
						de.pop_back();
						sub.push_front(c);
					}
					c = de.back();
					de.pop_back();
					de.push_front(c);
					//cout << c << endl;
					while(!sub.empty()){
						c = sub.back();
						sub.pop_back();
						de.push_front(c);
					}
				}
				else{
					for(int k = 0;k < de.size()/2;k++){
						c = de.front();
						de.pop_front();
						de.push_back(c);
					}
				}
			}
			else if(s[j] == 'M'){
				for(int k = 0;k < de.size();k++){
					if(de[k] >= '0' && de[k] <='8'){
						de[k]++;
					}
					else if(de[k] == '9'){
						de[k] = '0';
					}
				}
			}
			else if(s[j] == 'P'){
				for(int k = 0;k < de.size();k++){
					if(de[k] >= '1' && de[k] <='9'){
						de[k]--;
					}
					else if(de[k] == '0'){
						de[k] = '9';
					}
				}
			}
		}
		for(int j = 0;j < de.size();j++){
			cout << de[j];
			if(j == de.size()-1)cout <<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1204
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        h: usize, w: usize, k: usize,
        c: [Chars; h],
    }

    let mut v = vec![vec![0; w]; h];
    for y in 0..h {
        for x in 0..w {
            if y == 0 {
                if x == 0 {
                    v[y][x] = if c[y][x] == '.' { 0 } else { 1 };
                } else {
                    v[y][x] = v[y][x - 1] + if c[y][x] == '.' { 0 } else { 1 };
                }
            } else {
                if x == 0 {
                    v[y][x] = v[y - 1][x] + if c[y][x] == '.' { 0 } else { 1 };
                } else {
                    v[y][x] = v[y - 1][x] + v[y][x - 1] - v[y - 1][x - 1]
                        + if c[y][x] == '.' { 0 } else { 1 };
                }
            }
        }
    }

    let mut count = 0;
    for ybit in 0..(1 << h) {
        for xbit in 0..(1 << w) {
            let mut blacks = v[h - 1][w - 1];
            let ys: Vec<_> = (0..h).into_iter().filter(|y| ybit >> y & 1 == 1).collect();
            let xs: Vec<_> = (0..w).into_iter().filter(|x| xbit >> x & 1 == 1).collect();
            let dup: usize = ys
                .iter()
                .map(|y| xs.iter().filter(|x| c[*y][**x] == '#').count())
                .sum();
            blacks += dup;
            let yc: usize = ys
                .iter()
                .map(|y| (0..w).into_iter().filter(|i| c[*y][*i] == '#').count())
                .sum();
            let xc: usize = xs
                .iter()
                .map(|x| (0..h).into_iter().filter(|i| c[*i][*x] == '#').count())
                .sum();
            blacks -= xc + yc;
            if blacks == k {
                count += 1;
            }
        }
    }
    println!("{}", count);
}


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

const int N=1e5+5;
int indeg[N],path[N];
vector<int>ed[N];

int  dfs(int u)
{
  if(path[u]!=-1)
    return path[u];
  int ans=0;
  for(int c: ed[u])
  {
    ans=max(ans,1+dfs(c));
  }
  return path[u]=ans;
}
int32_t main()
{
  
  int n,m,x,y;
  cin>>n>>m;

  for(int i=1;i<=m;i++)
  {
    cin>>x>>y;
    ed[x].push_back(y);
    indeg[y]++;
  }
  int ans=0,t=0;
  memset(path,-1,sizeof(path));
  for(int i=1;i<=n;i++)
  {
    if(indeg[i]==0)
    {
      t=max(t,dfs(i));
    }
  }
 
  cout<<t;

  return 0;  
}   

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int n;
	scanf("%d", &n);
	vector<int> l(n * 2);
	rep(i, n * 2) scanf("%d", &l[i]);
	sort(l.begin(), l.end());
	int count = 0;
	for(int i = 0; i < (n * 2); i = i + 2) {
		count += l[i];
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 3740
//A.java
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        sc.close();

        if (a > b) System.out.println(--a);
        else System.out.println(a);
    }
}

Measured memory_bytes: 21204
dat = input().split()
h = int(dat[0])
w = int(dat[1])

while (True):
    if (h==0 and w==0):
        break
    
    i = 0
    while (i<h):
        print('#'*w)
        i = i + 1
    try:
        dat = input().split()
        h = int(dat[0])
        w = int(dat[1])
        print()
    except EOFError:
        break
    


Measured memory_bytes: 5616
from collections import defaultdict

N, M = map(int, input().split())
p = [""]*M
S = [""]*M

for i in range(M):
    p[i], S[i] = map(str, input().split())

memo_p = defaultdict(int)
memo_s = defaultdict(str)

penalty = 0

for x, y in zip(p, S):
    if memo_s[x]=="AC":
        continue
    elif y=="WA":
        memo_p[x] += 1
    else:
        memo_s[x] = "AC"
        penalty += memo_p[x]
        memo_p[x] = 0

print(sum([i=="AC" for i in memo_s.values()]), penalty)

Measured memory_bytes: 31544
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

if a.max < k
  puts "IMPOSSIBLE"
  exit
elsif a.any? { |ai| ai == k }
  puts "POSSIBLE"
  exit
end
g = a.inject(0) { |memo, i| memo.gcd(i) }
if k % g == 0
  puts "POSSIBLE"
else
  puts "IMPOSSIBLE"
end

Measured memory_bytes: 8452
// Problem : F - Intervals on Tree
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define fi first
#define se second
#define pb push_back
 
#define ll long long
#define pii pair<int, int>
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll ans = 0;
    int n; cin >> n;
    rep1(L, n) {
        ll k = n - L + 1;
        ans += 1ll * k * (k+1) / 2;
    }
    rep(i, n-1) {
        int u, v; cin >> u >> v;
        ans -= 1ll * min(u, v) * (n - max(u, v) + 1);
    }
    cout << ans << endl;
}



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

int main() {
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    cout << (60 * h2 + m2) - (60 * h1 + m1) - k << '\n';
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(true){
            int a=scan.nextInt();
            int b=scan.nextInt();
            if(a == 0)break;
            for(int j=0;j<1;j++){
                for(int k=0;k<b;k++){
                    System.out.printf("#");
                }
                System.out.println("");
            }
            for(int j=1;j<a-1;j++){
                System.out.printf("#");
                for(int k=0;k<b-2;k++){
                    System.out.printf(".");
                }
                System.out.printf("#");
                System.out.println("");
            }
            for(int j=0;j<1;j++){
                for(int k=0;k<b;k++){
                    System.out.printf("#");
                }
                System.out.println("");
            }
 System.out.println("");
        }
        scan.close();
        return;
    }
}


Measured memory_bytes: 50956
#include <bits/stdc++.h>
using namespace std;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e%2 == 0) { p = (p*p)%mod; e /= 2; }
            else { a = (a*p)%mod; e--; }
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

const int MAX_N = 10010;
const int MAX_D = 110;
const int MOD = 1e9+7;

int main() {
    string S;
    int D;
    cin >> S >> D;
    int N = S.length();
    
    ModInt<MOD> dp[MAX_N][2][MAX_D];
    dp[0][0][0] = 1;
    for (int i = 0; i < N; i++) {
        const int c = S[i] - '0';
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k <= (j ? 9 : c); k++) {
                for (int d = 0; d < D; d++) {
                    dp[i+1][j || (k < c)][(d + k) % D] += dp[i][j][d];
                }
            }
        }
    }
    
    ModInt<MOD> ans = dp[N][0][0] + dp[N][1][0] - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8832
n=int(input())
for i in range(n):
    a,b,c=map(int,input().split())
    if a>b and a>c:
        if a**2==b**2+ c**2:
            print("YES")
        else:
            print("NO")
    elif b>a and b>c:
        if b**2==a**2+c**2:
            print("YES")
        else:
            print("NO")
    elif c>a and c>b:
        if c**2==a**2+b**2:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")


Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		map<char,vector<char> >in;
		rep(i,n){
			char a,b;
			cin>>a>>b;
			in[a].pb(b);
		}
		cin>>n;
		rep(i,n){
			char d;
			cin>>d;
			if(in[d].size())d=in[d][0];
			cout<<d;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1192
def insertionSort(A,N,g):
    global cnt
    for i in range(g,N):
        v = A[i]
        j = i-g
        while j >=0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

def ShellSort():
    global cnt
    A = []
    n = int(input())
    m = 1
    G = [1]
    for i in range(1,n):
        x = 3*G[i-1]+1
        if x > n:
            break
        m += 1
        G.append(3*G[i-1]+1)
    G.reverse()
    for i in range(n):
        A.append(int(input()))
    for i in range(m):
        insertionSort(A,n,G[i])
    #if cnt > int(n**1.5)+1 :
    #    print('over!')
    print(m)
    str = ""
    for i in range(m):
        str += "{} ".format(G[i])
    print(str[:len(str)-1])
    print(cnt)
    for i in range(n):
        print(A[i])

if __name__ == '__main__':
    cnt = 0
    ShellSort()



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

int main()
{
	long long h, w; cin >> h >> w;
	
	if (w == 1 || h == 1 ) {
		cout << 1 << endl;
		return 0;
	}

	long long ans = (h*w + 1) / 2;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

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

    vector<ll> v(n+1), p(n+1);
    REP(i, n){
        ll a;
        cin >> a;
        v[i+1] = v[i] + a;
        p[i+1] = max(p[i], p[i] + a);
    }

    ll ans = 0;

    for(int i=1; i+k-1<=n; i++){
        ans = max(ans, p[n] - p[i+k-1] + p[i-1] + max(0LL, v[i+k-1] - v[i-1]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#![allow(unused)]

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

macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

//
// Based on EbTech's Scanner https://stackoverflow.com/q/56449027
//
struct Scanner<'a, R: std::io::BufRead> {
    reader: R,
    buf: String,
    iter: std::str::SplitWhitespace<'a>,
}

impl<'a, R: std::io::BufRead> Scanner<'a, R> {
    fn new(reader: R) -> Scanner<'a, R> {
        Scanner { reader: reader, buf: String::new(), iter: "".split_whitespace() }
    }

    fn get_str(&mut self) -> &str {
        if let Some(t) = self.iter.next() {
            return t;
        }
        self.buf.clear();
        self.reader.read_line(&mut self.buf).expect("I/O error");
        self.iter = unsafe { std::mem::transmute(self.buf.split_whitespace()) };
        self.get_str()
    }

    fn get<T: std::str::FromStr>(&mut self) -> T {
        self.get_str().parse().ok().expect("Parse error")
    }
}

fn main() {
    let stdin = std::io::stdin();
    solve(Scanner::new(stdin.lock()));
}

fn solve<R: std::io::BufRead>(mut sc: Scanner<R>) {
    let n: usize = sc.get();
    let hs: Vec<i64> = (0..n).map(|_| sc.get()).collect();

    let mut dp = vec![std::i64::MAX; n];

    dp[0] = 0;
    dp[1] = (hs[1] - hs[0]).abs();
    for i in 2..n {
        dp[i] = min(
            dp[i - 2] + (hs[i - 2] - hs[i]).abs(),
            dp[i - 1] + (hs[i - 1] - hs[i]).abs());
    }

    println!("{}", dp[n - 1]);
}

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

int main() {
	int A, B;
	cin >> A >> B;
	if (A <= 9 && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << "-1" << endl;
	}
	
		return 0;
	}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int za[90000][2];
int mp[90000];
int l[100000];
int r[100000];
int main(void){
    int h, w, d;
    scanf("%d %d %d", &h, &w, &d);
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            int a;
            scanf("%d", &a);
            a--;
            za[a][0] = i;
            za[a][1] = j;
        }
    }
    int q;
    scanf("%d", &q);
    for(int i = 0;i < q;i++){
        scanf("%d %d", &l[i], &r[i]);
        l[i]--;
        r[i]--;
    }
    for(int i = 0;i < d;i++){
        mp[i] = 0;
    }
    for(int i = d;i < h*w;i++){
        mp[i] = mp[i-d] + abs(za[i][0] - za[i-d][0]) + abs(za[i][1] - za[i-d][1]);
    }
    for(int i = 0;i < q;i++){
        printf("%d\n", mp[r[i]] - mp[l[i]]);
    }
    /*for(int i = 0;i < h*w;i++){
        printf("%d ", mp[i]);
    }*/
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int N;
	cin >> N;
	vector<int> sum(N);
	for (int i = 0; i < N-1; i++)
	{
		int A;
		cin >> A;
		sum[A-1]++;
	}
	for (int i = 0; i < N; i++)
	{
		cout << sum[i] << endl;
	}
}



Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)

struct LCA {
	vector<int> height, euler, first, logs;
	vector<bool> visited;
	vector<vector<int>> st;

	int min_height(int a, int b) {
		if (height[a] < height[b])
			return a;
		return b;
	}

	void build_sparse(int maxN) {
		st = vector<vector<int>>(maxN, vector<int>(30));
		logs = vector<int>(maxN+1);
		logs[1] = 0;
		for (int i = 2; i <= maxN; i++) {
			logs[i] = logs[i/2]+1;
		}
		for (int i = 0; i < maxN; i++) {
			st[i][0] = euler[i];
		}

		for (int j = 1; j <= 30; j++) {
			for (int i = 0; i + (1 << j) <= maxN; i++) {
				st[i][j] = min_height(st[i][j-1], st[i+(1<<(j-1))][j-1]);
			}
		}
	}

	int lca(int u, int v) {
		u = first[u];
		v = first[v];
		if (u > v)
			swap(u, v);

		int lg = logs[v-u+1];
		return min_height(st[u][lg], st[v-(1<<lg)+1][lg]);
	}



	void dfs(vector<int>* g, int n, int depth) {
		visited[n] = 1;
		height[n] = depth;
		first[n] = euler.size();
		euler.push_back(n);
		for (auto i : g[n]) {
			if (!visited[i]) {
				dfs(g, i, depth+1);
				euler.push_back(n);
			}
		}
	}

	LCA(vector<int>* g, int n) {
		height = vector<int>(n);
		visited = vector<bool>(n);
		first = vector<int>(n);
		dfs(g, 1, 0);
		build_sparse(euler.size());
	}

};

const int N = 1e5 + 7;
vector<int> conn[N];
vector<pair<int, pair<ll, ll>>> g[N];
pair<ll, ll> colors[N];
unordered_map<int, unordered_map<int, pair<ll, ll>>> mp;
ll dists[N];
bool visited[N];


struct query {
	int u, v, x, y;
	query(int u, int v, int x, int y) {
		this->u = u;
		this->v = v;
		this->x = x;
		this->y = y;
	}
};

void dfs(int n, int cost = 0) {
	dists[n] = cost;
	visited[n] = 1;
	for (auto c : mp[n]) {
		mp[n][c.first] = colors[c.first];
	}
	for (auto i : g[n]) {
		if (visited[i.first])
			continue;
		colors[i.second.first].first++;
		colors[i.second.first].second += i.second.second;
		dfs(i.first, cost+i.second.second);
		colors[i.second.first].first--;
		colors[i.second.first].second -= i.second.second;
	}
}



int main() {
	fastIO;
	int n;
	cin >> n;
	int q;
	cin >> q;
	for (int i = 0; i < n-1; i++) {
		int u, v, c, d;
		cin >> u >> v >> c >> d;
		conn[u].push_back(v);
		conn[v].push_back(u);
		g[u].push_back({v, {c, d}});
		g[v].push_back({u, {c, d}});
	}
	LCA lca(conn, n+1);

	vector<query> queries;
	while(q--) {
		int u, v, x, y;
		cin >> x >> y >> u >> v;
		mp[u][x] = {0,0};
		mp[v][x] = {0,0};
		mp[lca.lca(u,v)][x] = {0, 0};
		queries.push_back(query(u,v,x,y));
	}
	dfs(1,0);
	for (auto i : queries) {
		ll dist = dists[i.u] + dists[i.v] - 2 * dists[lca.lca(i.u, i.v)];
		ll frq = mp[i.u][i.x].first + mp[i.v][i.x].first - 2 * mp[lca.lca(i.u, i.v)][i.x].first;
		ll weight = mp[i.u][i.x].second + mp[i.v][i.x].second - 2 * mp[lca.lca(i.u, i.v)][i.x].second;
		assert(weight <= dist);
		cout << dist - weight + frq*i.y << '\n';
	}


}


Measured memory_bytes: 81752
// Aizu Vol0 0018: Sorting Five Numbers
// 2017.7.28

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int data[10];
	int i, j, t, max;

	for (i = 0; i < 5; i++) scanf("%d", &data[i]);
	for (i = 0; i < 5; i++) {
		max = i;
		for (j = i + 1; j < 5; j++) {
			if (data[j] > data[max]) max = j;
		}
		if (max != i) t = data[i], data[i] = data[max], data[max] = t;
	}
	printf("%d", data[0]);
	for (i = 1; i < 5; i++) printf(" %d", data[i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 600
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const double EPS=1e-8;

const int N_MAX=252;

bool Gauss_Jordan(int n,const double A[N_MAX][N_MAX],const double *b,double *x){
	static double B[N_MAX][N_MAX+1];
	rep(i,n){
		rep(j,n) B[i][j]=A[i][j];
		B[i][n]=b[i];
	}

	rep(i,n){
		int piv=i;
		for(int j=i;j<n;j++) if(abs(B[j][i])>abs(B[piv][i])) piv=j;
		rep(j,n+1) swap(B[i][j],B[piv][j]);

		if(abs(B[i][i])<EPS) return false;

		for(int j=i+1;j<=n;j++) B[i][j]/=B[i][i];
		rep(j,n) if(i!=j) for(int k=i+1;k<=n;k++) B[j][k]-=B[j][i]*B[i][k];
	}

	rep(i,n) x[i]=B[i][n];
	return true;
}

int H,W;
char B0[5][6],B1[5][6];

struct state{
	char B[5][5];
	bool operator==(const state &s)const{
		rep(i,H) rep(j,W) if(B[i][j]!=s.B[i][j]) return false;
		return true;
	}
};

void dfs(int y,int x,state &s,vector<state> &S){
	if(x==-1){
		S.push_back(s);
		return;
	}

	for(int i=y;i<=H;i++){
		for(int k=0;k<i;k++) s.B[k][x]='?';
		if(i>y) s.B[i-1][x]='x';
		for(int k=i;k<H;k++) s.B[k][x]='o';
		dfs(i,x-1,s,S);
	}
}

state board_to_state(const char B[5][6]){
	state s;
	rep(i,H) rep(j,W) {
		if(B[i][j]==B1[i][j]) s.B[i][j]='o';
		else                  s.B[i][j]='x';
	}
	int len=7777777;
	for(int i=H-1;i>=0;i--){
		int j;
		for(j=W-1;j>=0;j--) if(s.B[i][j]=='x' || W-j>len) break;
		if(W-j<=len){
			len=W-j-1;
			j--;
		}
		for(;j>=0;j--) s.B[i][j]='?';
	}
	return s;
}

int main(){
	for(;scanf("%d%d",&H,&W),H;){
		rep(i,H) scanf("%s",B0[i]);
		rep(i,H) scanf("%s",B1[i]);

		vector<state> S; // set of possible states
		state s;
		dfs(0,W-1,s,S);

		int m=S.size();
		static double P[252][252]; // transition matrix, P[i][j] := (probability to transit from state i to j)
		static double C[252][252]; // coefficient for b
		rep(i,m) rep(j,m) P[i][j]=C[i][j]=0;
		rep(k,m){
			rep(i,H) rep(j,W) rep(c,2) { // operate (i, j) with color c
				char B[5][6];
				rep(y,H) rep(x,W) {
					if     (S[k].B[y][x]=='o') B[y][x]=B1[y][x];
					else if(S[k].B[y][x]=='x') B[y][x]=(B1[y][x]=='W'?'B':'W');
					else                       B[y][x]='?';
				}
				rep(y,i+1) rep(x,j+1) B[y][x]=(c==0?'W':'B');

				state s=board_to_state(B);
				int to=find(S.begin(),S.end(),s)-S.begin();
				P[k][to]+=1/(H*W*2.0);
				C[k][to]+=(i+1)*(j+1)/(H*W*2.0);
			}
		}

		int i0=find(S.begin(),S.end(),board_to_state(B0))-S.begin();
		int i1=find(S.begin(),S.end(),board_to_state(B1))-S.begin();

		static double A[252][252];
		double b[252]={},x[252];
		rep(i,m){
			if(i==i1){
				b[i]=0;
				rep(j,m) A[i][j]=(i==j?1:0);
			}
			else{
				rep(j,m){
					A[i][j]=(i==j?1:0)-P[i][j];
					b[i]+=C[i][j];
				}
			}
		}

		Gauss_Jordan(m,A,b,x);

		printf("%.9f\n",x[i0]);
	}

	return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {
	
	ll a, b, n;
	cin >> a >> b >> n;

	if (n == 1) {
		cout << (a / b) - a * (1 / b) << endl;
		return 0;
	}
	
	if (b > n) {
		cout << (a*n / b) - a * (n / b) << endl;
		return 0;
	}

	ll m = n / b * b;

	m += b - 1;
	while (m > n) {
		m -= b;
	}
	cout << (a*m / b) - a * (m / b) << endl;
	
}


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

int main() {
    int n, t, result = 0;
    cin >> n >> t;
    pair<int, int> dish[n];
    for (int i = 0; cin >> dish[i].first >> dish[i].second; i++) {
    }
    sort(dish, dish + n);
    int dp[n + 1][t];
    fill(&dp[0][0], &dp[0][t], 0);
    for (int i = 0; i < n; i++) {
        for (int w = t - 1; w >= 0; w--) {
            if (dish[i].first <= w) {
                dp[i + 1][w] = max(dp[i][w], dp[i][w - dish[i].first] + dish[i].second);
            } else {
                dp[i + 1][w] = dp[i][w];
            }
        }
        result = max(result, dp[i][t - 1] + dish[i].second);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    int N; cin >> N;
    int cnt = 0;
    rep(i, N) {
        int a; cin >> a;
        if (a % 2) continue;
        while(a % 2 != 1) {
            cnt++;
            a /= 2;
        }
    }
    COUT(cnt);

}

Measured memory_bytes: 256
/*
▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐
 
*/
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <iomanip>
#include <random>


using namespace std;
  


#define ll long long
#define ld long double
#define null NULL
#define prev prev228
#define next next228
#define index index228
#define count count228


const int N = 100 * 1000 + 228;


int a[N];

int n;


inline bool bad(int i) {
	return i == a[i];
}


signed main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	int i = 1;
	int res = 0;
	while (i <= n) {
		int j = i;
		if (a[i] != i) {
			++i;
			continue;
		}
		while (j + 1 <= n && bad(j + 1)) {
			++j;
		}
		int len = j - i + 1;
		res += (len + 1) / 2;
		i = j + 1;
	}
	printf("%d\n", res);
	return 0;
}






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

int main(){
    ll n,ans=1e9;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0; i<n; ++i) cin>>a[i];
    sort(a.begin(),a.end());
    for(ll i=-100; i<=100; i++) {
        ll cost=0;
        for(ll j=0; j<n; j++) {
            cost += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const LL MOD = 1e9+7;
void ex_gcd(LL a, LL b, LL& x, LL& y) {
    if(!b) {
        x = 1, y = 0;
    } else {
        ex_gcd(b, a%b, y, x);
        y -= x * (a / b);
    }
}

LL inv(LL t, LL p) {
    LL x, y, d;
    ex_gcd(t, p, x, y);
    return (x%p+p)%p;
}

LL quick_pow(LL a, LL b, LL p) {
    LL ret = 1;
    while(b) {
        if(b & 1) ret = (ret * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ret;
}

void run_case() {
    LL n, a, b;
    cin >> n >> a >> b;
    if(n <= 2) {
        cout << "0";
        return;
    }
    LL all = quick_pow(2, n, MOD) - 1;
    LL fa = 1, fb = 1;
    for(LL i = a; i >= 1; --i)
        fa = (fa * i) % MOD;
    for(LL i = b; i >= 1; --i)
        fb = (fb * i) % MOD;
    LL n1 = 1, n2 = 1;
    for(LL i = n; i >= n-a+1; --i)
        n1 = (n1 * i) % MOD;
    for(LL i = n; i >= n-b+1; --i)
        n2 = (n2 * i) % MOD;
    LL invfa = inv(fa, MOD), invfb = inv(fb, MOD);
    all = ((all - n1*invfa%MOD)+MOD)%MOD;
    all = ((all - n2*invfb%MOD)+MOD)%MOD;
    cout << all;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(10);
    run_case();
    cout.flush();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int maxn=2100;

int n, Z, W;
int a[maxn];
int f[maxn][2];

void read()
{
	scanf("%d%d%d", &n, &Z, &W);
	for (int i=1; i<=n; ++i)
		scanf("%d", &a[i]);
}
int dfs(int k, int nid, int x, int y)
{
	if (k>n) return abs(x-y);
	if (f[k][nid]!=-1) return f[k][nid];
	for (int i=k+1; i<=n+1; ++i)
	{
		if (f[k][nid]==-1)
		{
			if (nid & 1) f[k][nid]=dfs(i, nid^1, x, a[i-1]);
			else f[k][nid]=dfs(i, nid^1, a[i-1], y);
		}
		else
		{
			if (nid & 1) f[k][nid]=min(f[k][nid], dfs(i, nid^1, x, a[i-1]));
			else f[k][nid]=max(f[k][nid], dfs(i, nid^1, a[i-1], y));
		}
	}
	return f[k][nid];
}
void solve()
{
	for (int i=1; i<=n; ++i)
		f[i][0]=f[i][1]=-1;
	printf("%d\n", dfs(1, 0, Z, W));
}
int main()
{
	read();
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

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

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 2000005;
const int mod = 1e9 + 7;

int x[7], y[7], fac[MAXN], inv[MAXN], ans;

inline int C(int x, int y) { return 1LL * fac[x + y] * inv[x] % mod * inv[y] % mod; }
inline int F(int x1, int y1, int x2, int y2) { return (1LL * C(x2 + 1, y2 + 1) + C(x1, y1) - C(x1, y2 + 1) - C(x2 + 1, y1) + mod + mod) % mod; }

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	for (int i = 1; i <= 6; i ++)
		x[i] = Read();
	for (int i = 1; i <= 6; i ++)
		y[i] = Read();
	fac[0] = inv[0] = fac[1] = inv[1] = 1;
	for (int i = 2; i <= 2000000; i ++)
		fac[i] = 1LL * fac[i - 1] * i % mod, inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 2; i <= 2000000; i ++)
		inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
	for (int i = x[3]; i <= x[4]; i ++)
		ans = (1LL * (mod - y[3] - i) * F(i - x[2], y[3] - 1 - y[2], i - x[1], y[3] - 1 - y[1]) % mod * F(x[5] - i, y[5] - y[3], x[6] - i, y[6] - y[3]) + ans) % mod;
	for (int i = x[3]; i <= x[4]; i ++)
		ans = (1LL * (i + y[4] + 1) * F(i - x[2], y[4] - y[2], i - x[1], y[4] - y[1]) % mod * F(x[5] - i, y[5] - y[4] - 1, x[6] - i, y[6] - y[4] - 1) + ans) % mod;
	for (int i = y[3]; i <= y[4]; i ++)
		ans = (1LL * (mod - x[3] - i) * F(i - y[2], x[3] - 1 - x[2], i - y[1], x[3] - 1 - x[1]) % mod * F(y[5] - i, x[5] - x[3], y[6] - i, x[6] - x[3]) + ans) % mod;
	for (int i = y[3]; i <= y[4]; i ++)
		ans = (1LL * (i + x[4] + 1) * F(i - y[2], x[4] - x[2], i - y[1], x[4] - x[1]) % mod * F(y[5] - i, x[5] - x[4] - 1, y[6] - i, x[6] - x[4] - 1) + ans) % mod;
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
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;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

int N,K;
int p[5005];
int C[5005];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N>>K;
	rep(i,N){
		cin>>p[i];
		p[i]--;
	}
	rep(i,N)cin>>C[i];
	int res=-inf;
	rep(i,N){
		int now=p[i];
		int sc=C[now];
		vector<int>mx(5005,-inf);
		mx[1]=sc;
		int cnt=1;
		while(cnt<K){
			now=p[now];
			sc+=C[now];
			chmax(mx[cnt+1],max(mx[cnt],sc));
			cnt++;
			if(now==i)break;
		}
		if(cnt==K)chmax(res,mx[cnt]);
		else {
			if(sc>=0){
				int ans=sc*(K/cnt);
				int KK=K;
				KK-=KK/cnt*cnt;
				if(mx[KK]>0)ans+=mx[KK];
				chmax(res,ans);
				int ans2=sc*((K/cnt)-1);
				ans2+=mx[cnt];
				chmax(res,ans2);
			}else {
				chmax(res,mx[cnt]);
			}
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 3772
n=int(input())
ss=list(input())
res= ss.count('R') * ss.count('G') * ss.count('B')
for i in range(n):
  for j in range(i+1,n):
    k = 2*j-i
    if k >= n:
      continue
    if all([ss[i] != ss[j],ss[j] != ss[k],ss[k] != ss[i]]):
      res-=1
print(res)

Measured memory_bytes: 68836
/*
      بسم اللہ الرحمن الرحیم
    Bismillahir Rahmanir Raheem.
    In the name of Allah, Most Gracious, Most Merciful.

*/
/*
    Masum
    RUET
    CSE-19
    #1903086
    NDC
    #11901058
*/

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define endl '\n'
#define watch(x) cout << (#x) << " is " << x << endl;
/***********************MASUM**********************/

void sol();
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    /* Test cases */
    bool isT = 0;
    if (isT) {
        int t;
        cin >> t;
        while (t--)
            sol();
    } else
        sol();
    return 0;
}

void sol() {
    /* Remember about test cases --> exits or not */

    int x;
    cin >> x;
    int g=__gcd(x,(int)360);
    cout << 360/(ld)g;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define pb push_back
#define mp make_pair

void solve()
{
	int n;
	cin >> n;
	if (n % 1000 == 0)
		cout << 0 << "\n";
	else
	{
		cout << ((n / 1000) + 1) * 1000 - n << "\n";
	}
}

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

Measured memory_bytes: 3616
let n = cin.int
var count = 0

func toInt(_ A: [Int]) -> Int {
    var sum = 0
    A.enumerated().forEach { a in
        sum += a.element * (10 ^^ a.offset)
    }
    return sum
}

func dfs(_ A: inout [Int]) {
    if toInt(A) > n {
        return
    } else {
        /// 3,5,7 が1回以上含まれている
        if A.contains(3) && A.contains(5) && A.contains(7) {
            count += 1
        }
    }

    for v in [3,5,7] {
        A.append(v)
        dfs(&A)
        A.removeLast()
    }
}

var A = [Int]()
dfs(&A)

print(count)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 13456
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll> 
#define clr(x) memset(x,0,sizeof(x))
const ll size=1e6+7;
ll arr[size];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll a,b;cin>>a>>b;
    if(a>8 or b>8)cout<<":(";
    else cout<<"Yay!";
}   

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll c=1000;
    ll x=0;
    int l=0;
    while(l<n)
    {
        int r=l;
        while(r+1<n&&a[r]<=a[r+1]) r++;
        x=(c/a[l]);
        c-=(a[l]*x);
        c+=(a[r]*x);
        x=0;
        l=r+1;
    }
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main()
{
    int x,y,z;
    while(scanf("%d %d %d",&x,&y,&z)!=EOF)
    {
        if(x>z)
            printf("NO\n");
        else if(x+y>=z)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 760
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <string>
#include <stack>
#include <tuple>

using namespace std;
typedef long long ll;

ll ans = 0;
string s;

int main()
{
    string w;
    cin >> w;
    vector<int> cnt(30,0);
    for (auto& c : w)
    {
        cnt[c - 'a']++;
    }
    for (int i = 0; i < 30; i++)
    {
        if (cnt[i] % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
//17
#include<iostream>
#include<algorithm>

using namespace std;

int w,h;
char g[50][51];

int res(int y,int x){
  if(y<0||h<=y||x<0||w<=x){
    return 0;
  }else if(g[y][x]=='.'){
    g[y][x]='t';
    int a=0;
    for(int i=0;i<4;i++){
      int d[]={0,1,0,-1,0};
      a|=res(y+d[i],x+d[i+1]);
    }
    return a;
  }else{
    return g[y][x]=='B'|(g[y][x]=='W')<<1;
  }
}

void ff(int y,int x,int v){
  if(y<0||h<=y||x<0||w<=x){
    return;
  }else if(g[y][x]=='t'){
    const char *w="nbwn";
    g[y][x]=w[v];
    for(int i=0;i<4;i++){
      int d[]={0,1,0,-1,0};
      ff(y+d[i],x+d[i+1],v);
    }
  }  
}

int main(){
  while(cin>>w>>h,w|h){
    fill(g[0],g[50],0);
    for(int y=0;y<h;y++){
      cin>>g[y];
    }
    for(int y=0;y<h;y++){
      for(int x=0;x<w;x++){
	ff(y,x,res(y,x));
      }
    }
    cout<<count(g[0],g[50],'b')<<' '<<count(g[0],g[50],'w')<<endl;
  }
  return 0;
}

Measured memory_bytes: 1356