akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //c
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int ans = 0;
  vector<int> neg, pos;
  for (int i = 1; i + 1 < n; i++) {
    if (a[i] < 0) neg.push_back(a[i]), ans -= a[i];
    else pos.push_back(a[i]), ans += a[i];
  }
  neg.push_back(a[0]);
  cout << ans - a[0] + a.back() << endl;
  while (pos.size()) {
    cout << neg[0] << " " << pos.back() << '\n';
    neg[0] -= pos.back();
    pos.pop_back();
  }
  while (neg.size()) {
    cout << a.back() << " " << neg.back() << '\n';
    a.back() -= neg.back();
    neg.pop_back();
  }
  return 0;
}

Measured memory_bytes: 2808
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int bip, s[2], col[100001];
vector<int> G[100001];
bitset<100001> vis;

void dfs(int u, int c) {
    vis[u] = 1, col[u] = c, ++s[c];
    for (int v : G[u]) {
        if (!vis[v]) dfs(v, !c);
        else if (col[u] == col[v]) bip = 0;
    }
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

    int N, M; cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int u, v; cin >> u >> v;
        G[u].push_back(v), G[v].push_back(u);
    }

    ll a = 0, b = 0, c = 0;
    for (int u = 1; u <= N; ++u) if (!vis[u]) {
       bip = 1, s[0] = s[1] = 0;
       dfs(u, 0);
       if (!bip) ++c;
       else if (s[1]) ++b;
       else ++a;
    }

    cout << 2*a*N-a*a+2*b*b+2*b*c+c*c;
}

Measured memory_bytes: 14276
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int parent[(int)1e5+3];
int size[(int)1e5+3];
int ans[(int)1e5+3];
int find(int a){
  if(a == parent[a]){
    return a;
  }else{
    return parent[a] = find(parent[a]);
  }
}

void unite(int a, int b){
  int pa = find(a);
  int pb = find(b);
  if(pa == pb) return;
  size[pb] += size[pa];
  size[pa] = 0;
  parent[pa] = pb;
}

void init(){
  rep(t, 1e5+3){
    parent[t] = t;
    size[t] = 1;
    ans[t] = 0;
  }
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  init();
  int n,m,k;cin>>n>>m>>k;
  rep(t,m){
    int a,b;cin>>a>>b;a--;b--;
    unite(a,b);
    ans[a]--;
    ans[b]--;
  }

  rep(t,k){
    int c,d;cin>>c>>d;
    c--;d--;
    if(find(c) == find(d)){
      ans[c]--;
      ans[d]--;
    }
  }

  rep(i,n){
    cout<<ans[i] + size[find(i)] - 1;
    if(i == n-1) break;
    cout<<" ";
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <numeric>
using namespace std;

int main(void){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for(int i = 0; i <= m; i++){
        for(int j = 22; j <= d; j++){
            if(j-(j/10)*10>=2&&(j/10)*(j-(j/10)*10)==i){
                ans++;
                
            }
                
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using s32 = int;
using u32 = unsigned int;
using s64 = long long int;
using u64 = unsigned long long int;

s32 a, b;

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

  printf("%d\n", a*b);
  return 0;
}


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

using namespace std;

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

using int64 = long long;
const int64 INF = 1LL << 59;

struct edge
{
  int u, v, cost;
};

int main()
{
  int N, M;
  vector< edge > edges;

  cin >> N >> M;
  rep(i, M) {
    int a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    edges.push_back((edge) {a, b, c});
  }

  vector< int64 > m(N, -INF);
  m[0] = 0;
  rep(i, 2 * N + 1) {
    for(auto &e : edges) {
      if(m[e.u] + e.cost > m[e.v]) {
        m[e.v] = m[e.u] + e.cost;
        if(i >= N && e.v == N - 1) {
          cout << "inf" << endl;
          return (0);
        }
      }
    }
  }

  cout << m[N - 1] << endl;
}



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

using namespace std;

typedef long long ll;
typedef vector<int> pi;
typedef pair<int,int> vi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(vi c, vi d){
	return c.S < d.S;
}

int main() {
	int N;
	cin >> N;
	string ans = "No";
	while(N > 0){
		if(N % 10 == 7) ans = "Yes";
		N /= 10;
	}
	cout << ans;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <string.h>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define INF 100000000

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
const ll M = 998244353;

int main(void) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    while(true) {
        c -= b;
        if(c <= 0) { cout << "Yes" << endl; return 0; }
        a -= d;
        if(a <= 0) { cout << "No" << endl; return 0; }
    }

}



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

long acs(const void *a,const void *b){
	
	return *(long *)a - *(long *)b;	
}
int main(){
	long N;
	long A[200200];
	scanf("%ld",&N);
	
	for(int i=0;i<N;i++){
		scanf("%ld",&A[i]);
	}
	
	qsort(A,N,sizeof(long),acs);
	
	for(int i=0;i<N;i++){
		if(A[i]==A[i+1]){
			printf("NO\n");
			return 0;
		}	
	}
	printf("YES\n");
	return 0;	
}

Measured memory_bytes: 3324
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
#define M 1000000007

  
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    int p=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==t[i])
        continue;
        else
        {
            p=1;
            break;
        }
    }
    if(p==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
   
    
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long  int lli;

vector<lli> val, weight;

lli dp(lli i, lli w, vector< vector<lli> > &memo)
{
	if(i==-1)
	{
		return 0;
	}
	if(memo[i][w]!=-1)
	{
		return memo[i][w];
	}

	if(weight[i] > w)
	{
		memo[i][w] = dp(i-1,w,memo);
		return memo[i][w];
	}

	memo[i][w] = max(dp(i-1,w,memo), val[i] + dp(i-1,w-weight[i],memo));
	return memo[i][w];



}

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

	lli w;
	cin>>w;
	w++;

	val.resize(n);
	weight.resize(n);
	

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

	vector< vector<lli> > memo(n, vector<lli>(w, -1));

	//recurrences
	// dp(i,w) = dp(i-1, w) if weight[i] > w
	// dp(i,w) = max(val[i] + dp(i,w - weight[i]), dp(i-1,w)) otherwise
	// base case: dp(0,w) = 0
	w--;
	cout<<dp(n-1,w, memo)<<endl;

}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	string s;
  	int i,n=0;
  
  	cin >> s;
  	for(i = 0; i <= 2; i++){
  		if(s[i]=='1'){
    		n++;
    	}
    }
  	cout << n << endl;
}

Measured memory_bytes: 256
D = int(input())
c = [int(x) for x in input().split()]
s = []
for i in range(D):
    s.append([int(x) for x in input().split()])
kotae = 0
nissuu = [0] * 26
key = ""
for k in range(26):
  nissuu = [0] * 26
  ans = 0  
  for i in range(D):
    t = (i+k) % 26 + 1
    for j in range(26):
        if j == t-1:
            nissuu[j] = 0
        else:
            nissuu[j] += 1
        ans -= c[j]*nissuu[j]
    ans += s[i][t-1]
    if kotae <= ans:
        kotae = ans
        key = k
for i in range(365):
    print((i+2) % 26 + 1)

Measured memory_bytes: 9512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    x = I()
    s = (x-1)//11
    x -= s*11
    ans = s*2
    if x < 7:
        ans += 1
    else:
        ans += 2
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38256
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		Mise[] mise = new Mise[n];
		for (int i = 0; i < n; i++) {
			mise[i] = new Mise(sc.nextInt(), sc.nextInt());
		}
		sc.close();

		// aの昇順
		Arrays.sort(mise, new Comparator<Mise>() {
			public int compare(Mise m1, Mise m2) {
				return m1.a - m2.a;
			}
		});

		long ans = 0L;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			long a = mise[i].a;
			int b = mise[i].b;
			if (cnt + b >= m) {
				ans += a * (m - cnt);
				break;
			} else {
				cnt += b;
				ans += a * b;
			}
		}
		System.out.println(ans);
	}

	static class Mise {
		int a;
		int b;
		public Mise(int a, int b) {
			this.a = a;
			this.b = b;
		}
	}
}


