akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int a = Integer.parseInt(st.nextToken());
	 		int b = Integer.parseInt(st.nextToken());
	 		int c = Integer.parseInt(st.nextToken());
	 		int d = Integer.parseInt(st.nextToken());
	 		int e = Integer.parseInt(st.nextToken());
	 		
 		if (a == 0){
 			out.println(1);
 		}
 		else if (b == 0){
 			out.println(2);
 		}
 		else if (c == 0){
 			out.println(3);
 		}
 		else if (d == 0){
 			out.println(4);
 		}
 		else if (e == 0){
 			out.println(5);
 		}
 		
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 		
 		
 		
 		
	




Measured memory_bytes: 25448
n,m = map(int,input().split())
numSet = set(range(1,n+1))
L,R = [],[]
for i in range(m):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
if min(R) >= max(L):
  print(min(R)-max(L)+1)
else:
  print(0)

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

int main() {
  int32_t n, m;
  cin >> n >> m;

  int32_t e[n];

  for (int32_t i = 0; i < n; i++) {
    e[i] = 0;
  }

  for (int32_t i = 0; i < m; i++) {
    int32_t a, b;
    cin >> a >> b;
    if (a == 1 || a == n) {
      e[b]++;
    }
    if (b == 1 || b == n) {
      e[a]++;
    }
  }

  for (int32_t i = 0; i < n; i++) {
    if (e[i] >= 2) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  int s = 1;
  int count = 0;
  while(s <= n) {
    s *= k;
    count++;
  }
  cout << count << endl;
} 

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

town = [False]*(N+1)
visited_town = []
p = 1
while True:
    if town[p]:
        break
    visited_town.append(p)
    town[p] = True
    p = A[p-1]
#ループに入るまでに訪れた街
m = visited_town.index(p)

#ループ内の街
c = len(visited_town)-m

# print(m,c)
# print(visited_town,town)

if K <= m:
    print(visited_town[K])
else:
    print(visited_town[m+(K-m) % c])

Measured memory_bytes: 32172
#include<bits/stdc++.h>
using namespace std;
long long n,l[90];
int main()
{
    cin>>n;
    l[0]=2;l[1]=1;
    for(int i=2;i<=n;i++)
      l[i]=l[i-1]+l[i-2];
    cout<<l[n];
    return 0;
}

Measured memory_bytes: 256
<?php

$a = trim(fgets(STDIN));
$b = strlen($a);
$input = str_split($a);
$result = "No";
sort($input);

if (($input[0] == $input[1] && $input[2] == $input[3]) and ($input[2] != $input[1])) {
    $result = "Yes";
} else if ($input[0] == $input[1] && $input[0] == $input[2]) {
    $result = "No";
} else if ($input[0] == $input[1] && $input[0] == $input[3]) {
    $result = "No";
}
echo $result;
?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ignore ignore
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define YES printf("YES\n")
#define NO printf("NO\n")
#define yes printf("Yes\n")
#define no printf("No\n")
#define lin printf("\n")
// Iterator
#define rep(i,n) for(i=0;i<n;++i)
#define rrep(i,n) for(i=n-1;i>=0;--i)
#define lp(i,a,b) for(i=a;i<b;++i)
#define rlp(i,a,b) for(i=a;i>=b;--i)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// function
#define sz(x) x.size()
#define inrange(i,a,b) (i>=a && i<=b)
#define FLUSH fflush(stdout)
#define precision(x) cout << setprecision(x) << fixed
#define remax(a,b) a=max(a,b)
#define remin(a,b) a=min(a,b)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
// Constant
const double PI = acos(-1);
const double eps = (1e-9);
const ll INF = 2e15;
const int M = (1e9)+7;
const int N = (1e5);  // check the limit, man
int main()
{
    int n,k,i;
    in2(n,k);
    vi v(n);
    read(v,i,n);
    sort(all(v));
    ll sum=0;
    rep(i,n-k)
        sum+=v[i];
    llout(sum);
}







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

main() {
    int N; cin >> N;
    if(N==1) cout << "Hello World" << endl;
    else {int A,B; cin >> A >> B;
    cout << A+B << endl;} 

    return 0;
}

Measured memory_bytes: 256
N = int(input())
N_keta = len(str(N))
ans = 0
if N_keta % 2 == 1:
  ans += N-10**(N_keta-1)+1
  for keta in range(N_keta-1,0,-1):
    if keta % 2 == 1:
      ans += (10**keta-1)-(10**(keta-1))+1
else:
  for keta in range(N_keta-1,0,-1):
    if keta % 2 == 1:
      ans += (10**keta-1)-(10**(keta-1))+1

print(ans)

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

long long getdigit(long long num){
    long long digit=0;
    while(num>0){
        num/=10;
        digit++;
    }
    return digit;
}


int main(){
    long long N;
    cin >> N;
    long long x=sqrt(N);
    int ans=getdigit(N);
    int cur;
    for (long long i = 1; i<=x+1; i++){
        if(N%i==0){
            ll B=N/i;
            cur=max(getdigit(i),getdigit(B));
        }
        if(ans>cur){
            ans=cur;
        }
    }
    cout << ans << endl;
    
    
}


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

using namespace std;

int main()
{
    int A[3];
    for(int i = 0; i < 3; ++i) cin >> A[i];
    sort(A, A+3);
    int sum = 0;
    for(int i = 0; i < 2; ++i){
        sum += A[i+1] - A[i];
    }
    cout << sum << endl;
    return 0;
}



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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

#O(nlogn)
def f(x):
    cnt = 0 #幸福度x以上になるペアの個数(A_i + A_j >= xを満たす(i,jの個数))
    # 変形して,x - A_i <= A_j
    for i in a:
        idx = bl(a,x-i)
        cnt += n - idx
        # mペア以上出来るならTrue
        if cnt >= m:
            return True
    return False

n,m = LI()
a = LI()
a.sort()
ng,ok = 2*max(a)+1,2
#O(log(max(a)))
while ng - ok > 1:
    mid = (ng+ok) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid

ans = 0
tmp = 0
b = [0] + list(accumulate(a))
#O(nlogn)
for i in a:
    idx = bl(a,ok-i)
    # i*(n-idx) := 左手で握手する人の幸福度(i)*左手で握手する回数(n-idx)
    # (b[-1] - b[idx]) := 右手で握手する人の幸福度の総和
    ans += i*(n - idx) + (b[-1] - b[idx])
    # tmp := 左手で握手する人を決めたときの右手で握手した人の数の総和 = ペアの総数
    tmp += n - idx

# ペアの数がm以上なら答えからペアの数がmになるよう最小のペアの幸福度(ok)を引く
ans = ans - (tmp - m)*ok
print(ans)


Measured memory_bytes: 60816
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct rect {
    int h,w;
} rect;

bool compr(const rect & a, const rect & b){
    int sa = a.w*a.w + a.h*a.h;
    int sb = b.w*b.w + b.h*b.h;
    if(sa != sb) return sa < sb;
    return a.h < b.h;
}

int main(){
    vector<rect> dic;
    dic.reserve(150*75);
    for(int h=1; h<=150; h++){
        for(int w=h+1; w<=150; w++){
            rect r = {h,w};
            dic.push_back(r);
         }
    }
    sort(dic.begin(), dic.end(), compr);
    int h,w;
    while(cin >> h >> w, h||w){
        rect r = {h,w};

        vector<rect>::iterator it = upper_bound(dic.begin(), dic.end(), r, compr);
        cout << (it->h) << " " << (it->w) << endl;
    }
    return 0;
}

Measured memory_bytes: 1300
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] p = new int[M];
		String[] S = new String[M];

		for (int i = 0; i < M; i++) {
			p[i] = sc.nextInt() - 1;
			S[i] = sc.next();
		}
		sc.close();

		boolean[] ac = new boolean[N];
		Arrays.fill(ac, false);

		boolean[] b = new boolean[N];
		for(int i=0;i<M;i++) {
			if(S[i].equals("AC")) {
				b[p[i]] = true;
			}
		}
		
		
		int numOfAC = 0;
		int numOfWA = 0;

		for (int i = 0; i < M; i++) {
			if (S[i].equals("AC")) {
				if (!ac[p[i]]) { //AC済みでないなら
					numOfAC++;
					ac[p[i]] = true;
				}
				//AC済みならすでにカウントされているので何もしない
				
			} else { // WA
				if (!ac[p[i]] && b[p[i]]) { //AC済みでないなら
					numOfWA++; //ペナルティを増やす
				}
				//AC済みならペナルティなし
			}
		}

		out.println(numOfAC + " " + numOfWA);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 69484
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	map<long long int, long long int> cnt;
	for(int i = 0; i < n; i++){
		long long int a;
		cin >> a;
		if(cnt.find(a) == cnt.end()) cnt[a] = 1;
		else cnt[a]++;
	}
	vector<long long int> v;
	for(auto itr = cnt.begin(); itr != cnt.end(); itr++){
		if((*itr).second >= 2){
			v.push_back((*itr).first);
		}
		if((*itr).second >= 4){
			v.push_back((*itr).first);
		}
	}
	int s = v.size();
	if(s < 2){
		cout << 0 << endl;
	} else {
		long long int ans = v[s - 1] * v[s - 2];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6528
import sys
import math
from collections import deque
n,m = map(int, input().split())

q = [0]*(n+1)

graph = [[] for _ in range(n+1)]
for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

dist = [-1] * (n+1)
dist[0] = 0
dist[1] = 0

if m == 0:
    print(1)
    exit()

d = deque()
a = 0
for l,j in enumerate(q):
    b = set()
    if j == 0:
        d.append(l)
        while d:
            v = d.popleft()
            b.add(v)
            q[v] = -1

            for i in graph[v]:
                b.add(i)
                q[i] = -1

                if dist[i] != -1:
                    continue
                dist[i] = dist[v] + 1
                d.append(i)
        a = max(a,len(b))
print(a)

Measured memory_bytes: 133236
import Control.Applicative

main :: IO ()
main = do
  [b,c] <- map read . words <$> getLine
  putStrLn $ solve b c

solve :: Int -> Int -> String
solve a b
  | a == 1 && b >= 2 = "Alice"
  | a >= 2 && b == 1 = "Bob"
  | a <= 13 && b <= 13 && a < b = "Bob"
  | a <= 13 && b <= 13 && a > b = "Alice"
  | otherwise = "Draw"


Measured memory_bytes: 508
import copy

from collections import deque


def check(s):
    que = deque()
    que.append(s)
    while len(que) != 0:
        tmp_ele = que.pop()
        flgs[tmp_ele] = True
        for ele in tmp_G[tmp_ele]:
            if not flgs[ele]:
                que.append(ele)

    for flag in flgs:
        if not flag:
            return False
    else:
        return True


if __name__ == '__main__':
    N, M = map(int, input().split())
    graph_list = []

    for i in range(M):
        tmp_a, tmp_b = map(int, input().split())
        graph_list.append((tmp_a, tmp_b))

    G = [[] for _ in range(N + 1)]
    for a, b in graph_list:
        G[a].append(b)
        G[b].append(a)

    ans = 0

    for a, b in graph_list:
        tmp_G = copy.deepcopy(G)
        tmp_G[a].remove(b)
        tmp_G[b].remove(a)
        flgs = [False for _ in range(N + 1)]
        flgs[0] = True
        if not check(1):
            ans += 1

    print(ans)

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {
public static void main(String[]args) {
	Scanner tc = new Scanner (System.in);
	int a,b;
	a=tc.nextInt();
	b=tc.nextInt();
	if(a>b) {
		System.out.println(a*2-1);
	}
	if(b>a) {
		System.out.println(b*2-1);
	}
	if(a==b) {
		System.out.println(a+b);
	}
}
}


Measured memory_bytes: 25300
N, A, B, C, D = map(lambda  x: int(x) - 1, input().split())
S = input()
if C < D:
    if "##" in S[A: D + 1]:
        print("No")
    else:
        print("Yes")
else:
    if "##" in S[A: D + 1] or not("..." in S[B - 1: D + 2]):
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 9392
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void solve();

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

void solve() {
  int X, N; cin >> X >> N;
  set<int> s;
  for (int i = 0; i < N; i++) {
    int p; cin >> p;
    s.insert(p);
  }

  int ans = 0;
  for (int i = 0; i < 1000; i++) {
    if (!s.count(X-i)) {
      ans = X-i;
      break;
    }
    if (!s.count(X+i)) {
      ans = X+i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3196
#include<stdio.h>
int main(void)
{
    int N,i,a,b,c;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
    	scanf("%d %d %d",&a,&b,&c);
    	if(a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)
    	{
    		printf("YES\n");
    	}
    	else
    	{
    		printf("NO\n");
    	}
    }
    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
int d[202020];
int ans[2020];
int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x = 0;
		for (int j = 0; j < 10; j++)
		{
			int z;
			scanf("%d", &z);
			x += z << j;
		}
		d[i] = x;
	}
	for (int q = 0; q < n; q++)
	{
		int t[11];
		for (int i = 0; i < 11; i++)scanf("%d", &t[i]);
		for (int p = 0; p < 1024; p++)
		{
			int x = p&d[q];
			int c = 0;
			for (int i = 0; i < 10; i++)if (x&(1 << i))c++;
			ans[p] += t[c];
		}
	}
	int maxi = -2000000000;
	for (int i = 1; i < 1024; i++)maxi = max(maxi, ans[i]);
	printf("%d\n", maxi);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

struct card{int num; char suit;};
card a[100000];
#define inf 1000000001
void merge(card a[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    card l[n1 + 1], r[n2 + 1];
    rep(i, n1) l[i] = a[left + i];
    rep(i, n2) r[i] = a[mid + i];
    l[n1].num =  inf;
    r[n2].num = inf;
    int i = 0, j = 0;
    for(int k = left; k < right; k++){
        if(l[i].num <= r[j].num){
            a[k] = l[i];
            i++;
        }else{
            a[k] = r[j];
            j++;
        }
    }
}

void mergesort(card a[], int left, int right){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        mergesort(a, left, mid);
        mergesort(a, mid, right);
        merge(a, left, mid, right);
    }
}

int partition(int p, int r){
    int x = a[r].num;
    int i = p - 1;
    for(int j = p; j < r; j++){
        if(a[j].num <= x){
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i+1], a[r]);
    return i + 1;
}

void quicksort(int p, int r){
    if(p < r){
        int q = partition(p, r);
        quicksort(p, q-1);
        quicksort(q+1, r);
    }
}

int main(){
    int n;
    cin >> n;
    card b[n];
    rep(i, n) cin >> a[i].suit >> a[i].num;
    rep(i, n) b[i] = a[i];
    quicksort(0, n-1);
    mergesort(b, 0, n);
    bool ans = true;
    rep(i, n){
        if(a[i].suit != b[i].suit) ans = false;
    }
    if(ans) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    rep(i, n){
        cout << a[i].suit << " " << a[i].num << endl;
    }
}




Measured memory_bytes: 5360
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<pair<int,int>> cities(m);
    vector<vector<int>> s(100001,vector<int>());
    for(int i = 0; i < m; ++i)
    {
        int p,y;
        cin >> p >> y;
        cities[i] = make_pair(p,y);
        s[p].push_back(y);
    }

    for(int i = 0; i < 100001; ++i)
    {
        sort(s[i].begin(),s[i].end());
    }

    cout << setfill('0');
    for(pair<int,int> c : cities)
    {
        int pnum = c.first;
        int cnum = distance(s[pnum].begin(),lower_bound(s[pnum].begin(),s[pnum].end(),c.second))+1;
        cout << setw(6) << pnum << setw(6) << cnum << endl;
    }
}

Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int taro, hanako; cin >> taro >> hanako;
        if(taro == 0 and hanako == 0) return 0;
        else {
            vector<int> TaroCard(taro), HanakoCard(hanako);
            int taroSum = 0, hanakoSum = 0;
            REP(i, taro){
                cin >> TaroCard[i];
                taroSum += TaroCard[i];
            }
            REP(i , hanako){
                cin >> HanakoCard[i];
                hanakoSum += HanakoCard[i];
            }
            bool flag = false;
            pair<int, int> ans = make_pair(INF, INF);
            REP(i, taro){
                REP(j, hanako){
                    if(taroSum - TaroCard[i] + HanakoCard[j] == hanakoSum - HanakoCard[j] + TaroCard[i] 
                    and ans.first + ans.second > TaroCard[i] + HanakoCard[j]){
                        flag = true;
                        ans = make_pair(TaroCard[i], HanakoCard[j]);
                    }
                }
            }
            if(flag) cout << ans.first << " " << ans.second << endl;
            else cout << -1 << endl;
        }
    }
}


