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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    for (int i = k; i < n; i++) {
        if (a.at(i - k) < a.at(i)) {
            cout << "Yes" << endl;
        }
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4000
#include <stdio.h>
#include <math.h>

double get_angle(double x1, double x2, double y1, double y2) {
	if(fabs(x1-x2)<0.000001) {
		return 180;
	} else if(fabs(y1-y2)<0.000001) {
		return 0;	
	} else {
		return tan((y2-y1)/(x2-x1))*180/M_PI;
	}
}

int main(void) {
	int i, n;
	double x1, y1, x2, y2, x3, y3, x4, y4;
	double a1, a2;
	scanf("%d\n", &n);
	for(i=0;i<n;i++) {
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf\n", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
		a1 = get_angle(x1, x2, y1, y2);
		a2 = get_angle(x3, x4, y3, y4);

		if(fabs(a1-a2)<0.00001) {
			printf("YES\n");
		} else {
			printf("NO\n");
		}
	}
	
	return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

/////////////////////////////////////////////////////////////
ll mypow_core(ll x, int n, ll result) {
  if (n == 0) {
    return result;
  }

  if (n % 2 == 0) {
    return mypow_core(x * x, n / 2, result);
  } else {
    return mypow_core(x, n - 1, x * result);
  }
}

ll mypow(ll x, int n) { return mypow_core(x, n, 1); }
/////////////////////////////////////////////////////////////

const int MAX_N = (int)(1e3 + 5);

int n, k;

ll a[MAX_N];

bool check(ll target, int m) {
  int cnt = 0;

  ll hope = target + mypow(2LL, m);

  for (int i = 0; i < n; ++i) {
    ll tmp = 0LL;
    for (int j = i; j < n; ++j) {
      tmp += a[j];

      cnt += ((hope & tmp) == hope) ? 1 : 0;
    }
  }

  return cnt >= k;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &k);

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

  ll ans = 0LL;

  for (int i = 40 + 3; i >= 0; --i) {
    if (check(ans, i)) {
      ans += mypow(2LL, i);
    }
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#![allow(unused)]

use std::{cell, cmp, collections, fmt, ops};

use cell::{Cell, RefCell};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use fmt::{Debug, Display};

// 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 mut 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")
    };
}

#[cfg(feature = "debug")]
macro_rules! d {
    ($($args: tt)*) => { dbg!($($args)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! d {
    ($($args:tt)*) => {};
}

mod num {
    //
}

macro_rules! vmin {
    ($x: expr, $y: expr) => { cmp::min($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::min($x, vmin!($($args),*)) };
}

macro_rules! vmax {
    ($x: expr, $y: expr) => { cmp::max($x, $y) };
    ($x: expr, $($args: expr),*) => { cmp::max($x, vmax!($($args),*)) };
}

mod bits {
    pub fn is_high(bits: u64, pos: u64) -> bool {
        bits & (1 << pos) != 0
    }
}

fn main() {
    input!(t: i32, x: i32);
    println!("{}", t as f64 / x as f64);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352
X,Y = map(int,input().split())

ans = 0
if X == 1 and Y == 1:
    ans += 400000

if X == 3:
    ans += 100000
if X == 2:
    ans += 200000
if X == 1:
    ans += 300000


if Y == 3:
    ans += 100000
if Y == 2:
    ans += 200000
if Y == 1:
    ans += 300000

print (ans)


Measured memory_bytes: 38384
# coding: utf-8
# Your code here!
K = int (input())
line= list(map(int,input().split()))
a,b = line[0],line[1]
if b<K:
    print("NG")
    

else:
    for i in range(a,b+1):
        if i%K==0:
            print("OK")
            break
        elif i==b:
            print("NG")

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  ll n, k; cin >> n >> k;
  ll ans = LINF;
  while(true) {
    if (n==k) {
      ans = 0;
      break;
    } else if (n > k) {
      n=n%k;
    } else {
      ll v = abs(n-k);
      if (n <= v) { ans = n; break; }
      n = v;
    }
  }

  COUT(ans);
  return 0;
}


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;

int main(){
    int n, node, d, p;
    cin >> n;
    int a[n][n];
    rep(i, n)rep(j, n) a[i][j] = 0;
    rep(i, n){
        cin >> node >> d;
        rep(i, d){
            cin >> p;
            a[node - 1][p - 1] = 1;
        }
    }
    rep(i, n){
        rep(j, n){
        if(j) cout << " ";
        cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3084
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

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

int bar[110];

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

	ll ans = 0;

	for (int i = 0; i < N * 2; i++) 
		cin >> bar[i];
	
	sort(bar,bar+N*2);
	for (int i = 0; i < N * 2; i += 2) {
		ans += min(bar[i], bar[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	string s;
	int n, i, j, k, q, t, f, x;
	char ch;

	cin >> s;
	deque<char> qq;
	for (auto ch : s) qq.push_back(ch);

	x = 0;
	cin >> q;
	while (q--) {
		cin >> t;
		if (t == 1) x = 1 - x;
		else {
			cin >> f >> ch;
			f--;
			if (f == x) qq.push_front(ch);
			else qq.push_back(ch);
		}
	}

	if (x == 0) {
		while (!qq.empty()) {
			ch = qq.front();
			cout << ch;
			qq.pop_front();
		}
	}
	else {
		while (!qq.empty()) {
			ch = qq.back();
			cout << ch;
			qq.pop_back();
		}
	}

	cout << "\n";
	return 0;
}


Measured memory_bytes: 960
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	ll a, b, x;
  	cin >> a >> b >> x;
  	ll ax = a/x;
	ll bx = b/x;
  	ll ans = bx - ax;
  	if(a%x == 0){
    	ans++;
    }
  
  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template <typename T>
inline bool chmax (T& a, T b)
{
  if(a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  int N, ac = 0, wa = 0, tle = 0, re = 0;
  cin >> N;
  vector<string> S (N);
  rep(i, N)
  {
    cin >> S[i];
  }
  rep(i, N)
  {
    if(S[i] == "AC")
    {
      ac++;
    }
    else if(S[i] == "WA")
    {
      wa++;
    }
    else if(S[i] == "TLE")
    {
      tle++;
    }
    else if(S[i] == "RE")
    {
      re++;
    }
  }

/*  for(string x : S)
  {
    cout << x << endl;
  } */
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 6360
import java.util.*;
import java.io.*;

public class Main{

   private static void Even(int K, int N, PrintWriter output){
       output.print(K / 2);
       for(int i = 1; i < N; ++ i) output.print(" " + K);
       output.println();
   }

   private static void Odd(int K, int N, PrintWriter output){
       ArrayList<Integer> arrayMid = new ArrayList<Integer>();
       for(int i = 0; i < N; ++ i) arrayMid.add(i, (K + 1) / 2);    
       for(int i = 0; i < N / 2; ++ i){
           if(arrayMid.get(arrayMid.size() - 1) <= 1) arrayMid.remove(arrayMid.size() - 1);
           else{
               arrayMid.set((arrayMid.size() - 1), arrayMid.get(arrayMid.size() - 1) - 1);
               while(arrayMid.size() < N) arrayMid.add(K);
           }
       }
       for(int i = 0; i < arrayMid.size(); ++ i){
           output.print(arrayMid.get(i));
           if(i < arrayMid.size() - 1) output.print(" ");
           else output.println();
       }
   }

   public static void main(String [] args){
       InputStream inputStream = System.in;
       OutputStream outputStream = System.out;
       Scanner input = new Scanner(inputStream);
       PrintWriter output = new PrintWriter(outputStream);
       int K = input.nextInt();
       int N = input.nextInt();
       if(K % 2 == 0) Even(K, N, output);
       else Odd(K, N, output);
       input.close();
       output.close();
   }
}

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    switch (n % 10) {
        case 3:
            cout << "bon" << ln;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << ln;
            break;
        default:
            cout << "hon" << ln;
            break;
    }

    return 0;
}


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;


class Program
{
    static void Main () 
    {
        String[] fsline = Console.ReadLine().Split(' ');
        String[] sdline = Console.ReadLine().Split(' ');

        long x = long.Parse(fsline[0]);
        long n = long.Parse(fsline[1]);
        List<long> pn = new List<long>();
        long ans = 0;

        for (int i = 0; i < n; i++)
        {
            pn.Add(long.Parse(sdline[i]));
        }

        for (int i = 0; i <= x; i++)
        {
            ans = x - i;
            if (!pn.Contains(ans))
            {
                Console.WriteLine(ans);
                Environment.Exit(0);
            }

            ans = x + i;
            if(!pn.Contains(ans))
            {
                Console.WriteLine(ans);
                Environment.Exit(0);
            }
        }

    }
}

Measured memory_bytes: 28168
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll p; cin>>p;
	string s;
	cin>>s;
	if(p==2 || p==5){
		ll ans=0;
		REP(i,n){
			if((s[i]-'0')%p==0){
				ans+=i+1;
			}
		}
		cout<<ans<<endl;
		return 0;
	}
	map<ll,ll> t;
	t[0]++;
	ll tmp=0,power=1;
	REPR(i,n){
		tmp+=(s[i]-'0')*power;
		tmp%=p;
		t[tmp]++;
		power*=10;
		power%=p;
		//cout<<tmp<<endl;
	}
	ll ans=0;
	for(auto &it:t){
		ans+=it.second*(it.second-1)/2;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int P[100000], Y[100000];
  vector<int> city[100001];
  REP(i, M) {
    cin >> P[i] >> Y[i];
    city[P[i]].push_back(Y[i]);
  }
  REP(i, N) sort(city[i + 1].begin(), city[i + 1].end());
  REP(i, M) {
    printf("%012lld\n",
           ll(P[i]) * 1000000 +
               int(lower_bound(ALL(city[P[i]]), Y[i]) - city[P[i]].begin()) +
               1);
  }
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
using namespace std;
typedef long long lld;
#define MOD 1000000007ll

int N;
string node[1111];
vector<lld> edge[1111];
lld dp[1111];

lld solve(lld now){
  if(dp[now] != -1) return dp[now];
  lld ret = 1;
  if(node[now][0] == 'E'){
    for(int i=0;i<edge[now].size();i++){
      ret = (ret*solve(edge[now][i]))%MOD;
    }
    if(node[now].size() != 1) ret++;
  } else if(node[now][0] == 'A'){
    ret = 0;
    for(int i=0;i<edge[now].size();i++){
      ret = (ret+solve(edge[now][i]))%MOD;
    }
    if(node[now].size() != 1) ret++;
  } else {
    ret = 0;
    if(node[now].size() != 1) ret++;
    for(int j=1;j<=(int)(pow(2.0,(double)(edge[now].size()))-1);j++){
      long long next=1;
      long long d=1;
      for(int i=0;i<edge[now].size();i++){
	if((j&d)!=0){
	  next = (next*solve(edge[now][i]))%MOD;
	}
	d=d<<1;
      }
      ret+=next;
    }
  }    
  return dp[now] = ret%MOD;
}

int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> node[i];
  }
  for(int i=0;i<N-1;i++){
    lld a,b;
    cin >> a >> b;
    a--; b--;
    edge[a].push_back(b);
  }
  memset(dp,-1,sizeof(dp));
  cout << solve(0) << endl;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,a,n) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
 
 
//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
typedef long long ll;

const ll M = MOD;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}
 
int main() {
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }
    
  int s;
  cin >>s;
  long long int ans=0;
  rep(i,0,s/3){
      //db2(s-i*2-3, i)
      ans += comb(s-i*2-3, i);
      ans%=MOD;
  }

  cout<<(ans+MOD)%MOD<<endl;
  
 return 0;
}

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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

inline void File() {
	freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);
}

typedef long long ll;

const int N = 3e5 + 10;
int n, a[N];

int main() {
	int all = (1 << 20) - 1, l = 1;

	scanf("%d", &n);
	For(i, 1, n) scanf("%d", a + i);

	ll ans = 0, sum = 0;

	For(r, 1, n) {
		for (; (sum ^ a[r]) != sum + a[r]; sum ^= a[l], ++ l);
		ans += (r - l + 1), sum ^= a[r];
	}

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


Measured memory_bytes: 1024
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;
 
/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int count = 0;
		
		for(int i = a; i <= b; i++){
			if(i > c) break;
			if(c % i == 0) count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 26312
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    A = [SS() for _ in range(H)]

    d = ((1, 0), (0, 1), (-1, 0), (0, -1))

    dist = [[INF] * W for i in range(H)]
    que = collections.deque()

    for i, j in itertools.product(range(H), range(W)):
        if A[i][j] == '#':
            que.append((i, j))
            dist[i][j] = 0

    while que:
        cy, cx = que.popleft()
        for dy, dx in d:
            ny = cy + dy
            nx = cx + dx
            if 0 <= ny < H and 0 <= nx < W and dist[cy][cx] + 1 < dist[ny][nx]:
                dist[ny][nx] = dist[cy][cx] + 1
                que.append((ny, nx))

    # for i in dist:
    #     print(i)

    ans = max([max(i) for i in dist])
    print(ans)

if __name__ == '__main__':
    resolve()


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

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

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

int i,j,k,l;

int main(){
    int n,m;cin>>n>>m;
    vector<int> h(n),maxi(n,0);

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

    for(i=0;i<m;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        maxi[a]=max(maxi[a],h[b]);//a周辺のmax
        maxi[b]=max(maxi[b],h[a]);//b周辺のmax
    }

    int ans=0;
    for(i=0;i<n;i++){
        if(h[i]>maxi[i]){ans++;}//周辺より高いなら加算
    }

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

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

int main(int argc, const char * argv[]) {
  int N;
  string s1="",s3="";
  cin>>N;
  stack<char> mystack;
  string s;
  cin>>s;
  for(int i=0;i<N;i++){
    char tmp;
    tmp=s[i];
    if(tmp=='(') mystack.push(tmp);
    else{
      if(!mystack.empty()&&mystack.top()=='(') {mystack.pop();}
      else mystack.push(tmp);
    }
  }
  while(!mystack.empty()){
    if(mystack.top()=='(') {mystack.pop();s3=s3+')';}
    else {mystack.pop();s1=s1+'(';}
  }
  string result=s1+s+s3;
  
  cout<<result;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<cstdlib>
using namespace std;



int main(){
   string chars;
   int inp;
  while(cin >> chars && chars !="0"){
    // inp=atoi(chars.c_str());
    int keta=chars.size();
    int ans=0;
    int amari[keta][11];
    int t;
    int s;
    for(int i=0;i<keta;i++){
      t=(int)chars[i]-(int)'0';

      if(i==0){
	for(int j=0;j<11;j++){
	  amari[i][j]=0;
	}
      }else{
      
	for(int j=0;j<11;j++){
	  s=((10-j)+t+1)%11;
	  amari[i][j]=amari[i-1][s];
	}
      }
      if(t!=0){amari[i][t]++;}

      ans+=amari[i][0];
    }

    cout << ans <<endl;
  }
}


  
    

Measured memory_bytes: 4748
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner stdIn=new Scanner(System.in);

        String s=stdIn.next();

        char[] c=s.toCharArray();

        if(c[2]==c[3]&&c[4]==c[5]){
            System.out.println("Yes");
            
        }
        else{
            System.out.println("No");
            
        }
        
        
    }

}

Measured memory_bytes: 23252
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
  int i,j,n,c,a[10][10],x,y,frag,f2;
  c = 0;
  while(1){
    cin >> n;
    if(n == 0) break;

    f2 = x = y = 0;
    frag = 1;
    for(i=1;i<=n*n;i++){
      a[y][x] = i;
      if(y == 0 && x < n-1 && f2 == 0 && frag == 1){
	x++;
	frag = 0;
      }
      else if(x == 0 && y < n-1 && f2 == 0 && frag == 0){
	y++;
	frag = 1;
      }
      else if(y == 0 && x == n-1 && frag == 1){
	y++;
	frag = 0;
	f2 = 1;
      }
      else if(x == 0 && y == n-1 && frag == 0){
	x++;
	frag = 1;
	f2 = 1;
      }
      else if(x == n-1 && f2 == 1 && frag == 1){
	y++;
	frag = 0;
      }
      else if(y == n-1 && f2 == 1 && frag == 0){
	x++;
	frag = 1;
      }

      else if(frag == 0){
	x--;
	y++;
      }
      else if(frag == 1){
	x++;
	y--;
      }
    }

    c++;
    cout << "Case " << c << ":" << endl;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	printf(" %2d",a[i][j]);
      }
      cout << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int T[2020],n,len,ans,B[12];
void Check(){
	int x=0;
	memset(B,0,sizeof(B));
	for (int i=1;i<=len;i++)
		x=x*10+T[i],B[T[i]]++;
	if (!B[3]||!B[5]||!B[7]) return;
	if (x<=n) ans++;
}
void Dfs(int x){
	if (x==len+1){
		Check(); return;
	}
	T[x]=3; Dfs(x+1);
	T[x]=5; Dfs(x+1);
	T[x]=7; Dfs(x+1);
}
int main(){
	scanf("%d",&n);
	int x=n,L=0;
	while (x) L++,x/=10;

	for (len=1;len<=L;len++) Dfs(1);		
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  int n, t, a;
  cin >> n;
  cin >> t >> a;
  int h[n];
  int i;
  for (i = 0; i < n; i++){
    cin >> h[i];
  }

  int ans;
  double dif_max = 10000000;
  double dif;
  for (int i = 0;i < n; i++){
    dif = abs(a - (t - h[i] * 0.006));
    if (dif < dif_max){
      ans = i;
      dif_max = dif;
    }
  }
  cout << ans + 1<< endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <unordered_map>
#include <string>
#include <vector>

using namespace std;

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

  int max_freq = 0; // numeric_limit<int>::min(); 
  unordered_map<string, int> m;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    if (m.find(s) == m.end()) {
      m[s] = 1;
    } else {
      m[s] += 1;
    }

    if (m[s] > max_freq) {
        max_freq = m[s];
      }
  }

  vector<string> dict;
  for (auto it = m.begin(); it != m.end(); ++it) {
    if (it->second == max_freq) {
      dict.push_back(it->first);
    }
  }

  sort(dict.begin(), dict.end());

  for (auto s : dict) {
    cout << s << endl;
  }
  
  return 0;
}



Measured memory_bytes: 26692
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define fill(a) memset(a,0,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll a[n];
    repA(i,1,n)
    cin>>a[i];
    map<ll,ll>mp;
    ll cnt=1;
    ll i=1;
    vi v;
    while(mp[i]==0 && k)
    {
       // cout<<i<<" "<<cnt<<endl;
       v.pb(i);
      mp[i]=cnt;
      cnt++;
      i=a[i];
      k--;
      
    }
    if(k==0)
      cout<<i<<endl;
    else
    {
      ll cyc=cnt-mp[i];
    //  cout<<cyc;
      k%=cyc;
      cout<<v[mp[i]-1+k]<<endl;
    }
 }

Measured memory_bytes: 15436
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
int h[100005];
int d[100005];
int dp(int i, int n, int k);

int main()
{
  memset(d,-1,sizeof d);
  int n, k;
  cin >> n >> k;
  for(int i = 1; i <= n; i++) cin >> h[i];
  cout << dp(1, n, k) << endl;
}

int dp(int i, int n, int k)
{
  //cout << i << endl;
  if(i == n) return 0;
  if(d[i] != -1) return d[i];
  d[i] = INFINITY;
  for(int x = 1; x <= k; x++)
  {
    if(i + x > n) continue;
    d[i] = min(d[i], dp(i + x, n, k) + abs(h[i + x] - h[i]));
  }
  return d[i];
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    string S;
    cin >> S;
    int ans = 0;
    int N = S.size();
    for (int i = 0; i < N; i++)
    {
        if ((S[i] - '0') == i % 2) ans++;
    }
    ans = min(ans, N - ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n=sc.nextLong();
        long p=sc.nextLong();
        if(n==1){
            System.out.println(p);
        }else{
            for(long i=(long)Math.pow(p, 1/n)+1;i>0;i--){
                if(p%Math.pow(i,n)==0){
                    System.out.println(i);
                    return;
                }
            }
        }
    }
 
    
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
#define mod 998244353
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

bool prime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
    return a.fi>b.fi;
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
string s; cin>>s;
if(s=="ARC")cout<<"ABC\n";
else cout<<"ARC\n";
return 0;

}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];

void dijkstra()  {
  int minv;
  int d[MAX], color[MAX];
  
  for (int i = 0; i < n; i++)  {
    d[i] = INFTY;
    color[i] = WHITE;
  }
  
  d[0] = 0;
  color[0] = GRAY;
  while ( 1)  {
    minv = INFTY;
    int u = -1;
    for ( int i = 0; i < n; i++)  {
      if (minv > d[i] && color[i] != BLACK )  {
        u = i;
        minv = d[i];
      }
    }
    if (u == -1)  break;
    color[u] = BLACK;
    for (int v = 0; v < n; v++)  {
      if (color[v] != BLACK && M[u][v] != INFTY)  {
        if (d[v] > d[u] + M[u][v] )  {
          d[v] = d[u] + M[u][v];
          color[v] = GRAY;
        }
      }
    }
  }

  for (int i = 0; i < n; i++)  {
    cout << i << " " << ( d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main()  {
  cin >> n;
  for (int i = 0; i < n; i++)  {
    for (int j = 0; j < n; j++)  {
      M[i][j] = INFTY;
    }
  }
  
  int k, c, u, v;
  for (int i = 0; i < n; i++)  {
    cin >> u >> k;
    for (int j = 0; j < k; j++)  {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
 
  dijkstra();
  
  return 0;
} 

Measured memory_bytes: 3112
#include <iostream>

using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int i, j, k;

    for (i = 0; i < n1; i++) L[i] = A[left + i];
    for (i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;

    i = 0; j = 0;
    for (k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(int A[], int n, int left, int right)
{
    int mid = (left + right) / 2;

    if (left + 1 < right) {
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main()
{
    int A[MAX], n, i;
    cnt = 0;

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

    mergeSort(A, n, 0, n);

    for (i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 6932
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

int main() {
  kyun;
  int a,b;
  cin >> a >> b;
  if((a+b) % 2 == 0) cout << (a+b)/2;
  else cout << "IMPOSSIBLE";
  hinata;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

  
        signed main() {
     int a,b,c;
     cin>>a>>b>>c;
     if(c-a-b<0){
             cout<<"No";
             return 0;
     }
     if(4*a*b<(c-a-b)*(c-a-b))cout<<"Yes";
     else cout<<"No";
   
     
     
    

      
        


      }


        


Measured memory_bytes: 256
#pragma GCC target("avx")
//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL vector<LL>
#define VP vector<pair<LL,LL>>
#define VVL vector<vector<LL>>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define EB emplace_back
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;i++)
#define FORR(i,a,n) for(i=n-1;i>=a;i--)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FOR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define LB(a,n) *lower_bound(ALL(a),n)
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
//#define ERR 0.00000000000001
#define NUM 200010
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)printf("Yes\n");else printf("No\n");}
void YN(LL a){if(a)printf("YES\n");else printf("NO\n");}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL LBn(VL &v,LL a){LL mx=v.size(),mn=-1,md;while(mx-mn>1){md=(mx+mn)/2;if(v[md]<a)mn=md;else mx=md;}return mx;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a%m<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(m,d);x-=k*y;swap(x,y);}return mod(a*mod(x,MOD),MOD);}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(pair<LL,LL> a,pair<LL,LL> b){if(a.second!=b.second)return a.second<b.second;return a.first<b.first;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  FAST;
  LL i,ans=0,N,K,a,b;
  cin>>N>>K;
  FOR(i,K,N+2){
    a=(i-1)*i/2,b=i*N-a;
    ans+=b-a+1;
    ans%=MOD;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3656
//
//  main.cpp
//  c++proj
//
//  Created by chiiia12 on 2016/04/18.
//
//

#include <iostream>
#include <vector>
using namespace std;

int cnt;
vector<int> G;

void insertionSort(int* a,int g,int n){
    for(int i = g-1;i<n;i++){
        int j = i;
        while(j-g>=0&&a[j-g]>a[j]){
            int tmp = a[j];
            a[j] = a[j-g];
            a[j-g] = tmp;
            j=j-g;
            cnt++;
        }
    }
}
void selectionSort(int* a,int n){
    cnt = 0;
    for(int h =1;;){
        if(h>n)break;
        G.push_back(h);
        h=3*h+1;
    }
    for(int i = G.size()-1;i>=0;i--){
        insertionSort(a,G[i],n);
    }
}

int main() {
    int n;
    cin>>n;
    int a[n];
    for(int i =0;i<n;i++){
        cin>>a[i];
    }
    selectionSort(a,n);
    cout<<G.size()<<endl;
    cout<<G[G.size()-1];
    for(int i = G.size()-2;i>=0;i--){
        cout<<" "<<G[i];
    }
    cout<<endl;
    cout<<cnt<<endl;
    for(int i = 0;i<n;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef long l;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    const l mod = 1000000007;
    l t;
    t = 1;
    //cin>>t;
    while(t--)
    {
        l n;
        cin>>n;
        l ans = (n*(n-1))/2;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys


H, W = map(int, input().split())
field = ["o" for _ in range(H+2)] #indexed from 1
for i in range(1, H+1):
    field[i] = "#" + input() + "#"
field[0] = "#"*(W+2)
field[H+1] = "#"*(W+2)

idxs = []
dxdy = [(1,0), (-1,0), (0,1), (0,-1)]
for row in range(1, H+1):
    for col in range(1, W+1):
        if field[row][col] == ".":
            idxs.append((row, col))
# graph = {idx: deque() for idx in idxs}
# for idx in idxs:
#     x = idx[0]
#     y = idx[1]
#     for dx, dy in dxdy:
#         if field[x+dx][y+dy] == ".":
#             graph[idx].append((x+dx, y+dy))


def bfs(u,v):
    dist = [[-1] * (W+1) for _ in range(H+1)] #indexed from 1
    seen = [[0] * (W+1) for _ in range(H+1)] #indexed from 1
    queue = deque()
    seen[u][v] = 1
    dist[u][v] = 0
    queue.append((u,v))
    graph = {idx: deque() for idx in idxs}
    for idx in idxs:
        x = idx[0]
        y = idx[1]
        for dx, dy in dxdy:
            if field[x+dx][y+dy] == ".":
                graph[idx].append((x+dx, y+dy))
    while queue:
        p, q = queue[0]
        if not graph[(p,q)]:
            queue.popleft()
            continue
        g,h = graph[(p,q)].popleft()
        if seen[g][h]:
            continue
        seen[g][h] = 1
        dist[g][h] = dist[p][q] + 1
        queue.append((g,h))
    ans = -1
    for i in range(1, H+1):
        for j in range(1, W+1):
            ans = max(ans, dist[i][j])
    return ans


res = -1
for sx, sy in idxs:
    res = max(res, bfs(sx, sy))
print(res)


Measured memory_bytes: 78572
#include <bits/stdc++.h>
using namespace std;
#define int long long int
set<int> sqs;
int ar[13][13];
int32_t main(){
	for(int i=0;i<=1000;i++) sqs.insert(i*i);
	int n,d,ans=0;cin>>n>>d;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=d;j++){
			cin>>ar[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int cur=0;
			for(int k=1;k<=d;k++){
				cur+=(ar[i][k]-ar[j][k])*(ar[i][k]-ar[j][k]);
			}
			ans += sqs.count(cur);
		}
	}
	cout<<ans;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; }
template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; }
template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); }
template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); }

int main() {
  ioinit();
  int a, b, q;
  cin >> a >> b >> q;
  vi64 s(a + 2), t(b + 2);
  s[0] = t[0] = -1e18, s[a + 1] = t[b + 1] = 1e18;
  reps(i, a) cin >> s[i];
  reps(i, b) cin >> t[i];
  rep(i, q) {
    i64 x;
    cin >> x;
    int sr = ubi(s, x), sl = sr - 1;
    int tr = ubi(t, x), tl = tr - 1;
    i64 ans = 1e18;
    amin(ans, abs(x - s[sl]) + abs(s[sl] - t[tl]));
    amin(ans, abs(x - t[tl]) + abs(t[tl] - s[sl]));
    amin(ans, abs(x - s[sr]) + abs(s[sr] - t[tr]));
    amin(ans, abs(x - t[tr]) + abs(t[tr] - s[sr]));
    amin(ans, abs(x - s[sl]) + abs(x - t[tr]) * 2);
    amin(ans, abs(x - s[sr]) + abs(x - t[tl]) * 2);
    amin(ans, abs(x - t[tl]) + abs(x - s[sr]) * 2);
    amin(ans, abs(x - t[tr]) + abs(x - s[sl]) * 2);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;

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

	long long int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i <= b; ++i){
		if (i < a+k || i > b-k){
			cout << i << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <bitset>
#include <map>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(){
	ll a[100];
	ll dp[21][100];
	int N;
	cin >> N;
	REP(i, N){
		cin >> a[i];
	}
	REP(i, 21){
		REP(j,100){
			dp[i][j] = 0;
		}
	}
	dp[a[0]][0] = 1;
	FOR(i, 0, N-1){
		FOR(j, 0, 21){
			if(j-a[i+1] >= 0){
				dp[j-a[i+1]][i+1] += dp[j][i];
			}
			if(j+a[i+1] <=20){
				dp[j+a[i+1]][i+1] += dp[j][i];
			}
		}
	}

	cout << dp[a[N-1]][N-2] << endl;
}

Measured memory_bytes: 3104
"""
kari1 = '4 8'
kari2 = '7 9 8 9' #5
#kari1 = '3 8'
#kari2 = '6 6 9' #0
#kari1 = '8 5'
#kari2 = '3 6 2 8 7 6 5 9' #19
#kari1 = '33 3'
#kari2 = '3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3' #8589934591
n, a = map(int, kari1.split())
x_a = list(map(lambda x: int(x) - a, kari2.split()))
"""
n, a = map(int, input().split())
x_a = list(map(lambda x: int(x) - a, input().split()))
dic = dict()
dic[0] = 1

for x in x_a:
    for key, value in list(dic.items()):
        dic[x + key] = value + dic.get(x + key, 0)

print(dic[0] - 1)


Measured memory_bytes: 3188
N=[]
counter=0
for i in range(4):
  N.append(int(input()))

for a in range(N[0]+1):
  for b in range(N[1]+1):
    for c in range(N[2]+1):
      if 500*(a)+100*(b)+50*(c)==N[3]:
        counter+=1
print(counter)

Measured memory_bytes: 3060
#!/usr/bin/ruby

n = gets.to_i
$x = Array.new(n)
$y = Array.new(n)

(0..n-1).each do |i| 
  $x[i],$y[i] = gets.split.map(&:to_i)
end

def dist(i,j)
  tmp = ($x[i]-$x[j])**2 + ($y[i]-$y[j])**2
  return Math.sqrt(tmp)
end

def fact(n)
  return 1 if n == 1
  return n * fact(n-1)
end

# main
sum = 0 

(0..n-1).each do |i| 
  (i..n-1).each do |j| 
    sum += dist(i,j)*fact(n-1)*2
  end 
end

puts sum/fact(n)


Measured memory_bytes: 1788
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>

using namespace std;

int A[200010],B[200010];
int flag = 0;
int main()
{
	int N,M,a,b;
	scanf("%d%d",&N,&M);
	for( int i = 0; i < M; i++){
		scanf("%d %d",&a,&b);
		if(a == 1) A[b] = 1;
		else if( b == N) B[a] = 1;
	}
	for( int i = 1; i <= M; i++){
//		printf("%d %d\n",A[i],B[i]);
		if( A[i] == 1 && B[i] == 1){
			flag = 1;
			break;
		}
	}
	if(flag == 1) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}


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

int main() {
	string S;  cin >> S;
	int ans = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S.substr(i - 1, 2) == "WB" || S.substr(i - 1, 2) == "BW") ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
N, K = map(int, input().split())

sunuke = [0] * N

for i in range(K):
  d = int(input())
  A = list(map(int, input().split()))

  for j in A:
    sunuke[j-1] += 1

sum = 0
for i in range(N):
  if sunuke[i] == 0:
    sum += 1

print(sum)

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
//char a[100][100];

int main(){
    unsigned ll a,b,x;
    cin>>a>>b>>x;
    int cnt=0;
    //unsigned ll a1 = max((unsigned ll)0,a-1);
    unsigned ll val1 = a/x;
    unsigned ll val2 = b/x;
    if(a%x==0) cnt++;
    cout<<val2-val1+cnt<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    int N;
    cin >> N;
    int M;
    cin >> M;
    vector<int> X(M);
    for(int i = 0; i < M; ++i) cin >> X[i];
    sort(all(X));

    if(N >= M) {
        puts("0");
        return 0;
    }
    vector<int> dis(M - 1);
    for(int i = 0; i < M - 1; i++){
        dis[i] = X[i + 1] - X[i];
    }
    sort(all(dis));
    ll sum = 0;
    for(int i = 0; i < M - N; i++){
        sum += dis[i];
    }
    cout << sum << endl;

}

Measured memory_bytes: 1024
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int a[101],sf[101],sb[101];
void solve()
{
	int n,sum=0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum = sum + a[i];
	}
	sf[0] = a[0];
	for (int i = 1; i < n; i++)
		sf[i] = sf[i - 1] + a[i];
	int sol = 1000000;
	for (int i = 0; i < n - 1; i++)
	{
		sol = min(sol, abs(sum - 2 * sf[i]));
	}
	cout << sol;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return(0);
}

Measured memory_bytes: 256