Measured memory_bytes: 89568
def dice_and_coin(n, k)
  ret = n < k ? 0 : (n - k + 1) / n.to_f

  1.upto(n) do |i|
    break if i == k

    count = 1
    val = i * 2
    while val < k
      val *= 2
      count += 1
    end

    ret += (1 / n.to_f) * (0.5 ** count)
  end

  ret
end

n, k = gets.split.map(&:to_i)
puts dice_and_coin(n, k)

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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    int a, ans = 0, p1 = -1, p2 = -1;

    for(int i = 0; i < n; ++i){
        cin >> a;
        //cout << p1 << " " << a << " " << p2 << endl;
        if(i > 1 && ((p1 < p2 && p2 < a) || (a < p2 && p2 < p1)) )
            ++ans;
        int sw = p2;
        p2 = a;
        p1 = sw;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 1010

int main() {
	int a, b, c, cnt=0;
	scanf("%1d%1d%1d", &a, &b, &c);
	
	if(a) cnt++;
	if(b) cnt++;
	if(c) cnt++;
	
	printf("%d", cnt);
} 

Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int a,b,c;
  scanf("%d %d %d", &a, &b, &c);
  printf("%d %d %d\n", c, a, b);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<memory.h>
using namespace std;
const int g[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };
int f[10] = { 0 };
vector<int> p;
int main()
{
	int n;
	while (cin >> n){
		p.clear();
		memset(f, 0, sizeof(f));
		
		
		while (n != 0){
			for (int i = 9; i >= 0; i--){
				if (n - g[i] >= 0 && f[i] == 0){
					n -= g[i];
					f[i] = 1;
					p.push_back(g[i]);
				}
			}
		}
		for (int i = p.size() - 1; i >= 1; i--){
			cout << p[i] << " ";
		}
		cout << p[0] << endl;
	}
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
typedef long long ll;
using namespace std;
int main(void){
    // Your code here!
    string S;
    cin>>S;
    int N=S.length(),ans=0;
    string A[N];
    rep(0,i,N){
        A[i]=S.substr(i,1);
        if(i>=N/2 && A[N-1-i]!=A[i]){
            ++ans;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

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

int main() {
  int n;
  cin >> n;
  int x = (n + 1000 - 1) / 1000;
  int ans = x * 1000 - n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
N = int(input())
a = list(map(int, input().split()))
 
# ソートしたとき、Aliceは偶数(0,2,...)番目を、Bobは偶数(1,3,...)番目を取る
a = sorted(a, reverse=True)
A = 0
B = 0
for i in range(N):
  if i % 2 == 0: A += a[i]
  else: B += a[i]

print(A-B)

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

int64_t dp[1000][1000], mod = int64_t(1e9 + 7);
char b[1000][1000];
vector<pair<int, int>> dd = {{0, -1}, {-1, 0}};

int64_t recurse(int i, int j) {
	int64_t& state = dp[i][j];
  	if(state != -1) return  state;
  	if(b[i][j] == '#') return state = 0;
  	if(i == 0 and j == 0) return state = 1;
  	state = 0;
  	for(auto& d: dd) {
    	int x, y; tie(x, y) = d;
    	if(x + i >= 0 and y + j >= 0) state = (state % mod + recurse(x + i, y + j) % mod) % mod;
    }
  	return state;
}

int main() {
  	int h, w; cin >> h >> w;
  	for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j)
        cin >> b[i][j];
  	memset(dp, -1, sizeof dp);
	cout << recurse(h - 1, w - 1) << endl;  	
	return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include "math.h"
#include <string>
#include "stdio.h"
#include "stdlib.h"

using namespace std;

int main(){

    string a,b,str;
    float sqrt_result,sqrt_tmp = 0;
    float num=0;
    cin >> a >> b;

    str = a + b;
    num = (float)stoi(str);
    sqrt_result = sqrt(num);
    sqrt_tmp = ceil(sqrt_result);

    if(sqrt_result==sqrt_tmp){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    }

    return 0;
}


Measured memory_bytes: 256
using System;

namespace abc107_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] AB = Console.ReadLine().Split(' ');
            int A = Convert.ToInt32(AB[0]);
            int B = Convert.ToInt32(AB[1]);
            int sum = 0;
            for(int i = A; i <= B; i++)
            {
                int dec = 0;
                string iss = Convert.ToString(i);
                for(int n = 0; n < iss.Length / 2; n++)
                {
                    if (iss.Substring(n, 1) != iss.Substring(iss.Length - n - 1, 1))
                    {
                        dec++;
                    }
                }
                if(dec == 0)
                {
                    sum++;
                }
            }
            Console.WriteLine(sum);
            Console.ReadLine();



        }
    }
}


Measured memory_bytes: 38772
import fileinput


def deque_score(item_list):
    player_a_scores = [0] * (len(item_list) * len(item_list))
    player_b_scores = [0] * (len(item_list) * len(item_list))

    for gap in range(len(item_list)):
        for li in range(len(item_list) - gap):

            if gap == 0:
                player_a_scores[li + len(item_list) * li] = item_list[li]
                player_b_scores[li + len(item_list) * li] = -item_list[li]
            else:
                ri = li + gap
                player_a_scores[li + len(item_list) * ri] = max(
                    item_list[li] + player_b_scores[(li + 1) + len(item_list) * ri],
                    item_list[ri] + player_b_scores[li + len(item_list) * (ri - 1)]
                )

                player_b_scores[li + len(item_list) * ri] = min(
                    player_a_scores[(li + 1) + len(item_list) * ri] - item_list[li],
                    player_a_scores[li + len(item_list) * (ri - 1)] - item_list[ri]
                )
    return player_a_scores[len(item_list) * (len(item_list) - 1)]


inp = fileinput.FileInput()
inp.readline()

item_list = [int(v) for v in inp.readline().split(" ")]
print(deque_score(item_list))

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

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


int main()
{
    string S;
    cin >> S;

    int N = S.size();
    int ans = 0, carry = 0;
    for(int i = N-1; i >= 0; --i){
        int now = (S[i]-'0') + carry;
        ans += min(now, 10-now);
        if(now > 5 or (i > 0 and now == 5 and S[i-1] >= '5')) carry = 1;
        else carry = 0;
    }
    if(carry == 1) ++ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n, -1);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        if (v[a] == -1 || v[a] == b) {
            v[a] = b;
        } else {
            cout << -1 << endl;
            return;
        }
    }
    cerr << v << endl;
    
    // 0でないのに先頭に0がある
    if (n == 1) {
        if (v[0] == -1) cout << 0 << endl;
        else cout << v[0] << endl;
        return;
    }
    
    if (v[0] == 0) {
        cout << -1 << endl;
        return;
    }
    
    if (v[0] == -1) {
        v[0] = 1;
    }
    
    rep3(i, 1, n) if (v[i] == -1) v[i] = 0;
    rep(i, n) cout << v[i]; cout << endl;
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin >> n;
    if(n % 1000 == 0) cout << "0";
    else cout << (1000 - (n % 1000));
    
	return 0;
}

