akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main(void) {

    int N; cin >> N;
    int a[N + 1];
    for (int i = 2; i <= N; ++i) cin >> a[i];
    int ans[N + 1];
    rep(i, N + 1) ans[i] = 0;
    for (int i = 2; i <= N; ++i) {
        ++ans[a[i]];
    }
    for (int i = 1; i <= N; ++i) {
        out(ans[i]);
    }


    return 0;
}











Measured memory_bytes: 5144
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;

int main(){
    int n,m; cin >> n >> m;
    vector<int> uv[n * 3];
    rep(i,m){
        int u,v;cin >> u >> v;
        u--;v--;
        rep(j,3){
            if(j != 2)uv[u*3+j].pb(v*3+j+1);
            else uv[u*3+j].pb(v*3+0);
        }
    }
    int s,t; cin >> s >> t;
    s--;t--;

    int dis[n*3];
    fill(dis,dis+n*3,N);
    queue<int> que;
    que.push(s*3);
    dis[s*3] = 0;
    bool ok = false;
    while(que.size()){
        int p = que.front();que.pop();
        if(p == t*3){
            ok = true;
            break;
        }
        for(auto j : uv[p]){
            if(dis[j] == N){
                dis[j] = dis[p] + 1;
                que.push(j);
            }
        }
    }
    if(ok) cout << dis[t*3]/3 << endl;
    else cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 17792
#include <iostream>
#include <cmath>
using namespace std;
#define MAX_N 50
#define INF 1930000000
int  N,M;//Nは学生の数、Ｍはチェックポイントの数
int a[MAX_N]= {0},b[MAX_N]= {0},c[MAX_N]= {0},d[MAX_N] = {0};

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

    for(int i = 0; i < MAX_N;i++){
        a[i] = b[i] = c[i] = d[i] = INF;
    }
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
    }
    for(int j = 0; j < M; j++){
        cin >> c[j] >> d[j];
    }
    //一番近いチェックポイントの座標を調べる。
    int min = INF;
    int itr = 0;
    for(int i = 0; i < N; i++){//学生の数
        for(int j = 0; j < M; j++){//目的地の数
            if(min > abs(a[i]-c[j]) + abs(b[i]-d[j]) ){
                min = abs(a[i]-c[j]) + abs(b[i]-d[j]);
                itr = j;
            }
        }
        cout << itr+1 << endl;
        min = INF;
    }


    return 0;
}

Measured memory_bytes: 256
/*i-=-1*/
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn int
#define ll long long 
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define mod 1000000007
#define globalbool 2000000
#define pii pair<int,int>
#define vi vector<int>
#define all(x) x.begin(),x.end()
using namespace std;
using namespace std::chrono;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	auto start = high_resolution_clock::now();
	int n,m[2];
	cin>>n>>m[0]>>m[1];
	if(abs(m[0]-m[1])%2==0)
		cout<<abs(m[0]-m[1])/2;
	else
	{
		sort(m,m+2);
		int ans=min(abs(1-m[0]),abs(n-m[1]));
		cout<<ans+1+(m[1]-m[0]-1)/2;
	}

	auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start); 
  
    //cout << "Time taken by function: "
    //<< duration.count() << " microseconds" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		String[] weather = {"Sunny","Cloudy","Rainy"};
		for(int i = 0; i < weather.length; i++) {
			if(s.equals(weather[i])) 
				System.out.println(i < weather.length - 1 ? weather[i + 1] : weather[0]);
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <atcoder/segtree.hpp>

using namespace std;

int e() { return 0; }
int op(int a, int b) { return max(a, b); };

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

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

  int max_n = *max_element(va.begin(), va.end());
  atcoder::segtree<int, op, e> segtree(max_n + 1);
  segtree.set(va.front(), 1);
  for (int i = 1; i < va.size(); ++i) {
    int l = max(0, va[i] - k);
    int r = min(max_n, va[i] + k) + 1;
    int m = segtree.prod(l, r);
    segtree.set(va[i], m + 1);
  }

  cout << segtree.all_prod() << '\n';
  return 0;
}

Measured memory_bytes: 9600
from fractions import gcd
a,b=map(int,input().split())
m=gcd(a,b)
if m==1:print(1);exit()
pf={}
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
print(len(pf.keys())+1)


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

typedef long long ll;

using namespace std;

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

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;


int main(){
    string s;
    cin >> s;
    rep(i,s.size()-1){
        for(int j=i+1;j<s.size();j++){
            if(s[j]==s[i]){
                cout << "no" << endl;
                return 0;
            }
        }
    }
    cout << "yes" << endl;
    return 0;
}




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



