akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<map>
#include<deque>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,b,e) for(int i=(int)b;i<(int)e;i++)
#define Rep(i,n) REP(i,0,n)
#define rep(i,n) REP(i,1,n+1)
typedef long long ll;

int a,b,h;
int main(){
    cin>>a>>b>>h;
    cout<<((a+b)*h)/2<<endl;
    return 0;
}

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

 int main()
 {
     int i, n, p, q, r;
     int a[100000], b[100000];
     cin>>n;
     for(i = 0; i < n; i++)
     {
         cin>>a[i];
         cin>>b[i];
     }
     p = a[0];
     for(i = 1; i < n; i++)
     {
         if(a[i] > p)
         {
             p = a[i];
             r = i;
         }
         else
         {
             continue;
         }
     }
     q = b[r];
     cout<<p + q<<endl;
     return 0;
 }

Measured memory_bytes: 1024
# import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq # priolity-queue
# import time
# import itertools
# import collections # queue
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def main():
    n,k = map(int,input().split())
    l = list(map(int,input().split()))
    l.sort(reverse=True)
    ans = 0
    for i in range(k):
        ans += l[i]
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 3060
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
map = [0]*(n+1)
for i in range(m):
	map[a[i]] += 1
ans_l = map[1:x]
ans_r = map[x+1:n]
ans = min(sum(ans_l),sum(ans_r))
print(ans)

Measured memory_bytes: 9076
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) assert(type(default_val) ~= 'table') local n=dimension local m={}if default_val~=nil then m[1]={__index=function()return default_val end}end for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
----
local A, B = read.l():split()
A = tonumber(A)
B = B:totable()
local B100 = tonumber(B[1]) * 100 + tonumber(B[3]) * 10 + tonumber(B[4])
local P100 = A * B100
local s = tostring(P100)
if #s <= 2 then
    print(0)