Measured memory_bytes: 3608
import sys
import numpy as np


def input():
    return sys.stdin.readline()[:-1]


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


def factorize(n):
    res = dict()
    for i in range(2, int(np.sqrt(n)) + 10):
        if n % i:
            continue
        res.setdefault(i, 0)
        while (n % i == 0):
            n //= i
            res[i] += 1
    if n != 1:
        res.setdefault(n, 1)
    return res


def solve():
    a, b = map(int, input().split())
    n = gcd(a, b)
    print(len(factorize(n))+1)


if __name__ == "__main__":
    solve()


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

using namespace std;

using int64 = long long;

int main() {
  int N, M, A[500];
  cin >> N >> M;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }

  vector< double > dp(N + 1, -1e9);
  dp[0] = 0;
  for(int i = 0; i < M; i++) {
    vector< double > dp2(dp);
    for(int j = 0; j < N; j++) {
      int64 sum = 0;
      for(int k = j; k < N; k++) {
        sum += A[k];
        dp2[k + 1] = max(dp2[k + 1], dp[j] + 1.0 * sum / (k - j + 1));
      }
    }
    dp.swap(dp2);
  }
  cout << fixed << setprecision(10) << dp.back() << endl;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n,y;
  cin >> n >> y;
  int x=-1,yy=-1,z=-1;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      int k=n-i-j;
      if(10000*i+5000*j+1000*k==y){
        x=i;
        yy=j;
        z=k;
      }
    }
  }
  cout << x << " " << yy << " " << z;
      
}


