akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

bool isok(int *cx, int m, int x)
{
    for( int k = 0; k < m; k++ )
    {
        if( cx[k] < x ) return false;
    }
    return true;
}

int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    int *a = (int *)malloc( sizeof(int) * n * m );
    int *c = (int *)malloc( sizeof(int) * n );
    for( int i = 0; i < n; i++ )
    {
        cin >> c[i];
        for( int k = 0; k < m; k++ ) cin >> a[ k + i * m ];
    }
    int *cx = (int *)malloc( sizeof(int) * m );
    int cmin = (1 << 30);
    for( int b = 0; b < (1 << 12); b++ )
    {
        int ct = 0;
        for( int k = 0; k < m; k++ ) cx[k] = 0;
        for( int i = 0; i < n; i++ )
        {
            if( b & (1 << i) )
            {
                ct += c[i];
                for( int k = 0; k < m; k++ )
                {
                    cx[k] += a[ k + i * m ];
                }
            }
        }
        if( isok(cx, m, x) )
        {
            if( ct < cmin ) cmin = ct;
        }
    }

    if( cmin == (1 << 30) )
    {
        cout << -1;
    }
    else
    {
        cout << cmin;
    }
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define ll long long
using namespace std;
const int N=1e6+6,P=998244353;
int a[N];
int gcd(int x,int y){ return y==0?x:gcd(y,x%y); }
int main(){
	int n,ans=1; scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	rep(i,1,n) ans=(ll)ans*gcd(i-1,a[i])%P;
	cout<<ans<<endl;
	return 0;
}

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

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

    ll h,w;
    cin >> h >> w;
    vector<vector<char>> a(h, vector<char>(w));
    for (ll i = 0;i < h;i++){
        for (ll j = 0;j < w;j++){
            cin >> a[i][j];
        }
    }
    vector<bool> wh(h);
    for (ll i = 0; i < h; i++){
        bool b = true;
        for (ll j = 0; j < w; j++){
            if (a[i][j] == '#'){
                b = false;
            }
        }
        wh[i] = b;
    }
    vector<ll> ww(w);
    for (ll j = 0; j < w; j++){
        bool b = true;
        for (ll i = 0; i < h; i++){
            if (a[i][j] == '#'){
                b = false;
            }
        }
        ww[j] = b;
    }

    for (ll i = 0;i < h;i++){
        if (wh[i]){
            continue;
        }
        for (ll j = 0;j < w;j++){
            if (ww[j]){
                continue;
            }
            cout << a[i][j];
        }
        cout << endl;
    }
    
}

Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