else
    print(s:sub(1,#s-2))
end

Measured memory_bytes: 2796
import sys
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
ab = [[int(x) for x in input().split()] for _ in range(n)]
from collections import defaultdict, Counter
import math
double_zero_cnt = 0
a_zero_cnt = 0
b_zero_cnt = 0
d = defaultdict(list) # [a, b] ngのそれぞれの個数
a_b = []
for a, b in ab:
    if a == 0 and b == 0: 
        double_zero_cnt += 1
        continue
    elif a == 0:
        a_zero_cnt += 1
        continue
    elif b == 0:
        b_zero_cnt += 1
        continue
    g = math.gcd(a, b)
    a //= g
    b //= g
    if b < 0:
        b *= (-1)
        a *= (-1) # 必ずbは正
    a_b.append((a, b))
c = Counter(a_b)
key_list = list(c.keys())
for key in key_list:
    a, b = key
    if a < 0:
        a_ = a*(-1)
        b_ = b*(-1)
    else:
        a_ = a
        b_ = b
    if d[(-b_, a_)] != []:
        continue
    if c[(-b_, a_)] != 0:
        d[(a, b)] = [c[(a, b)], c[(-b_, a_)]]
ans = 1
used_cnt = double_zero_cnt
for key in d.keys():
    if d[key] == []:
        continue
    x, y = d[key]
    used_cnt += (x + y)
    mul = (pow(2, x, mod) + pow(2, y, mod) - 1) % mod
    ans *= mul
    ans %= mod
if a_zero_cnt > 0 and b_zero_cnt > 0:
    ans *= (pow(2, a_zero_cnt, mod) + pow(2, b_zero_cnt, mod) - 1)
    ans %= mod
    used_cnt += a_zero_cnt + b_zero_cnt
elif a_zero_cnt > 0:
    ans *= pow(2, a_zero_cnt, mod)
    ans %= mod
    used_cnt += a_zero_cnt
elif b_zero_cnt > 0:
    ans *= pow(2, b_zero_cnt, mod)
    ans %= mod
    used_cnt += b_zero_cnt
ans *= pow(2, n - (used_cnt), mod)
ans %= mod
ans -= 1
ans += double_zero_cnt
ans %= mod
print(ans)







Measured memory_bytes: 169676
import java.util.*;
import java.lang.*;

public class Main {
  
    public int dp(int[] a,int[] b,int[] c,int[] dp1 ,int[] dp2,int[] dp3,int n,int index,int type) {
    	if(index==n-1) {
    		dp1[n-1]=a[n-1];
    		dp2[n-1]=b[n-1];
    		dp3[n-1]=c[n-1];
    	}
    	else {
    		if(dp1[index]==-1)
    		dp1[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,0)+a[index];
    	if(dp2[index]==-1)
    		dp2[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,1)+b[index];
    	if(dp3[index]==-1)
    	dp3[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,2)+c[index];
    	}
    	if(type==0) {
    		return Math.max(dp2[index], dp3[index]);
    	}
    	if(type==1) {
    		return Math.max(dp1[index],dp3[index]);
    	}
    	else {
    		return Math.max(dp2[index], dp1[index]);
    	}
    	
    }
	public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int w=sc.nextInt();
        long[] arr1=new long[n];//weight
        long[] arr2=new long[n];
        long[][] dp=new long[n][w+1];
        for(int i=0;i<n;i++) {
        	arr1[i]=sc.nextInt();
        	arr2[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++) {
        	for(int j=0;j<=w;j++) {
        		if(i==0) {
        			if(arr1[0]<=j) {
        				dp[i][j]=arr2[0];
        			}
        		}
        		else {
        			long temp=j-arr1[i];
        			if(temp>=0) {
        				dp[i][j]=Math.max(dp[i-1][j],dp[i-1][(int)temp]+arr2[i]);
        			}
        			else {
        				dp[i][j]=dp[i-1][j];
        			}
        		}
        	}
        
        }
       System.out.println(dp[n-1][w]);
	}
}


Measured memory_bytes: 128980
import java.util.*;

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

        int res = 0;
        for(int a=0;a<=A;a++){
            for(int b=0;b<=B;b++){
                int c = (X-a*500-b*100)/50;
                if(c>=0 && c<=C){
                    res++;
                }
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    ll x, y;
    cin >> x >> y;
    int ans = 0;

    ll tmp = x;
    while(tmp <= y) {
        tmp *=2;
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**31-1)
input = sys.stdin.readline
write = lambda x: sys.stdout.write(str(x))
LMIIS = lambda : list(map(int,input().split()))
II = lambda : int(input())
dbg = lambda *something : print(*something) if DEBUG is True else 0
DEBUG = False

def main():

    N = II()
    t = [-1] * N


    E = [  [] for _ in range(N)]
 
    reached = [False] * N
    for _ in range(N-1):
        u,v,w = LMIIS()
        u -=1
        v -=1
        E[u].append((v,w))
        E[v].append((u,w))
    dbg(E)
    t[E[0][0][0]] = 0

     
    # def search(u):
    #     for v,w in E[u]:
    #         if t[v] == -1:
    #             t[v] = t[u] if w % 2 == 0 else t[u]^1
    #             search(v)
                

    # search(E[0][0][0])
    reached = [False] * N
    q = [E[0][0][0]]
    while q:
        u = q.pop()
        reached[u] = True
        for v,w in E[u]:
            if reached[v] != True and  t[v] == -1:
                t[v] = t[u] if w % 2 == 0 else t[u]^1
                q.append(v)

                



    for i in t:
        write(i)
        write(' ')






    pass
if __name__ == '__main__':
    main()

Measured memory_bytes: 64800
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr long long INF = 0xffffffffffff;

class union_find {
private:
	vector<int> uf;
	vector<long long> pd;

public:
	union_find(int n):uf(n, -1), pd(n, 0) {}
	
	inline int find(int x) {
		if(uf[x] < 0)
			return x;

		const int tmp = uf[x];
		uf[x] = find(uf[x]);
		pd[x] += pd[tmp];
		return uf[x];
	}

	inline void unite(int xx, int yy, int d) {
		int x = find(xx), y = find(yy);
		if(x == y)
			return;
		
		d += pd[yy] - pd[xx];
		if(uf[x] < uf[y]) {
			swap(x, y);
			d = -d;
		}

		else if(uf[x] == uf[y])
			--uf[y];
		
		uf[x] = y;
		pd[x] = d;
	}
	
	inline bool same(int x, int y) {
		return find(x) == find(y);
	}

	inline long long get_dist(int x, int y) {
		return same(x, y) ? pd[x] - pd[y] : INF;
	}
};


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

	for(int n, m; cin >> n >> m && n;) {
		union_find uf(n + 1);
		for(int i = 0; i < m; ++i) {
			char q;
			int a, b;
			cin >> q >> a >> b;

			if(q == '!') {
				int d;
				cin >> d;
				uf.unite(a, b, d);
			}
			else {
				const long long ans = uf.get_dist(a, b);
				if(ans == INF)
					cout << "UNKNOWN" << endl;
				else
					cout << ans << endl;
			}
		}
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2380
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    
    for(let h=1; h<=3500; h++) {
        for(let n=1; n<=3500; n++) {
            let w = (N * h * n) / (4 * h * n - N * n - N * h);
            
            if(w % 1 === 0 && w > 0) {
                console.log(h + " " + n + " " + w);
                return;
            }
        }
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21576
using System;

class Program
{
  static void Main(string[] args)
  {
    string str = Console.ReadLine();
	string result = "";
    for( int i = 1 ; i <= str.Length ; i++)
    {
      int amari = i % 2;
      switch( str[i-1] )
      {
          case 'R':
          	  if ( amari == 0 )
              {
              	Console.WriteLine("No"); 
                return;
              }
              break;
          case 'L':
              if ( amari == 1 )
              {
              	Console.WriteLine("No"); 
                return;
              }
              break;
          case 'U':
              break;
          case 'D':
              break;
          default:
			  Console.WriteLine("No"); 
              return;
      }
    }

    Console.WriteLine("Yes"); 
  }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main()
{
	long long a,r = 0; char b[5] = { 0, }; scanf ("%lld %s", &a, b);

	r *= 10, r += a * (b[0] - '0');
	r *= 10, r += a * (b[2] - '0');
	r *= 10, r += a * (b[3] - '0');
	r /= 100;
	printf ("%lld\n", r);

	return 0;
}


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

using namespace std;

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

int main(){

	int n,x;
	cin>>n>>x;
	int a[n];
	rep(i,n)cin>>a[i];

	ll ans=0;
	if(a[0]>x){
		ans+=a[0]-x;
		a[0]=x;
	}
	rep(i,n-1){
		if(a[i]+a[i+1]>x){
			ans+=a[i+1]+a[i]-x;
			a[i+1]=x-a[i];
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    char[] b = sc.next().toCharArray();
    char[] c = sc.next().toCharArray();
    for(int i = 0;i < a;i++){
      System.out.print(b[i]);
      System.out.print(c[i]);      
    }
  }
}

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

int main() {
    std::string S;
    int K;

    std::cin >> K;
    std::cin >> S;

    if(S.size() <= K) {
        std::cout << S << std::endl;
    }
    else {
        for(int i = 0; i < K; i++) {
            std::cout << S.at(i);
        }
        std::cout << "..." << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3628
H,W,K = [int(x) for x in input().split()];
c=[];
for i in range(H) :
    c.append(input());
#h = bin(2**H);
#w = bin(2**W);
cnt =0;
for i in range(2**H) :
    for j in range(2**W) :
        k = 0;
        for x in range(H) :
            for y in range(W) :
                idxx = (i >> x)%2;
                idxy = (j>>y)%2;
                if c[x][y] == '#' and idxx == 0 and idxy == 0 :
                    k = k +1;
        if k == K :
            cnt = cnt + 1;
print(cnt);

Measured memory_bytes: 9176
#include<map>
#include<queue>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<iostream>
#include<algorithm>
#define SIZE 110
using namespace std;

typedef pair<int,int> P;

void solve(void);       //処理

int n;             //ブロックの個数
int w,h;           //ボードの幅、高さ
int goal;          //迷路になっているか
int scolor;        //スタート位置の色
int sx,sy,gx,gy;   //スタートの座標、ゴールの座標
int mass[SIZE][SIZE];
int data[SIZE][SIZE];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int c,d,x,y;       //ブロックの色、向き、左上の座標


int main(){

  int i,j;             //カウンタ変数

  while(1){

    goal=0;

    /*情報の入力*/
    cin>>w>>h;

    if(w==0 && h==0)break;
    
    cin>>sx>>sy;
    cin>>gx>>gy;  
    cin>>n;
    
    memset(mass,0,sizeof(mass));

    for(i=0;i<n;i++){
      cin>>c>>d>>x>>y;
      
    if(d==0){       //横向きなら
      for(j=0;j<4;j++){
	mass[y][x+j]=c;
	mass[y+1][x+j]=c;
      }
    }
    else if(d==1){              //縦向きなら
      for(j=0;j<4;j++){
	mass[y+j][x]=c;
	mass[y+j][x+1]=c;
      }
    }
  }
  
  scolor=mass[sy][sx];

  if(gx==sx && gy==sy)cout<<"OK"<<endl;

  else if(scolor==mass[gy][gx]){
  
    solve();
    
    if(goal==1){
      cout<<"OK"<<endl;
    } else {
      cout<<"NG"<<endl;
    }
  }
  else {
    cout<<"NG"<<endl;
  }

  }
  
  return 0;
}
void solve(void){
  
  int i,j;
  queue<P> que;
  memset(data,-1,sizeof(data));
  que.push(P(sy,sx));     //queにスタート位置の座標を格納
  data[sy][sx]=0;
  
  while(!que.empty()){    //queが空でない間
    P p=que.front();
    que.pop();
    
    if(p.first==gy && p.second==gx){
      goal=1;
      break;
    }
    for(i=0;i<4;i++){
      int ny=p.first+dy[i];
      int nx=p.second+dx[i];
      if(nx>=0 && nx<=w && ny>=0 && ny<=h && mass[ny][nx]==scolor && data[ny][nx]==-1){
	que.push(P(ny,nx));
	data[ny][nx]=1;
      }
    }
  }
  return;
}

Measured memory_bytes: 1296
#include <iostream>
#include <vector>

using namespace std;

const int N = 1e6;

struct TreeNode {
    int id;
    TreeNode* parent;
    TreeNode* child;
    TreeNode* sibling;

    TreeNode(int x): id(x), parent(nullptr), child(nullptr), sibling(nullptr) {}
};

bool isRoot(TreeNode* node) {
    return node->parent == nullptr;
}

bool isLeaf(TreeNode* node) {
    return node->child == nullptr;
}

int getDepth(TreeNode* node) {
    if (isRoot(node))
        return 0;
    else
        return getDepth(node->parent) + 1;
}

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

    TreeNode* nodes[N];
    for (int i = 0; i < n; i++)
        nodes[i] = new TreeNode(i);

    for (int i = 0; i < n; i++) {
        int id;
        cin >> id;
        int k;
        cin >> k;
        if (k == 0)
            continue;
        vector<int> children(k);
        for (int j = 0; j < k; j++) {
            cin >> children[j];
            if (j == 0)
                nodes[id]->child = nodes[children[j]];
            else
                nodes[children[j - 1]]->sibling = nodes[children[j]];
            nodes[children[j]]->parent = nodes[id];
        }
    }

    for (int i = 0; i < n; i++) {
        cout << "node " << i << ": ";
        
        cout << "parent = ";
        if (isRoot(nodes[i]))
            cout << -1 << ", ";
        else
            cout << nodes[i]->parent->id << ", ";
        
        cout << "depth = " << getDepth(nodes[i]) << ", ";

        if (isRoot(nodes[i]))
            cout << "root" << ", ";
        else if (isLeaf(nodes[i]))
            cout << "leaf" << ", ";
        else
            cout << "internal node" << ", ";

        cout << "[";
        if (nodes[i]->child != nullptr) {
            cout << nodes[i]->child->id;
            TreeNode* p = nodes[i]->child->sibling;
            while (p != nullptr) {
                cout << ", ";
                cout << p->id;
                p = p->sibling;
            }
        }
        cout << "]" << endl;
    }

    for (int i = 0; i < n; i++)
        delete nodes[i];

    return 0;
}



Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	a--;
	if (b/n - a/n) cout << "OK" << endl;
	else cout << "NG" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n,k;cin>>n>>k;
  
  long double ans = 0;
  rep(i,n){
    int tmp = i+1;
    int mul = 1;
    while(tmp < k){
      tmp *= 2;
      mul *= 2;
    }
    ans += (1.0 / (long double)(mul * n));
  }
  printf("%.10lf",(double)ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char c;
  string aiueo = "aiueo";
  cin >> c;
  
  int eval = 0;
  for (int i=0;i<5;i++) {
    if (c==aiueo.at(i)) {
      eval++;
    }
  }
  if (eval>0)
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def f(n):
    if n < 2:
        return 1
    else:
        return n * f(n - 2)

N = int(input())

#result = f(N)
#print(result)
#
#number = 0
#str_result = list(str(result))
#for s in reversed(str_result):
#    if s == '0':
#        number += 1
#    else:
#        break
#
#print(number)

number = 0
seed = 10
if (N % 2 == 0):
    while seed < 10**18:
        number += N // seed
        seed = seed * 5
        #print((N // 1250) + (N // 250) + (N // 50) + (N // 10))
    print(number)
else:
    print(0)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define pb push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

#define MAX_N 100000

ll N,M;
vector<ll> g[MAX_N];
int color[MAX_N];

bool dfs(int v,int c){
    color[v] = c;
    bool ret=true;
    for(int i=0;i<g[v].size();i++){
        if(color[g[v][i]] == c) ret=false;
        if(color[g[v][i]] == 0 and !dfs(g[v][i],-c)) ret=false;
    }
    return ret;
}

int main(){
    cin >> N >> M;
    rep(i,M){
        ll u,v;
        cin>>u>>v;
        u--;
        v--;
        g[u].pb(v);
        g[v].pb(u);
    }

    ll a=0,b=0,c=0;

    rep(i,N) if(color[i]==0){
        if(g[i].size()==0) a++;
        else{
            if(dfs(i,1)) b++;
            else c++;
        }
    }

//    cerr << a << " " << b << " " << c << endl;

    ll ans=0;
    ans += a*a; // one x one
    ans += a*(N-a)*2;   // one * ? + ? * one (? is not one)
    ans += c*b*2+c*c;   // not bipartite graph
    ans += b*b*2;
    cout << ans << endl;
}


Measured memory_bytes: 13824
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String S = sc.next();

		int x = 0;
		int max = 0;

		for(int i = 0; i < N; i++){
			char c = S.charAt(i);
			if(c == 'I'){
				x++;
			}else if(c == 'D'){
				x--;
			}

			if(x > max){
				max = x;
			}
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 21716
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BTwoSwitches {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b, c, d;
	    in >> a >> b >> c >> d;

	    int res = 0;
	    if(b < c || d < a) out << 0 << endl;
	    else if(a <= c && c <= b && b <= d) out << b-c << endl;
	    else if(c <= a && a <= d && d <= b) out << d-a << endl;
	    else if(c <= a && b <= d) out << b-a << endl;
	    else if(a <= c && d <= b) out << d-c << endl;
	    else out << 0 << endl;
	}
};


int main() {
	BTwoSwitches solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int x;
  cin >> x;
  int n = 0;
  int maxx = 0;
  if(x == 1) {
    cout << 1 << endl;
    return 0;
  }
  REP2(b,2,100){
    REP2(p,2,20){
      int tmp = pow(b,p);
      if(tmp > x) continue;
      maxx = max(maxx, tmp);
    }

  }

  cout << maxx << endl;
  return 0;
}


Measured memory_bytes: 4120
//
//  main.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/20.
//  Copyright © 2019 yuya. All rights reserved.
//

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




int main(){
    
    int p,q,r;
    cin>>p>>q>>r;
    cout << min(min(p+q,q+r),r+p) << endl;
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
X = input()
cnt = X.count('1')
Y, Z = 0, 0
for i in range(N):
    if cnt > 1:
        Y = (Y + int(X[i])*pow(2, N-i-1, cnt-1))%(cnt-1)
    Z = (Z + int(X[i])*pow(2, N-i-1, cnt+1))%(cnt+1)

def popcount(n):
    c = bin(n).count('1')
    return c

for i in range(N):
    if X[i] == '1':
        pc = cnt - 1
        if pc <= 0:
            print(0)
            continue
        else:
            Y_i = (Y - pow(2, N-i-1, cnt-1))%(cnt-1)
            ans = 1
            while Y_i > 0:
                Y_i = Y_i % popcount(Y_i)
                ans += 1
            print(ans)
    else:
        Z_i = (Z + pow(2, N-i-1, cnt+1))%(cnt+1)
        ans = 1
        while Z_i > 0:
            Z_i = Z_i % popcount(Z_i)
            ans += 1
        print(ans)








Measured memory_bytes: 9556
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

score = 0
pre = n
for i in range(n):
    score += b[a[i]-1]
    if pre == a[i]-1:
        score += c[pre-1]
    pre = a[i]
print(score)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var a int
	var b string
	fmt.Scan(&a)
	fmt.Scan(&b)

	temp := ""
	res := 0

	for i := 0; i < a; i++ {
		if temp == b[i:i+1] {
			continue
		}
		temp = b[i : i+1]
		res++
	}

	fmt.Println(res)
}

func spritString(input string) (res []string) {
	for i := 0; i < utf8.RuneCountInString(input); i++ {
		res = append(res, input[i:i+1])
	}
	return
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, N, S;
  cin >> H >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);  
  }
  
  S = 0;
 
  for (int i = 0; i < N; i++) {
    S = S + A.at(i);  
  }
  
  if ( H-S <= 0 ) {
    cout << "Yes" << endl; 
  }
  else {
    cout << "No" << endl; 
  }
  
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		while(sc.hasNext()) {
			String s = sc.next();
			if(palindrom(s)) {
				cnt++;
			}
		}
		sc.close();
		System.out.println(cnt);
	}
	static boolean palindrom(String s) {
		if(s.length() == 1) return true;
		for(int i = 0; i < s.length() / 2; i++) {
			if(s.charAt(i) != s.charAt(s.length() - i - 1)) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 26172
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define all(a) (a).begin(), (a).end()


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


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

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

using namespace std;

int main(){
  int n;cin>>n;
  int sum=0,maxl=0;
  rep(i,n){
    int l;cin>>l;
    sum+=l;
    maxl=max(maxl,l);
  }

  if(maxl<sum-maxl){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 1010
 
bool a[MAX][MAX];
int dp[MAX][MAX];
int H, W;
 
bool get_dir(int n, bool dir)
{
    return (n % 2 == 0 ? dir : !dir);
}
 
void find_last_point()
{
    int x = 0, y = 0;
    while (true) {
        if (a[y][x] == 1) {
            x++;
        } else {
            y++;
        }
        if (x >= W || y >= H) break;
    }
    cout << y+1 << " " << x+1 << endl;
}
 
int main()
{
    int N;
    while (cin >> H >> W >> N, H) {
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> a[i][j];
            }
        }

        memset(dp, 0, sizeof(dp));
        dp[0][0] = N-1;

        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (dp[i][j] == 0) continue;
                a[i][j] = get_dir(dp[i][j], a[i][j]);
                if (dp[i][j] % 2 == 1) {
                    if (a[i][j] == 0) {
                        dp[i+1][j] += dp[i][j] / 2;
                        dp[i][j+1] += dp[i][j] / 2 + 1;
                    } else {
                        dp[i+1][j] += dp[i][j] / 2 + 1;
                        dp[i][j+1] += dp[i][j] / 2;
                    }
                } else {
                    dp[i+1][j] += dp[i][j] / 2;
                    dp[i][j+1] += dp[i][j] / 2;
                }
            }
        }
        find_last_point();
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  ll A, B, K;
  cin >> A >> B >> K;
  if (A > K) {
    cout << A - K << " " << B << endl;
  } else if ((A + B) > K) {
    cout << 0 << " " << A + B - K << endl;
  } else {
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
sys.setrecursionlimit(200000)
# input関係の定義
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
# template

H, W = mi()
S = [li() for i in range(H)]
ans = []
for i in range(H):
    for j in range(W):
        if S[i][j] == "B":
            ans.append((i, j))
        
ans.sort(key=lambda x: x[0] + x[1])
debug(ans[-1])
debug(ans[0])
tmp = abs(ans[-1][0] - ans[0][0]) + abs(ans[-1][1] - ans[0][1])
ans.sort(key=lambda x: x[0] + (W - x[1]))
debug(ans[-1])
debug(ans[0])
tmp2 = abs(ans[-1][0] - ans[0][0]) + abs(ans[-1][1] - ans[0][1])
print(max(tmp,tmp2))


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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    ll q,h,s,d,n;
    cin >> q >> h >> s >> d;
    cin >> n;

    ll twol = q * 8;
    twol = min(twol, h * 4);
    twol = min(twol, s * 2);
    twol = min(twol, d);

    ll ans = 0;

    if(n % 2 == 0){
        ans = n / 2 * twol;
    }else{
        ll onel = q * 4;
        onel = min(onel, h * 2);
        onel = min(onel, s);

        ans = n / 2 * twol + onel;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
//#define double long double
const double PI=acos(-1.0);
int sig(double d) {
	return fabs(d) < 1e-8 ? 0 : d < 0 ? -1 : 1;
}

struct Point {
	double x, y;
	double k;
	Point(){}
	Point(double x, double y): x(x), y(y) {}
	void set(double x, double y) {
		this->x = x;
		this->y = y; 
	}
	double mod() {
		return sqrt(x*x+y*y);
	}
	double mod_pow() {
		return x*x + y*y;
	}
	void output() {
		printf("x = %f, y = %f\n", x, y);
	}
	bool operator < (const Point &p) const {
		return sig(x-p.x) != 0 ? x < p.x : sig(y-p.y) < 0;
	}
}P[110];
int ch[110];
double ang[110],ans[110];
double dot(Point &o, Point &a, Point &b) {
	return (a.x-o.x)*(b.x-o.x) + (a.y-o.y)*(b.y-o.y);
}

double dot(Point &a, Point &b) {
	return a.x*b.x + a.y*b.y;	//(a.x-o.x)*(b.x-o.x) + (a.y-o.y)*(b.y-o.y);
}
double cross(Point o, Point a, Point b) {
	return (a.x - o.x)*(b.y - o.y)-(b.x - o.x)*(a.y - o.y);
}
int btw(Point &x, Point &a, Point &b) {
	return sig(dot(x, a, b));
}
double dis(Point a, Point b) {
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

double cos(Point o, Point a, Point b) {
	return dot(o,a,b)/dis(o,a)/dis(o,b);
}

int jarvis(Point *p, int n, int *ch) {
	static int d, i, o, s, l, t;
	for(d = i = 0; i < n; i ++)
		if(p[i] < p[d])
			d = i;
	l = s = *ch = d;
	d = 1;
	do {
		o = l;
		for(i = 0; i < n; i ++)
			if((t=sig(cross(p[o], p[l], p[i])))>0 || (t==0 && btw(p[l], p[o], p[i])<=0))
				l = i;
		ch[d ++] = l;
	} while(l != s); 
	return d-1;
}


int main()
{
	memset(ang,0,sizeof(ang));
	memset(ans,0,sizeof(ans));
	int n,xx,yy;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&xx,&yy);
		P[i].set(xx,yy);
	}
	if(n==2){
		puts("0.5");
		puts("0.5");
	}else{
		int m=jarvis(P,n,ch);
		double sum=0;
//for(int i=0;i<m;i++){
//	printf("%d ",ch[i]);
//}puts("");
		if(m==2){
			ans[ch[0]]=0.5;
			ans[ch[1]]=0.5;
		}else{
			for(int i=0;i<m;i++){
				ang[ch[i]]=PI-acos(cos(P[ch[i]],P[ch[(i-1+m)%m]],P[ch[(i+1)%m]]));
			}
			for(int i=0;i<n;i++){
				ans[i]=ang[i]/2./PI;
			}
		}
		for(int i=0;i<n;i++){
			printf("%.20f\n",ans[i]);
		}
	}
	return 0;
}

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

int main()
{
	int a, b;

	scanf("%d%d", &a, &b);
	if (a < b) printf("a < b\n");
	else if (a > b) printf("a > b\n");
	else printf("a == b\n");
	return 0;
}



Measured memory_bytes: 2092
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;

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

ll func(ll x){
	return (x>0?x:-x);
}

int main(){
	ll n,x;
	cin>>n>>x;
	ll in[n];
	rep(i,n){
		cin>>in[i];
		in[i]-=x;
	}
	ll ans=func(in[0]);
	loop(i,1,n){
		ans=gcd(ans,func(in[i]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String res = "YES";
        int[] C = new int[3];
        char[] S = sc.next().toCharArray();
        for(char ch : S) C[ch - 'a']++;
        if(S.length < 3) {
            for(int a : C) if(a > 1) res = "NO";
        }
        else if(S.length % 3 == 0) {
            if(C[0] != C[1] || C[1] != C[2]) res = "NO";
        } else {
            for(int a : C) if(a < S.length / 3 || a > S.length / 3 + 1) res = "NO";
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 26932
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using li = long long;
using vi = vector<li>;
using vs = vector<string>;


int main()
{
    int h,w,n,x=0,a;
    cin>>h>>w>>n;
    int ans[h*w];
    rep(i,n) {
        cin>>a;
        rep(j,a) ans[x+j]=i+1;
        x+=a;
    }
    rep(i,h){
        if(i%2==0) rep(j,w) cout<<ans[i*w+j]<<" ";
        else rep(j,w) cout<<ans[i*w+w-1-j]<<" ";
        cout<<endl;
    }
    return 0;
}


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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define l(i,a,b) for(int i=a;i<b;i++)
#define L(i,a,b) for(int i=a;i<=b;i++)
#define r(i,a,b) for(int i=a;i>=b;i--)
#define R(i,a,b) for(int i=a;i>b;i--)
#define scanl(a) scanf("%lld",&a)
#define scani(a) scanf("%d",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanil(a,b) scanf("%d %lld",&a,&b)
#define pr(a) cout<<a<<" "<<endl;
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" a "<<b<<" b "<<c<<"\n"
#define input(a,n) l(i,0,n) cin>>a[i];

long long int m = 998244353;

//long long int mod = 1000000000;
//ll mod=998244353;
long long  int modularExponentiation(long long int x,long long int n)
{   x = abs(x);
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return  modularExponentiation((x*x),n/2)%m;
    else                             //n is odd
        return (x*(modularExponentiation((x*x)%m,(n-1)/2)))%m;
}

long long int GCD(long long int a,long long  int b)
{
    if (a == 0)
        return b;
    return GCD(b % a, a);
}

/*
int n=10;
struct node1 {
    long long int sum,prefix,suffix;
    sum=prefix=suffix=0;
};
struct node1 tree[2*n+2];

void join(int node){
    int l=2*node,r=l+1;
    tree[node].sum = tree[l].sum+tree[r].sum;
    tree[node].prefix = max(tree[l].prefix,tree[l].sum+tree[r].prefix);
    tree[node].suffix = max(tree[r].suffix,tree[l].suffix+tree[r].sum);
}

void build(int node , int l ,int r){
    if(l==r){
        tree[node].sum = a[l];
        tree[node].prefix = max(0,a[l]);
        tree[node].suffix = max(0,a[l]);
    } else {
        int mid = (l+r)/2;
        auto first,second;
        build(2*node,l,mid);
        build(2*node+1,mid+1,r);
        join(node,2*node,2*node+1);
    }
}

void update(int node,int l,int r,int p){
    if(l>r){
        return ;
    } else if(l==p && r==p){
        tree[node].sum=a[p];
        tree[node].prefix=max(0,a[p]);
        tree[node].suffix = max(0,a[p]);
    } else {
        int mid = (l+r)/2;
        update(2*node,l,mid,p);
        update(2*node+1,mid+1,r,p);
        join(node);
    }
}

node1 query(int node,int l,int r, int start,int last){
    if(start<=l && last>=r){
        return tree[node];
    } else if(l>r){
        return null;
    }
    int mid = (l+r)/2;
    auto first,second;
    first= query(2*node,l,mid,start,last);
    second = query(2*node+1,mid+1,r,start,last);
    join
}
*/



int main(){
    int n;
    cin>>n;
    int a[n+1];
    a[0]=0;
    l(i,1,n+1)  cin>>a[i];
    long long int dp[n+1];
    l(i,0,n+1){
        dp[i]=1e18;
    }
    a[0]=a[1];
    dp[0]=0,dp[1]=0;
    l(i,2,n+1){
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n]<<endl;
}




Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,t;
	cin>>n>>t;
	vector<int> a(n),b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	vector<vector<int>> dp1(n+1,vector<int>(t,0));
	vector<vector<int>> dp2(n+1,vector<int>(t,0));
	rep(i,n){
		rep(j,t){
			chmax(dp1[i+1][j],dp1[i][j]);
			if(j-a[i]>=0) chmax(dp1[i+1][j],dp1[i][j-a[i]]+b[i]);
		}
	}
	for(int i=n-1;i>=0;i--){
		rep(j,t){
			chmax(dp2[i][j],dp2[i+1][j]);
			if(j-a[i]>=0) chmax(dp2[i][j],dp2[i+1][j-a[i]]+b[i]);
		}
	}
	int ans=0;
	rep(i,n){
		rep(j,t){
			chmax(ans,dp1[i][j]+dp2[i+1][t-1-j]+b[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 70912
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().execute(System.in);
	}

	public void execute(InputStream in) {
		Scanner sc = new Scanner(in);
		
		int k = sc.nextInt();
		String s = sc.next();
		
		if (s.length() <= k) {
			System.out.println(s);
		}
		else {
			System.out.println(s.substring(0, k) + "...");
		}
		sc.close();
	}
}


Measured memory_bytes: 38652
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();
		int ans = 1;
		for (int i =0;i<n ;i++ ) {
			ans = Math.min(ans*2,ans+k);
		}
		System.out.println(ans);


	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
        int memo = A + B + C;
        if(memo >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }
}


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

int main(){
    double a,b,ans;
    cin >> a >> b;
    for(ll i=1;i<2000;i++){
        double c,d;
        c=i*0.08;
        d=i*0.1;
        if(c>=a&&c<a+1.0){
            if(d>=b&&d<b+1.0){
                cout << i << endl;
                return 0;
            }
        }
    }
    
    cout << -1 << endl;

    return 0;
}











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

vector<int> v[200100];
queue<int> q;
int visited[200100];
int x[200100];
int parent[200100];
int n,e;


void bfs()
{
	while(!q.empty())
	{
		int u = q.front();
		q.pop();

		for(int i=0;i<v[u].size();i++)
		{
			if(!visited[v[u][i]])
			{
				visited[v[u][i]]=1;
				x[v[u][i]]=x[u]+1;
				parent[v[u][i]]=u;
				q.push(v[u][i]);
			}
		}
		
	}

}

int main(void)
{

	int a,b;
	cin >> n >> e;

	for(int i=0;i<e;i++)  //directed graph with path from a->b
	{      
		cin >> a >> b;
		v[a].push_back(b);    //simple graph
		v[b].push_back(a);    //simple graph        

	}

	for(int i=1;i<=n;i++)
	{
		x[i]=-1;
		visited[i]=0;
		parent[i]=-1;
	}

	q.push(1);
	visited[1]=1;
	parent[1]=1;
	x[1]=0;
	bfs();

	int possible=1;
	for(int i=1;i<=n;i++)
	{
		if(parent[i] == -1)
		{
			cout << "No\n";
			possible=-1;
			break;
		}
	}
	if(possible == 1)
	{
		cout << "Yes\n";
		for(int i=2;i<=n;i++)
			cout << parent[i] << endl;
	}

	return 0;
}




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

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

    if (N < 10) {
        cout << R + 100 * (10 - N) << endl;
    }

    else {

        cout << R << endl;
    }

return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

ans = 'IMPOSSIBLE'
if max(A) >= K:
    # from math import gcd
    from fractions import gcd
    from functools import reduce
    g = reduce(gcd,A)
    # print(g)
    if K % g == 0: ans = 'POSSIBLE'

print(ans)

Measured memory_bytes: 14224