Measured memory_bytes: 3624
<?php
    list($max,$sum) = explode(" ",trim(fgets(STDIN)));
    $x = 0;
    $y = 0;
    $z = 0;
    $count = 0;
    $rest = 0;
    for($x=0;$x<=$max;$x++){
        $rest = $sum - $x;
        if($rest<=2*$max&&$rest>=0){
            $makkusu = min($rest,$max);
            $min = $rest - $makkusu;
            $tasu = $makkusu - $min + 1;
            $count += $tasu;
        }
    }
    
    echo $count;
?>  

Measured memory_bytes: 3704
#cotest_temp
n = int(input())
#n,m = map(int,input().split())
lst1 = list(map(int,input().split()))

dic1 = dict()

for i in lst1:
    if i in dic1:
        print("NO")
        exit()
    else:
        dic1[i] = 1

print("YES")

Measured memory_bytes: 108244
import sys
N = int(input())
As = list(map(int, input().split()))
def f(K):
    c = 0
    for a in As:
        c += (a+K+1)//(N+1)
#    print(K, K-c)
    return c<=K
def f2(K):
    c = 0
    for a in As:
        c += (a+K+1)//(N+1)
#    print(K, K-c)
#    print(K, c)
    return c<=K
for a in As:
    if a>=N:
        break
else:
    print(0)
    sys.exit()
mn, mx = 0, 10**18
idx = mx//2
while mx-mn>1:
    if f(idx):
        mx, idx = idx, (idx+mn)//2
        continue
    mn, idx = idx, (mx+idx)//2
#print(idx+1)
mn = max(1, idx-10**3)
for i in range(mn, mn+10**3+2):
    if f2(i):
        print(i)
        break


Measured memory_bytes: 39024
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#define REP(i,n) for(int i=0;i<n;i++)
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    char a[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(a[i][j] == '#'){
                break;
            }
            if(j==W-1){
                for(int k = 0; k < W; k++){
                    a[i][k] = '@';
                }
            }
        }
    }
    for(int j = 0; j < W; j++){
        for(int i = 0; i < H; i++){
            if(a[i][j] == '#'){
                break;
            }
            if(i==H-1){
                for(int k = 0; k < H; k++){
                    a[k][j] = '@';
                }
            }
        }
    }

    for(int i = 0; i < H; i++){
        bool newline = false;
        for(int j = 0; j < W; j++){
            if(a[i][j]!='@'){
                cout << a[i][j];
                newline = true;
            }
        }
        if(newline)
            cout << endl;
    }  
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextDouble()) {
			Rectangle r1 = new Rectangle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble());
			Rectangle r2 = new Rectangle(sc.nextDouble(), sc.nextDouble(), sc.nextDouble(), sc.nextDouble());

			System.out.println(hasIntersection(r1, r2)? "YES": "NO");
		}
		sc.close();
	}
	
	static boolean hasIntersection(Rectangle r1, Rectangle r2) {
		boolean LR_r1r2r1 = (r1.left <= r2.left && r2.left <= r1.right) || (r1.left <= r2.right && r2.right <= r1.right);
		boolean LR_r2r1r2 = (r2.left <= r1.left && r1.left <= r2.right) || (r2.left <= r1.right && r1.right <= r2.right);
		boolean UD_r1r2r1 = (r1.down <= r2.down && r2.down <= r1.up) || (r1.down <= r2.up && r2.up <= r1.up);
		boolean UD_r2r1r2 = (r2.down <= r1.down && r1.down <= r2.up) || (r2.down <= r1.up && r1.up <= r2.up);
		
		return (LR_r1r2r1 || LR_r2r1r2) && (UD_r1r2r1 || UD_r2r1r2);
	}
}

class Rectangle{
	double left;
	double right;
	double up;
	double down;
	
	Rectangle(double ldx, double ldy, double rux, double ruy){
		this.left = ldx;
		this.right = rux;
		this.up = ruy;
		this.down = ldy;
	}
}