int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];

   int dp[n+5]={0};
   dp[0]=0;

   for(int i=1;i<n;i++)
   {
       if(i==1)
       {
           dp[i]=dp[i-1]+(abs(arr[i]-arr[i-1]));
       }
       else
       {
           dp[i]=min(dp[i-1]+(abs(arr[i]-arr[i-1])),dp[i-2]+(abs(arr[i]-arr[i-2])));
       }
   }
   cout<<dp[n-1];
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s[0] == '7' || s[1] == '7' || s[2] == '7'){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}



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

using namespace std;
int n,m;

int main()
{
    scanf("%d%d",&n,&m);
    int i,j,res;
    res = m*1900+(n-m)*100;
    for(i=1;i<=m;i++)res *= 2;
    printf("%d",res);
    return 0;
}


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = 100100100100100100;
const int mod = 1e9;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
string alphabet = "abcdefghijklmnopqrstuvwxyz";


/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




/* main */
int ceil(int a, int b){
    if(a % b == 0) return a/b;
    else return a/b + 1;
}


signed main(){

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

    

    int a, b, c; cin >> a >> b >> c;

    int acut = abs((a/2) * b * c - ceil(a, 2) * b * c);
    int bcut = abs(a * (b/2) * c - a * ceil(b, 2) * c);
    int ccut = abs(a * b * (c / 2) - a * b * ceil(c, 2));

    print(min({acut, bcut, ccut}));




    




    
    



    
    



 
    
    


    

    
   
    













}






    










    




    










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

using namespace std;
typedef long long ll;

const ll MAX = (ll)1e6 + 6;
vector<ll> h(MAX);
vector<ll> dp(MAX, -1);

ll func(ll n)
{
    if (dp[n] != -1)
    {
        return dp[n];
    }
    else
    {
        return dp[n] = min(func(n - 1) + abs(h[n] - h[n - 1]), func(n - 2) + abs(h[n] - h[n - 2]));
    }
}

int main()
{
    ll n;
    cin >> n;
    for (int x = 1; x <= n; x++)
    {
        cin >> h[x];
    }
    dp[0] = (ll)1e18 + 18;
    h[0] = dp[0];
    dp[1] = 0;
    func(n);
    cout << dp[n] << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
  string S;
  string T;
  cin >> S >> T;
  int res = 0;
  rep(i,3){
    if (S[i]==T[i])
      res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define watch(x); cout<<#x<<"="<<x<<endl;
#define watch2(x,y); cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl;
#define int long long

int32_t main() 
{ 
    fast
    int n,m;
    cin>>n>>m;
    int sum=0;
    int temp;
    for(int i=0;i<m;i++){
    	cin>>temp;
    	sum+=temp;
    }
    if(sum>n)cout<<-1<<endl;
    else cout<<(n-sum)<<endl;

    return 0; 
} 


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 924844033LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};
int main() {
    int n, k;
    cin >> n >> k;
    int c = 0;
    string s;
    cin >> s;
    int l = 0;
    int ans = 0;
    for(int r = 0; r < n; r++) {
        if(s[r] == '0') {
            if(r == 0 || s[r - 1] == '1') {
                c++;
            }
        }
        if(c > k) {
            while(s[l] == '1') {
                l++;
            }
            while(s[l] == '0') {
                l++;
            }
            c--;
        }
        chmax(ans, r - l + 1);
    }
    cout << ans << endl;
}


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

int main() {
    char a, b;
    cin >> a >> b;
    
    if (a == 'H') {
      if (b == 'H') {
        cout << "H" << endl;
      } else {
        cout << "D" << endl;
      }
    } else {
      if (b == 'H') {
          cout << "D" << endl;
      } else {
        cout << "H" << endl;
      }
    }
}


Measured memory_bytes: 3000
a, b, c, x, y = map(int, input().split(' '))

c2 = c * 2
itr_end = max(x, y) + 1
results = []

for i in range(0, itr_end):
    # Cを2つi個だけ買って、残りはa、bで買う。ただし、マイナスの時(余っている時)は計算してはいけない。
    result = c2 * i
    if (x - i) > 0:
        result += a * (x - i)
    if (y - i) > 0:
        result += b * (y - i)

    results.append(result)

print(min(results))

Measured memory_bytes: 12664
#include <stdio.h>

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

  int *a = new int[n];
  for(int i=0; i<n; i++){
    scanf("%d", &a[i]);
  }

  int cnt = 0;
  for(int i=0; i<n; i++){
    if(a[i] != i + 1) cnt++;
  }

  if(cnt > 2) printf("NO\n");
  else printf("YES\n");

  delete [] a;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	static List <Integer>[] Edge;
	static int [][]d;
	static boolean []visit;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		Edge = new ArrayList [n];
		
		for(int i = 0 ; i< n ;i++) {
			Edge[i] = new ArrayList<Integer>();
		}
		
		for(int i = 0 ; i < n-1 ;i++) {
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			Edge[a-1].add(b-1);
			Edge[b-1].add(a-1);
		}
		d = new int [n][2];
		visit = new boolean [n];
		DFS(0,0);
		visit = new boolean [n];
		DFS(n-1,1);
		
		int fe = 1;
		int snu = 1;
		
		for(int i = 1 ; i < n-1 ;i++) {
			if(d[i][0] <= d[i][1]) {
				fe++;
			}
			else if(d[i][0] > d[i][1]) {
				snu++;
			}
			
		}
		if(snu >= fe) {
			System.out.println("Snuke");
		}
		else {
			System.out.println("Fennec");
		}
		
		
		
		
	}
	
	static void DFS(int st , int id) {
		visit[st] = true;
		for(int num : Edge[st]) {
			if(!visit[num]) {
			d[num][id] = d[st][id] + 1;
			DFS(num,id);
			}
		}
	
	}
	
}