int main() {
    int n, m, l;
    cin >> n >> m >> l;
    vector<vector<int> > m1, m2;
    vector<vector<long> > ans;
    REP(i,n) {
        vector<int> mm;
        REP(j,m) {
            int k;
            cin >> k;
            mm.push_back(k);
        }
        m1.push_back(mm);
    }
    
    REP(i,m) {
        vector<int> mm;
        REP(j,l) {
            int k;
            cin >> k;
            mm.push_back(k);
        }
        m2.push_back(mm);
    }
    
    REP(i,n) {
        vector<long> mm;
        REP(j,l) {
            long s = 0;
            REP(k,m) {
                s += m1[i][k] * m2[k][j];
            }
            mm.push_back(s);
        }
        ans.push_back(mm);
    }
    
    REP(i,n) {
        REP(j,l-1) {
            cout << ans[i][j] << " ";
        }
        cout << ans[i][l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1412
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] x = new int[M];
        int[] y = new int[M];
        for(int i=0;i<M;i++){
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        int[] num = new int[N+1];
        Arrays.fill(num,1);
        boolean[] red = new boolean[N+1];
        red[1]=true;
        for(int i=0;i<M;i++){
            int from = x[i];
            int to = y[i];
            if(red[from]) red[to]=true;
            num[from]--;
            num[to]++;
            if(num[from]==0) red[from]=false;
        }
        int ans = 0;
        for(int i=1;i<=N;i++){
            if(red[i]) ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 65436
#include <stdio.h>

int main()
{
  int a, b, c, count=0;
  int i, j;

  scanf("%d %d %d",&a,&b,&c);

  for(i=a; i<=b; i++){
    if(c%i==0) count++;
  }

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

Measured memory_bytes: 596
N =int(input())
ans = 0
L =[]
for i in range(2,1000001):
    if N % i == 0:
        M = N/i
        L.append(M+i)
        ans += 1
if ans == 0:
    print(N-1)
else:
    print(round(min(L)-2))
        


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3620
import fractions


def anti_division(n, d1, d2):
    g = fractions.gcd(d1, d2)
    l = (d1 * d2) // g
    ret = n - (n//d1 + n//d2) + n//l
    return ret


a, b, c, d = [int(i) for i in input().split()]
ans = anti_division(b, c, d) - anti_division(a - 1, c, d)
print(ans)

Measured memory_bytes: 65260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI 3.141592653589793

int main(){
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  
  double rd = PI / 180;
  double xa, xb, ya, yb;
  xa = a * sin(((60*h+m) * 0.5) * rd);
  ya = a * cos(((60*h+m) * 0.5) * rd);
  xb = b * sin((m * 6) * rd);
  yb = b * cos((m * 6) * rd);
  double d, dd;
  d = (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb);
  dd = sqrt(d);
  cout << fixed << setprecision(15) << dd;
}

Measured memory_bytes: 4160
N,M,P = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for _ in range(N)]
rs = [[] for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    es[a].append((b,P-c))
    rs[b].append(a)

stack = [0]
govisit = set([0])
while stack:
    v = stack.pop()
    for to,_ in es[v]:
        if to in govisit: continue
        govisit.add(to)
        stack.append(to)

stack = [N-1]
backvisit = set([N-1])
while stack:
    v = stack.pop()
    for to in rs[v]:
        if to in backvisit: continue
        backvisit.add(to)
        stack.append(to)
use = govisit & backvisit

INF = float('inf')
dist = [INF] * N
dist[0] = 0
for i in range(N):
    for fr,e in enumerate(es):
        if fr not in use: continue
        for to,c in e:
            if to not in use: continue
            if dist[to] > dist[fr] + c:
                dist[to] = dist[fr] + c
                if i==N-1:
                    print(-1)
                    exit()
print(max(0,-dist[-1]))

Measured memory_bytes: 56024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f3f3f
#define PI acos(-1.0)
#define eps 1e-6
#define R freopen("555input.txt","r",stdin);
#define OP freopen("555output.txt","w",stdout);
//
#define N 200005
#define M 1000000007
int i,j,k,n;
LL a[N],mi=INF,sum,s;

int main()
{
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%lld",&a[i]);
        sum+=a[i];
    }
    for(i=0;i<n-1;i++){
            s+=a[i];
       mi=min(mi,abs(sum-2*s));
    }
    printf("%lld",mi);
    return 0;
}



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

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    num = ii()
    print((num / 3) ** 3)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int H, W;
	cin >> H >> W;
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    int ans = 0;
    rep(si,H) rep(sj,W) {
        if (S[si][sj] == '#') continue;
        vector<vector<int>> dist(H, vector<int>(W, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x) {    // lambda関数
            if (dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j)); // .emplace(i,j)
        };
        update(si,sj,0);
        while (!q.empty()) {
            int i = q.front().first;
            int j = q.front().second; q.pop();
            rep(dir,4) {
                int ni = i + di[dir] , nj = j + dj[dir];
                if (ni<0 || ni>=H || nj<0 || nj>=W) continue;
                if (S[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j]+1);
            }
        }
        rep(i,H) rep(j,W) {
            if (dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }

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


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

long long dp[1000000];

int main()
{
    for (int i = 1; i != 1000000; ++i) dp[i] = 1000000000000000000;
    
    int n, w;
    cin >> n >> w;
    for (int i = 0; i != n; ++i)
    {
        int x, y;
        cin >> x >> y;
        
        for (int j = n * 1000; j >= y; --j)
            dp[j] = min(dp[j], dp[j - y] + x);
    }
    
    long long ans = 0;
    for (int i = 0; i <= 100000; ++i) if (dp[i] <= w) ans = i;
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<string>
#include<cstdio>

int main(){
  char c[2][3];
  for(int i = 0; i <= 1; i++)
    for(int j = 0; j <= 2; j++)
		  scanf(" %c", &c[i][j]);
  if(c[0][0] == c[1][2] && c[0][1] == c[1][1] && c[0][2] == c[1][0])
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
const long long mod=1000000007;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j,k;
    cin>>n;
    string s;
    cin>>s;
    vector<long long>dp(n);
    dp[0]=1;
    for(j=1;j<=n-1;j++)
    {
        if(s[j-1]=='>')
        {
            dp[j]=0;
            for(i=j-1;i>=0;i--) dp[i]=(dp[i+1]+dp[i])%mod;
        }
        else
        {
            long long tmp,pre=dp[0];
            for(i=1;i<=j;i++)
            {
                tmp=dp[i];
                dp[i]=pre;
                pre=(pre+tmp)%mod;
            }
            dp[0]=0;
        }
    }
    long long ans=0;
    for(i=0;i<=n-1;i++) ans=(ans+dp[i])%mod;
    cout<<ans;
}


Measured memory_bytes: 256
S = input()
l= len(S)
ans = 0

for i in range(l):
    for j in range(l-i+1):
        seq = S[i:i+j]
        seq2 = seq.replace("A","").replace("G","").replace("T","").replace("C","")
        if seq2 == "":
            ans = max(ans, len(seq))
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;


int main()
{
	int K;
	cin >> K;
	for (int i = 0; i < K; i++) {
		cout << "ACL";
	}
	cout << endl;
}

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

using namespace std;

long long int l_abs(long long int n)
{
    if(n<0)
    {
        return -n;
    }

    else
    {
        return n;
    }
}

int main()
{
    long long int N, K;

    cin >> N >> K;

    long long int x=N;
    int moves=0;

    while(l_abs(x-K)<x && x>K)
    {
        x=x%K;
    }

    while(l_abs(x-K)<x)
    {
        x=abs(x-K);
    }

    cout << x << endl;

}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> cost(n);
  vector<vector<int>> level(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (auto &j : level[i]) cin >> j;
  }
  int ans = 2e18;
  for (int bit = 0; bit < (1 << n); bit++) {
    int sum_cost = 0;
    vector<int> sum_level(m);
    for (int i = 0; i < n; i++) {
      if ((1 << i) & bit) {
        sum_cost += cost[i];
        for (int j = 0; j < m; j++) {
          sum_level[j] += level[i][j];
        }
      }
    }
    bool flag = 1;
    for (int j = 0; j < m; j++) {
      if (sum_level[j] < x) {
        flag = 0;
        break;
      }
    }
    if (flag) ans = min(ans, sum_cost);
  }
  if (ans == 2e18) cout << -1 << '\n';
  else cout << ans << '\n';
}


Measured memory_bytes: 3556
n = int(input())
a = []
for i in range(n):
    b = int(input())
    a.append(b)
large = max(a)
maxi = a.index(max(a))
a[maxi] = 0
next1 = max(a)
for i in range(n):
    if i == maxi:
        print(next1)
    else:
        print(large)

Measured memory_bytes: 12520
# ARC078D - Fennec VS. Snuke (ABC067D)
from collections import deque


def bfs(s: int, d: "List[int]") -> None:
    q = deque([s])
    while q:
        v = q.popleft()
        for u in G[v]:
            if not d[u]:
                q.append(u)
                d[u] = d[v] + 1


def main():
    global G, DB, DW
    N, *E = map(int, open(0).read().split())
    G = [[] for _ in range(N + 1)]
    for i in range(0, (N - 1) * 2, 2):
        v, u = E[i : i + 2]
        G[v] += [u]
        G[u] += [v]
    DB, DW = [0] * (N + 1), [0] * (N + 1)
    bfs(1, DB), bfs(N, DW)
    b, w = 0, 0
    for i, j in zip(DB[1:], DW[1:]):
        if i <= j:
            b += 1
        else:
            w += 1
    flg = b > w
    print("Fennec" if flg else "Snuke")


if __name__ == "__main__":
    main()

Measured memory_bytes: 32492
#include <iostream>

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

int main(){
    ll a, b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a == b){
        cout << "a == b" << endl;
    }else{
        cout << "a > b" << endl;
    }
    return 0;
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	string s, t;
	cin >> N >> s >> t;
	rep(i, N) {
		cout << s[i] << t[i];
		if (i == N - 1)cout << "\n";
	}


	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int a,b,k;
int main(){
	scanf("%d%d%d",&a,&b,&k);
	for (int i=1;i<=k;i++){
		if (i&1){
			b+=a>>1;
			a>>=1;
		}else{
			a+=b>>1;
			b>>=1;
		}
	}
	printf("%d %d",a,b);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define Vec(a,n) vector<int> (a)((n))
using namespace std;
signed main(){
	int n,ans=0;
	cin >> n;
	Vec(a,n);
	Vec(b,n);
	REP(i,n){
		cin >> a[i] >> b[i];
	ans += b[i]-a[i]+1;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int count = 0;
int n,m;
int connect[20][20];
void dfs(int x, int k, int use[]){
    if(x==0) count++;
    for(int i = 0; i < n; i++){
        if(!use[i] & connect[k][i] == 1) {
      //      cout << i;
            use[i] = 1;
            dfs(x - 1, i, use);
            use[i] = 0;
        }
    }
    //cout << "\n";
}


int main(void){
    cin >> n >> m;
    int use[n];
    
    for(int i = 0; i < n; i++){
        use[i] = 0;
        for(int j = 0; j < n; j++){
            connect[i][j] = 0;
        }
    }
    use[0] = 1;
    for(int i = 0; i < n; i++)connect[n][i] = 1;
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        connect[a-1][b-1] = 1;
        connect[b-1][a-1] = 1;
    }
    dfs(n-1, 0, use);
    cout << count << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
    string S;
    cin >> S;
    
    bool flag = true;
    for (int i = 0; i < S.size() / 2; i++) {
        flag = flag
        && (S[i] == S[S.size()-1-i])
        && (S[i] == S[S.size()/2 - i - 1])
        && (S[S.size() - i - 1] == S[S.size()/2 + 1 + i]);
    }
    
    cout << (flag ? "Yes" : "No");

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
struct edge{
	int to,nx;
}e[5000001];
int h[100005],p;
int n,ok=0;

void ae(int fr,int to){
	e[++p]=(edge){to,h[fr]};h[fr]=p;
}
int dfs(int u,int fa){
	int ret=0;
	for(int i=h[u];i;i=e[i].nx){
		if(e[i].to!=fa) ret+=dfs(e[i].to,u);
		if(ok==1) return 0;
	}
	if(ret>=2){
		puts("First");
		ok=1;
		return 0;
	}
	else if(ret) return 0;
	return 1;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		ae(x,y);ae(y,x);
	}
	int ans=dfs(1,-1);
	if(!ok) if(ans) puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 2176
n,a = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split(" ").map{|i|i.to_i-a}
done = Array.new(n).map{Hash.new(0)}
done[0][x[0]] += 1
done[0][0] += 1
for i in 1..n-1
  done[i-1].each do |k,v|
    done[i][k] += v
    done[i][k+x[i]] += v
  end
end
puts done[-1][0]-1

Measured memory_bytes: 3196
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
vector<int>link[100];
bool vis[100];
int num=0;
int tot=1;
int n,m;
void dfs(int v)
{
	if(tot==n)
	{
		num++;
		return;
	}
	int ss=link[v].size();
	for(int i=0;i<ss;i++)
	{
		if(vis[link[v][i]]==false)
		{
			tot++;
			vis[link[v][i]]=true;
			dfs(link[v][i]);
			tot--;
			vis[link[v][i]]=false;
		}
	}
}
int main()
{
	memset(vis,false,sizeof(vis));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		link[a].push_back(b);
		link[b].push_back(a);
	}
	vis[1]=true;
	dfs(1);
	printf("%d",num);
	return 0;
} 

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define maxn 16005
using namespace std;
int n,nx,ny;
char s[maxn];
int dp1[2][maxn],now1,pre1=1;
int dp2[2][maxn],now2,pre2=1;
int main()
{
	scanf("%s",s+1); n=strlen(s+1);
	scanf("%d%d",&nx,&ny);
	int pos;
	int sx=0,sy=0;
	for(pos=1;pos<=n;pos++)
	{
		if(s[pos]=='F')
			sx++;
		else
			break;
	}
	if(pos>n)
	{
		if(sx==nx && sy==ny)
			printf("Yes\n");
		else
			printf("No\n");
		return 0;
	}
	int f=0;// 0 表示在向x边，1表示在向y
	dp1[0][sx+8000]=1;
	dp2[0][sy+8000]=1;
	for(int i=pos;i<=n;i++)
	{
		if(s[i]=='T')
		{
			f^=1;
			continue;
		}
		int cnt=0;
		while(s[i]=='F' && i<=n)
			cnt++,i++;
		i--;
//		cout<<"its "<<i<<endl;
		if(f==1)
		{
//			cout<<"this is y "<<endl;
			swap(now2,pre2);
			memset(dp2[now2],0,sizeof(dp2[now2]));
			for(int j=0;j<=16000;j++)
			if(dp2[pre2][j])
			{
				if(j-cnt>=0)
					dp2[now2][j-cnt]=1;//,cout<<j-cnt<<endl;
				if(j+cnt<=16000)
					dp2[now2][j+cnt]=1;//,cout<<j+cnt<<endl;
			}
		}
		else
		{
//			cout<<"this is x"<<endl;
			swap(now1,pre1);
			memset(dp1[now1],0,sizeof(dp1[now1]));
			for(int j=0;j<=16000;j++)
			if(dp1[pre1][j])
			{
				if(i-cnt>=0)
					dp1[now1][j-cnt]=1;//,cout<<j-cnt<<endl;
				if(i+cnt<=16000)
					dp1[now1][j+cnt]=1;//,cout<<j+cnt<<endl;
			}
		}
	}
	if(dp1[now1][nx+8000] && dp2[now2][ny+8000])
		printf("Yes\n");
	else 
		printf("No\n");
}


Measured memory_bytes: 512
/*    _                     _     
  __| | _____   _____  ___| |__  
 / _` |/ _ \ \ / / _ \/ __| '_ \ 
| (_| |  __/\ V /  __/\__ \ | | |
 \__,_|\___| \_/ \___||___/_| |_|
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define  endl    '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define F           first
#define S           second
#define rep(i,j,k)  for(int i=j;i<k;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define what_is(x)  cout << #x << " is " << x << endl;
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


using namespace std;
using namespace __gnu_pbds;
 
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
#define N  100005

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
 
int main(){
  faster
   int n,k;
   cin>>n>>k;

  int a[n],b[n+1];
  rep(i,0,n)cin>>a[i];
  b[0]=0,b[1]=abs(a[1]-a[0]);
  rep(i,2,n){
    b[i]=INT_MAX;

    rep(j,max(0,i-k),i){
      b[i]=min(b[i],b[j]+abs(a[j]-a[i]));
    }

  } 
  cout<<b[n-1]<<endl;
}


 

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

using Graph = vector<vector<int>>;

int bfs(Graph &g, queue<int> &q){
    int graph_size = g.size();
    vector<int> dist(graph_size, -1);
    dist[q.front()] = 0;
    while(!q.empty()){
        int from = q.front();
        q.pop();
        for(int to: g[from]){
            if(dist[to] != -1) continue;
            dist[to] = dist[from] + 1;
            q.push(to);
        }
    }
    return *max_element(dist.begin(), dist.end());
}

int main(){
    int N, M; cin >> N >> M;
    bool map_info[N][M];
    Graph g(N*M);

    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            char c; cin >> c;
            if(c=='.') map_info[i][j] = true;
            else map_info[i][j] = false;
        }
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(map_info[i][j]==true){
                if((i-1>=0) && map_info[i-1][j]==true) g[i*M+j].push_back((i-1)*M+j);
                if((i+1< N) && map_info[i+1][j]==true) g[i*M+j].push_back((i+1)*M+j);
                if((j-1>=0) && map_info[i][j-1]==true) g[i*M+j].push_back(i*M+(j-1));
                if((j+1< M) && map_info[i][j+1]==true) g[i*M+j].push_back(i*M+(j+1));
            }
        }
    }
    int result = -1;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if( map_info[i][j] == false) continue;
            queue<int> q;
            q.push(i*M+j);
            result = max(result, bfs(g, q));
        }
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	cout << S.substr(0, 4) << " " << S.substr(4, S.back());
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define Pb push_back
#define  FI first
#define  SE second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define IOS ios::sync_with_stdio(false)
#define DEBUG cout<<endl<<"DEBUG"<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF = 0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL qpow(LL a, LL b) {LL s = 1; while (b > 0) {if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1;} return s;}
LL gcd(LL a, LL b) {return b ? gcd(b, a % b) : a;}
int dr[2][4] = {1, -1, 0, 0, 0, 0, -1, 1};
typedef pair<int, int> P;
int main(void)
{
	int A, B;
	cin >> A >> B;
	if (B == 1) return 0 * puts("0");
	B--;
	cout << (B - 1) / (A - 1) + 1 << endl;
	// for (int i = 0; i <= 100; ++i) {
	// 	if ((A - 1)*i + 1 >= B) {
	// 		cout << i  << endl;
	// 		return 0;
	// 	}
	// }
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int N; int K;
	while(~scanf("%d%d", &N, &K)) {
		const int A = 26;
		vector<int> cnt(A, 0);
		rep(i, N) {
			char buf[11];
			scanf("%s", buf);
			++ cnt[*buf - 'A'];
		}
		int lo = 0, up = N / K;
		while(up - lo > 0) {
			int mid = (lo + up + 1) / 2;
			int num = 0;
			rep(a, A)
				num += min(mid, cnt[a]);
			if(num >= mid * K)
				lo = mid;
			else
				up = mid - 1;
		}
		printf("%d\n", lo);
	}
	return 0;
}


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

#define R 0x52
#define W 0x57

using namespace std;

int main() {
    long int n;
    long int cnt;
    long int right, left;
    char row[200001];
    long long ans;
    int w_exist;
    int r_exist;

    r_exist = 0;
    w_exist = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> row[i];
        if (row[i] == R){
            r_exist = 1;
        } else {
            w_exist = 1;
        }
    }

    if ((r_exist == 0) || (w_exist == 0)){
        cout << "0" << endl;
        return 0;
    }

    ans = 0;
    right = n-1;
    left = 0;
    while (1){
        while (row[right] == W){
            right--;
        }
        while (row[left] == R){
            left++;
        }
        if (left >= right) break;
        ans++;
        right--;
        left++;
        //cout << left << " " << right << endl;
        
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(long long i=0;i<(n);i++)
#define REP1(i,n) for(long long i=1;i<=(n);i++)
#define REP2D(i,j,h,w) for(long long i=0;i<(h);i++) for(long long j=0;j<(w);j++)
#define REP2D1(i,j,h,w) for(long long i=1;i<=(h);i++) for(long long j=1;j<=(w);j++)
#define PER(i,n) for(long long i=((n)-1);i>=0;i--)
#define PER1(i,n) for(long long i=(n);i>0;i--)
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define FORE(i,a,b) for(long long i=(a);i<=(b);i++)
#define ITE(arr) for(auto ite=(arr).begin();ite!=(arr).end();++ite)
#define ALL(a) ((a).begin()),((a).end())
#define RANGE(a) (a),((a)+sizeof(a))
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define YNPRT(b) cout<<((b)?"Yes":"No")<<endl
#define ENTER printf("\n")
#define REV(arr) reverse(ALL(arr))
#define PRT(a) cout<<(a)<<endl
#ifdef DEBUG
#define DBPRT(a) cout << "[Debug] - " << #a << " : " << (a) << endl
#define DBSTART if(1){
#define DBEND }
#else
#define DBPRT(a) do{}while(0)
#define DBSTART if(0){
#define DBEND }
#endif
#define PRTLST(arr,num) REP(_i,num) cout<<_i<<" - "<<arr[_i]<<endl;
#define PRTLST2(arr2,d1,d2) REP(_i,d1) REP(_j,d2) cout<<_i<<","<<_j<<" : "<<arr2[_i][_j]<<endl;
#define PRTLST2D(arr2,d1,d2) do{cout<<"L\t";REP(_i,d2) cout<<_i<<"\t"; cout<<endl; REP(_i,d1){cout<<_i<<"\t";REP(_j,d2){cout<<arr2[_i][_j]<<"\t";}cout<<endl;}}while(0);

#define TOSUM(arr,sum,n) {sum[0]=arr[0];REP1(i,n-1) sum[i]=sum[i-1]+arr[i];}

#define MIN(target,v1) (target)=min(target,v1)
#define MAX(target,v1) (target)=max(target,v1) 
#define P1 first
#define P2 second
#define PB push_back
#define UB upper_bound
#define LB lower_bound
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;
const int Move[4][2] = {-1,0,0,1,1,0,0,-1};
const int Move_[8][2] = {-1,0,-1,-1,0,1,1,1,1,0,1,-1,0,-1,-1,-1};
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p) {os<<"( "<<p.P1<<" , "<<p.P2<<" )";return os;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {ITE(v) os << (ite-v.begin()) << " : " << *ite <<endl;return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v) {os<<" { ";ITE(v) {os<<*ite;if(ite!=--v.end()){os<<" , ";}} os<<" } ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& m) {ITE(m) {os<<ite->P1<<"\t\t|->\t\t"<<ite->P2<<endl;} return os;}

//---------------------
#define MAXN 100000
//---------------------

ll a,b,x;
double angle;

int main(){
	cin >> a >> b >> x;
	double h = ((double)x) / (a*a);

	if(x == a*a*b) {printf("%.10f\n",0.0); return 0;}

	if(h>=(double)b/2){
		DBPRT("a");
		angle = atan2(2*(a*a*b-x),a*a*a)*57.295779513082320;
	}
	else
		angle = atan2(a*b*b,2*x)*57.295779513082320;
	printf("%.10f\n",angle);
	return 0;
}









Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int gp[15] = {10,0,2,0,1,0,1,0,0,1,0,1,0};
	int a, b;
	cin >> a >> b;
	if (gp[a] == gp[b]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    set<int> num_set;
    vector<int> vec_set;

    rep(i,N){
        int tmp; cin >> tmp;
        num_set.insert(tmp);
        vec_set.push_back(tmp);
    }

    if (num_set.size() == vec_set.size()){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 13428
// test.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#include <iostream>
#include <algorithm>
#include <vector>




using namespace std;


int main()
{
	// 整数の入力
	int N;
	cin >> N ;
	
	
	cout << N*N*N << endl;
	
	
	
	

	return 0;
}





// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  int N, C;
  scanf("%d %d", &N, &C);

  std::vector<int> prog(100010);
  for (int i=0; i<N; ++i) {
    int s, t, c;
    scanf("%d %d %d", &s, &t, &c);

    if (prog[s]>>c & 1) {
      prog[s] ^= 1 << c;
    } else {
      prog[s-1] ^= 1 << c;
    }

    if (prog[t-1]>>c & 1) {
      prog[t-1] ^= 1 << c;
    } else {
      prog[t] ^= 1 << c;
    }
  }

  for (int i=1; i<=100000; ++i)
    prog[i] ^= prog[i-1];

  int res=0;
  for (int i=0; i<=100000; ++i)
    res = std::max(res, __builtin_popcount(prog[i]));

  printf("%d\n", res);
}


Measured memory_bytes: 640
// 2016-12-01
#include <iostream>
using namespace std;

int main() {
	int n, q, m, d;
	while (cin >> n >> q, n) {
		int c[100] = {};
		for (int i = 0; i < n; i++) {
			cin >> m;
			for (int j = 0; j < m; j++) {
				cin >> d;
				c[d]++;
			}
		}
		int x = 0;
		for (int i = 1; i < 100; i++) {
			if (c[i] >= q && c[i] > c[x]) {
				x = i;
			}
		}
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<iostream>
using namespace std;
int main(){
  int a,b,n,x=0;
  while(1){
    cin>>n;
    if(n==0)break;
    a=n/4;
    for(int i=0;i<a;i++){
      cin>>b;
      x+=b;
    }
  cout<<x<<endl;
  x=0;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	char c; cin >> c;
	cout << ((c=='a'||c=='i'||c=='u'||c=='e'||c=='o')?"vowel":"consonant") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;
    vector<int> C;
    for (int i = 0; i < N; i++)
    {
        C.emplace_back(0);
    }

    int tmp;
    for (int i = 0; i < 2 * M; i++)
    {
        cin >> tmp;
        C[tmp - 1]++;
    }

    int sum = accumulate(C.begin(), C.end(), 0);

    for (int i = 0; i < N; i++)
    {
        cout << C[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
xy = []
for _ in range(M):
    xy.append(list(map(int,input().split())))
    xy[-1][0] -= 1
    xy[-1][1] -= 1
redp = [[False,1] for _ in range(N)]
redp[0] = [True,1]
for x,y in xy:
    if redp[x][0]:
        if redp[x][1] == 1:
            redp[x][0] = False
            redp[x][1] = 0
            redp[y][0] = True
            redp[y][1] += 1
        else:
            redp[x][1] -= 1
            redp[y][0] = True
            redp[y][1] += 1
    else:
        redp[x][1] -= 1
        redp[y][1] += 1


count = 0
for i in redp:
    if i[0]:
        count += 1
print(count)
           

Measured memory_bytes: 34656
#include<stdio.h>


int main(){

  int i, t, n;

  for(i = 0;i < 4;i++){

    scanf("%d %d", &t, &n);

    if(t == 1){
      printf("%d\n", 6000*n);
    }
    if(t == 2){
      printf("%d\n", 4000*n);
    }
    if(t == 3){
      printf("%d\n", 3000*n);
    }
    if(t == 4){
      printf("%d\n", 2000*n);
    }
  }

  return 0;
}

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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  set<int> st;

  for (int i = a; i < min(b, a + k); i++) st.insert(i);
  for (int i = max(a, b - k + 1); i <= b; i++) st.insert(i);

  for (auto i: st) cout << i << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <string>
#include <vector>
#include <functional>
#include <iomanip>
using namespace std;

typedef struct
{
    string title;
    string author;
    int date;
} book;

book nyaan[100];
int nyan(string str);

int main(void)
{
    int i, j, N;

    cin >> N;

    for (i = 0; i < N; i++)
    {
        string str;
        cin >> nyaan[i].title >> nyaan[i].author >> str;
        int y = 10000 * stoi(str.substr(0, 4)) + 100 * stoi(str.substr(5, 2)) + stoi(str.substr(8, 2));
        nyaan[i].date = y;
    }

    int Q;

    cin >> Q;

    for (j = 0; j < Q; j++)
    {
        string in1, in2, in3, in4;
        cin >> in1 >> in2 >> in3 >> in4;

        for (i = 0; i < N; i++)
        {
            bool ok = true;

            if (nyaan[i].title.find(in1) != string::npos || in1 == "*")
                ;
            else
                ok = false;

            if (nyaan[i].author.find(in2) != string::npos || in2 == "*")
                ;
            else
                ok = false;

            if (in3 != "*" && nyaan[i].date < nyan(in3))
                ok = false;

            if (in4 != "*" && nyaan[i].date > nyan(in4))
                ok = false;

            if (ok)
                cout << nyaan[i].title << endl;
        }

        if (j != Q - 1)
            cout << endl;
    }

    return 0;
}

int nyan(string str)
{
    int y = 10000 * stoi(str.substr(0, 4)) + 100 * stoi(str.substr(5, 2)) + stoi(str.substr(8, 2));
    return y;
}


Measured memory_bytes: 3240
import sys
sys.setrecursionlimit(10**5+10)

n = int(input())
h = [int(i) for i in input().split()]

# 無限大の値
f_inf = float('inf')

# メモ用のDP テーブルを初期化　(最小化問題なので INF に初期化)
dp = [f_inf] * (10**5+10)

# dpの最小値を変更する関数
def chmin(a, b):
    if a > b:
        return b
    else:
        return a

# メモ化再帰の関数
def rec(i):
    # DPの値が更新されている場合はその値を返す
    if dp[i] <  f_inf:
        return dp[i]
    
    # 再帰の終了条件。足場0のコストは0
    if i == 0:
        return 0
    
    # i-1, i-2　を再帰
    res = f_inf
    # i-1 から来た場合
    res = chmin(res, rec(i-1) + abs(h[i] - h[i-1]))
    # i-2 から来た場合
    if i > 1:
        res = chmin(res, rec(i-2) + abs(h[i] - h[i-2]))
    
    # 結果をメモする
    dp[i] = res
    return res

ans = rec(n-1)
print(ans)

Measured memory_bytes: 94100
import numpy as np

class SieveOfEratosthenes:
    def __init__(self, V):
        self.is_prime = np.ones(V + 1, dtype=bool)
        self.is_prime[2::2] = False
        self.is_prime[3::3] = False
        self.is_prime[5::5] = False
        self.primes = [2, 3, 5]
        for i in range(7, V + 1, 2):
            if self.is_prime[i]:
                self.primes.append(i)
                if i * i < V + 1:
                    self.is_prime[i * i::i] = False
    
    def factorize(self, x, return_dict=False):
        if x == 1:
            return {1:1} if return_dict else [(1, 1)]
        result = []
        for p in self.primes:
            exp = 0
            while x % p == 0:
                exp += 1
                x = x // p
            if exp > 0:
                result.append((p, exp))
            if p * p > x:
                break
        if x > 1:
            result.append((x, 1))
        if return_dict:
            result = {p: e for p, e in result}
        return result


N = int(input())
M = 10**9 + 7
A = list(map(int, input().split()))

sieve = SieveOfEratosthenes(10**3)
F = [sieve.factorize(a, return_dict=True) for a in A]

lcm = F[0]
for i in range(1, len(F)):
    for p, e in F[i].items():
        if p in lcm:
            lcm[p] = max(lcm[p], e)
        else:
            lcm[p] = e

val = 1
for p, e in lcm.items():
    val = val * pow(p, e, M) % M

B = [val * pow(a, M - 2, M) % M for a in A]
print(sum(B) % M)
    

Measured memory_bytes: 30700
#include <iostream>

using namespace std;

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

    int A[N - 1];
    int count_buka[N];
    int i;
    for (i = 0; i < N - 1; i++) {
        cin >> A[i];
        count_buka[i] = 0;
    }
    count_buka[N - 1] = 0;

    for (i = 0; i < N - 1; i++) {
        count_buka[A[i] - 1]++;
    }

    for (i = 0; i < N; i++) {
        cout << count_buka[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 5156
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int A, B, C, X, Y,d,e,f;
cin >> A >> B >> C >> X >> Y;
if(X > Y){
d = 2*C*Y+(X-Y)*A;
}else{
d = 2*C*X+(Y-X)*B;
}
e = A*X+B*Y;
f = 2*C*max(X,Y);
	d=min(d,e);
	d=min(d,f);
cout << d << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
typedef long long ll;
int main()
{
    ll K,t=7;
    scanf("%lld",&K);
    for(int i=0;i<K;i++){
        if(t%K==0){
            printf("%d",i+1);
            return 0;
        }
        t=(t*10+7)%K;
    }
    puts("-1");
}


Measured memory_bytes: 1716
import java.util.*;

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

        int[] c = new int[N];
        int[] t = new int[N];

        int ans = 1000000;

        for(int i = 0; i < N; i++){
            c[i] = sc.nextInt();
            t[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++)
        {
            if(t[i] <= T && c[i] <= ans){
                ans = c[i];
            }
        }
        if(ans <= 10001){
            System.out.println(ans);
        }
        else{
            System.out.println("TLE");
        }
    }
}

Measured memory_bytes: 21844
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

int p(int i){return (i/2);}
int l(int i){return (2*i);}
int r(int i){return (2*i+1);}

main(){
	long n,i,m;
	long *A;
	scanf("%ld",&n);
	mymalloc(A,n+1);
	for(i=1;i<=n;i++){
		scanf(" %ld",&m);
		A[i]=m;
	}
	for(i=1;i<=n;i++){
		printf("node %ld: key = %ld, ",i,A[i]);
		if(i!=1){
			printf("parent key = %ld, ",A[p(i)]);
		}
		if(l(i)<=n){
			printf("left key = %ld, ",A[l(i)]);
			if(r(i)<=n){
				printf("right key = %ld, ",A[r(i)]);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 600
[n,a,b]=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
y=[]
for i in range(n-1):
 z=(x[i+1]-x[i])*a
 if z<b:
   y.append(z)
 else:
   y.append(b)
print(sum(y))

Measured memory_bytes: 14224
n=int(input())
t_won=0
h_won=0
for _ in range(n):
	t_wd,h_wd=input().split()
	if t_wd>h_wd: t_won+=1
	elif t_wd<h_wd: h_won+=1
print(t_won*3+(n-t_won-h_won),h_won*3+(n-t_won-h_won))


Measured memory_bytes: 5596
S = input()
if S[0] != "A":
    print("WA")
    exit()

if S[2:-1].count("C") != 1:
    print("WA")
    exit()

X = 0
for s in S:
    if s.lower() != s:
        X += 1

if X != 2:
    print("WA")
else:
    print("AC")


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

int main(void) {
  int n;
  int t, a;
  vector<int> h;
  cin >> n;
  cin >> t >> a;
  int t1000 = t * 1000;
  int a1000 = a * 1000;

  long minT = 1000000;
  int min = -1;

  for(int i = 0; i < n; i++)
  {
    int th;
    cin >> th;
    
    long thT = abs(a1000 -(t1000 - 6 * th));
    if (thT < minT)
    {
      minT = thT;
      min = i;
    }
  }

  cout << min + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;
#define sz(c) int((c).size())

int parse(map<char, int>& m, string& s)
{
  int i, res, cur, next;
  res = 0;
  if (sz(s) == 1)
    return m[s[i]];
  for (int i = 0; i < sz(s) - 1; i++) {
    cur = m[s[i]]; next = m[s[i+1]];
    if (cur < next)
      res -= cur;
    else
      res += cur;
  }
  res += next;
  return res;
}

int main(int argc, char **argv)
{
  string s;
  map<char, int> m;
  m['I'] = 1;
  m['V'] = 5;
  m['X'] = 10;
  m['L'] = 50;
  m['C'] = 100;
  m['D'] = 500;
  m['M'] = 1000;

  for (;;) {
    cin >> s;
    if (cin.eof())
      break;
    cout << parse(m, s) << endl;
  }

  return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;

#define REP(var, i, j) for (int var=(i); var<(j); var++)

typedef pair<int, int> P;
typedef pair<string, P> PP;

map<string, int> solve(){
    map<string, int> d;
    queue<PP> que;
    string t;
    que.push(PP("01234567", P(0, 0)));
    while(que.size()){
        PP p = que.front();
        que.pop();
        string str = p.first;
        int n = p.second.first+1;
        int zero = p.second.second;
        d[str] = n;
        if (zero!=0 && zero!=4){
            t = str;
            swap(t[zero], t[zero-1]);
            if (!d[t]) que.push(PP(t, P(n, zero-1)));
        }
        if (zero!=3 && zero!=7){
            t = str;
            swap(t[zero], t[zero+1]);
            if (!d[t]) que.push(PP(t, P(n, zero+1)));
        }
        if (zero<4){
            t = str;
            swap(t[zero], t[zero+4]);
            if (!d[t]) que.push(PP(t, P(n, zero+4)));
        }
        if (zero>3){
            t = str;
            swap(t[zero], t[zero-4]);
            if (!d[t]) que.push(PP(t, P(n, zero-4)));
        }
    }
    return d;
}

int main(){
    map<string, int> d = solve();
    string str;

    while (getline(cin, str)){
        string t;
        REP(i, 0, str.size()){
            if(str[i]!=' '){
                t+=str[i];
            }
        }
        cout << d[t]-1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5516
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int el[n];
    for (int i = 0; i < n; i++)
    {
        cin >> el[i];
    }
    sort(el, el+n);
    for (int i = 0; i < n-1; i++)
    {
        if (el[i] == el[i+1])
        {
            cout << "NO"; return 0;
        }
    }
    cout << "YES";
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
s = []
for i in range(N):
    s_ = "".join(sorted(input()))
    s.append(s_)

s = sorted(s)

s.append("=end=")
t = ""
c = 0
total = 0
for a in s:
    if a != t:
        t = a
        total += c * (c-1) // 2
        c = 0
    c += 1

print(total)

Measured memory_bytes: 11408