Measured memory_bytes: 29148
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	ll h, w; cin >> h >> w;
	vector<vector<ll>> v(h, vector<ll>(w));
	rep(i, h)
		rep(j, w)
		cin >> v[i][j];
	rep(i,h)
		rep(j, w) {
		ll buf; cin >> buf;
		v[i][j] = abs(v[i][j] - buf);
	}
	vector<vector<vector<bool>>> flag(h, vector<vector<bool>>(w, vector<bool>((h + w) * 80, false)));
	flag[0][0][v[0][0]] = true;
	rep(r, h+w-1) {
		ll i, j;
		if (r < w) {
			j = r;
			i = 0;
		}
		else {
			j = w - 1;
			i = r - (w - 1);
		}
		while (i < h && 0 <= j) {
			if (i > 0) {
				rep(k, (h + w) * 80) {
					if (flag[i - 1][j][k]) {
						flag[i][j][abs(k + v[i][j])] = true;
						flag[i][j][abs(k - v[i][j])] = true;
					}
				}
			}
			if (j > 0) {
				rep(k, (h + w) * 80) {
					if (flag[i][j-1][k]) {
						flag[i][j][abs(k + v[i][j])] = true;
						flag[i][j][abs(k - v[i][j])] = true;
					}
				}
			}
			j--;
			i++;
		}
	}
	rep(i, (h + w) * 80) {
		if (flag[h - 1][w - 1][i]) {
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
 int main(){
     int a[10010];
      int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)scanf("%d",&a[i]);
 int s=0;
for(int i=0;i<m;i++)s+=a[i];
if(s>n){ printf("-1\n");
 }else{
 printf("%d\n",n-s);
 }
 }


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


int main(){
    ll n;cin>>n;
    vector<pair<ll,ll> > MN(n);
    vector<pair<ll,ll> > MX(n);
    rep(i,0,n){
        ll a,b;cin>>a>>b;
        MN[i]=make_pair(a,b);
        MX[i]=make_pair(b,a);
    }
    sort(MN.begin(),MN.end());
    sort(MX.begin(),MX.end());
    ll an;
    if(n%2==1){
        double l=MN[(n-1)/2].first;
        double r=MX[(n-1)/2].first;
        an=(r-l);
    }
    else{
        double l=(MN[n/2].first+MN[n/2-1].first),r=(MX[n/2].first+MX[n/2-1].first);
        an=(r-l);
    }
    cout<<an+1<<endl;
    
}

    









Measured memory_bytes: 9504
#include<iostream>
using namespace std;
int main(void) {
	int n, game[201][3], ten[201] = { 0 };
	cin >> n;
	for (int i = 0;i < n;i++) {
		for (int j = 0;j < 3;j++) {
			cin >> game[i][j];
		}
	}
	for (int i = 0;i < 3;i++) {
		for (int j = 0;j < n;j++) {
			for (int k = 0;k < n;k++) {
				if (k!=j){
					if (game[j][i] == game[k][i]) {
						break;
					}
				}
				if (k == n - 1) {
					ten[j] += game[j][i];
				}
			}
		}
	}
	for (int i = 0;i < n;i++) {
		cout << ten[i] << endl;
	}
	return 0;
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 4 * N, INF = 0x3f3f3f3f;

int n, m;
int h[N], e[M], w[M], ne[M], idx;
int q[N], dist[N];

void add(int a, int b, int c)
{
	e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

bool bfs(int st)
{
	int hh = 0, tt = -1;
	q[ ++ tt] = st;
	dist[st] = 0;
	
	while (hh <= tt)
	{
		int t = q[hh ++ ];
		
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			
			if (dist[j] == INF)
			{
				dist[j] = dist[t] + w[i];
				q[ ++ tt] = j;
			}
			else if (dist[j] != dist[t] + w[i]) return false;
		}
	}
	
	return true;
}

int main()
{
	memset(h, -1, sizeof h);
	memset(dist, 0x3f, sizeof dist);
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i ++ )
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		add(a, b, c), add(b, a, -c);
	}
	
	for (int i = 1; i <= n; i ++ )
		if (dist[i] == INF && !bfs(i))
		{
			puts("No");
			return 0;
		}
	
	puts("Yes");
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long> A(N);
    set<long long> ans_set;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        ans_set.insert(A[i]);
    }
    sort(A.begin(), A.end());
    long long a_max = *(A.end() -1 );
    
    for (int i = 0; i < N-1; i++) {
        if (ans_set.find(A[i]) == ans_set.end()) continue;
        bool same = false;
        if (A[i] == A[i+1]) same = true;
        for (long long j = A[i] * 2; j <= a_max; j += A[i]) {
            ans_set.erase(j);
        }
        if (same) ans_set.erase(A[i]);
    }
    cout << ans_set.size() << endl;  
}

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

struct Card { char suit, value;};

void bubbleSort(struct Card C[],int N){
  for(int i=0; i<N; i++){
    for(int j=N-1;j>=i+1;j--){
      if(C[j].value<C[j-1].value){
	Card t=C[j];
	C[j]=C[j-1];
	C[j-1]=t;
      }
    }
  }
}