Measured memory_bytes: 3044
#include <stdio.h>
#define M 100000
#define N -10

void cal();


int G[101][101],n;

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

  for(i=0;i<n;i++){
    
    for(j=0;j<n;j++){
      
      scanf("%d",&m);
      if(m==-1){
	G[i][j] = M;
      } else{
	G[i][j] = m;}
    }
  }

  cal();
  
  return 0;
}

void cal()
{
  int i;
  int min,u,v;
  int gou=0;
  int a[101],b[101],c[101];
  
  for(i=0;i<n;i++){
    a[i] = M;
    b[i] = N;
    c[i] = 0;
  }

  a[0] = 0;

  while(1){
    min = M;
    u = N;
    for(i=0;i<n;i++){
      if(c[i]!=2 && a[i]<min){
	min = a[i];
	u = i;
      }
    }
    if(u==N)break;
    
    c[u] = 2;

    for(v=0;v<n;v++){
      if(c[v]!=2 && G[u][v]!=M){

	if(a[v]>G[u][v]){
	  a[v] = G[u][v];
	  b[v] = u;
	  c[v] = 1;
	}
      }
    }
    
  }
  for(i=0;i<n;i++){
    if(b[i]!=N)gou += G[i][b[i]];
  }
  
  printf("%d\n", gou);
}




