akhauriyash/Code-Regression huggingface dataset:
//2019.7.14 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 5.6e-8
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N=1e5+10;
namespace MAIN{
    int n,m;
    struct E{
        int next,to;
        E() {}
        E(res next,res to):next(next),to(to) {}
    }edge[N<<1];
    int head[N],cnt;
    inline void addedge(const res &u,const res &v){
        edge[++cnt]=E(head[u],v),head[u]=cnt;
        edge[++cnt]=E(head[v],u),head[v]=cnt;
    }
    int dfn[N],idx;
    int du[N];
    void dfs(res x,res fax){
        dfn[x]=++idx;
        for(res i=head[x];~i;i=edge[i].next){
            res tox=edge[i].to;
            if(tox==fax)continue;
            if(!dfn[tox])dfs(tox,x);
            else if(dfn[tox]<dfn[x])printf("%d %d\n",x,tox),du[x]++;
        }
        if(x!=1)
            if(du[x]&1)printf("%d %d\n",x,fax),du[x]++;
            else printf("%d %d\n",fax,x),du[fax]++;
    }
    inline void MAIN(){
        n=read(),m=read();
        for(res i=1;i<=n;i++)head[i]=-1;
        for(res i=1;i<=m;i++)addedge(read(),read());
        if(m&1){puts("-1");return;}
        dfs(1,0);
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("zao.in","r",stdin);
//    freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 8832
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i <= a; ++i) {
        if (a % i == 0) {
            facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    ll s;
    cin >> s;
    ll sq = sqrt(s);
    if (sq * sq != s)
        sq++;

    // cout << sq << "\n";
    ll x = 0;
    ll y = 0;
    vl ret(6, 0);

    ll mult = sq * sq - s;
    if (mult == 0) {
        x = 0;
        y = 0;
        ret[0] = 0;
        ret[1] = 0;
        ret[2] = x;
        ret[3] = sq;
        ret[4] = sq;
        ret[5] = y;
    } else {
        auto facs = factors(mult);
        for (auto &f : facs) {
            if (f <= sq && mult / f <= sq) {
                x = f;
                y = mult / f;
                break;
            }
        }
        if (x == 0) {
            auto facsx = factors(s);
            for (auto &f : facsx) {
                if (f <= 1000000000 && s / f <= 1000000000) {
                    x = f;
                    y = s / f;
                }
            }
            assert(x != 0);
            ret[0] = 0;
            ret[1] = 0;
            ret[2] = x;
            ret[3] = 0;
            ret[4] = 0;
            ret[5] = y;

        } else {
            ret[0] = 0;
            ret[1] = 0;
            ret[2] = x;
            ret[3] = sq;
            ret[4] = sq;
            ret[5] = y;
        }
    }

    // ll test = (ret[2] - ret[0]) * (ret[5] - ret[1]);
    // cout << test << "\n";
    for (int i = 0; i < 6; ++i) {
        cout << ret[i];
        if (i == 5)
            cout << endl;
        else
            cout << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int kazu;
	if(a == b && b == c) {
		kazu = 1;
	} else if(a == b || b == c || c == a) {
		kazu = 2;
	} else {
		kazu = 3;
	}
	cout << kazu << endl;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class UnionFind {
    private :
        std::vector<int> par;
    public :
        UnionFind(int n) {
            par.resize(n);
            for (int i=0; i<n; i++) par[i] = i;
        }
        void unite(int x, int y) {
            int xPar = find(x);
            int yPar = find(y);
            if (xPar == yPar) return;

            par[xPar] = yPar;
        }
        int find(int x) {
            if (par[x] == x) return x;
            else return par[x] = find(par[x]);
        }
        bool same(int x, int y) { return find(x) == find(y); }
};

void dfs(int cur, int pre, const Graph &t, Graph &ans) {
    for (int nx : t[cur]) {
        if (nx != pre) dfs(nx, cur, t, ans);
    }
    if (pre != -1) {
        if ((int)ans[cur].size()%2 == 0) ans[pre].push_back(cur);
        else ans[cur].push_back(pre);
    }
}

void solve() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> es(M);
    for (int i=0; i<M; ++i) {
        int a, b;
        cin >> a >> b;
        es[i] = {a-1, b-1};
    }

    if (M%2 == 1) {
        cout << -1 << '\n';
        return;
    }

    UnionFind uf(N);
    Graph t(N), ans(N);
    for (auto p : es) {
        if (!uf.same(p.first, p.second)) {
            uf.unite(p.first, p.second);
            t[p.first].push_back(p.second);
            t[p.second].push_back(p.first);
        } else {
            ans[p.first].push_back(p.second);
        }
    }
    dfs(0, -1, t, ans);
    for (int i=0; i<N; ++i) {
        for (int j : ans[i]) {
            cout << i + 1 << ' ' << j + 1 << '\n';
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 18856
#include<iostream>
#include<cstdlib>

using namespace std;

int d[5], k;

int main(){
  for(int i = 0; i < 5; i++){
    cin >> d[i];
  }
  cin >> k;

  for(int i = 0; i < 4; i++){
    for(int j = 4; j >=  i + 1; j--){
      if(d[j] - d[i] > k){
        cout << ":(" << endl;
        exit(0);
      }
    }
  }

  cout << "Yay!" << endl;
  return 0;
}


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

int min(int a, int b){
	return a <= b ? a : b;
}

int main(){
	int N, i;
	scanf("%d", &N);
	char *S = (char *)malloc(sizeof(char) * (N + 2));
	scanf("%s", &S[1]);
	int *A = (int *)malloc(sizeof(int) * (N + 1));
	int *B = (int *)malloc(sizeof(int) * (N + 1));
	A[0] = 0;
	B[0] = 0;
	for(i = 1; i <= N; i++){
		A[i] = A[i - 1];
		B[i] = B[i - 1];
		if(S[i] == '#'){
			A[i]++;
		}
		else{
			B[i]++;
		}
	}
	int ans = N;
	for(i = 0; i <= N; i++){
		ans = min(ans, A[i] + B[N] - B[i]);
	}
	printf("%d\n", ans);
	return 0;
}

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

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

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

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

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

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

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

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

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

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        n: usize,
        _t: usize,
        a: [i32; n],
    }
    let mut mia = std::i32::MAX;
    let mut income = 0;
    let mut ans = 0;
    for i in 0..n {
        if mia > a[i] {
            mia = a[i];
        }
        if income < a[i] - mia {
            income = a[i] - mia;
            ans = 1;
        } else if income == a[i] - mia {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	int a = (N-1) / 2; 
	int M; 
	if(N % 2 == 0) M = 2 * a * (a + 1); 
	else M = 2 * a * a; 
	vector<pair<int, int>> E; 
	E.push_back(make_pair(2, 3)); 
	E.push_back(make_pair(1, 3)); 
	E.push_back(make_pair(0, 2)); 
	E.push_back(make_pair(0, 1)); 
	for(int i = 4; i <= N; i++){
		if(i % 2 == 0){
			for(int j = 0; j < E.size(); j++){
				E[j].first ++; 
				E[j].second ++; 
			}
		}
		if(i % 2 == 1){
			for(int j = 1; j < i; j++){
				E.push_back(make_pair(0, j)); 
				E.push_back(make_pair(i, j)); 
			}
		}
	}
	cout << M << endl; 
	for(int i = 0; i < E.size(); i++){
		if(E[i].first > 0 && E[i].second > 0){
			cout << E[i].first << " " << E[i].second << endl; 
		}
	}
}

Measured memory_bytes: 384
# coding: utf-8

nm = gets.chomp.split()
n = nm[0].to_i
m = nm[1].to_i
si = Array.new(n)
for i in 0..n-2
  si[i] = gets.chomp.to_i
end
sum_ary = [0]
for i in 0..n-2
  sum_ary.push(sum_ary[i]+si[i])
end

#puts  "#{1}:#{sum_ary} "

  
place =0
sum =0
before = 0
for i in 0..m-1
 # puts "?????¨??????:?????´???#{place}"
  t = gets.chomp.to_i

  before = place
  if place + t > n-1
    place = 100
  elsif place + t < 0
    place = 0
  else
    place += t
  end
  
    #puts "?§???????:?????´???#{place}"
  sub = sum_ary[place] - sum_ary[before]
 
  if sub <0
    sub =  sub * (-1)
  end
  sum += sub
 # puts "?§?????????¢#{sub},????§?????????¢#{sum}"
end

puts sum%100000

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 100;

int N, M, Nr[MAX_N];
ll Sum[MAX_N * 2], Slope[MAX_N * 2], SlopeC[MAX_N * 2];
ll Ans[MAX_N];
int main() {
	cin >> N >> M;
	for(int i=0; i<N; i++) scanf("%d", &Nr[i]);
	for(int i=0; i<N-1; i++) {
		int l = Nr[i], r = Nr[i+1];
		if(r < l) r += M;
		Slope[r]++; Slope[l]--; SlopeC[l] += r-l;
		Sum[l+M] += r-l; Sum[r] -= r-l;
	}
	ll plus = 0;
	for(int i=2*M; i>=1; i--) {
		Sum[i] += Sum[i+1];
		Slope[i] += Slope[i+1];
		plus += Slope[i];
		plus -= SlopeC[i];
		Ans[(i-1)%M] += Sum[i] + plus;
	}
	ll ans = LINF;
	for(int i=0; i<M; i++) ans = min(ans, Ans[i]);
	printf("%lld\n", ans);
	return 0;
}


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

using namespace std;
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; scanf("%d", &n);
    int a[n], m[n];
    m[0]=0;
    for (int i=0; i<n; ++i){
        scanf("%d", a+i);
        m[0] += i&1 ? -a[i] : a[i];
    }
    for(int i=1; i<n; ++i){
        m[i] = 2*(a[i-1] - m[i-1]/2);
    }
    for (auto i : m) printf("%d ", i);
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;

int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  string a,b,c,d;
  rep(i,ty-sy){a+="U";c+="D";}
  rep(i,tx-sx){b+="R";d+="L";}
  cout<<a<<b<<c<<d<<"L"<<a<<"U"<<b<<"RDR"<<c<<"D"<<d<<"L"<<"U"<<endl;
  return 0;
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main(){
      int r,g,b;
      cin >> r >> g >> b;
      if((r*100+g*10+b)%4 == 0) cout << "YES" << endl;
      else cout << "NO" << endl;
      return 0;
    }

Measured memory_bytes: 256
s=input()
a=int(s[:2])
b=int(s[2:])
if (1<=a<=12) and (1<=b<=12):
  print('AMBIGUOUS')
elif (1<=a<=12) and (b==0 or 12<b):
      print('MMYY')
elif (1<=b<=12) and (a==0 or 12<a):
      print('YYMM')
else:
      print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n),q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> perm(n);
    rep(i,n) perm[i] = i+1;

    int cnt = 0;
    int a,b;
    do {
        cnt++;
        bool is_a = true, is_b = true;
        rep(i, n) if(p[i] != perm[i]) {is_a = false;break;}
        if(is_a) a = cnt;
        rep(i, n) if(q[i] != perm[i]) {is_b = false;break;}
        if(is_b) b = cnt;
    } while(next_permutation(perm.begin(), perm.end()));
    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

if(A == B):
    print(0)
    exit()

ans = sum(A)
dis = 10**10
for a, b in zip(A, B):
    if a > b:
        dis = min(dis, b)
print(ans - dis)


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

int N,M,S,G1,G2;
int d[110][110] = {};
int inf = 1e8;

int main(){
    while(cin >> N >> M >> S >> G1 >> G2 && N>0){
        int b1,b2,c;
        for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) if(i!=j) d[i][j] = inf;
        for(int i=0;i<M;i++){
            cin >> b1 >> b2 >> c;
            d[b1][b2] = c;
        }
        for(int k=1;k<=N;k++){
            for(int i=1;i<=N;i++){
                for(int j=1;j<=N;j++){
                    d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
                }
            }
        }
        int ans = inf;
        for(int i=1;i<=N;i++){
            ans = min(ans,d[S][i]+d[i][G1]+d[i][G2]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3128
# -*- coding: utf-8 -*-
N = int(input())
T, A = map(int, input().split())
Hs = list(map(int, input().split()))
hikaku = 1000000

result = 0

for i in range(len(Hs)):
    temp = T - (Hs[i] * 0.006)
    sa = abs(temp - A)
    if sa < hikaku:
        hikaku = sa
        result = i + 1

print(result)



Measured memory_bytes: 3060
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

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

signed main(void) {
	string a,b,c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b << endl;
}

Measured memory_bytes: 256
letters = input()
while True:
    not_equal = 0
    length = len(letters)
    letters = letters[:length-1]
    if len(letters) % 2 != 0:
        continue

    if int(len(letters)) % 2 == 0:
        half = int(len(letters)/2 -1)
    else:
        half = int((len(letters)-1)/2)
    i = 0
    while i <= half:
        if letters[i] != letters[i + half + 1]:
            not_equal = 1
            break
        i += 1

    if not_equal == 0:
        print(len(letters))
        break


Measured memory_bytes: 3064
#include <stdlib.h>
#include <stdio.h>
int main(){
  int n,a,b;
  if(scanf("%d %d %d", &n, &a, &b)){

  }else{

  }
  if((a * n) < b){
    printf("%d", a * n);
  }else{
    printf("%d", b);
  }
  return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		//?????£?????????
		int a = 0;
		int b = 0;

		String strInput = null;

		try {
			//??\????????????????????????
			BufferedReader strLine = new BufferedReader(new InputStreamReader(System.in));
			strInput = strLine.readLine();

			String[] strNumList = strInput.split(" ");

			a = Integer.parseInt(strNumList[0]);
			b = Integer.parseInt(strNumList[1]);

			//??\?????°???????????§??????
			if (1 <= a && a <= 100) {

				if (1 <= b && b <= 100) {

					//???????????????
					System.out.println(a * b + " " + (a + b + a + b));
				}
				//??¨???????????§????????¨
				/*else{
					System.out.println("b = ERROR");
				}*/
			}
			/*else{
				System.out.println("a = ERROR");
			}*/

		} catch (IOException e) {
			System.out.println(e);
		}catch (NumberFormatException e2) {
			System.out.println(e2);
		}
	}

}

Measured memory_bytes: 24076
from collections import deque

N = int(input())

node = [[] for _ in range(N + 1)]

for u, v, w in [map(int, input().split()) for _ in range(N - 1)]:
    node[u].append((v, w % 2 == 0))
    node[v].append((u, w % 2 == 0))


color = [-1] * (N + 1)
Q = deque()
for n, p in node[1]:
    Q.append((n, p, 1))

color[1] = 0

while Q:
    a, b, cur = Q.popleft()
    if b:
        color[a] = color[cur]
    else:
        color[a] = 1 - color[cur]

    for n, p in node[a]:
        if color[n] == -1:
            Q.append((n, p, a))

print(*color[1:], sep="\n")



Measured memory_bytes: 113184
#include<iostream>
using namespace std;
int main()
{
    string N;
    cin >> N;
    int length = N.size();
    for(int i = 0; i < length; ++i){
        if ( N[i] == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define fo(i,ini,n) for(int i=ini;i<n;i++)
#define rfo(i,ini,n) for(int i=ini;i>=n;i--)
int const inf=1e9+7;
typedef long long ll;

int main(){
	int t=1;
	while(t--){
		ll n,W,v,w;
		cin>>n>>W;
		vector<ll>dp(W+1,0);
		fo(i,0,n){
			cin>>w>>v;
			rfo(j,W-w,0){
				dp[j+w]=max(dp[j+w],dp[j]+v);
			}
		}
		ll ans=0;
		for(ll val:dp){

		ans=max(val,ans);
	}
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 4048
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
const int INF = 1e9 + 5;
int main() {
    int n;
    cin >> n;
    int h[n];
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j : {i + 1, i + 2}) {
            if (j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        } 
    }

    /*
    for (auto x : dp) {
        cerr << x << " ";
    } cerr << endl;
    */

    cout << dp[n -1] << endl;

    return 0;
}


Measured memory_bytes: 4056
l, r = gets.split.map(&:to_i)

min_diff = l * r

[[l, r], [r, l]].each do |pair|
  w, h = pair
  1.upto(w) do |left_w|
    # 1 column/2 columns
    right_w = w - left_w
    top_h = h / 2
    bottom_h = h - top_h


    ss = [ left_w * h, 
      right_w * top_h,
      right_w * bottom_h]
    
    diff = ss.max - ss.min
    min_diff = diff if min_diff > diff
    
    # 3 columns
    mid_w = (w - left_w) / 2
    right_w = w - left_w - mid_w
    ss = [ left_w * h, mid_w * h, right_w * h]
    diff = ss.max - ss.min
    min_diff = diff if min_diff > diff

  end
end

  # p [[left_w, h], [right_w, top_h], [right_w, bottom_h] ]

puts min_diff



Measured memory_bytes: 1788
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,x,t; cin >> n >> x >> t;
    ll r = (n + x  - 1) / x;
    cout << r * t << "\n";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////
 
void solve(){
    ll n,k;
    cin >> n >> k;
    Vi a(n);
    rp(i,n) cin >> a[i];
    ll mid, ok = 1000000002, ng = 0;
    while(abs(ok-ng)>1){
        mid = (ok+ng)/2;
        ll ctr=0;
        rp(i,n) ctr+=(a[i]-1)/mid;
        if(ctr<=k)ok = mid;
        else ng = mid;
    }//midではなくokを使わないとバグる!
    print(ok);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 4748
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>

using namespace std;

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

#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
#define MOD 1000000007ll

template<class A, class B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<class A, class B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcount((unsigned int)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll A, P; cin >> A >> P;
    P += A*3;
    cout << P / 2 << endl;
    return 0;
}


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

const int INF = 1e9+7;

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

    int n,k;
	cin>>n>>k;

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

	vector<int> dp(n,INF);
	dp[0] = 0;
	//dp[i] is min cost to reach i 

	for(int i=1;i<n;i++){
		for(int j=i-k;j<i;j++){
			if(j>=0){
				dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));			
			}
		}
	}

	cout<<dp[n-1]<<"\n";

	return 0;
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    rep(i, h) {
        string w;
        cin >> w;
        cout << w << endl;
        cout << w << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int A, B, C, X, Y;
  int ans[2];
    cin >> A>> B>> C>> X>> Y;
  
    int tmp = 0;
    if (X > Y){
        ans[0] = (X - Y)*A;
        ans[1] = (X *2)*C;
        X = X - (X - Y);
    } else if (Y > X) {
        ans[0] = (Y - X)*B;
        ans[1] = (Y *2)*C;
        Y = Y - (Y - X);
    } else {
        ans[1] = (Y *2)*C;
    }
    if(X!=0 && Y!=0) {
        int CM = C * (X * 2);
        int ABM = (A + B) * X ;
        if (CM > ABM) ans[0] += ABM;
        else ans[0] += CM;
    }
    
    if (ans[0] > ans[1])
        cout << ans[1]<< endl;
    else 
        cout << ans[0] << endl;
    
    
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for(auto& e : h) {
        cin >> e;
    }
    int ans = 0;
    for(int i=0; i<n; i++) {
        bool see = true;
        for(int j=i; j>=0; j--) {
            if(h[j] > h[i]) see = false;
        }
        if (see) ans++; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a, b = map(str, input().split())
a_list =[]
b_list =[]

for i in range(int(b)):
   a_list.append(a)

for i in range(int(a)):
   b_list.append(b)    

map_result = map(str, a_list)
result_a = ''.join(map_result)
map_result = map(str, b_list)
result_b = ''.join(map_result)

sorted_list = sorted([result_a,result_b])
print(sorted_list[0])


Measured memory_bytes: 3316
# -*- coding: utf-8 -*-
from itertools import groupby
N, K = map(int,input().split())
S = input()
L = []
for i in range(len(S)):
  L.append(S[i])
sum = 0
for key, value in groupby(L):
    sum += len(list(value))-1

print(min(N-1,sum+K*2))

Measured memory_bytes: 4724
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  double L;
  cin >> L;
  cout << fixed << setprecision(9) << L * L * L / 27 << endl;
}

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

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> C(H);
    rep(i, H) cin >> C.at(i);
    int ans = 0;
    rep(i, 1<<H){
        rep(j, 1<<W) {
        int cnt = 0;
            rep(m, H){
                rep(n, W){
                    if(i>>m&1) continue;
                    if(j>>n&1) continue;
                    if(C[m][n] == '#') cnt++;
                }
            }
        if (cnt == K) ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define endl "\n"
	#define space " "
	#define ll long long int
	#define vl vector<ll>
	#define vvl vector < vll >
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define vpl vector < pll >
	#define mod 1000000007
	#define pi 3.1415926535897932384626433
	#define inf 1000000000000000001;
	#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y) 
	#define mem(a,val) memset(a,val,sizeof(a))
	#define pb push_back
	#define f first
	#define s second
	
	void solve()
	{
		char a; cin>>a;
		if(int(a)<=90) cout<<"A";
		else cout<<"a";
	}

	signed main()
	{

	fast;
	#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
     #endif

	ll T=1;
	// cin>>T;
	while(T--)
	{
		solve();
	}
	return 0;
	}


Measured memory_bytes: 3644
//abc129_e.cpp
//Tue Oct  1 21:21:23 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;
ll MOD = 1000000007;

int main(){
	string l;
	cin >> l;


	ll dp[l.length()][2];
	dp[0][1] = 1;
	dp[0][0] = 2;
	for (ll i=1;i<l.length();i++){
		if (l[i]=='0'){
			dp[i][1] = dp[i-1][1]*3%MOD;
			dp[i][0] = dp[i-1][0]*1%MOD;
		}else {
			dp[i][1] = (dp[i-1][1]*3%MOD+dp[i-1][0]*1%MOD)%MOD;
			dp[i][0] = dp[i-1][0]*2%MOD;
		}
	}

	ll ans = (dp[l.length()-1][0]%MOD+dp[l.length()-1][1]%MOD)%MOD;

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
"""
Created on Wed May 27 16:14:37 2020

@author: naoki
"""

H,W = map(int,input().split()) # 行の数Hと列の数Wを入力
moji = [input() for i in range(H)] # H*Wの文字列を入力
s = [str(0) for i in range(W+2)]
string1 = "".join(s) # 全て0で長さW+２の文字列を作成
string = [string1]
for i in range(H):
    moji[i] ="0" + moji[i] + "0" # 端の部分を0で埋める
moji = string + moji + string # ０行目に0のみの文字列を追加する 最後の行にも0のみの文字列を追加する
dx = [-1,-1,-1,0,0,1,1,1]
dy = [-1,0,1,-1,1,-1,0,1] # 8方位の配列を用意
count = [[0 for i in range(W+2)] for j in range(H+2)] 
new_list2 = [[str(0) for i in range(W+2)] for j in range(H+2)]
for i in range(1,H+1): # 全て０で埋められていない行のみを評価
    for j in range(1,W+1): # 最初から０でないもののみを評価
        if moji[i][j] == ".": # .の場合には以下の処理を実行
            for k in range(8):
                if moji[i+dy[k]][j+dx[k]] ==  "#": # "#"の個数によって加算する
                    count[i][j]+=1
         # "#"の場合には処理を実行しない 

for i in range(1,H+1):
    for j in range(1,W+1):
        new_list = list(moji[i]) # i行目の文字列を一旦リストに変換し該当箇所を数字に変換
        if new_list[j] == ".": # j文字目が　.ならば数字を代入  
           new_list2[i][j] = str(count[i][j])    
        else: # j文字目が # ならばそのまま代入
           new_list2[i][j] = str("#") 
    new_string = "".join(new_list2[i])
    print(new_string[1:W+1])       

Measured memory_bytes: 3188
n= int(input())
ans=0
nn = int((n-1)//2)+1
for i in range(2,nn):
    for j in range(i,nn):
        if i*j>n-1:
            break
        else:
            if i==j:
                ans += 1
            else:
                ans+=2
# a or b =1
ans += (n-1-1)*2
print(ans+1)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include <math.h>
#include <limits.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

int main(void){
  long long int n,z,w;
  long long int a[n];
  cin >> n >> z >> w;
  long long int maxA = 0;
  long long int lastA = w;
  long long int an1 = 0;
  rep(i,n){
    cin >> lastA;
    maxA = max(maxA,lastA);
    if(i==n-2){
      an1 = lastA;
    }
  } 
  if(lastA==maxA){
    //cout << abs(maxA-w) << endl;
  }
  else{
    //cout << abs(maxA-lastA) << endl;
  }
  if(n>=2)
  	cout << max(abs(lastA-w),abs(lastA-an1)) << endl;
  else
    cout << abs(lastA-w) << endl;
  return 0;
}




Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		String S = sc.next();
		int a = 0; int b = 0; int c = 0;
		for(int i = 0; i < 3; i++){
			char cc = S.charAt(i);
			if(cc == 'a') a++;
			if(cc == 'b') b++;
			if(cc == 'c') c++;
			
		}
		
		System.out.println((a == b && b == c)?"Yes":"No");
	}
}

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

int main(){
	int point = 0;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++) point += "gp"[i & 1] == s[i] ? 0 : "gp"[i & 1] > s[i] ? 1 : -1;
	cout << point << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B&&B==C&&A%2==0){
    cout << -1 << endl;
    return 0;
  }
  else{
    int i = 0;
    while(A%2 == 0&& B%2 == 0&& C%2 == 0){
    int a = A;
    int b = B;
    int c = C;
      A = (b+c)/2;
      B = (a+c)/2;
      C = (a+b)/2;
      i++;
    }
    cout << i << endl;
    return 0;
  }
    
}

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

const int N = 500005;
int n, m;
int c[N];
int maxn;
int sum = 0;
int ans[N];
 
int cnt[N];
 
struct query {
  int l, r, id;
  bool operator<(const query &x) const {
    if (l / maxn != x.l / maxn) return l < x.l;
    return (l / maxn) & 1 ? r < x.r : r > x.r;
  }
} a[N];
 
inline void add(int i){
	if(cnt[i]==0){
		sum +=1;
	}
	cnt[i]++;
}
inline void del(int i){
	if(cnt[i]==1){
		sum -= 1;
	}
	cnt[i]--;
}
 
 
int main (){
	#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	IOS
	cin >> n >> m;
	for(long long i = 1; i <= n; i++) {
		cin >> c[i];
	}
	maxn = sqrt(n);
	rep(i, m) {
		cin >> a[i].l >> a[i].r;
		a[i].id = i;
	}
	sort(a,a+m);
	for(int i = 0,l=1,r=0; i<m; i++){
		while(r > a[i].r) del(c[r--]);
		while(r < a[i].r) add(c[++r]);
		while (l > a[i].l) add(c[--l]);
		while (l < a[i].l) del(c[l++]);
 
	    ans[a[i].id] = sum;
	}
	for(int i = 0; i < m; i++){
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 15460
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXN = 100000 + 5;
int n, h[MAXN], f[MAXN];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", h + i);
  f[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) f[i] = min(f[i - 2] + abs(h[i] - h[i - 2]), 
                                        f[i - 1] + abs(h[i] - h[i - 1]));
  printf("%d", f[n - 1]);
  return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>

void initilize(int a[9][9]){
	int i, j;
	for(i = 0; i < 9; i++){
		for(j = 0; j < 9; j++){
			a[ i ][ j ] = ( i + 1 )*( j + 1 );
		}
	}
}

void takahashi(int a[9][9], int N){
	int i, j;
	char *b = {"No\n"};
	for(i = 0; i < 9; i ++){
		for(j = 0; j < 9; j++){
			if(a[ i ][ j ] == N){
				b = "Yes\n";
			}
		}
	}
	printf("%s", b);
}

int main(){
	int a[9][9];
	initilize(a);
	int N;
	scanf("%d", &N);
	takahashi(a, N);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
int n;
int dp[2][N];
int arr[105];

int add(int a, int b)
{
  return (((a + mod) % mod) + ((b + mod) % mod)) % mod;
}

void solve()
{
  for(int i = 0; i < N; i++)
    dp[n & 1][i] = 1;
  for(int i = n - 1; i >= 0; i--)
  {
    for(int j = 0; j < N; j++)
    {
      int st = j, en = j - min(arr[i], j);
      if(en)
        dp[i & 1][j] =  add(dp[(i + 1) & 1][st], -dp[(i + 1) & 1][en - 1]);
      else
        dp[(i & 1) & 1][j] = dp[(i + 1) & 1][st];

      if(j)
        dp[i & 1][j] = add(dp[i & 1][j], dp[i & 1][j - 1]);
    }
  }
}

int main()
{
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int k;
  cin >> n >> k;
  for(int i = 0; i < n; i++)
    cin >> arr[i];
  solve();
  if(k)
    cout << add(dp[0][k], -dp[0][k - 1]);
  else
    cout << dp[0][0];
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

const int INF = 10000;

void p(vector<int> v){
	for(int i = 0; i < v.size(); i++){
//		cout << v[i] << ' ';
		printf("%6d", v[i]);
	}
	cout << endl;
}

void p(vector<vector<int> > v){
	for(int i = 0; i < v.size(); i++){
		p(v[i]);
	}
}

int main(){
	int n, m;

	cin >> n >> m;

	vector<vector<int> > road(++n);
	for(int i = 0; i < n; i++){
		road[i].resize(n, INF);
	}

	for(int i = 0; i < m; i++){
		int a, b, c, d;
		scanf("%d,%d,%d,%d", &a, &b, &c, &d);
		road[a][b] = c;
		road[b][a] = d;
	}

	for(int i = 1; i < n; i++){
		for(int j = 1; j < n; j++){
			for(int k = 1; k < n; k++){
				road[j][k] = min(road[j][k], road[j][i] + road[i][k]);
			}
		}
	}

//	p(road);

	int x1, x2, y1, y2;
	scanf("%d,%d,%d,%d", &x1, &x2, &y1, &y2);

	int reward = y1 - (y2 + road[x1][x2] + road[x2][x1]);

	cout << reward << endl;

	return 0;
}

Measured memory_bytes: 1244
'''
Introduction to Heuristics Contest
A - AtCoder Contest Scheduling
'''

def main():
    # 本番テストケースは365
    D = int(input())

    # コンテストタイプごとの満足度の下がりやすさ
    C = list(map(int, input().split()))

    # 満足度row日目にコンテストcolタイプを開催したときの満足度の増加
    S = []
    for _ in range(D):
        sday = list(map(int, input().split()))
        S.append(sday)

    ''' とりあえず順番にやってくだけ
    for i in range(D):
        tmp = i % 26 + 1
        print(tmp)
    '''

    ''' 満足度Siの最高を選ぶ、満足度低下するCは未考慮 '''
    for i in range(D):
        high = S[i].index(max(S[i])) + 1
        print(high)

main()

#def intro_heuristics_b():

#def intro_heuristics_c():


Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
#define itn int

int main(void){
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i = 0;i < n;i++)cin >> h[i];
    sort(h,h+n);
    
    int ans = h[k-1] - h[0];
    for(int i = 1;i+(k-1) < n;i++)ans = min(ans,h[(k-1)+i]-h[i]);
    
    cout << ans << endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    int ans=0;;
    rep(i,n){
        rep(j,30){
            if(a[i]%2==0){
                ans+=1;
                a[i]/=2;
            }
            else break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <functional>

using namespace std;

int main() {
    int n,a,b,c,d;

    cin >> n;

    a = n / 1000;

    b = (n - a * 1000) / 100;

    c = (n - a * 1000 - b * 100) / 10;

    d = n % 10;

    if(a + b + c + d == 7){
        cout << a << '+' << b << '+' << c << '+' << d << "=7" << endl;
    }
    else if(a + b + c - d == 7){
        cout << a << '+' << b << '+' << c << '-' << d << "=7" << endl;
    }
    else if(a + b - c + d == 7){
        cout << a << '+' << b << '-' << c << '+' << d << "=7" << endl;
    }
    else if(a + b - c - d == 7){
        cout << a << '+' << b << '-' << c << '-' << d << "=7" << endl;
    }
    else if(a - b + c + d == 7){
        cout << a << '-' << b << '+' << c << '+' << d << "=7" << endl;
    }
    else if(a - b + c - d == 7){
        cout << a << '-' << b << '+' << c << '-' << d << "=7" << endl;
    }
    else if(a - b - c + d == 7){
        cout << a << '-' << b << '-' << c << '+' << d << "=7" << endl;
    }
    else if(a - b - c - d == 7){
        cout << a << '-' << b << '-' << c << '-' << d << "=7" << endl;
    }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}

int main(){
    int H, W; cin >> H >> W;
    int N; cin >> N;
    int x, y; cin >> x >> y; x--, y--;
    string S, T;
    cin >> S;
    cin >> T;
    int left = 0;
    int right = W-1;
    int up = 0;
    int down = H-1;
    bool f = true;
    for(int i=N-1;i>=0;--i) {
        if(T[i]=='L' && right+1<W) right++;
        if(T[i]=='R' && left-1>=0) left--;
        if(S[i]=='L') left++;
        if(S[i]=='R') right--;
        if(left>right) {
            f = false;
            break;
        }
    }
    for(int i=N-1;i>=0;--i) {
        if(T[i]=='U' && down+1<H) down++;
        if(T[i]=='D' && up-1>=0) up--;
        if(S[i]=='U') up++;
        if(S[i]=='D') down--;
        if(down<up) {
            f = false;
            break; }
    }
    if(down<x || x<up || left>y || y>right) f = false;
  //cout << up << " " << down << " " << left << " " << right << endl;
    cout << (f ? "YES" : "NO") << endl;
    return 0;
}

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

using namespace std;

int a[25];
int b[25];
int c[25];

main() {
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> b[i];
    for (int i = 1; i < n; ++i) cin >> c[i];
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += b[a[i]];
        if (i != 1 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1]];
    }
    cout << ans << '\n';
    return 0;
}



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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct scc{
    vector<vector<int>> graph,rgraph;
    vector<bool> done;
    vector<int> vs,cmp;
    const int size;
    int cnt;
    scc(vector<vector<int>> &graph):size(graph.size()),graph(graph),rgraph(graph.size()),done(graph.size()),cmp(graph.size()),cnt(0){
        //rep(v,0,size){
        for(int v=0; v<size; ++v){
            for(int u:graph[v]) rgraph[u].push_back(v);
        }
        //rep(v,0,size)
        for(int v=0; v<size; ++v){
            if(done[v]) continue;
            dfs(v);
        }
        fill(done.begin(),done.end(),false);
        for(int i=vs.size()-1; i>=0; --i){
            if(done[vs[i]]) continue;
            rdfs(vs[i],++cnt);
        }
    }
    void dfs(int v){
        if(done[v]) return;
        done[v]=true;
        for(int u:graph[v]) dfs(u);
        vs.push_back(v);
    }
    void rdfs(int v,int k){
        if(done[v]) return;
        done[v]=true;
        cmp[v]=k;
        for(int u:rgraph[v]) rdfs(u,k);
    }
};

void solve(){
    int v,e;
    cin >> v >> e;
    vector<vector<int>> graph(v);
    rep(i,0,e){
        int s,t;
        cin >> s >> t;
        graph[s].push_back(t);
    }
    scc scc_(graph);

    int q;
    cin >> q;
    rep(i,0,q){
        int u,v;
        cin >> u >> v;
        if(scc_.cmp[u]==scc_.cmp[v]) cout << 1 << endl;
        else cout << 0 << endl;
    }
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}

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

int main(){
    int n; cin>>n;
    string s;
    map<string, int> ms;
    
    rep(i,n){
        cin>>s;
        sort(s.begin(), s.end());
        ms[s]++;
    }
    
    ll ans = 0;
    
    for(auto p: ms){
        ll len = p.second;
        ans += len*(len-1)/2;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 11136