void selectionSort(struct Card C[],int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(C[j].value<C[minj].value)minj=j;
    }
    Card t=C[i];
    C[i]=C[minj];
    C[minj]=t;
  }
} 

void out(struct Card C[],int N){
  for(int i=0;i<N;i++){
    if(i>0) cout << " ";
    cout << C[i].suit << C[i].value;
  }
  cout << endl;
}

bool hikaku(struct Card C1[], struct Card C2[],int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}

int main(){
  Card C1[100],C2[100];
  int N;
  char ch;

  cin >> N;
  for(int i=0;i<N;i++){
    cin >> C1[i].suit >> C1[i].value;
  }
  for(int i=0;i<N;i++) C2[i]=C1[i];

  bubbleSort(C1,N);
  selectionSort(C2,N);

  out(C1,N);
  cout << "Stable" << endl;
  out(C2,N);
  if(hikaku(C1,C2,N)){
    cout << "Stable" << endl;
  } else{
    cout << "Not stable" << endl;
  }
  return 0;
}



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

int main()
{
    int N, A;
    cin >> N;
    int min = 10000, cnt;

    for (int i = 0; i < N; i++)
    {
        cnt = 0;
        cin >> A;

        while (A % 2 == 0)
        {
            A /= 2;
            cnt++;
        }

        if (cnt < min)
            min = cnt;
    }

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


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		
		int[][] cell = new int[r][c];
		
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++)
				cell[i][j] = scanner.nextInt();
		}
		
		int[] csum = new int[c];
		
		for (int i = 0; i < r; i++) {
			int rsum = 0;
			for (int j = 0; j < c; j++) {
				rsum += cell[i][j];
				csum[j] += cell[i][j];
				System.out.print(cell[i][j] + " ");
			}
			System.out.println(rsum);
		}
		int sum = 0;
		for (int i = 0; i < c; i++) {
			sum += csum[i];
			System.out.print(csum[i] + " ");
		}
		System.out.println(sum);

	}

}