Measured memory_bytes: 2084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    set<string> s;
    cin >> n;
    rep(i,n){
        string si;
        cin >> si;
        s.insert(si);
    }
    if (s.size() == 3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	b -= a;
	if (b < 0) b *= -1;

	if (b > d * (n-1)){
		cout << "NO" << endl;
		return 0;
	}

	REP(i,n-1){
		ll po = n - i - 1, ng = i;
		ll ma = po * d - ng * c;
		ll mi = po * c - ng * d;
		// cout << mi << " " << ma << endl;
		if (mi <= b && b <= ma){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;

	return 0;
}

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

using namespace std;

const int Inf = 1e9;

int main()
{
    int n, m, k;    cin >> n >> m >> k;

    vector <int> C(n);
    vector <vector <int>> A(n, vector <int> (m));

    for(int i = 0; i < n; i++)
    {
        scanf("%d", &C[i]);
        for(int& x : A[i])  scanf("%d", &x);
    }

    int Ans = Inf;

    for(int Mask = 0; Mask < (1 << n); Mask++)
    {
        int Cost = 0;
        vector <int> B(m);

        for(int i = 0; i < n; i++)
            if(Mask & (1 << i))
                Cost += C[i];

        for(int i = 0; i < n; i++)
            if(Mask & (1 << i))
                for(int j = 0; j < m; j++)
                    B[j] += A[i][j];

        if(*min_element(B.begin(), B.end()) >= k)   Ans = min(Ans, Cost);
    }

    if(Ans == Inf)  Ans = -1;

    cout << Ans << endl;
}


Measured memory_bytes: 3700
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
int p[10] = { 0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2 };
int Q[10] = { 1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3 };
int R[10] = { 2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4 };
ll a, r, c;
int main() {
	int N; cin >> N;
	map<char, ll> count;

	string MARCH = "MARCH";
	for (int i = 0; i < 5; ++i) count[MARCH[i]] = 0;

	for (int i = 0; i < N; ++i) {
		string S;  cin >> S;
		count[S[0]] += 1;
	}

	// conbinations
	int first[10] = { 0, 0, 0, 0, 0, 0, 1, 1, 1, 2 };
	int second[10] = { 1, 1, 1, 2, 2, 3, 2, 2, 3, 3 };
	int third[10] = { 2, 3, 4, 3, 4, 4, 3, 4, 4, 4 };

	long long res = 0;
	for (int i = 0; i < 10; ++i) res += count[MARCH[first[i]]] * count[MARCH[second[i]]] * count[MARCH[third[i]]];
	cout << res << endl;
}

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

// 
int main() {
    long long A, B, V, W, T;
    cin >> A >> V >> B >> W >> T;

    long long currentDiff = abs(A - B);
    long long runDiff = (V - W);
    // cout << runDiff * T << endl;
    // if ((A + (V * T)) >= (B + (W * T))) {
    if (currentDiff <= (runDiff* T)) {
        cout << "YES";
    } else {
        cout << "NO";
    }
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}

const int N = 18;

vector<ii> ar[(1<<N)];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  //c = x&-x, r = x+c; (((r^x) >> 2)/c) | r
  int n; cin>>n;
  vi a(n), b(n);
  rep(i,0,n) {
    cin>>a[i];
  }
  rep(i,0,n) cin>>b[i];
  rep(i,0,n) {
    if(i%2 == 0)
      ar[(1<<i)].pb({a[i], 0});
    else ar[(1<<i)].pb({b[i], 0});
    debug(ar[(1<<i)]);
  }
  rep(i,1,n) {
    int x = (1<<(i+1))-1;
    int k = ((1<<(i+1))-1)<<(n-i-1);
    debug(x, k);
    do {
      debug(x, "mask");
      int cnt = 0;
      rep(j,0,n) {
        if(x & (1<<j)) {
          int p = a[j];
          if(i%2 != j%2) p = b[j];
          int f = MOD;
          for(auto y: ar[x^(1<<j)]) {
            if(y.fi<=p) {
              f = min(f, y.se + i-cnt);
            }
          }
          cnt++;
          if(f == MOD) continue;
          ar[x].pb({p, f});
          debug(ar[x], j, "subm");
        }
      }
      if(x == k) break;
      int c = x&-x, r = x+c; x = (((r^x) >> 2)/c) | r;
    }
    while(true);
  }
  int ans = MOD;
  for(auto x: ar[(1<<n)-1]) ans = min(ans, x.se);
  //assert(ans == MOD || ans%2 == 0);
  if(ans == MOD) cout<<-1<<endl;
  else cout<<ans<<endl;

}



Measured memory_bytes: 36480
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

int f[2000][2000];
int c[20];
int p[20];
int s[20];
int n , G ;

int main ()
{
	int i , j , k ;
	scanf("%d%d",&n,&G);G/=100;
	for ( i=1 ; i<=n ; i++ ) scanf("%d%d",c+i,p+i),p[i]/=100,s[i]=s[i-1]+c[i];
	for ( i=1 ; i<=n ; i++ ) 
		for ( j=1 ; j<=s[i] ; j++ )
			for ( k=0 ; k<=min(j,c[i]) ; k++ )
				if ( k==c[i] ) f[i][j]=max(f[i][j],f[i-1][j-c[i]]+i*c[i]+p[i]);
				else f[i][j]=max(f[i][j],f[i-1][j-k]+i*k);
	// for ( i=1 ; i<=s[n] ; i++ ) printf("%d ",f[n][i]);puts("");
	for ( i=1 ; i<=s[n] ; i++ ) 
		if ( f[n][i]>=G ) break;
	printf("%d\n",i);
	return 0 ;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int a[]= new int[N];
		for (int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		Arrays.parallelSort(a);
		int count =0;
		for (int i=0;i<N;i++) {
			if (x>=a[i]) {
				count++;
				x-=a[i];
			}
		}
		if (x>0&&count==N) {
			count --;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 36040
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// ここまで

fn run() {
    input! {
        n: usize,
        m: usize,
        e: [(usize1, usize1); m],
    }
    let mut a = vec![false; n];
    let mut b = vec![false; n];
    for (x, y) in e {
        if x == 0 {
            a[y] = true;
        }
        if y == n - 1 {
            b[x] = true;
        }
    }
    for i in 1..(n - 1) {
        if a[i] && b[i] {
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}

fn main() {
    run();
}


Measured memory_bytes: 13944
n,k=map(int,input().split())
a=input()
ans=0
cnt=0
for i in range(n-1):
  if a[i]==a[i+1]:
    ans+=1
  if a[i]!=a[i+1]:
    cnt+=1
ans=min(n-1,ans+min(cnt,k)*2)
print(ans)
    

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	int w[200000];
	int b[200000];
	fill(w,w+n,0);
	fill(b,b+n,0);
	for(int i=0;i<n;i++){
		if(s[i]=='#'){
			b[i]++;
		}else{
			w[i]++;
		}
	}
	for(int i=1;i<n;i++){
		b[i]+=b[i-1];
	}
	for(int i=n-1;i>0;i--){
		w[i-1]+=w[i];
	}
	int ans=min(n-b[n-1],n-w[0]);
	for(int i=0;i<=n-2;i++){
		ans=min(ans,b[i]+w[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2180
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [[n-1 for n in list(map(int, input().split()))] + [-1] for _ in range(N)]
A = [a[::-1] for a in A]

def main(N, A):
    now = [A[i].pop() for i in range(N)]
    day = 0
    rest = N * (N-1)
    candidate = set(range(N))

    # WCS O(N**2) <- 1日に1試合だけのときN(N-1)/2回while文が繰り返される
    while True:
        # terminal condition
        # O(1)
        if rest == 0:
            return day

        # see if we have match today
        # O(N)
        have_match = False
        # tmp = now.copy()
        # for i in range(N):
        #     if now[now[i]] == i:
        #         tmp[i] = A[i].pop()
        #         rest -= 1
        #         have_match = True
        # now = tmp
        change = []
        next_candidate = set()
        for i in candidate:
            if now[now[i]] == i:
                j = A[i].pop()
                change.append((i, j))
                # あとで(a, b)でnow[a] = bに更新する
                next_candidate.add(i)
                if j != -1:
                    next_candidate.add(j)
                
                rest -= 1
                have_match = True

        if len(change) == 0:
            return -1
        for (a, b) in change:
            now[a] = b
            
        candidate = next_candidate
        
        day += 1

print(main(N, A))

Measured memory_bytes: 42608
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 Y = sc.nextInt();
    int ans = Integer.MAX_VALUE;
    for(int i=0; i<=100000; i++){
      int temp = 2*C*i + A*Math.max(0,X-i) + B*Math.max(0, Y-i);
      ans = Math.min(ans, temp);
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 22100
#include<stdio.h>
#include<math.h>
#include<string.h>

#define FR(N) for(int i = 0;i < N;i++)
#define PR(N) printf("%d\n",N)
#define MJ(S) printf("%s\n",S)

int min(int a,int b){
  if(a < b)return a;
  return b;
}
int max(int a,int b){
  if(a > b)return a;
  return b;
}
int z(int a){
  if(a < 0)return -a;
  return a;
}
int yu(int a,int b){
  if(a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
void swap(int *x,int *y) {
  int temp = *x;
  *x = *y;
  *y = temp;
}
int partition(int array[],int left,int right) {
  int i,j,pivot;
  i = left;
  j = right + 1;
  pivot = left;
  do{
    do{i++;}while(array[i] < array[pivot]);
    do{j--;}while(array[pivot] < array[j]);
    if(i < j)swap(&array[i],&array[j]);
  }while(i < j);
  swap(&array[pivot],&array[j]);
  return j;
}
void q_sort(int array[],int left,int right) {
  int pivot;
  if(left < right){
    pivot = partition(array,left,right);
    q_sort(array,left,pivot - 1);
    q_sort(array,pivot + 1,right);
  }
}

int main(void){
  int n;
  scanf("%d",&n);
  PR(180 * (n - 2));
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

typedef tuple<ll, ll> mtupl;

bool mycomp(mtupl x, mtupl y) {
	return get<1>(x) < get<1>(y);
}

vector<vector<ll>> memo;

ll get(int x, int y) {
	if (memo[x][y] != -1)
		return memo[x][y];

	if (x == 0) return 1;
	if (y < x) return 0;

	memo[x][y] = get(x, y - 1) + get(x - 1, y - 1);
	return memo[x][y];
}

ll mpow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; i < b; i++) {
		ans *= a;
		ans %= 1000000007;
	}
	return ans;
}

ll nCr(ll n, ll r) {
	ll res = 1;
	for (int i = 0; i < r; i++) {
		res *= (n - i);
	}
	for (int i = 1; i <= r; i++) {
		res /= i;
	}
	return res;
}

int vsum(vector<int> v) {
	int res = 0;
	for (auto it = v.begin(); it != v.end(); it++)
		res += *it;
	return res;
}
int vmin(vector<int> v) {
	int min = INT32_MAX;
	for (auto it = v.begin(); it != v.end(); it++)
		min = std::min(min, *it);
	return min;
}
int vmax(vector<int> v) {
	int max = INT32_MIN;
	for (auto it = v.begin(); it != v.end(); it++)
		max = std::max(max, *it);
	return max;
}

ll gcd(ll A, ll B) {
	if (A == 0 || B == 0) return max(A, B);
	int r = A % B;
	while (r != 0) {
		A = B;
		B = r;
		r = A % B;
	}

	return B;
}

vector<bool> to_binary(int x) {
	vector<bool> res;
	while (x != 0) {
		res.push_back(x % 2);
		x /= 2;
	}
	return res;
}

template<int index>
bool comp(tuple<ll, ll, ll, ll> a, tuple<ll, ll, ll, ll> b) {
	return get<index>(a) < get<index>(b);
}

int vector_finder(std::vector<ll> vec, ll number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return index;
	}
	else { // 発見できなかったとき
		return 0;
	}
}


int len(int x) {
	return (int)log10(x) + 1;
}


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

	int N;
	cin >> N;
	vector<ll> H(N);
	rep(i, N) cin >> H[i];

	ll ans = 1, prev = 10000000000;
	for (int i = N - 1; i >= 0; i--) {
		//cout << to_string(H[i]) + " : " + to_string(prev) << endl;
		if (H[i] <= prev) {
			prev = H[i];
		}
		else {
			//cout << H[i] << endl;
			if (H[i] - 1 <= prev) {
				prev = H[i] - 1;
			}
			else {
				ans = 0;
			}
		}
	}

	cout << (ans ? "Yes" : "No") << endl;

ProgramEndPointLabel:;

	//Program End
	system("pause");

	return 0;
}
/*

*/




Measured memory_bytes: 1272
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,ans=LLINF;
    cin>>n;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,n/i+i);
        }
    }
    cout<<ans-2<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-16-01.38.11 Sunday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5+1000;
int n, h[maxn], dp[maxn];

int myabs(int a, int b) {return (a-b>0?a-b:b-a);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> n;
    for1(i, n) cin >> h[i];
    ms(dp, 0x3f);
    dp[1] = 0;
    for (int i = 1; i <= n; ++i) {
        //cerr << dp[2] << endl;
        if (i+1 <= n) dp[i+1] = min(dp[i+1], dp[i]+myabs(h[i], h[i+1]));
        if (i+2 <= n) dp[i+2] = min(dp[i+2], dp[i]+myabs(h[i], h[i+2]));
        //cerr << '&' << dp[2] << endl;
    }
    cout << dp[n] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1024
char r[99],g[99],*G,d[99];main(c,i,k){for(;scanf("%s%s%s",r,g,d)>1;puts(G))for(i=k=0,G=g,c=*G++;*(G-1);)c==d[k]?k++,c=r[i++]:(putchar(c),c=*G++);exit(0);}

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

int main(){
    int n;
    cin >> n;
    int a[n+1] = {};
    int count[n+1] = {};
    for (int i = 2; i < n+1; i++){
        cin >> a[i];
        count[a[i]]++;
    }
    for (int i = 1; i < n+1; i++){
        cout << count[i] <<endl;
    }
    return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  rep(i,N) A[i]-=i+1;
  sort(all(A));
  ll ans=0;
  ll ans2=0;
  if(N%2) rep(i,N) ans+=abs(A[i]-A[N/2]);
  else rep(i,N) ans+=abs(A[i]-(A[N/2]+A[N/2-1])/2);
  cout<<ans<<endl;
}

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

int main(){
  int n;
  cin >> n;
  if(n < 105)
    cout << "0" << endl;
  else if( n >= 105 && n < 135)
    cout << "1" << endl;
  else if( n >= 135 && n < 165)
    cout << "2" << endl;
  else if( n >= 165 && n < 189)
    cout << "3" << endl;
  else if( n >= 189 && n < 195)
    cout << "4" << endl;
  else
    cout << "5" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    private long fac[];
    private long finv[];
    private long inv[];
    private static int MAX_LEN = 510000;
    private static int MOD = 1000000007;
    public static void main(String[] args) {
        Main main = new Main();
        main.COMinit();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        Arrays.sort(A);
        HashMap<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            int count = map.getOrDefault(A[i], 0);
            map.put(A[i], count + 1);
        }
        List<Point> list = new ArrayList<>();
        for (long x : map.keySet()) {
            Point p = new Point(x, map.get(x));
            list.add(p);
        }
        list.sort(new PointComparator());
        int len = list.size();
        long max_sum = 0;
        long min_sum = 0;
        int count = 0;
        for (int i = 0; i < len; i++) {
            int current_group = list.get(i).count;
            long current_value = list.get(i).x;
            int remain = N - count;
            for (int j = 0; j < current_group; j++) {
                long x = COM(remain - (j + 1), K - 1) * current_value;
                x %= MOD;
                min_sum += x;
                min_sum %= MOD;
            }
            for (int j = 0; j < current_group; j++) {
                long x = COM(count +  j, K - 1) * current_value;
                x %= MOD;
                max_sum += x;
                max_sum %= MOD;
            }
            count += current_group;
        }
        long answer = max_sum - min_sum + MOD;
        answer %= MOD;
        System.out.println(answer);
    }
    void COMinit() {
        this.fac = new long[MAX_LEN];
        this.finv = new long[MAX_LEN];
        this.inv = new long[MAX_LEN];
        this.fac[0] = this.fac[1] = 1;
        this.finv[0] = this.finv[1] = 1;
        this.inv[1] = 1;
        for (int i = 2; i < MAX_LEN; i++) {
            fac[i] = fac[i-1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i-1] * inv[i] % MOD;
        }
    }
    long COM(int n, int k) {
        if (n < k) {
            return 0;
        };
        if (n <0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k]%MOD)%MOD;
    }
    class Point {
        long x;
        int count;
        Point(long x, int count) {
            this.x = x;
            this.count = count;
        }
    }
    class PointComparator implements Comparator<Point> {
        @Override
        public int compare(Point o1, Point o2) {
            return Long.compare(o1.x, o2.x);
        }
    }
}


Measured memory_bytes: 78016
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#define mk make_pair
#define pb push_back
#define scanf scanf_s
#define printf printf_s
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> pos;
const ll N = 200010, MOD = 1000000007;

ll  d, a, n;
pos xh[N];
queue<pos> q;

int main() {
	cin >> n >> d >> a;
	for (int i = 1; i <= n; i++) {
		cin >> xh[i].first >> xh[i].second;
	}
	sort(xh + 1, xh + n + 1);
	ll dlt = 0, ans = 0;
	for (int i = 1; i <= n; i++) {
		while (!q.empty()) {
			if (q.front().first < xh[i].first) { dlt -= q.front().second; q.pop(); }
			else break;
		}
		xh[i].second -= dlt;
		if (xh[i].second >= 0) {
			ans += (xh[i].second + a - 1) / a; 
			dlt += a * ((xh[i].second + a - 1) / a);
			q.push(mk(xh[i].first + d * 2, a * ((xh[i].second + a - 1) / a)));
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int L,R,d,Ans=0;
  cin>>L>>R>>d;
  
  for(int i=L;i<=R;i++){
    if(i%d==0){Ans++;}
  } 
  cout<<Ans<<endl;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    int i;
    int count;
    
    count = 0;
    
    cin >> a >> b >> c;
    
    for(i = a;i <= b;i++){
        if(c % i == 0){
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


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

using namespace std;

int main(){
  int rows, cols, k;
  cin>>rows>>cols>>k;

  vector<string> matrix;

  for(int i=0;i<rows;i++){
    string s;
    cin>>s;
    matrix.push_back(s);
  }

  int res=0;

  for(int rowMask=0; rowMask< (1<<rows); rowMask++){
    for(int colMask=0; colMask< (1<<cols); colMask++){
      // scan matrix to look for k blacks
      int blk_count=0;
      for(int i=0;i<rows;i++){
        for(int j=0;j<cols;j++){
          // if row or col colored continue
          if( ((rowMask&(1<<i))==0)&&((colMask&(1<<j))==0) && (matrix[i][j]=='#') ){
            blk_count++;
          }
          
        }
      }

      if(blk_count==k){
        res+=1;
      }
    }
  }
  cout<<res<<endl;
    
}

Measured memory_bytes: 3612