akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
const int MaxN = 1e6 + 10;
int S;
int main() {
	int X = 0, Y = 0;
	//getchar();
	char Order[MaxN];
	scanf("%s", Order);
	int Len = strlen(Order);
	int Cnt1 = 0, Cnt2 = 0, Cnt3 = 0, Cnt4 = 0;
	for(int i = 0; i < Len; i++) {
		if(Order[i] == 'N') Cnt1 += 1;
		if(Order[i] == 'S') Cnt2 += 1;
		if(Order[i] == 'W') Cnt3 += 1;
		if(Order[i] == 'E') Cnt4 += 1;
	}
	if(Cnt1 + Cnt2 == 1 || Cnt3 + Cnt4 == 1 || (Cnt1 > 0 && Cnt2 == 0) || (Cnt2 > 0 && Cnt1 == 0) || (Cnt3 > 0 && Cnt4 == 0) || (Cnt4 > 0 && Cnt3 == 0)) puts("No");
	else puts("Yes");
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,d=INT_MIN,x=0;
string s;
cin>>n>>s;
for(int i=0;i<n;i++){
	if(s[i]=='I') x++;
	else x--;
	if(x>d) d=x;
}
if(d<0) cout<<0<<endl;
else cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

ll A[210], mat[210];
int f[210];

int main() {
	int T;
	cin >> T;
	for(int t=0; t<T; ++t){
		int N;
		string S;
		cin >> N;
		for(int i=0; i<N; ++i){
			cin >> A[i];
		}
		cin >> S;
		for(int i=0; i<N; ++i) mat[i]=0, f[i]=-1;
		int now=0;
		bool flag=true;
		for(int i=N-1; i>=0; --i){
			for(int j=0; j<now; ++j){
				if(A[i]&((ll) 1<<f[j])) A[i] ^= mat[j];
			}
			if(S[i]=='0'){
				for(int d=0; d<60; ++d){
					if(A[i]&((ll) 1<<d)){
						for(int j=0; j<now; ++j){
							if(mat[j]&((ll) 1<<d)) mat[j] ^= A[i];
						}
						mat[now]=A[i];
						f[now]=d;
						++now;
						break;
					}
				}
			}
			else{
				if(A[i]>0){
					flag=false;
					break;
				}
			}
		}
		if(flag) cout << 0 << endl;
		else cout << 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int d;
  cin >> d;
  int n = 25-d;
  cout << "Christmas" << " ";
  REP(i,n){
    cout << "Eve" << " ";
  }
  cout << endl;
  return 0;
}


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

int main()
{
	int x, y;
	cin >> x >> y;

	int a[][12] = { { 1,3,5,7,8,10,12 }, { 4,6,9,11 }, { 2 } };

	bool xFlag = false;
	bool yFlag = false;
	for (int i = 0; i < 3; i++) {
		xFlag = false;
		yFlag = false;
		for (int d : a[i]) {
			if (x == d) {
				xFlag = true;
			}
			if (y == d) {
				yFlag = true;
			}
		}
		if (xFlag && yFlag) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

void solve(){
	int x;
	cin >> x;
	cout << !x << "\n";
}

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

Measured memory_bytes: 3636
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    for (i, c) in s.chars().enumerate() {
        if i % 2 == 0 {
            print!("{}", c);
        }
    }
    println!();
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std;

const int mod=1e6+3;
int x,d,n,T,fac[mod+10];

int ksm(int a,int b){
	int res=1;
	for (; b; a=1ll*a*a%mod,b>>=1)
		if (b & 1) res=1ll*res*a%mod;
	return res;
}

int main(){
	fac[0]=1; rep(i,1,mod-1) fac[i]=1ll*fac[i-1]*i%mod;
	for (scanf("%d",&T); T--; ){
		scanf("%d%d%d",&x,&d,&n);
		if (!d){ printf("%d\n",ksm(x,n)); continue; }
		x=1ll*x*ksm(d,mod-2)%mod;
		if (!x || x+n-1>=mod) puts("0");
			else printf("%lld\n",1ll*fac[x+n-1]*ksm(fac[x-1],mod-2)%mod*ksm(d,n)%mod);
	}
	return 0;
}

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

using namespace std;


typedef long long LL;


inline LL gcd(LL a, LL b) { return !b ? a : gcd(b, a % b); }


int main()
{
	LL A, B;
	cin >> A >> B;
	
	int cnt = 0;
	
	LL x = gcd(A, B);
	if (x == 1) { puts("1"); return 0; }
	for (LL i = 2; i * i <= x; i++)
	{
		if (x % i == 0)
		{
			while (x % i == 0) x /= i;
			cnt++;
		}
	}
	if (x != 1) cnt++;
	
	printf("%d\n", cnt + 1);
	
	return 0;
}

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

int main(){
  long int N;
  long int city[5];
  long int min = 0;

  cin >> N;
  for(int i=0; i<5; i++){
    cin >> city[i];
    if(i==0 || min > city[i]){
      min = city[i];
    }
  }

  long int ans;
  if(N%min == 0){
    ans = N / min +4;
  } else {
    ans = N / min +5;
  }

  printf("%ld\n", ans);
}


Measured memory_bytes: 256
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<char> Vc;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<char>> VVc;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define rEach(i, mp) for (auto i = mp.rbegin(); i != mp.rend(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgset(st) cerr << #st << ":"<<endl; for (auto i = st.begin(); i != st.end(); ++i) { cerr << *i <<" ";}cerr<<endl;
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#else
#define dbg(...)
#define dbgmap(...)
#define dbgset(...)
#define dbgarr(...)
#define dbgdp(...)
#endif
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int solve(){
    string s;
    cin>>s;
    cout<<"ABC"<<s<<endl;
    return  0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);
    solve();
}


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

using namespace std;

typedef pair<int,int> P;
const int dx[] = {-1,0,0,1};
const int dy[] = {0,-1,1,0};

int main(){
  int Tc,M,N;

  cin >> Tc;
  while(Tc--){
    vector<P> vec;
    for(int i = 0 ; i < 4 ; i++){
      vec.push_back(P(dx[i],dy[i]));
    }
    cin >> M >> N;
    vec.push_back(P(M,N));
    vec.push_back(P(-N,M));
    vec.push_back(P(-M,-N));
    vec.push_back(P(N,-M));
    int cnt = 0;

    for(int m = -100 ; m <= 100 ; m++){
      for(int n = -100 ; n <= 100 ; n++){
        if(m == n && m == 0) continue;
        int X = m*m + n*n;
        if(!((m*M+n*N) % X == 0 && (m*N-n*M)%X == 0)) continue;
        int Y = (m*M+n*N)/X;
        int Z = (m*N-n*M)/X;
        if((M*M+N*N)/X == Y*Y+Z*Z){
          bool ok = true;
          for(int i = 0 ; i < 8 ; i++){
            if(vec[i].first == m && vec[i].second == n){
              ok = false;
              break;
            }
          }
          if(ok) cnt++;
        }
      }
    }
   
    if(cnt == 0) cout << "P" << endl;
    else cout << "C" << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    println!("{}", [a + b, a - b, a * b].iter().max().unwrap());
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
import java.util.*;
public class Main {
    private static int[] move = {1, -1, 4, -4};
    private static Map<String, Integer> map = new HashMap<>();
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        dsf();
        while (in.hasNext()) {
            String str = in.nextLine();
            str = str.replaceAll("\\s+", "");
            System.out.println(map.get(str));
        }
    }
    private static void dsf() {
        Queue<String> q = new LinkedList<>();
        map.put("01234567", 0);
        q.add("01234567");
        while (!q.isEmpty()) {
            String init = q.peek();
            q.poll();
            int p = 0;
            for (int i = 0; i < 8; i++) {
                if (init.charAt(i) == '0') {
                    p = i;
                    break;
                }
            }
            for (int i = 0; i < 4; i++) {
                int dx = p + move[i];   // ?????¢????¬??????????
                if (0 <= dx && dx < 8 &&
                        !(p == 3 && i == 0) && // ??????????????????????§?
                        !(p == 4 && i == 1)) { // ??????????????????????§?
                    String next = swap(init, p, dx);
                    if (!map.containsKey(next)) {
                        int val = map.get(init) + 1;
                        map.put(next, val);
                        q.add(next);
                    }
                }
            }
        }
    }
    private static String swap(String str, int init, int toChange) {
        char[] chars = str.toCharArray();
        char temp = chars[init];
        chars[init] = chars[toChange];
        chars[toChange] = temp;
        return new String(chars);
    }
}

Measured memory_bytes: 43652
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

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

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

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

  int64_t n, m;
  cin >> n >> m;

  if (n == 1 && m == 1) { cout << 1 << endl; return 0; }
  if (n == 1) { cout << m-2 << endl; return 0; }
  if (m == 1) { cout << n-2 << endl; return 0; }
  cout << (n-2)*(m-2) << endl;
  return 0;
}

Measured memory_bytes: 3620
from collections import deque


def init_tree(x, par):
    for i in range(x + 1):
        par[i] = i


def find(x, par):
    q = deque()
    q.append(x)
    while len(q) > 0:
        v = q.pop()
        if v == par[v]:
            return v
        q.append(par[v])


def union(x, y, par, rank):
    px, py = find(x, par), find(y, par)
    if px == py:
        return
    if rank[px] < rank[py]:
        par[px] = py
        return
    elif rank[px] == rank[py]:
        rank[px] += 1
    par[py] = px


n, m, k = map(int, input().split())
par = [0] * (n + 1)
rank = [0] * (n + 1)
init_tree(n, par)
eg = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    union(a, b, par, rank)
    eg[a].append(b)
    eg[b].append(a)
for _ in range(k):
    a, b = map(int, input().split())
    eg[a].append(b)
    eg[b].append(a)

xs = [0] * (n + 1)
ys = [0] * (n + 1)
for i in range(1, n + 1):
    p = find(i, par)
    xs[p] += 1
    for v in eg[i]:
        if p == find(v, par):
            ys[i] += 1

ans = [-1] * (n + 1)
for i in range(1, n + 1):
    ans[i] += xs[find(i, par)] - ys[i]
ans = [-1] * (n + 1)
for i in range(1, n + 1):
    ans[i] += xs[find(i, par)] - ys[i]
print(*ans[1:])


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

const int MAX = 100005;
int MOD = 1e9 + 7;
int N;
vector<ll> G[MAX];
vector<vector<ll>> dp(MAX, vector<ll>(2, -1)); // 0: white, 1: black

void dfs(int x) {
  dp[x][0] = 1;
  dp[x][1] = 1;
  for (auto y: G[x]) {
    if (dp[y][0] == -1) {
      dfs(y);
      dp[x][0] *= ((dp[y][0] + dp[y][1]) % MOD);
      dp[x][1] *= dp[y][0];
      dp[x][0] %= MOD;
      dp[x][1] %= MOD;
    }
  }
  return;
}

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

  cin >> N;
  for (ll i = 0; i < N - 1; i++) {
    ll x, y; cin >> x >> y;
    x--; y--;
    G[x].emplace_back(y);
    G[y].emplace_back(x);
  }
  dfs(0);
  cout << (dp[0][0] + dp[0][1]) % MOD << '\n';
  return 0;
}

Measured memory_bytes: 15360
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) {
  if (b == 0ll)
    return a;
  else

    return gcd(b, a % b);
}

int lcm(int a, int b) {
  int c = gcd(a, b);
  int d = a / c * b;



  
  return d;
}

signed main() {
  int n;
  cin >> n;
  vector<int> t(n);
  for (auto&& w : t) cin >> w;
  int ret = t[0];
  for (int i = 1; i < n; i++) {
    ret = lcm(ret, t[i]);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
//最大公約数
int gcd(int a,int b){
  int r=a%b; 
  while(r!=0){ 
    a=b; 
    b=r; 
    r=a%b; 
  }
  return b;
}

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>ball(n);
  cin>>ball[0];
  int now=ball[0];
  for(int i=1;i<n;i++){
    cin>>ball[i];
    now=gcd(now,ball[i]);
  }
  sort(ball.begin(),ball.end(),greater<int>());
  if(k%now==0&&k<=ball[0]){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())
inf = 10**9+7
maze = [list(input()) for i in range(H)]
dp = [[0 for i in range(W+1)] for j in range(H+1)]

#dp[i+1][j+1]:maze[i][j]に至るまでの方法の数
#dp[0][0] = 1
#dp[i][j] = dp[i][j-1] + dp[i-1][j]

dp[1][1] = 1
maze[0][0] = '#' #こうすると都合がいい
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1]

print(dp[H][W] % inf)

Measured memory_bytes: 166224
let n = (stdin.ReadLine() |> int)
let aArray = stdin.ReadLine().Split()|>Array.map int64
let bArray = stdin.ReadLine().Split()|>Array.map int64

let countKill (total,surplus) (aBefore,aNext,b) =
    let aBefore = min aBefore surplus
    let modu = max (aBefore + aNext - b) 0L
    let total = total + min b (aBefore + aNext) 
    total,modu

let total,_ = 
    aArray |> Array.pairwise |> Array.zip bArray 
    |>Array.map (fun (b,(a1,a2))->(a1,a2,b))
    |>Array.fold countKill (0L,aArray.[0])

stdout.WriteLine total


Measured memory_bytes: 45440
#include <stdio.h>
 
int num[45];
 
int fib(int n) {
  if ( n == 0 || n == 1)
    return num[n] = 1;
  if ( num[n] !=  -1)
    return num[n];
  return num[n] = fib(n - 1) + fib(n - 2);
}
 
int main (void)  {
  int n, i;
  for (i = 0; i < 45; i++)  
    num[i] = -1;
  scanf("%d", &n);
  printf("%d\n", fib(n));
   
  return 0;
}

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

const int maxn = 1e2 + 10;

int n, a[maxn];

long long calc(int mid)
{
  long long sum = 0;
  for (int i = 0; i < n; ++i)
    sum += 1LL * (a[i] - mid) * (a[i] - mid);
  return sum;
}

long long solve()
{
  long long ans = (long long)(1e18);

  for (int mid = -100; mid <= 100; ++mid)
    ans = min(ans, calc(mid));

  return ans;
}

int main()
{
  cin.sync_with_stdio(false);

  cin >> n;

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

  cout << solve() << '\n';

  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll r; cin >> r;
  ll D; cin >> D;
  ll x; cin >> x;
  for (ll j=0; j < 10; ++j) {
    x = r*x - D;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
char s[128];
int i, len;
scanf("%s", s);
len = strlen(s);
for(i = 1;i < len;++i)
if('A'==s[i-1]&&'C'==s[i])
{
puts("Yes"); return 0;
}
puts("No");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int m,n;
  cin >> m >> n;
  if (m == n) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3624
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]

ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]

i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())

ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]

# NG: 021, 201, 012, 0x21, 02x1
def check(c0, c1, c2, c3):
    if c0 == 1 and c1 == 2 and c2 == 0:
        return False
    if c0 == 1 and c1 == 0 and c2 == 2:
        return False
    if c0 == 2 and c1 == 1 and c2 == 0:
        return False
    if c0 == 1 and c1 == 2 and c3 == 0:
        return False
    if c0 == 1 and c2 == 2 and c3 == 0:
        return False
    return True

def main(N):
    mod = int(1e+9) + 7
    
    dp1 = [0 for _ in range(4)]
    for c0 in range(4):
        if check(c0, -1, -1, -1) == False:
            continue
        dp1[c0] = 1
    if N == 1:
        ans = 0
        for c1 in range(4):
            ans += dp1[c1]
            ans %= mod
        print(ans)
        return
    
    dp2 = [[0 for _ in range(4)] for _ in range(4)]
    for c1 in range(4):
        for c0 in range(4):
            if check(c0, c1, -1, -1) == False:
                continue
            dp2[c0][c1] += dp1[c1]
            dp2[c0][c1] %= mod
    if N == 2:
        ans = 0
        for c1 in range(4):
            for c2 in range(4):
                ans += dp2[c1][c2]
                ans %= mod
        print(ans)
        return
    
    dp3 = [[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)]
    for c1 in range(4):
        for c2 in range(4):
            for c0 in range(4):
                if check(c0, c1, c2, -1) == False:
                    continue
                dp3[c0][c1][c2] += dp2[c1][c2]
                dp3[c0][c1][c2] %= mod
    if N == 3:
        ans = 0
        for c1 in range(4):
            for c2 in range(4):
                for c3 in range(4):
                    ans += dp3[c1][c2][c3]
                    ans %= mod
        print(ans)
        return
    
    dp = [[[[0 for _ in range(4)] for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
    for c1 in range(4):
        for c2 in range(4):
            for c3 in range(4):
                dp[3][c1][c2][c3] = dp3[c1][c2][c3]
    
    for l in range(3, N):
        for c1 in range(4):
            for c2 in range(4):
                for c3 in range(4):
                    for c0 in range(4):
                        if check(c0, c1, c2, c3) == False:
                            continue
                        dp[l+1][c0][c1][c2] += dp[l][c1][c2][c3]
                        dp[l+1][c0][c1][c2] %= mod
    ans = 0
    for c1 in range(4):
        for c2 in range(4):
            for c3 in range(4):
                ans += dp[N][c1][c2][c3]
                ans %= mod
    print(ans)

main(i2n())

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int func(int a,int b,int c){
    vector<int>A={a,b,c};
    sort(A.begin(),A.end());
    return A[1];
}


int main(){
  int n;
  cin>>n;
  int a[n],cnt=0;
  for(int i=0;i<n;i++)
  cin>>a[i];
  for(int i=0;i<n-2;i++)
  if(a[i+1]==func(a[i],a[i+1],a[i+2]))
    cnt++;
  cout<<cnt;
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int h, n;
long long sum;
int main()
{
	cin>>h>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		sum+=x;
	}
	if (sum<h)	cout<<"No";
	else cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

const int N_MAX = 8;
vector<vector<int>> graph;
int n, m;


void dfs(int v, vector<bool> &used, int &res) {
    bool complete = true;

    rep(i, n) {
        if (!used[i] && i != v) complete = false;
    }

    if (complete) {
        res++;
        return;
    }

    used[v] = true;
    for (auto u: graph[v]) {
        if (used[u]) continue;
        dfs(u, used, res);
    }
    used[v] = false;
}


int main(){
    cin >> n >> m;
    graph.assign(n, vector<int>());
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<bool> used(n, false);

    int res = 0;
    dfs(0, used, res);
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Union_Find_Tree{
	public:
	vi Par;
	Union_Find_Tree(int n){
		Par=vi(n);
		for(int i=0;i<n;i++) Par[i]=i;
	}
	int Find_Par(int x){
		if(Par[x]==x) return x;
		return Par[x]=Find_Par(Par[x]);
	}
	bool Unite(int x,int y){
		x=Find_Par(x);
		y=Find_Par(y);
		if(x==y) return 0;
		Par[x]=y;
		return 1;
	}
};

int w,n;
vi a;

bool f(int x){
    vi L(n),R(n);
    int li=1,ri=1,ls=a[0],rs=a[0];
    for(int i=0;i<n;i++){
        ls-=(i?a[i-1]+x:0);
        while(li<n&&ls<w){
            ls+=x+a[li];
            li++;
        }
        rs-=(i?a[i-1]+1:0);
        while(ri<n&&rs<=w){
            rs+=1+a[ri];
            ri++;
        }
        if(rs<=w&&ri==n){
            ri++;
        }
        L[i]=li;
        R[i]=ri;
    }
	Union_Find_Tree uft(n+1);
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int p=q.front();
        q.pop();
        if(R[p]==n+1) return 1;
		int i=uft.Find_Par(L[p]);
		while(i<R[p]){
			q.push(i);
			uft.Unite(i,i+1);
			i=uft.Find_Par(i);
		}
    }
    return 0;
}

int main(){
    while(1){
        cin>>w>>n;
        if(!w) break;
        a=vi(n);
        for(int i=0;i<n;i++) cin>>a[i];
        int l=0,r=w;
        while(r-l>1){
            int m=(l+r)/2;
            if(f(m)) r=m;
            else l=m;
        }
        cout<<r<<endl;
    }
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
#define ll long long
#define MAXN 200005
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    #define int ll
    string s;
    cin>>s;
    if(s[1]=='B'){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3648
n,k=map(int,input().split())
a=list(map(int,input().split()))
mod=10**9+7
a.sort()
mx=10**5+1
fac=[0]*mx
finv=[0]*mx
inv=[0]*mx
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,mx):
  fac[i]=(fac[i-1]*i)%mod
  inv[i]=mod-(inv[mod%i]*(mod//i))%mod
  finv[i]=(finv[i-1]*inv[i])%mod
comb=lambda a,b:(fac[a]*finv[b]*finv[a-b])
minX=0
maxX=0
for i in range(n-k+1):
  minX+=a[i]*comb(n-i-1,k-1)
for i in range(k-1,n):
  maxX+=a[i]*comb(i,k-1)
print((maxX-minX)%mod)

Measured memory_bytes: 19152
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{//構造を決める
	char suit;
	int value;
};

struct Card L[MAX / 2 + 2],R[MAX / 2 + 2];

//安定したソートなのか確認するためのマージソート実装部分
void merge(struct Card A[] , int left , int mid , int right){
	int a,b,c;
	int n1 = mid - left;
	int n2 = right - mid;
	for(a = 0;a < n1;a++) L[a] = A[left + a];
	for(a = 0;a < n2;a++) R[a] = A[mid + a];
	L[n1].value = R[n2].value = SENTINEL;
	a = b = 0;
	for(c = left;c < right;c++){
		if(L[a].value <= R[b].value){
			A[c] = L[a++];
		}else{
			A[c] = R[b++];
		}
	}
}

void mergeSort(struct Card A[],int left,int right){
	int mid;
	if(left + 1 < right){
		mid = (left + right) / 2;
		mergeSort(A,left,mid);//マージソートもクイックソートも二回呼び出している
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}//ここまでが確認用のマージソート実装部分

int partition(struct Card A[],int p,int r){//クイックソートのメインの作業を行う
	int a,b;
	struct Card t,x;
	x = A[r];
	a = p-1;
	for(b=p;b<r;b++){
		if(A[b].value <= x.value){
			a++;
			t=A[a];A[a]=A[b];A[b]=t;//入れ替えを行なっている。
		}
	}
	t=A[a+1];A[a+1]=A[r];A[r]=t;
	return a+1;
}

void quickSort(struct Card A[],int p,int r){//分割したものをそれぞれクイックソートとして呼び出す
	int q;
	if(p<r){
		q = partition(A,p,r);
		quickSort(A,p,q-1);//分割しているため二回呼び出す
		quickSort(A,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable = 1;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];//トランプの文字が与えられるので頭文字だけ抽出
		A[i].value=B[i].value=v;//数値を入力
	}
	
	mergeSort(A,0,n);//マージソートには最初と最後を与える
	quickSort(B,0,n-1);//クイックソートには最後の判定用の値を除いたものを与える
	
	for(i=0;i<n;i++){//一文字ずつトランプの文字の方を比較
		if(A[i].suit != B[i].suit) stable = 0;
	}
	
	if(stable == 1) printf("Stable\n");//マージソートとクイックソートの結果が一致しているか確認
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}
//何個のデータがあるかを示す変数nはソート事態では使用しなかったため消した


Measured memory_bytes: 4076
#include <iostream>

using namespace std;

int main() {
		int D, G;
		cin >> D >> G;
		int p[D+1], c[D+1];
		for (int i = 1; i <= D; i++) {
				cin >> p[i] >> c[i];
		}

		int ans = 1e9;
		for (int mask = 0; mask < (1 << D); mask++) {
				int rest = -1, num = 0, s1 = 0;
				for (int i = 1; i <= D; i++) {
						if (mask >> (i-1) & 1) { 
								num += p[i];
								s1 += 100 * i * p[i] + c[i];
						} else {
								rest = i;
						}
				}
				if (G > s1) {
						int s2 = 100 * rest;
						int need = (G - s1 + s2 - 1) / s2;
						if (need >= p[rest]) continue;
						num += need;
				}
				ans = min(num, ans);
		}

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


Measured memory_bytes: 256
# Union-Find Set

fa = [x for x in range (100002)]
ans = [-1 for i in range (100002)]
siz = [1 for i in range (100002)]
rank = [0 for i in range (100002)]


def find (x) : # find the highest ancestor of x
    fa[x] = x if fa[x] == x else find (fa[x])
    return fa[x]

def union (x, y) :
    # fa[find (x)] = find (y)
    u, v = find (x), find (y)
    if (rank[u] >= rank[v]) :
        fa[v] = u
        if (u != v) :
            siz[u] += siz[v]
        if (rank[u] == rank[v]) :
            rank[u] += 1
    else :
        fa[u] = v
        if (v != u) :
            siz[v] += siz[u]

N, M, K = list (map (int, input().split()))

for i in range (M) :
    a, b = list (map (int, input().split()))
    union (a, b)
    ans[a] -= 1
    ans[b] -= 1
    
# TODO : .... build ans[]
for i in range (1, N + 1) :
    ans[i] += siz[find (i)]

# TODO : eliminate blockships
for i in range (K) :
    c, d = list (map (int, input().split()))
    if (find (c) == find (d)) :
        ans[c] -= 1
        ans[d] -= 1

print (' '.join (list (map (str, ans[1:N + 1]))))




Measured memory_bytes: 19764
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = float('inf')

for i in range(1<<N):
  a = A[::]
  cur,add = 0,0
  see = 0
  for j in range(N):
    if (i>>j)&1:
      see += 1
      if cur >= a[j]:
        add += (cur-a[j])+1
        a[j] = cur+1
      cur = max(cur,a[j])
    else:
      cur = max(cur,a[j])

  if see == K:
    ans = min(ans, add)

print(ans)

Measured memory_bytes: 80816
n = int(input())
w = list(map(int,input().split()))

right_left = sum(w)

for i in range(n):
    right_left -= 2*w[i]
    if right_left <= 0:
        break

s1_s2 = -right_left
s2_s1 = right_left + 2 * w[i]

if s1_s2 <= s2_s1:
    print(s1_s2)
else:
    print(s2_s1)


Measured memory_bytes: 3060
#include<stdio.h>

#define INF 9999999
#define NIL -1
#define BLACK 1
#define WHITE 0

int n;
int G[100][100];
int d[100];
int pi[100];
int color[100];

void initializeSingleSourse(int s){
  int i;
 for(i=0;i<n;i++){
    d[i] = INF;
    pi[i] = NIL;
  }
  d[s] = 0;
}

void dijkstra(int s){
  int i,j,u,mincost,v;
  
  initializeSingleSourse(s);
  while(1){
    mincost = INF;
    for(i=0;i<n;i++){
      if((color[i]!=BLACK)&&(d[i]<mincost)){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == INF)
      break;

    color[u] = BLACK;

    for(v=0;v<n;v++){
      if(G[u][v]!= -1)
	if((color[v] != BLACK)&&(G[u][v]+d[u]<d[v])){
	    pi[v] = u;
	    d[v] = d[u] +G[u][v];
	  }    
    
    }
  }
};

int main(){

  int u,k,i,j,v,sum=0;
  
  scanf("%d",&n);
 
 for(i=0;i<n;i++){
     for(j=0;j<n;j++){
       G[i][j]= NIL;
     }
 }

  
  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
     for(j=0;j<k;j++){
       scanf("%d",&v);
       scanf("%d",&G[u][v]);
     }
  }

  dijkstra(0);


  
 for(i=0;i<n;i++){
   printf("%d %d\n",i,d[i]);
 }
  
   return 0;
}



Measured memory_bytes: 2104
# https://atcoder.jp/contests/abc140/tasks/abc140_b
# -*- coding: utf-8 -*-

a_count = int(input())
b_value = list(map(int, input().strip().split()))

a_value = 0
a_value += b_value[0]

for i in range(1,a_count-1):
    if b_value[i - 1] > b_value[i]:
       a_value += b_value[i]
    else:
       a_value += b_value[i - 1]

a_value += b_value[a_count-2]
print(a_value)



Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
	int a[3];
	int b,i,j;

	scanf("%d %d %d", &a[0], &a[1], &a[2]);

	for (i = 0; i < 2; i++){
		for (j = 0; j<2; j++){
			if (a[j]>a[j + 1]){
				b = a[j];
				a[j] = a[j + 1];
				a[j + 1] = b;
			}
		}
	}

	for (j = 0; j < 2 ;j++){
		printf("%d ", a[j]);
	}

		printf("%d\n",a[2]);

		return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b)for(int i=(a);i<=(b);i++)
#define repR(i,n) for(int i=n;i>=0;i--)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int cnt = 0;
	int cnt2 = 0;
	vector<int>d(n + 1);
	rep(i, n) {
		d[i] = cnt - cnt2;
		if (s[i] == '(')cnt++;
		else cnt2++;
	}
	d[n] = cnt - cnt2;
	int tmp = cnt - cnt2;
	int mi = INF;
	rep(i, n + 1) {
		chmin(mi, d[i]);
	}
	rep(i, -mi) {
		cout << "(";
	}
	cout << s;
	rep(i, tmp - mi) {
		cout << ")";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if (s == 25) {
			System.out.println("Christmas");
		} else if (s == 24) {
			System.out.println("Christmas Eve");
		} else if (s == 23) {
			System.out.println("Christmas Eve Eve");
		} else if (s == 22) {
			System.out.println("Christmas Eve Eve Eve");
		}
	}
}


Measured memory_bytes: 21716
n,k,q = map(int,input().split())
a = []
for _ in range(q):
	a.append(int(input()))

b = [0]*n

for i in a:
	b[i-1] += 1

for i in range(n):
	minus_point = q - b[i]
	if k - minus_point > 0:
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 56664
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define init(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loopr(i, a, b) for (int i = a; i >= b; i--)
#define loops(i, a, b, step) for (int i = a; i < b; i += step)
#define looprs(i, a, b, step) for (int i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie();
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define all(a) a.begin(), a.end()
#define ld long double
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

int main()
{
    string s;
    cin >> s;
    if (s == "ARC")
        cout << "ABC";
    else if (s == "ABC")
        cout << "ARC";
    return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
#define MOD 1000000007

int main()
{
    int n, i;
    char s1[60], s2[60];
    unsigned long int p = 3;

    scanf("%d", &n);
    scanf("%s", s1);
    scanf("%s", s2);
    if (s1[0] != s2[0])
        p *= 2;
    for (i = 0; i < n - 1; i++)
    {
        if (s1[i] == s2[i])
        {
            p = (p * 2) % MOD;
        }
        else
        {
            if (s1[i + 1] != s2[i + 1] && s1[i] != s1[i + 1])
            {
                p = (p * 3) % MOD;
            }
        }
        //printf("%d\n",p);
    }
    printf("%d", p);
    return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K; cin >> N >> K;
    set<int> a;
    for(int i = 0; i < N; i++){
        a.insert(i+1);
    }
    for(int i = 0; i < K; i++){
        int b; cin >> b;
        vector<int> s(b);
        for(int f = 0; f < b; f++){
            cin >> s.at(f);
        }
        for(int j = 0; j < b;j++){
            a.erase(s.at(j));
        }
    }
    cout << a.size() << endl;
    return 0;
}

Measured memory_bytes: 3640
//
//  main.cpp
//  A - Frog 1
//
//  Created by Hashizo on 2019/06/12.
//  Copyright © 2019 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>

using namespace std;

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

int main(int argc, const char * argv[]) {
	int n;
	cin >> n;

	int footHold[n];
	int dp[n+1];
	
	REP(i, n){
		cin >> footHold[i];
	}

	dp[0] = 0;
	dp[1] = abs(footHold[0]-footHold[1]);

	FOR(i, 2, n) {
			dp[i] = min( (dp[i-1] + abs(footHold[i-1]-footHold[i])), (dp[i-2] + abs(footHold[i-2]-footHold[i])));
	}
	
	cout << dp[n-1] << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    double M;
    cin >> N >> M;

    int sum = 0;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum += A.at(i);
        }
    
    double m41 = sum / (4.0*M);

    int res = 0;
    for (int i = 0; i < N; i++)
    {
        if(A.at(i)>=m41){
            res++;
        }
    }

    if(res < M){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    

}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    s = defaultdict(lambda : 0)
    v = []
    for i in range(n):
        a,b = LI()
        s[a] += b
        v.append((a,b))
    v.sort()
    f = [0]*31
    i = 0
    j = 1
    su = 0
    for a,b in v:
        if a > j:
            f[i] = su
            i += 1
            j <<= 1
            j += 1
        su += b
    f[i] = su
    for j in range(i,30):
        f[j+1] = f[j]
    f.insert(0,0)
    l = []
    for i in range(31):
        if k&(1<<i):
            l.append(i)
    l = l[::-1]
    ans = s[0]
    p = 0
    for i in l:
        p |= (1<<i)-1
        res = 0
        for a,b in v:
            if a&p == a:
                res += b
        if ans < res:
            ans = res
        p += 1
        res = 0
        for a,b in v:
            if a&p == a:
                res += b
        if ans < res:
            ans = res
    print(ans)
    return


#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 63068
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
void ce(void){cerr << '\n';}
template <typename T>
void ce(const T n){cerr << n << '\n';}
template <typename T>
void cesp(const T n){cerr << n << ' ';}
template <typename T>
void ce(initializer_list<T> v){for(T i : v) cesp(i); ce();}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
// constexpr ll MOD = 1e9+7;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

using CP = complex<double>;

void fft(vector<CP> &a, bool inv){
	int n = a.size();
	if (n == 1) return;
	vector<CP> even(n / 2), odd(n / 2);
	for (int i = 0; i < n / 2; i++) {
		even[i] = a[2 * i];
		odd[i] = a[2 * i + 1];
	}
	fft(even, inv);
	fft(odd, inv);
	CP omega = polar(1.0, (-2 * inv + 1) * 2 * PI / n);
	CP pow_omega = 1.0;
	for (int i = 0; i < n / 2; i++) {
		a[i] = even[i] + pow_omega * odd[i];
		a[i + n / 2] = even[i] - pow_omega * odd[i];
		pow_omega *= omega;
	}
}

void conv(vector<CP> &a, vector<CP> b){
	int n = a.size() + b.size();
	int N = 1;
	while (N <= n) N <<= 1;

	a.resize(N);
	b.resize(N);

	fft(a, false);
	fft(b, false);

	for (int i = 0; i < N; ++i) {
		a[i] *= b[i] / CP(N);
	}

	fft(a, true);
}

int main(void){
	ll n, m;
	cin >> n >> m;
	Vec a(100001);
	rep(i, n) {
		ll t;
		cin >> t;
		a[t]++;
	}
	vector<CP> b(100001);
	rep(i, 100001) b[i] = CP(a[i], 0);

	conv(b, b);

	ll ans = 0, rest = m;
	repr(i, b.size()) {
		ll t = b[i].real() + 0.5;
		ans += i * min(t, rest);
		rest -= min(t, rest);
		if (!rest) break;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 20992
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {

  int n;
  int map[100];

  int wrong[100];
  int check[10];

  int index;

  cin >> n;

  for(int num=0;num<n;num++) {

    //wrongÌú»
    for(int i=0;i<81;i++) {

      wrong[i]=0;

    }

    //pYÌÇÝÝ
    for(int i=0;i<81;i++) {

      cin >> map[i];

    }

    //^eÌñð`FbN
    for(int i=0;i<9;i++) {

      for(int j=0;j<9;j++) check[j]=0;

      for(int j=0;j<9;j++) {

	check[map[9*j+i]-1]++;

      }

      for(int j=0;j<9;j++) {

	if(check[j]>1) {

	  for(int k=0;k<9;k++) {

	    if(map[9*k+i]==j+1) wrong[9*k+i]=1;

	  }

	}

      }
    
    }

    //RÌñð`FbN
    for(int j=0;j<9;j++) {

      for(int i=0;i<9;i++) check[i]=0;

      for(int i=0;i<9;i++) {

	check[map[9*j+i]-1]++;

      }

      for(int i=0;i<9;i++) {

	if(check[i]>1) {

	  for(int k=0;k<9;k++) {

	    if(map[9*j+k]==i+1) wrong[9*j+k]=1;

	  }

	}

      }

    }

    //gÌð`FbN
    for(int i=0;i<3;i++) {

      for(int j=0;j<3;j++) {

	index=27*j+3*i;

	for(int k=0;k<9;k++) check[k]=0;

	for(int k=0;k<3;k++) {

	  for(int l=0;l<3;l++) {

	    check[map[index+9*l+k]-1]++;

	  }

	}

	for(int k=0;k<9;k++) {

	  if(check[k]>1) {

	    for(int l=0;l<3;l++) {

	      for(int m=0;m<3;m++) {

		if(map[index+9*m+l]==k+1) wrong[index+9*m+l]=1;

	      }

	    }

	  }

	}

      }

    }

    for(int j=0;j<9;j++) {

      for(int i=0;i<9;i++) {

	if(wrong[9*j+i]==1) cout << "*";
      
	else cout << " ";

	cout << map[9*j+i];

      }

      cout << endl;

    }

    if(num!=n-1) cout << endl;

  }

  return 0;

}

Measured memory_bytes: 0
import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int cnt_2 = 0;
        int cnt_4 = 0;
        
        for(int i=0; i<n; i++){
            int a = sc.nextInt();
            if(a%4==0) {
                cnt_4++;
            }else if(a%2==0) {
                cnt_2++;
            }
        }
        if(cnt_2>1) n = n - cnt_2 +1;
        
        if(cnt_4>=n-cnt_4-1) {
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}

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

int main(){
  int x,y;
  int group[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};

  cin >> x >> y;
  if(group[x]==group[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256