Measured memory_bytes: 40588
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
       
        String[] correct = "CODEFESTIVAL2016".split("");
    
		// 文字列の入力
		String[] input = sc.next().split("");
        int ans = 0;
        for(int i = 0; i < input.length; i++) {
          if (!input[i].equals(correct[i])) {
            ans++;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long a = scan.nextLong();
		long b = scan.nextLong();
		scan.close();
		long ans = Math.min(n % (a+b), a);
		ans +=(n/(a+b))*a;

		System.out.println((a==0)? "0":ans);
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	int N;
	int F[100][10];
	int P[100][10];
	cin >> N;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < 10; j++){
			cin >> F[i][j];
		}
	}
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= 10; j++){
			cin >> P[i][j];
		}
	}
	int ans = -(1 << 30);
	for(int i = 1; i < (1 << 10); i++){
		int sum = 0;
		for(int j = 0; j < N; j++){
			int num = 0;
			for(int k = 0; k < 10; k++){
				if(i & (1 << k) && F[j][k]) num++;
			}
			sum += P[j][num];
		}
		if(sum > ans){
			ans = sum;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
def main():
  n = int(input())
  l = [0 for i in range(n+1)]
  for i in range(1,n+1):
    if i < 10:
      l[i] = l[i-1] + 1
    elif i < 100:
      l[i] = l[i-1]
    elif i < 1000:
      l[i] = l[i-1] + 1
    elif i < 10000:
      l[i] = l[i-1]
    elif i < 100000:
      l[i] = l[i-1] + 1
    elif i == 100000:
      l[i] = l[i-1]
    else:
      break
  print(l[n])

if __name__ == "__main__":
  main()

Measured memory_bytes: 6808
N = input()
l = len(N)
N_i = int(N)
ans = 0
 
p = int(l/2)
for i in range(p):
    q = i*2
    ans += 9 * (10**q)
 
if l%2 != 0:
    bottom = 10**(l-1)
    ans += N_i - bottom + 1
 
print(ans)

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

using namespace std;
#define mod 1000000007
typedef long long ll;


int main() {
	int n, m;
	cin >> n >> m;
	vector<long long> x(n);
	vector<long long> y(m);
	for (int i = 0; i < n; i++)cin >> x[i];
	for (int i = 0; i < m; i++)cin >> y[i];
	ll X = 0;
	ll Y = 0;
	for (int i = 0; i < n-1; i++) {
		X += (x[i + 1] - x[i]) * (i + 1)*(n - i - 1) % mod;
	}
	for (int i = 0; i < m-1; i++) {
		Y += (y[i + 1] - y[i]) * (i + 1)*(m - i - 1) % mod;
	}
	X %= mod;
	Y %= mod;
	cout << (X*Y) % mod << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int read(){
	int f=1,re=0;char ch;
	for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
	if(ch=='-'){f=-1,ch=getchar();}
	for(;isdigit(ch);ch=getchar()) re=(re<<3)+(re<<1)+ch-'0';
	return re*f; 
}
char s[10];
bool check(){
	if(s[1]==s[2]) return false;
	if(s[3]!=s[4]) return false;
	if(s[5]!=s[6]) return false;
	//if(s[3]==s[5]) return false;
	if(s[1]==s[3]) return false;
	if(s[1]==s[5]) return false;
	if(s[2]==s[3]) return false;
	if(s[2]==s[5]) return false;
	return true;
}
int main(){
	scanf("%s",s+1);
	if(check()) printf("Yes\n");
	else printf("No\n");
	return 0;
} 

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

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> csum(N+1, 0);
    rep(i, 0, N)
    {
        cin >> csum[i+1];
        csum[i+1] += csum[i];
    }
    rep(i, 0, N)
    {
        csum[i+1] -= i+1;
        csum[i+1] %= K;
        if (csum[i+1] < 0)
            csum[i+1] += K;
    }

    map<ll, ll> n_cnts;
    for (int i=0; i<K-1 and i<N; ++i)
        ++n_cnts[csum[i+1]];
    
    ll res = 0;
    rep(i, 0, N)
    {
        res += n_cnts[csum[i]];
        --n_cnts[csum[i+1]];
        if (i+K <= N)
        ++n_cnts[csum[i+K]];
    }
    cout << res << endl;
    return 0;
}

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

int main()
{
	bool is_prime[50001];
	
	is_prime[0]=is_prime[1]=false;
	
	for(int i=2;i<50001;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<50001;i++){
		if(is_prime[i]){
			for(int j=i*i;j<50001;j+=i){
				is_prime[j]=false;
			}
		}
	}
	
	while(true){
		int n;
		cin>>n;
		
		if(n==0)
			break;
			
		int match=0; 
		
		for(int i=2;i<=n/2;i++){
			if(is_prime[i]&&is_prime[n-i])
				match++;
		}
		
		cout<<match<<endl;
	}
	
	return 0;
}

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

ll n, dp[1000000], vet[1000000];

ll solve(int i) {
    if(dp[i] != -1)
        return dp[i];
    if(i == n-1)
        return 0;
    if(i > n-1)
        return 99999999;

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


Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}

int main(){
  int N,K,A[100000];
  cin>>N>>K;
  rep(i,N) cin>>A[i];
  //int position1(0);
  //rep(i,N){
  //  if (A[i] == 1){
  //    position1 = i;
  //    break;
  //  }
  //}
  //int ans(0);
  //ans += (position1 + K-2)/(K-1);
  //ans += (N-position1-1+K-2)/(K-1);
  //cout << ans << endl;
  cout << (N-1+(K-2))/(K-1) << endl;
  return 0;
}



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

#define MAX_N 82000
#define MAX_CARD 100

long long dp[MAX_CARD][MAX_N];
long long card[MAX_CARD][2];
int n, m, a, b, cnt, sum;

int main() {
	while (true) {
		memset(dp, 0, sizeof(dp));
		memset(card, 0, sizeof(card));
		//cin.
		cin >> n;
		if (n == 0) {
			break;
		}
		cnt = 0;
		sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			card[i][0] = a;
			card[i][1] = b;
			for (int j = 0; j < b; j++) {
				sum += a;
			}
		}
		//dp.
		dp[0][0] = 1;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= sum; j++) {
				if (dp[i - 1][j] != 0) {
					for (int k = 0; k <= card[i - 1][1]; k++) {
						dp[i][j + k*card[i - 1][0]] += dp[i - 1][j];
					}
				}
			}
		}
		//cin2.
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> a;
			cout << dp[n][a] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 65228
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()

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

  ll N;
  cin >> N;
  vector<pair<ll,ll>> A(N);
  rep(i, N) {
    cin >> A[i].first;
    A[i].second = i;
  }
  sort(all(A));
  reverse(all(A));
  
  vector<vector<ll>> dp(N+1, vector<ll>(N+1));
  
  rep(i, N) rep(j, i+1) {
    
    if (j==0) {
      dp[i+1][j] = dp[i][j] + A[i].first * (N-1-i+j - A[i].second);
    }else {
      dp[i+1][j] = max(dp[i][j-1] + A[i].first * (A[i].second - (j-1)),
                       dp[i][j] + A[i].first * (N-1-i+j - A[i].second)
                      );
    }
    
    if (j==i) {
      dp[i+1][j+1] = dp[i][j] + A[i].first * (A[i].second - j);
    }else {
      dp[i+1][j+1] = max(dp[i][j] + A[i].first * (A[i].second - j),
                         dp[i][j+1] + A[i].first * (N-1-i+j+1 - A[i].second)
                         );
    }
  }
  
  ll ans = dp[N][0];
  rep2(i, N) ans = max(ans, dp[N][i]);
  
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 34620
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>a(n);
    for(lint i=1;i<n;i++){
        lint x;std::cin>>x;x--;
        a.at(x)++;
    }
    for(lint i=0;i<n;i++){
        std::cout<<a.at(i)<<'\n';
    }
}


Measured memory_bytes: 4780
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

static const int N = 1e+5;
vector<int> fr[N], bl[N];
bool visited[N];
int n, group[N], color = 0, conj[N];

void dfs(int u){
	visited[u] = true;
	group[u] = color;
	conj[color]++;
	rep(i, fr[u].size()){
		if(visited[fr[u][i]]) continue;
		dfs(fr[u][i]);
	}
	return;
}