Measured memory_bytes: 77764
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

typedef long long ll;

const int MOD = (int)1e9 + 7;

int main() {
	int a, b, ans; char op;
	scanf("%d %c %d", &a, &op, & b);
	if(op == '-') ans = a - b;
	else ans = a + b;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b, c;
	cin>>a>>b>>c;
	int step = 1;
	while((b * step + c) % a != 0)
	{
		step++;
		if(step > 300)
		{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 int a[3][3];
 for(int i = 0; i < 3; i++){
   for(int j = 0; j < 3; j++) cin >> a[i][j];
 }
 int dif1 = a[0][0] - a[0][1];
 if(a[1][0] - a[1][1] != dif1 || a[2][0] - a[2][1] != dif1){cout << "No" << endl; return 0;}
 dif1 = a[0][1] - a[0][2];
 if(a[1][1] - a[1][2] != dif1 || a[2][1] - a[2][2] != dif1){cout << "No" << endl; return 0;}
 dif1 = a[0][0] - a[1][0];
 if(a[0][1] - a[1][1] != dif1 || a[0][2] - a[1][2] != dif1){cout << "No" << endl; return 0;}
 dif1 = a[1][0] - a[2][0];
 if(a[1][1] - a[2][1] != dif1 || a[1][2] - a[2][2] != dif1){cout << "No" << endl; return 0;}
 cout << "Yes" << endl;
}


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

using namespace std;

int n, m;
int a[60], b[60], c[60], d[60];

int func(int n) {
	int ans;
	int minv = 1000000000;
	for (int i = 0; i < m; i++) {
		int x = abs(a[n] - c[i]) + abs(b[n] - d[i]);
		if (x < minv) {
			minv = x;
			ans = i;
		}
	}
	return ans + 1;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> c[i] >> d[i];
	}
	for (int i = 0; i < n; i++) {
		cout << func(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll a[200100];
ll ans;
bool cmp(ll a,ll b)
{
	return a>b;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+n,cmp);
	ans=a[1];
	int p=1;
	for(int i=2;i<=n;i++)
	{
		p+=2;
		if(p<n)  ans+=a[i]*2;
		else      
		{
			if(p==n)   ans+=a[i];
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5244
import sys

class DoublyLinkedList:
    def __init__(self, value = -1):
        self.value = value
        self.prev = self
        self.next = self

    def insert(self, value):
        newNode = DoublyLinkedList(value)
        newNode.next = self.next
        newNode.prev = self
        self.next.prev = newNode
        self.next = newNode

    def delete(self, value):
        node = self.next
        while node.value != -1:
            if node.value == value:
                node.next.prev = node.prev
                node.prev.next = node.next
                break
            node = node.next

    def deleteFirst(self):
        if self.next.value != -1:
            self.next = self.next.next
            self.next.prev = self

    def deleteLast(self):
        if self.prev.value != -1:
            self.prev = self.prev.prev
            self.prev.next = self

    def printAll(self):
        node = self.next
        while node.next.value != -1:
            print node.value,
            node = node.next
        print node.value

if __name__ == "__main__":
    dll = DoublyLinkedList()
    lines = sys.stdin.readlines()
    lines.pop(0)
    for line in lines:
        if line[0] == "i":
            dll.insert(int(line[7:]))
        elif line[6] == "F":
            dll.deleteFirst()
        elif line[6] == "L":
            dll.deleteLast()
        else:
            dll.delete(int(line[7:]))
    dll.printAll()

Measured memory_bytes: 510432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Mod 1000000007
#define rep(i, l, r) for(int i = l; i <= r; ++i)
int n, cnt;
unordered_map <int, int> dp;
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int Inc(int a, int b){
    return (a += b) >= Mod ? a - Mod : a;
}
int dfs(int n){
    if(dp[n]) return dp[n];
    ++cnt;
    return dp[n] = Inc(Inc(dfs(n / 2), dfs((n - 1) / 2)), dfs((n - 2) / 2));
}
signed main(){
    n = read(), dp[0] = 1, dp[1] = 2;
    printf("%lld\n", dfs(n));
    return 0;
}

Measured memory_bytes: 3688
// C - Attack Survival
#include <stdio.h>

int main(void){
    int n, k, q, a, i, j;
    scanf("%d%d%d", &n, &k, &q);
    int na[100000];
    for(i = 0; i < n; i++)na[i]=k-q;
    for(i = 0; i < q; i++){
        scanf("%d", &a);
        na[a-1]++;
    }
    for(i=0; i<n; i++){
        if(na[i]<=0)printf("No\n");
        else printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 896
N = int(input())
a_list = [int(x) for x in input().split()]

nega_count = 0

for i, v in enumerate(a_list):
    if v < 0:
        nega_count += 1
        a_list[i] = -1*v
a_list
if nega_count % 2 == 0:
    print(sum(a_list))
else:
    print(sum(a_list)-2*min(a_list))        


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;

lli n,a,b,c;
lli l[e5];
lli abc[e5];
lli ans = 1000000000000ll;

lli solve(lli b){
	lli ban[4];
	lli boo[4];
	for(lli i = 0;i < 4;i++) ban[i] = boo[i] = 0;
	for(lli i = 0;i < n;i++){
		lli x = b%4;
		ban[x] += l[i];
		boo[x]++;
		b /= 4;
	}
	for(lli i = 1;i < 4;i++) if(boo[i] == 0) return 1000000000000ll;
	lli cost = 0;
	for(lli i = 1;i < 4;i++){
		cost += 10*(boo[i]-1);
		cost += abs(ban[i]-abc[i]);
	}
	return cost;
}

int main(){
	cin >> n >> abc[1] >> abc[2] >> abc[3];
	for(lli i = 0;i < n;i++) cin >> l[i];
	lli k = (1 << n) << n;
	for(lli b = 0;b < k;b++){
		ans = min(ans,solve(b));
	}
	cout << ans << endl;

}


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

int main(){
  
  int N;
  
  cin >> N;
  
  vector<tuple<string,int,int>> data;
  
  for (int i=0; i<N; i++){
    string s1;
    int n1;
    cin >>s1 >>n1;
    data.push_back(make_tuple(s1,-1*n1,i));  
  }
  
  sort(data.begin(),data.end());
  
/*
  string s,s_tmp;
  int n=0;
  for (int i=0; i<N; i++){
    if (i == 0){
      tie(s, ignore, ignore) = data.at(i);
    }
    else if(i == N-1){
      tie(s_tmp, ignore, ignore) = data.at(i);
      if (s == s_tmp){
        reverse(data.begin()+n,data.end());
      }
    }
    else{
      tie(s_tmp, ignore, ignore) = data.at(i);
      if (s != s_tmp){
        s = s_tmp;
        reverse(data.begin()+n,data.begin()+i);
        n=i;
      }
    }
  }
  */
  for (int i=0; i<N; i++){
    int nn, pp;
    string ss;
    tie(ss, pp, nn) = data.at(i);
    cout <<nn+1 <<endl;
    //cout <<ss <<pp <<nn+1 <<endl;
    //cout << get<1>(data.at(i)) <<' ' << get<2>(data.at(i)) << get<3>(data.at(i)) <<endl;
  }

}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	int pn = 1;
	if (*ci == '-') {
		pn = -pn;
		ci++;
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return pn * tmp;
}

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


	int N;
	N = getint();

	ll dp00 = 0;
	ll dp11 = 0;
	ll dp02 = -1e18;

	int n = N / 2;
	if (N % 2) {
		rep(i, n) {
			int a = getint();
			chmax(dp11, dp00);
			dp00 += a;
			dp02 += a;
			chmax(dp02, dp11);
			dp11 += getint();
		}
		chmax(dp11, dp00);
		dp02 += getint();
		printf("%lld\n", max(dp02, dp11));
	}
	else {
		rep(i, n) {
			chmax(dp11, dp00);
			dp00 += getint();
			dp11 += getint();
		}
		printf("%lld\n", max(dp11, dp00));
	}


	Would you please return 0;
}

Measured memory_bytes: 1684
#include <stdio.h>

#define PMAX 100
#define TMAX 21
#define INF 1001

void initary( int table[TMAX][TMAX] )
{
	for ( int i = 0 ; i < TMAX ; i++ ) {
		for ( int j = 0 ; j < TMAX ; j++ ) {
			table[i][j] = ( int ) INF;
		}
	}	
}

int main()
{
	int n = 0, m = 0, i = 0, s = 0, g = 0, V = 0, p = 0;
	int path[TMAX][TMAX];
	int a = 0, b = 0;

	initary( path );
	scanf( "%d", &n );
	if ( n > 20 )  { return 0; }
	scanf( "%d", &m );
	if ( m > 100 ) { return 0; }

	while ( i < m ) {
		scanf( "%d,%d,", &a, &b );
		scanf( "%d,%d", &path[a-1][b-1], &path[b-1][a-1] );
		i++;
	}
	scanf( "%d,%d,%d,%d", &s, &g, &V, &p );

	/*
	for ( int j = 0 ; j < n ; j++ ) {
		for ( int k = 0 ; k < n ; k++ ) {
			printf( "%4d ", path[j][k] );
		}
		printf( "\n" );
	}
	*/

	// ワーシャルフロイド
	for ( int j = 0 ; j < n ; j++ ) {
		for ( int k = 0 ; k < n ; k++ ) {
			for ( int l = 0 ; l < n ; l++ ) {
				if ( path[j][k]+path[l][j] > path[l][k] ) {
					;
				} else {
					path[l][k] = path[j][k] + path[l][j];
				}
			}
		}
	}
	// printf( "GO:%2d RET:%2d\n", path[s-1][g-1], path[g-1][s-1]);
	printf( "%d\n", V - ( path[s-1][g-1]+path[g-1][s-1]+p ) );
	return 0;
}



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

bool cmp(int a,int b){
        return a>b;
}


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

    //Insert code
    int n,h,w;
 	cin>>n>>h>>w;
  	cout<<(n-h+1)*(n-w+1);
    //End code


    cerr << "\nTime elapsed: " << 1000*clock() / CLOCKS_PER_SEC << "ms\n";
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n,r,l;
        cin>>n>>l>>r;
        if(n==0&&r==0&&l==0)break;
        vector<int>v(n+1);
        for(int i=1;i<=n;i++){
            cin>>v[i];
        }
        int count=0,f=0;
        for(int x=l;x<=r;x++){
            f=0;
            for(int i=1;i<=n;i++){
                if(x%v[i]==0&&i%2==1){
                    f=1;
                    break;
                }
                else if(x%v[i]==0&&i%2==0){
                    f=2;
                    break;
                }
            }
            if(f==1)count++;
            else if(f==0&&n%2==0)count++;
        }
        cout<<count<<endl;
    }
}


Measured memory_bytes: 3088
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int M = sc.nextInt();
   
   int two = 1;
   for(int i=0;i<M;i++) two *=2;
   
   int ans = (1900*M+(N-M)*100)*two;
   System.out.println(ans);
 }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if ((a + b) & 1)
		cout << "IMPOSSIBLE\n";
	else
		cout << (a + b) / 2 << '\n';
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    
    ans = 0
    for a in range(1, N):
        ans += (N - 1) // a
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 62800
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

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

  int n;
  string s;

  cin >> n;
  vector<int> h(n);
  REP(i,n) cin >> h[i];

  int max_val = h[0];

  if(n == 1){
    cout << "Yes" << endl;
    return 0;
  }
  
  FOR(i,1,n){
    if(h[i] < max_val-1) {
      cout << "No" << endl;
      return 0;
    }
    max_val = max(max_val, h[i]);
  }
  cout << "Yes" << endl;
  return 0;
}

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

int cmp(const void *a,const void *b)
{
  return *(int*)b-*(int*)a;
}

int main()
{
  int n,k;
  
  scanf("%d%d",&n,&k);
  
  int l[n];
  int i;
  int ans=0;
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&l[i]);
  }
  
  qsort(l,n,sizeof(int),cmp);
  
  for(i=0;i<k;i++)
  {
    ans+=l[i];
  }
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

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

int main(){
    int h,w;
    cin >> h >> w;
    char p[h][w+1], r[h][w+1], b[h][w+1];
    rep(i,h) cin >> p[i];
    rep(i,h){
        rep(j,w+1){
            if(j==w) r[i][j] = '\0';
            else if(j==0) r[i][j] = '#';
            else if(i%2==0){
                if(i==0||i==h-1) r[i][j] = '#';
                else if(j!=w-1) r[i][j] = '#';
                else r[i][j] = '.';
            }else r[i][j] = '.';
        }
    }
    rep(i,h){
        rep(j,w+1){
            if(j==w) b[i][j] = '\0';
            else if(r[i][j]=='#') b[i][j] = '.';
            else b[i][j] = '#';
        }
    }
    rep(i,h){
     rep(j,w){
         if(p[i][j]=='#'){
             if(r[i][j]=='#') b[i][j] = '#';
             else r[i][j] = '#';
         }
     }
    }
    rep(i,h) cout << r[i] << endl;
    cout << endl;
    rep(i,h) cout << b[i] << endl;
    return 0;
}

Measured memory_bytes: 1408
x,n = map(int,input().split())
p = list(map(int,input().split()))

i = 0
ans = -1

while True:
    temp1 = x - i
    temp2 = x + i
    if temp1 not in p:
        ans = temp1
        break
    if temp2 not in p:
        ans = temp2
        break
    i += 1
print(ans)

Measured memory_bytes: 9184
lis=[1 for i in range(int(1e6+1))]

lis[0]=lis[1]=0

for i in range(int(1e6)+1):
    if lis[i]:
        for j in range(i*2,int(1e6+1),i):
            lis[j]=0

while True:
    try:
        n=int(input())
        cnt=0
        for i in range(n+1):
            if lis[i]:
                cnt+=1

        print(cnt)
        
        
    except:
        break

Measured memory_bytes: 14552
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N,M;

string to_string_6(int x){
    string res;
    res = to_string(x);
    while(res.length()<6) res = "0" + res;
    return res;
}

struct city{
    int year,per,idx,cnt;
    string number;
    city(int y,int p,int i):year(y),per(p),idx(i){}
    void calnum(){
        number = to_string_6(per) + to_string_6(cnt);
    };
};
vector<city> C;

void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> M;
    for (int i = 0; i < M; i++)
    {
        int y,p;
        cin >> p >> y;
        C.emplace_back(y,p,i+1);
    }
    auto cmp_year = [&](city a, city b){return a.year < b.year;};
    sort(C.begin(),C.end(),cmp_year);
}

int solve(){
    vector<int> cnt(N+1,0);
    for (int i = 0; i < M; i++)
    {
        cnt[C[i].per]++;
        C[i].cnt = cnt[C[i].per];
        C[i].calnum();
    }
    auto cmp_idx = [&](city a, city b){return a.idx < b.idx;};
    sort(C.begin(),C.end(),cmp_idx);
    for (int i = 0; i < M; i++)
    {
        cout << C[i].number << "\n";
    }    
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 9456
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll k,a,b;
cin>>k>>a>>b;
bool flag=false;
for(ll i=a;i<=b;i++)
{
    if(i%k==0)
    {
        flag=true;
    }
}
if(flag)
{
    cout<<"OK"<<endl;
}else
{
    cout<<"NG"<<endl;
}
return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#define fo(i,n) for(i=0;i<n;i++)
#define ll long long
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    string s;
    int ac,re,wa,tle;
    ac=re=wa=tle=0;
    fo(i,n)
    {
        cin>>s;
        if(s=="AC")
        ac++;
        else
        {
            if(s=="RE")
            re++;
            else
            {
                if(s=="WA")
                wa++;
                else
                {
                    if(s=="TLE")
                    tle++;
                }
                
            }
            
        }
        
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    
}

Measured memory_bytes: 3628
import std.stdio, std.conv, std.string, std.range, std.algorithm, std.array,
  std.functional, std.container, std.typecons, std.math;

void main() {
  auto input = readln.split.to!(double[]);
  double a = input[0];
  double b = input[1];
  double x = input[2];

  double s = x / a;
  if(s < a * b / 2) {
    writefln("%.10f", atan2((a*b*b), (2 * x)) * (180 / PI));
  } else {
    writefln("%.10f", atan(2 * (a*b - s) / (a*a)) * (180 / PI));
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cctype>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    char ch;
    int num;
    int counter[26] = {};
    while(cin >> ch) {
        
        
        // if(num < 0) continue;
        if(!isalpha(tolower(ch)))continue;
        num = tolower(ch) - 'a';
        // cout << "NUM " << num << " CH " << (char)tolower(ch) <<endl;
        counter[num] += 1;
        
        
    }
    
    for (int i = 0; i < 26; i++) {
        cout << (char)(i + 'a') <<   " : " << counter[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1140
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    int x[100010], y[100010];
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];
    int ansX = 0, ansY = 0;
    rep(i, n - 1) {
        ansX = (ansX + Mul(x[i + 1] - x[i],Mul(i + 1, n - i - 1))) % mod;
        //cout << i << " " << ansX << endl;
    }
    rep(i, m - 1) {
        ansY = (ansY + Mul(y[i + 1] - y[i],Mul(i + 1, m - i - 1))) % mod;
    }


    cout << Mul(ansX, ansY) << endl;


    return 0;
}
// 2 + (2 + 1) + 1 = 6
// 2 + 5 + 3 = 10

//  3 4 3
// 1 2 3 4
// 1 + (1 + 1) + (1 + 1 + 1) + 1 + (1 + 1) + 1

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
const int MOD = 1e9+7;
const int MAX = 1e6+10;
const int INF = 0x3fffffff;
int n,m;
int t[MAX];
struct node{
	int id;
	int final;
}p[MAX];

int main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		for(int i=1;i<=n;i++)	scanf("%d",&t[i]);
		scanf("%d",&m);
		for(int i=1;i<=m;i++){
			scanf("%d%d",&p[i].id,&p[i].final);
		}
		for(int i=1;i<=m;i++){
			int temp=t[p[i].id];
			t[p[i].id]=p[i].final;
			int sum=0;
			for(int i=1;i<=n;i++)	sum+=t[i];
			printf("%d\n",sum);
			t[p[i].id]=temp;
		}
	}
	return 0;
}

Measured memory_bytes: 2304
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect


mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

ans = 0
ans = (N - 1) * (N)//2

print(ans) 


'''
1 0
2 1
3 3
4 6
5 10
6 15
7 21
8 28
9 36
10 45
11 55
12 66
13 78
'''


Measured memory_bytes: 7996
N, x = map(int, input().split())
a = list(map(int, input().split()))
B = a[:] # 魔法の回数がk以下のときのスライムjをてに入れる最小の時間（ただし、魔法を唱える時間は最後に
         # 加えるのでここでは除いている
ans = 10 ** 13
for i in range(N):
    B = [a[j - i] if B[j] > a[j - i] else B[j] for j in range(N)]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

print(ans)


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define lp(i, x, y) for(ll i = x ; i < y ; i++)
#define lp_rev(i, x, y) for(int i = x ; i >= y ; i--)
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(v)  v.begin(), v.end()
#define vll vector<long long int>
#define vi vector<int>
#define Fasttt ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
typedef unsigned long long ull;
typedef long long ll;
#define endl "\n"
ll mod = 1000000007;

int main()
{
	int n;
	cin>> n;
	vi v(n), dp(n);
	lp(i, 0, n)
		cin>> v[i];
	dp[0] = 0;
	dp[1] = abs(v[1] - v[0]);
	lp(i, 2, n)
		dp[i] = min(dp[i - 1] + abs(v[i] - v[i - 1]), dp[i - 2] + abs(v[i] - v[i - 2]));
	cout<< dp[n - 1];
	return 0;
}		

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

int main() {
    long long N,M;
    cin >> N >> M;

    if(N!=1 && M!= 1) cout << (N-2)*(M-2) << endl;
    else if(N==1 && M!=1) cout << M-2 << endl;
    else if(N!=1 && M==1) cout << N-2 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 256
import java.lang.Math.*

fun main(args: Array<String>) {
  val (n, m) = readLine()!!.split(" ").map { it.toInt() }
  var list = mutableListOf<Int>()
  val sqrtM = sqrt(m.toDouble()).toInt()
  for (i in 1..sqrtM) {
    if (m % i == 0) {
      if (i <= m / n) list.add(i)
      if (i * i != m && m / i <= m / n) list.add(m / i)
    }
  }
  val ans = list.max()
  println(ans)
}


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

char mp[55][55];

void dfs(int x, int y, int n, int m) {
	mp[x][y] = '0';

	for (int i = -1;i <= 1;i++) {
		for (int j = -1;j <= 1;j++) {
			int ax = x + i;
			int ay = y + j;
			if (ax >= 0 && ay >= 0 && ax < m&&ay < n&&mp[ax][ay] == '1') {
				dfs(ax, ay,n,m);
			}
		}
	}
	return;
}

int main() {
	int n, m;
	while (cin >> n >> m, n, m) {
		for (int i = 0;i < m;i++)
			for(int j=0;j<n;j++)cin >> mp[i][j];

		int al = 0;
		for (int i = 0;i < m;i++) {
			for (int j = 0;j < n;j++) {
				if (mp[i][j] == '1') {
					dfs(i, j, n, m);
					al++;
				}
			}
		}
		cout << al << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
N = int(input())

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

Y = list(map(int, input().split()))

sum_M = []
for i in range(0, N+1):
 if i == 0:
  p1 = max(0, Y[0] - M[0])
  sum_M.append(min(M[0], Y[0]) ) 
 elif i < N:
  sum_M.append(min(M[i], Y[i] + p1) )
  p1 = min(Y[i], max(0, Y[i] - M[i] + p1) )
 else:
  sum_M.append(min(M[i], p1) )
  p1 = max(0, p1 - M[i])  

print(sum(sum_M))


Measured memory_bytes: 18476
#include <bits/stdc++.h>
#ifdef dbg
#include "./printer.hpp"
#else
#define dump(x) void(0)
#endif

#define MOD 1000000007
#define INF 
using namespace std;
#define ll long long
inline long  toInt(string s) {long  v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int main(){
  ll n,m;
  while(cin >> n >> m && (n+m)){
    vector<ll> a(n);
    vector<ll> b(m);
    unordered_set<ll> bs;
    ll suma = 0, sumb = 0;
    for(ll i = 0; i < n; i++){
      cin >> a[i];
      suma += a[i];
    }
    for(ll i = 0; i < m; i++){
      cin >> b[i];
      bs.insert(b[i]);
      sumb += b[i];
    }
    for(ll i = 0; i < n; i++){
      if((sumb - suma + 2 * a[i]) % 2 == 0 && bs.find((sumb - suma + 2 * a[i]) / 2) != bs.end()){
	cout << a[i] << ' ' << (sumb - suma + 2 * a[i]) / 2 << endl;
	break;
      }
      if(i == n-1){
	cout << -1 << endl;
      }
    }

    // suma - a[i] + x == sumb - x + a[i]
    
  }

}

Measured memory_bytes: 2996
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	string s,t;
	cin >> s;
	cin >> t;
    
    int ans=0;
	rep(i,3)
    {
        if(s[i]==t[i])
            ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;

#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int main() 
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s; cin>>s;
	ll n=s.length();
	ll ans=0;
	for (ll i=1;i<n;i++) {
		if (s[i]!=s[i-1]) ans++;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////


int main() {
    ll N, M;
    cin >> N >> M;

    vector<ll> c(N + 1, 0);

    repn(i, M) {
        ll a, b;
        cin >> a >> b;
        c[a]++;
        c[b]++;
    }

    string ans = "YES";
    repn(i, N) {
        if (c[i] % 2 == 1) { ans = "NO"; }
    }
    cout << ans;
	system("PAUSE");
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;++i)

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(){
  ll n;
  cin >> n;
  ll ans =0;
//dpテーブル三つ必要！？
  ll dpa[100010];
  ll dpb[100010];
  ll dpc[100010];

  rep(i,100010)dpa[i]=dpb[i]=dpc[i]=-1;
  dpa[0]=dpb[0]=dpc[0]=0;
  ll a[n+10],b[n+10],c[n+10];
  rep(i,n)cin >> a[i+1] >> b[i+1] >> c[i+1];

  rep(i,n+1){
    if(i>0){
      chmax(dpa[i],dpb[i-1]+a[i]);
      chmax(dpa[i],dpc[i-1]+a[i]);
      //cout << "dpa"<< dpa[i] << " ";
      chmax(dpb[i],dpc[i-1]+b[i]);
      chmax(dpb[i],dpa[i-1]+b[i]);
      //cout << "dpb"<< dpb[i] << " ";
      chmax(dpc[i],dpa[i-1]+c[i]);
      chmax(dpc[i],dpb[i-1]+c[i]);
      //cout << "dpc"<< dpc[i] << " ";
    }
    ans=max(dpa[i],max(dpb[i],dpc[i]));
    //cout << ans <<endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
	int A[1001];
	int num;
	for(int i=0;i<1001;i++){
		A[i] = 0;
	}

	cin >>num;
	
	for(int i=0;i<num;i++){
		scanf("%d",&A[i]);
	}
	void insertionSort(int A[],int N);//A[]はポインタ渡し
	insertionSort(A,num);

	return 0;
}

void insertionSort(int A[],int N){
	int v,j;

	for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;

	for(int i=1;i<N;i++){
		v = A[i];
		j = i -1;
		while(j >= 0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(int k=0;k<N-1;k++){
			cout <<A[k] <<" ";
		}
		cout <<A[N-1];
		cout <<endl;
	}
}

Measured memory_bytes: 1244