void dfs_init(int s){
	rep(i, n){
		visited[i] = false;
		conj[i] = 0;
	}
	rep(i, n){
		if(visited[i]) continue;
		dfs(i);
		color++;
	}
	return;
}

int main(){
	int m, k, x, y;
	cin >> n >> m >> k;
	rep(i, m){
		cin >> x >> y;
		fr[x-1].push_back(y-1);
		fr[y-1].push_back(x-1);
	} rep(i, k){
		cin >> x >> y;
		bl[x-1].push_back(y-1);
		bl[y-1].push_back(x-1);
	}
	
	dfs_init(0);
	
	int cnt[n];
	rep(i, n){
		cnt[i] = 0;
		for(auto j = bl[i].begin(); j != bl[i].end(); j++){
			if(group[i] != group[*j]) cnt[i]++;
		}
	}
	rep(i, n){
		//cout << "conj[]: " << conj[group[i]] << endl;
		//cout << "fr[]: " << fr[i].size() << endl;
		//cout << "bl[]: " << bl[i].size() << endl;
		int ans = conj[group[i]] - fr[i].size() - bl[i].size() + cnt[i] - 1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 13048
#include<iostream>
using namespace std;
int main(){
  int n,a;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>a;
    if(a%2==0&&a%3!=0&&a%5!=0){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
}
  

Measured memory_bytes: 256
n,m=map(int,raw_input().split())
x=map(int,raw_input().split())
cnt=[0]*(max(x)+1)
for i in xrange(n):
    cnt[x[i]]+=1
samemod=[0]*m
for i in xrange(n):
    samemod[x[i]%m]+=1
ans=0
for i in xrange((m+1)/2):
    if i==0:
        ans+=samemod[0]/2
        samemod[0]=0
    else:
        ans+=min(samemod[i],samemod[m-i])
        if samemod[i]>=samemod[m-i]:
            samemod[i]-=samemod[m-i]
            samemod[m-i]=0
        else:
            samemod[m-i]-=samemod[i]
            samemod[i]=0
if (m+1)%2==1:
    ans+=samemod[(m+1)/2]/2
    samemod[(m+1)/2]=0
mp=[[] for _ in xrange(m)]
for i in xrange(1,max(x)+1):
    mp[i%m].append(cnt[i])
for i in xrange(m):
    mp[i].sort()
    mp[i].reverse()

for i in xrange(m):
    for j in xrange(len(mp[i])):
        if mp[i][j]>=2:
            if samemod[i]>=mp[i][j]:
                ans+=mp[i][j]/2
                if mp[i][j]%2==0:
                    samemod[i]-=mp[i][j]
                else:
                    samemod[i]-=mp[i][j]-1
            else:
                ans+=samemod[i]/2
                samemod[i]=0
        else:
            break
print(ans)


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

typedef long long LL;
typedef pair<int, int> II;

int main() {
    int n;
    int c[100] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        LL x;
        scanf("%lld", &x);
        for (int j = 0; j < 60; ++j) {
            c[j] += x >> j & 1;
        }
    }

    const int MOD = (int)1e9 + 7;
    int ans = 0;
    int mul = 1;
    for (int i = 0; i < 60; ++i) {
        int val = (LL)c[i] * (n - c[i]) % MOD;
        ans = (ans + (LL)val * mul) % MOD;
        mul = mul * 2 % MOD;
    }

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m;
char G[52][52];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<n+2;i++){
		G[0][i]='.';
		G[i][0]='.';
		G[n+1][0]='.';
		G[0][n+1]='.';
	}
		
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin>>G[i][j];
			
	for(int i=i;i<n;i++)
		for(int j=i;j<m;j++)
			if(G[i][j]=='#')
				if(G[i+1][j]!='#'&&G[i][j+1]!='#'&&G[i][j-1]!='#'&&G[i-1][j]!='#'){
					printf("No\n");
					return 0;
				}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
a=[list(map(int,input().split()))for _ in range(3)]
for i in range(int(input())):
  b=int(input())
  for j in range(3):
    for k in range(3):
      if a[j][k]==b:a[j][k]=0
ans="No"
for i in range(3):
  if a[i][0]==a[i][1]==a[i][2]==0:ans="Yes"
  if a[0][i]==a[1][i]==a[2][i]==0:ans="Yes"
if a[0][0]==a[1][1]==a[2][2]==0:ans="Yes"
if a[2][0]==a[1][1]==a[0][2]==0:ans="Yes"
print(ans)

Measured memory_bytes: 3064
m = [list(map(int,input().split())) for _ in range(3)]
n = int(input())

for _ in range(n):
    b = int(input())
    for rows in range(3):
        for columns in range(3):
            if m[rows][columns] == b:
                m[rows][columns] = 0

for i in range(3):
    if sum(m[i]) == 0:
        print('Yes')
        exit()
for i in range(3):
    if m[0][i] + m[1][i] + m[2][i] == 0:
        print('Yes')
        exit()
if m[0][0] + m[1][1] + m[2][2] == 0: print('Yes'); exit()
if m[0][2] + m[1][1] + m[2][0] == 0: print('Yes'); exit()
 
print('No')

Measured memory_bytes: 3064