akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
from heapq import heappop, heappush

n, m = map(int, input().split())
d = []
for i in range(m):#h:高さ
    d.append([int(m) for m in input().split()])

dist = d
#dist.append([i, j, c[i][j]])

class Graph(object):
    """
    隣接リストによる有向グラフ
    """

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, src, dst, weight=1):
        self.graph[src].append((dst, weight))

    def get_nodes(self):
        return self.graph.keys()


class Dijkstra(object):
    """
    ダイクストラ法（二分ヒープ）による最短経路探索
    計算量: O((E+V)logV)
    """

    def __init__(self, graph, start):
        self.g = graph.graph

        # startノードからの最短距離
        # startノードは0, それ以外は無限大で初期化
        self.dist = defaultdict(lambda: float('inf'))
        self.dist[start] = 0

        # 最短経路での1つ前のノード
        self.prev = defaultdict(lambda: None)

        # startノードをキューに入れる
        self.Q = []
        heappush(self.Q, (self.dist[start], start))

        while self.Q:
            # 優先度（距離）が最小であるキューを取り出す
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, weight in self.g[u]:
                alt = dist_u + weight
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q, (alt, v))

    def shortest_distance(self, goal):
        """
        startノードからgoalノードまでの最短距離
        """
        return self.dist[goal]

    def shortest_path(self, goal):
        """
        startノードからgoalノードまでの最短経路
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]
# (src, dst, weight)
inputs = dist

g = Graph()
for src, dst, weight in inputs:
    g.add_edge(src, dst, weight)
    g.add_edge(dst, src, weight)
ans = 0
for i in range(m):
    d = Dijkstra(g, dist[i][1])
    sp = format(d.shortest_distance(dist[i][0]))
    if int(sp) != dist[i][2]:
        ans += 1
print(ans)

Measured memory_bytes: 3700
n=int(input())
a=[int(i) for i in input().split()]

aaa=" ".join(map(str,a))
print(aaa)

for i in range(1,n):
    key=a[i]
    j=i-1
    while j >= 0 and a[j] > key:
        a[j+1]=a[j]
        j=j-1
    a[j+1]=key
    aaa=" ".join(map(str,a))
    print(aaa)

Measured memory_bytes: 7800
#include <stdio.h>

int main(void){
    int n, m, x, i, count1 = 0;
    scanf("%d%d%d", &n, &m, &x);
    while(1){
        scanf("%d", &i);
        if(i < x)
            count1++;
        else
            break;
    }
    if(count1 > (m - count1))
        count1 = m - count1;
    printf("%d\n", count1);
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static boolean solve() {
		int w = in.nextInt();
		int h = in.nextInt();
		if (w + h == 0) return false;

		int[][] table = new int[h][w];
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				table[i][j] = in.nextInt();
			}
		}

		boolean[][] visited = new boolean[h][w];
		int[] dx = { 0, 1, 1, 1, 0,-1,-1,-1};
		int[] dy = { 1, 1, 0,-1,-1,-1, 0, 1};
		int cnt = 0;
		for (int i=0; i<h; i++) {
			for (int j=0; j<w; j++) {
				if (visited[i][j] || table[i][j] == 0) continue;

				ArrayDeque<Integer> que = new ArrayDeque<>();
				que.add(i*w+j);
				while (que.size() > 0) {
					int c = que.pollFirst();
					int cy = c/w, cx = c%w;
					for (int k=0; k<8; k++) {
						int ny = cy + dy[k], nx = cx + dx[k];
						if (ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
						if (visited[ny][nx] || table[ny][nx] == 0) continue;
						visited[ny][nx] = true;
						que.add(ny*w+nx);
					}
				}

				cnt++;
			}
		}

		out.println(cnt);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		while(solve());
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

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

using namespace std;

template<int MOD>
struct ModInt {
   using Mint = ModInt;
   int val;
   ModInt(int64_t __val = 0) { fix(__val % MOD + MOD); }
   Mint& fix(int __val) { val = __val; if (val >= MOD) val -= MOD; return *this; }
   explicit operator int() { return val; }
   Mint operator + (const Mint &mt) const { return Mint().fix(val + mt.val); }
   Mint operator - (const Mint &mt) const { return Mint().fix(val - mt.val + MOD); }
   Mint operator * (const Mint &mt) const { return Mint().fix(int64_t(val) * mt.val % MOD + MOD); }
   Mint& operator += (const Mint &mt) { return *this = *this + mt; }
   Mint& operator -= (const Mint &mt) { return *this = *this - mt; }
   Mint& operator *= (const Mint &mt) { return *this = *this * mt; }
   Mint pow(int y) const {
      Mint x = *this;
      Mint ans(1);
      for (; y > 0; y >>= 1, x *= x) {
         if (y & 1) ans *= x;
      }
      return ans;
   }
   Mint operator -() const { return Mint().fix(MOD - val); }
   Mint inv() const { return pow(MOD - 2); }
   Mint operator / (const Mint &mt) const { return *this * mt.inv(); }
   Mint& operator /= (const Mint &mt) const { return *this / mt; }
   friend ostream& operator<<(ostream& os, const Mint& mt) { return os << mt.val; }
};

using Mint = ModInt<1000000007>;

const int MX = 500500;

int N;
int fenw[MX];
int P[MX];
int invP[MX];
int pref[MX];
Mint fact[MX];

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   cin >> N;
   for (int i = 1; i <= N; ++i) {
      cin >> P[i];
      if (P[i]) invP[P[i]] = i;
   }
   fact[0] = 1;
   for (int i = 1; i <= N; ++i) fact[i] = fact[i-1] * i;
   Mint ans = 1;
   for (int i = 1; i <= N; ++i) pref[i] = pref[i-1] + !invP[i];
   Mint invTot = Mint(pref[N]).inv();
   Mint inv2 = Mint(2).inv();
   int cnt = 0;
   Mint tot = 0;
   /*
   for (int i = 1; i <= N; ++i) {
      for (int j = i+1; j <= N; ++j) {
         Mint prob;
         if (P[i] && P[j]) prob = (P[i] > P[j]);
         if (!P[i] && !P[j]) prob = Mint(2).inv();
         if (!P[i] && P[j]) prob = Mint(pref[N] - pref[P[j] - 1]) / Mint(pref[N]);
         if (P[i] && !P[j]) prob = Mint(pref[P[i]-1]) / Mint(pref[N]);
         ans += prob * fact[N-i];
      }
   }*/
   for (int i = N; i > 0; --i) {
      if (P[i]) {
         ans += fact[N-i] * pref[P[i] - 1] * invTot * cnt;
         for (int p = P[i]; p > 0; p -= p & -p) ans += fact[N-i] * fenw[p];
         for (int p = P[i]; p <= N; p += p & -p) fenw[p]++;
         tot += Mint(pref[N] - pref[P[i] - 1]) * invTot;
      } else {
         ans += inv2 * cnt * fact[N-i];
         ans += tot * fact[N-i];
         ++cnt;
      }
   }
   for (int z = 1; z <= pref[N]; ++z) ans *= z;
   cout << ans << '\n';
   return 0;
}


Measured memory_bytes: 13432
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int x,n;
    cin >> x >> n;
    map<int,int> p;
    REP(i, n)
    {
        int input;
        cin >> input;
        p[input]++;
    }
    int min = 101;
    int ans;
    REP(i, 102)
    {
        int j = i;
        if (p[j] == 0)
        {
            if (min > abs(j - x))
            {
                ans = j;
                min = abs(j - x);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back

ll vis[100005],A[100005],C[100005],l,degree[100005],sum=0;
vector<ll>adj[100005];
void dfs(int s)
{
  vis[s]=1;
  A[s]=C[l];
  l++;
  for(int i=0;i<adj[s].size();i++)
  {
    int v = adj[s][i];
      if(vis[v]==0)
      {
          dfs(v);
      }
  }
}

int main()
{ 
  ll N,i,u,v,maxx,src;
  cin>>N;
  for(i=1;i<=N-1;i++)
  {
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
    degree[u]++;
    degree[v]++;
  }

  for(i=1;i<=N;i++)
  {
    cin>>C[i];
  }
  sort(C+1,C+1+N);
  maxx = C[N];

  for(i=1;i<=N;i++)
  {
    if(degree[i]==1)
    {
        A[i] = maxx;
        src=i;
        vis[i]=1;
        break;
    }
  }

 
 
   l=1;
  for(i=1;i<=N;i++)
  {
    if(degree[i]==1 && vis[i]==0)
    {
        A[i] = C[l];
       // cout<<i<<" "<<C[1]<<endl;
        l++;
        vis[i]=1;
    }
  }
  
  sort(C+1, C+1+N, greater<int>()); 
  l=1;

  dfs(src);

  for(i=2;i<=N;i++)
  {
    sum = sum + C[i];
  }
  cout<<sum<<endl;

  for(i=1;i<=N;i++)
  {
    cout<<A[i]<<" ";
  }
  return 0;
}

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

//爆弾の切れ目 or モンスター
struct Query {
    Query(int64_t x, int64_t h, bool m) : X(x), H_or_attack(h), is_monster(m) {}
    int64_t X, H_or_attack;
    bool is_monster;
    bool operator<(const Query& rhs) const {
        //モンスターが同じ位置にいることはないのでこれで良い
        return (X != rhs.X ? X < rhs.X : is_monster);
    }
    bool operator>(const Query& rhs) const {
        return !(*this < rhs);
    }
};

int main() {
    int64_t N, D, A;
    cin >> N >> D >> A;

    priority_queue<Query, vector<Query>, greater<Query>> queries;

    for (int64_t i = 0; i < N; i++) {
        int64_t X, H;
        cin >> X >> H;
        queries.push(Query(X, H, true));
    }

    int64_t ans = 0;
    int64_t attack = 0;
    while (!queries.empty()) {
        Query q = queries.top();
        queries.pop();

        if (q.is_monster) {
            //爆弾投下
            int64_t hp = max(q.H_or_attack - attack, (int64_t)0);
            int64_t num = (hp + A - 1) / A;
            ans += num;
            attack += num * A;
            queries.push(Query(q.X + 2 * D, num * A, false));
        } else {
            //爆弾範囲の途切れ
            attack -= q.H_or_attack;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 8304
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_comp(const Pair& firstP, const Pair& secondP){ 
    return firstP.second < secondP.second; 
}//sort(all(v),p_compare)で昇順ソート
bool pcomp(Pair &a,Pair &b){return !p_comp(a,b);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll x,y,z,k;
Vi a,b,c;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>x>>y>>z>>k;ll num;
    rep(i,x){
        cin>>num;
        a.pb(num);
    }
    rep(i,y){
        cin>>num;
        b.pb(num);
    }
    rep(i,z){
        cin>>num;
        c.pb(num);
    }
    Vi vv;
    Sort(c);Sort(b);Sort(c);
    priority_queue<ll> pq;
    rep(i,x)rep(j,y){
        vv.pb(a[i]+b[j]);
    }
    Sort(vv);
    rep(i,z)rep(j,min(k,x*y)){
        pq.push(c[i]+vv[j]);
    }
    ll ans = 0;
    rep(i,k){
        ans = pq.top();
        cout<<ans<<endl;
        pq.pop();
    }
    return 0;
}

Measured memory_bytes: 43384
n = int(input())
s = list(input())
r = s.count('R')
g = s.count('G')
b = s.count('B')
ans = r * g * b
for i in range(n-2):
    for j in range(i+1,n-1):
        if (j - i) + j < n:
            k = (j - i) + j
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1
print(ans)                

Measured memory_bytes: 73948
#include<iostream>
#include<algorithm>
#include<vector>
typedef long long int ll;
using namespace std;

int main(){
	while(1){
		int n; cin >>n;
		if(n==0)break;
		int m=1000-n;
		cout << m/500+m%500/100+m%100/50+m%50/10+m%10/5+m%5/1 << endl;
	}
}


Measured memory_bytes: 3068
using System;

namespace test2 {

    public class Program {

        public static void Main(string[] args) {

            var s = Console.ReadLine();

            var res = 0;
            var n = s.Length;

            for(int i = 0; i < n; i++) {

                if(s[i] != s[n - 1 - i]) {

                    res++;

                }

            }

            Console.WriteLine(res / 2);

        }

    }

}

Measured memory_bytes: 25824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;
                int c = 0;
                c = values[a];
                values[a] = values[b];
                values[b] = c;
            }
            for (int i = 0; i < values.length; i++) {
                System.out.println(values[i]);
            }
        }
    }
}



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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

string s;
int l, r;

int main() {
	cin >> s;
	rep(i,s.length()) {
		if (s[i]=='A') {
			l = i;
			break;
		}
	}
	repr(i,s.length()-1) {
		if (s[i]=='Z') {
			r = i;
			break;
		}
	}
	cout << r-l+1 << ln;
}

Measured memory_bytes: 720
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int[][] xs = new int[n][2];
		int[][] ys = new int[n][2];
		for (int i = 0; i < n; i++) {
			xs[i][0] = sc.nextInt();
			xs[i][1] = i;
			ys[i][0] = sc.nextInt();
			ys[i][1] = i;
		}

		Arrays.sort(xs, (a, b) -> Integer.compare(a[0], b[0]));
		Arrays.sort(ys, (a, b) -> Integer.compare(a[0], b[0]));
		PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> Integer.compare(a[0], b[0]));
		for (int i = 0; i < n - 1; i++) {
			pq.offer(new int[]{Math.abs(xs[i][0] - xs[i + 1][0]), xs[i][1], xs[i + 1][1]});
			pq.offer(new int[]{Math.abs(ys[i][0] - ys[i + 1][0]), ys[i][1], ys[i + 1][1]});
		}

		UnionFind uf = new UnionFind(n);

		long answer = 0;
		while (!pq.isEmpty()) {
			int[] d = pq.poll();
			if (uf.connected(d[1], d[2])) continue;
			uf.union(d[1], d[2]);
			answer += d[0];
		}

		System.out.println(answer);
	}

	private static class UnionFind {

		private int[] parent;

		public UnionFind(int n) {
			this.parent = new int[n];
			for (int i = 0; i < n; i++) {
				parent[i] = i;
			}
		}

		private int root(int v) {
			while (parent[v] != parent[parent[v]]) {
				parent[v] = parent[parent[v]];
			}
			return parent[v];
		}

		public boolean connected(int v, int u) {
			return root(v) == root(u);
		}

		public void union(int v, int u) {
			parent[root(v)] = parent[root(u)];
		}
	}
}


Measured memory_bytes: 104732
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define prtd(var, i) cout << fixed << setprecision(i) << var << endl;
#define ll long long
using namespace std;

int main(){
    int r; cin >> r;
    if(r < 1200) cout << "ABC" << endl;
    else if(r < 2800)   cout << "ARC" << endl;
    else cout << "AGC" << endl;
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char a[110], b[110], c[110];
  scanf("%s%s%s", a, b, c);
  printf("%c%c%c\n", a[0], b[0], c[0]);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<map>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 100005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ans = "Christmas";
    for(int i=n;i<25;i++){
        ans += " Eve";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	vector<int>q;
	loop(i,1,10000000){
		int tmp=i*(i+1)*(i+2)/6;
		if(tmp>1000000)break;
		q.pb(tmp);
	}
	vector<int>out(1000010);
	rep(i,1000010)out[i]=inf;
	out[0]=0;
	rep(i,q.size())loop(j,q[i],1000010)out[j]=min(out[j],out[j-q[i]]+1);
	
	vector<int>out2(1000010);
	rep(i,1000010)out2[i]=inf;
	out2[0]=0;
	rep(i,q.size()){
		if(q[i]%2==0)continue;
		loop(j,q[i],1000010)out2[j]=min(out2[j],out2[j-q[i]]+1);
	}
	int n;
	while(cin>>n,n)cout<<out[n]<<" "<<out2[n]<<endl;
}

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

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    int n;
    cin >> n;
    while (n--){
        char c;
        cin >> c;
        if (c == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}

template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=2e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;

ll d[MAXn];
ll a[MAXn];
int main(){
  IOS();
  ll n;
  cin>>n;
  REP(i,n){
    cin>>d[i];
    a[i] = d[i];
  }
  sort(d,d+n);
  ll x = d[n/2-1];
  ll y = d[n/2];
  REP(i,n){
    if(a[i]<=x) cout<<y<<endl;
    else cout<<x<<endl;
  }
}


Measured memory_bytes: 5376
S = list(input())
N = len(S)

S1 = S[0:int((N-1)/2):]
S2 = S[int((N+3)/2)-1::]

if S==S[::-1] and S2==S2[::-1] and S2==S2[::-1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main() 
{
int i, sum=0;
string s;
cin>>s;
for(i=0;i<s.size();i++)
{
sum+=(int)(s[i]-'0');

}
if(sum%9==0)
cout<<"Yes";
else
cout<<"No";

}

Measured memory_bytes: 3688
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")
    };
}

fn main() {
    input! {
        n: i64,
    }

    println!("{}", n * (n - 1) / 2)
}


Measured memory_bytes: 4352
import sys
import random
import time
import numpy as np
import bisect

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def prob(e1,e2,T):
    if e2 < e1:
        return 1
    else:
        return np.exp((e1-e2)/T)

def solve():
    m = 26
    start = time.time()
    dT = 0.995
    T = 200
    D = ni()
    c = nl()
    s = [nl() for _ in range(D)]
    H = [None]*D
    for i in range(D):
        g = [s[i][j] + 15 * c[j] for j in range(m)]
        y = min(g)
        h = sum(g) - m * y
        g = [(x-y)/h for x in g]
        for j in range(1, m):
            g[j] += g[j-1]
        H[i] = g

    def calc(sche, m=26):
        last = [-1] * m
        ans = 0
        for i in range(D):
            t = sche[i]
            ans += s[i][t]
            last[t] = i
            for j in range(m):
                ans -= c[j] * (i - last[j])
        return ans

    def change(d, q, sc):
        b = sche[d]
        fq, bq = -1, D
        fb, bb = -1, D
        for i in range(d):
            if sche[i] == q:
                fq = i
            if sche[i] == b:
                fb = i
        for i in range(D-1, d, -1):
            if sche[i] == q:
                bq = i
            if sche[i] == b:
                bb = i
        sc += ((bb - d) * (bb - d - 1) // 2 + (d - fb) * (d - fb - 1) // 2) * c[b]
        sc += ((bq - fq) * (bq - fq - 1) // 2) * c[q]
        sc -= s[d][b]
        sc -= ((bq - d) * (bq - d - 1) // 2 + (d - fq) * (d - fq - 1) // 2) * c[q]
        sc -= ((bb - fb) * (bb - fb - 1) // 2) * c[b]
        sc += s[d][q]
        return sc

    sche = [0] * D
    for i in range(D):
        sche[i] = s[i].index(max(s[i]))
    sc = calc(sche)
    bestst = sche[:]
    best = sc

    while time.time() - start < 1.8:
        for _ in range(200):
            d = random.randint(0, D-1)
            q = bisect.bisect(H[d], random.random())
            nsc = change(d, q, sc)
            if best < nsc:
                bestst = sche[:]
                best = nsc
            if random.random() < prob(-sc, -nsc, T):
                sche[d] = q
                sc = nsc
        T *= dT
    prn([1 + x for x in bestst])
    return

solve()


Measured memory_bytes: 27756
#include<iostream>
#include<vector>
#include<deque>
#define NOT_VISITED -1
using namespace std;

int main(){
  vector<vector<int> > path;
  vector<int> visited;
  int n,m,q;

  cin >> n >> m;
  path.resize(n);
  visited.resize(n);
  for(int j=0;j<n;j++){
    visited[j]=NOT_VISITED;
  }
  for(int i=0;i<m;i++){
    int s,t;

    cin >> s >> t;
    path[s].push_back(t);
    path[t].push_back(s);
  }

  cin >> q;
  for(int i=0;i<q;i++){
    deque<int> que;
    int s,t;
    
    cin >> s >> t;
    if(visited[s]==NOT_VISITED){
      visited[s]=s;
      que.push_back(s);
      while(!que.empty()){
        int myplace=que.front();

        que.pop_front();
        for(int j=0;j<path[myplace].size();j++){
          int to=path[myplace][j];
	
	  if(visited[to]==NOT_VISITED){
            visited[to]=s;
	    que.push_back(to);
	  }
        }
      }
    }

    if(visited[s]==visited[t]){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
}


Measured memory_bytes: 8672
board = []
direction = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
h, w = map(int, input().split(" "))
for i in range(h):
	board.append([k for k in input()])

for i in range(h):
	for j in range(w):
		if board[i][j] == ".":
			board[i][j] = "0"
			for k in range(8):
				x = j + direction[k][0]
				y = i + direction[k][1]
				if 0 <= x < w and 0 <= y < h:
					if board[y][x] == "#":
						board[i][j] = str(1 + int(board[i][j]))
for i in range(h):
	for j in range(w):
		print(board[i][j], end="")
	print("")


Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e16 + 7;
const int MOD = 1e9 + 7;

int main() {

	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	ll a_sum = 0, b_sum = 0;

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

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

	ll cnt = 0;

	for (int i = 0; i < n; i++)
	{
		if (a[i] < b[i])
		{
			cnt += (b[i] - a[i]) / 2;
		}
		else
		{
			cnt -= (a[i] - b[i]);
		}
	}

	if (cnt >= 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include<math.h>
#include<bitset>
#include<string>
#include<iostream>
#include<vector>
using namespace std;

int main()
{
    string s;
    cin>>s;
    int slen=s.length();
    int n=slen-1;
    long long ans=0;
    for (int bit = 0; bit < (1<<n); ++bit)
    {
        /* bit で表される集合の処理を書く */


        /* きちんとできていることを確認してみる */
        // bit の表す集合を求める
        vector<long long> S;
        vector<long long> Ans;
        string tmp=s;
        int cnt=0;
        int Tmp=0;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                if(1<Tmp) Ans.push_back(stoll(tmp.substr(0,i+1-Tmp)));
                else Ans.push_back(stoll(tmp.substr(0,i+1-cnt)));
                tmp=(s.substr(i+1));
                Tmp=s.length()-tmp.length();
                ans+=Ans[cnt];
                cnt++;
            }
        }
        Ans.push_back(stoll(tmp));
        ans+=Ans[(long long)Ans.size()-1];

       /* // bit の表す集合の出力
        cout << bit << ": {";
        for (int i = 0; i < (int)Ans.size(); ++i) {
            cout << Ans[i] << " ";
        }
        cout << "}" << endl;*/
        
        
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split())
ax = A * math.sin(math.radians(30 * H + M / 2))
ay = A * math.cos(math.radians(30 * H + M / 2))
bx = B * math.sin(math.radians(6 * M))
by = B * math.cos(math.radians(6 * M))
ans = ((ax - bx) ** 2 + (ay - by) ** 2) ** 0.5
print(ans)

Measured memory_bytes: 9576
#include <iostream>

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int res = 1919;
  for (int i = 0; i < N; ++i) {
    int c, t;
    cin >> c >> t;
    if (t <= T) res = min(res, c);
  }
  if (res == 1919) puts("TLE"); else cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
struct segtree{
private:
	T init;
	int n;
	function<T(T,T)> op;
	vector<T>arr;
	vector<T>st;
	vector<T>lz;
	void build(int lo,int hi,int u){
		if(lo==hi){
			st[u]=arr[lo];
		}
		else{
			int mi=(hi+lo)>>1;
			build(lo,mi,u<<1);
			build(mi+1,hi,u<<1|1);
			st[u]=op(st[u<<1],st[u<<1|1]);
		}
	}
	void apply(T x,int u,int lo,int hi){
// 		st[u]+=x*(hi-lo+1);
// 		st[u]+=x;
//		st[u]=x;
 		st[u]=x*(hi-lo+1);
// 		lz[u]+=x;
		lz[u]=x;
	}
	void push(int u,int lo,int hi){
		if(lz[u]!=init){
			int mi=(lo+hi)>>1;
			apply(lz[u],u<<1,lo,mi);
			apply(lz[u],u<<1|1,mi+1,hi);
			lz[u]=init;
		}
	}
	void modify(int l,int r,T x,int u,int lo,int hi){
		if(r<lo||l>hi||l>r)return;
		if(l<=lo&&r>=hi){
			apply(x,u,lo,hi);
			return;
		}
		push(u,lo,hi);
		int mi=(lo+hi)>>1;
		if(mi>=r){
			modify(l,r,x,u<<1,lo,mi);
		}
		else if(mi<l){
			modify(l,r,x,u<<1|1,mi+1,hi);
		}
		else{
			modify(l,mi,x,u<<1,lo,mi);
			modify(mi+1,r,x,u<<1|1,mi+1,hi);
		}
		st[u]=op(st[u<<1],st[u<<1|1]);
	}
	T query(int l,int r,int u,int lo,int hi){
		if(l>r||l>hi||r<lo)return init;
		if(l<=lo&&r>=hi){
			return st[u];
		}
		push(u,lo,hi);
		int mi=(hi+lo)>>1;
		if(mi>=r){
			return query(l,r,u<<1,lo,mi);
		}
		else if(mi<l){
			return query(l,r,u<<1|1,mi+1,hi);
		}
		else{
			return op(query(l,mi,u<<1,lo,mi),query(mi+1,r,u<<1|1,mi+1,hi));
		}
	}
public:
	segtree(T n,function<T(T,T)> op):n(n),st(n*4),op(op),lz(n*4){
		init=T();
	}
	segtree(vector<T> v,function<T(T,T)> op):n(v.size()),st(v.size()*4),op(op),lz(v.size()*4){
		init=T();
		arr=v;
		build(0,n-1,1);
	}
	T query(int l,int r){
		return query(l,r,1,0,n-1);
	}
	T query(int p){
		return query(p,p);
	}
	void setinit(T x){
		init=x;
		for(int i=0;i<4*n;i++){
			st[i]=init;
			lz[i]=init;
		}
	}
	void modify(int l,int r,T x){
		modify(l,r,x,1,0,n-1);
	}
	void modify(int p,T x){
		modify(p,p,x);
	}
	void debug(){
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				cout<<i<<" "<<j<<" "<<query(i,j)<<"\n";
			}
		}
	}
};
int main(){
	int n,q;
	cin>>n>>q;
	segtree<int> seg(n,[](int a,int b){
		return a+b;
	});
	seg.setinit(INF);
	while(q--){
		int c;
		cin>>c;
		if(c){
			int l;
			cin>>l;
			cout<<seg.query(l)<<"\n";
		}
		else{
			int l,r,x;
			cin>>l>>r>>x;
			seg.modify(l,r,x);
		}
	}
}




Measured memory_bytes: 5972
#include "bits/stdc++.h"
using namespace std;
#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 MOD 1000000007
const long long mod=1e9+7;

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

vector<int>oks(N+1,true);

for(int i=0;i<M;++i){
   int a;
   cin>>a;
   oks[a]=false;
}
// 渡ることができるのはtrue , 渡れないのはfalse 

 vector<long long int>dp(N+1);
 dp[0]=1;
for(int now = 0; now < N; now++){ //nowは今の時点
    for(int next = now+1; next <= min(N,now+2); next++){ // min() ２つのうちの最小値
        if(oks[next]){
            dp[next] += dp[now];
            dp[next] %= mod;
        }
    }    
}
cout<<dp[N]<<endl;
return 0;
}
   


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

using namespace std;

int main(){
	string s;
	int q;
	
	cin >> s;
	cin >> q;
	
	for(int i=0; i<q; ++i){
		string od, p;
		int a, b;
		
		cin >> od >> a >> b;
		if(od=="replace"){
			cin >> p;
			s = s.replace(a, b-a+1, p);
		}
		else if(od=="print"){
			cout << s.substr(a, b-a+1) << endl;
		}
		else if(od=="reverse"){
			string tmp = s.substr(a, b-a+1);
			reverse(tmp.begin(), tmp.end());
			s = s.replace(a, b-a+1, tmp);	
		}
		
		
	}
	return 0;
}



Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
string f[15];

bool forbid[15][15][15][15];

bool rec(int mask,vector<P>mch,bool ok){
	int yet = -1;
	for(int i=0;i<n;i++){
		if(!((mask>>i)&1)){
			yet = i; break;
		}
	}
	if(yet != -1){
		vector<int>zan;
		for(int i=yet+1;i<n;i++){
			if(!((mask>>i)&1)){
				zan.pb(i);
			}
		}
		{
			for(int i=0;i<zan.size();i++){
				int newmask = mask+(1<<yet)+(1<<zan[i]);
				mch.pb(mp(yet,zan[i]));
				if(rec(newmask,mch,ok)) return true;
				mch.pop_back();
			}
		}
		if(ok){
			int newmask = mask+(1<<yet);
			mch.pb(mp(yet,yet));
			if(rec(newmask,mch,false)) return true;
		}
		return false;
	}
	else{
		bool bad[15][15]={};
		for(int i=0;i<mch.size();i++){
			int a = mch[i].fi,b = mch[i].sc;
			for(int c=0;c<m;c++) for(int d=0;d<m;d++) bad[c][d] |= forbid[a][b][c][d];
		}
		bool okk[(1<<12)]={};
		okk[0] = true;
		for(int i=0;i<(1<<m);i++){
			if(okk[i] == false) continue;
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if( ((i>>j)&1) || ((i>>k)&1) ) continue;
					if(bad[j][k]) continue;
					if(__builtin_popcount(i) != m-1 && j==k) continue;
					okk[i | (1<<j) | (1<<k)] = true;
				}
			}
		}
		return okk[(1<<m)-1];
	}
}
int main(){
	cin>>n>>m;
	rep(i,n){
		cin>>f[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int a=0;a<m;a++){
				for(int b=0;b<m;b++){
					if(f[i][a] == f[j][b] && f[i][b] == f[j][a]);
					else{
						forbid[i][j][a][b] = true;
					}
				}
			}
		}
	}
	bool flag = rec(0,vector<P>(),n%2);
	puts(flag?"YES":"NO");
}

Measured memory_bytes: 256
l = []
flag = 0
for i in range(3):
  for j in input().split():
    l.append(j)
n = int(input())
for i in range(n):
  a = input()
  if a in l:
    l[l.index(a)] = 0
if not any(l[0:3])  or not any(l[3:6]) or not any(l[6:9]):
  flag = 1
if not any(l[0::3]) or not any(l[1::3]) or not any(l[2::3]):
  flag = 1
if not any(l[0::4]) or not any(l[2:7:2]):
  flag = 1
if flag:
  print("Yes")
else:
  print("No")

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

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

void solve(void) {
  ll n, k; cin >> n >> k;
  vector<double> p(n, 0);
  rep(n, i) cin >> p[i];

  double res = 0.0;

  vector<double> ruisekiwa(n+1, 0.0);
  for (ll i = 1; i <= n; ++i) {
    ruisekiwa[i] = ruisekiwa[i-1] + (p[i-1] + 1) / 2.0;
  }

  for (ll j = 0; j + k <= n; ++j) {
    double sbtr = ruisekiwa[j+k] - ruisekiwa[j];
    res = max(res, sbtr);
  }

  cout << setprecision(16) << res << endl;
}

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

Measured memory_bytes: 6468
n = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
ans = 0
now = 0
for a in A:
    ans += abs(a - now)
    now = a
for i in range(1, n+1):
    removei = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])
    concati = abs(A[i-1] - A[i+1])
    print(ans - removei + concati)

Measured memory_bytes: 14176
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int D = in.nextInt();
            int X = in.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
            }

            int res = X;
            for (int i = 0; i < N; i++) {
                for (int d = 1; d <= D; d += A[i]) {
                    res++;
                }
            }

            System.out.println(res);
        }
    }
}


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


int main()
{

    int a,b,c,p,q,r;
    cin>>a>>b>>c;
    p=a+b;
    q=b+c;
    r=c+a;

    if(p<=q && p<=r)
        cout<<p<<endl;
    else if(q<=p & q<=r)
        cout<<q<<endl;
    else
        cout<<r<<endl;


}


Measured memory_bytes: 256
using System;

class Program {
	static void Main(string[] args) {
		string s = Console.ReadLine();
		string t = "CODEFESTIVAL2016";
		int ans = 0;
		for(int i = 0; i < t.Length; i++) {
			if(s[i] != t[i]) ans++;
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 2648
#include<stdio.h>
int main()
{
    long long n,o=1,i,k;
    scanf("%lld",&n);
    long long dec[n];
    scanf("%lld",&dec[0]);
    k = dec[0];
    for(i=1;i<n;i++)
    {
        scanf("%lld",&dec[i]);
        if(dec[i]<=k)
        {
            k = dec[i];
            o++;
        }
    }
    printf("%lld\n",o);
    return 0;
}


Measured memory_bytes: 3272
N = input()
k = len(N)
mod = 10**9+7
DP = [[0,0] for i in range(k+1)]
DP[0][0] = 1
DP[0][1] = 0
for i in range(1,k+1):
    if N[i-1] == "1":
        DP[i][0] = (DP[i-1][0]*2)%mod
        DP[i][1] = (DP[i-1][1]*3+DP[i-1][0])%mod
    if N[i-1] == "0":
        DP[i][0] = DP[i-1][0]
        DP[i][1] = (DP[i-1][1]*3)%mod
print((DP[k][0]+DP[k][1])%mod)

Measured memory_bytes: 19664
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n,x;
  	ci(n>>x);
  vll A(n);
  FOR(i,0,n){
    ci(A[i])
  }
  vll B(n);
  ll ans=0;
  FOR(i,0,n-1){
    if(A[i]+A[i+1]>x){
      B[i]=A[i]+A[i+1]-x;//消すべき数
      if(A[i+1]<=B[i]){
        ans+=B[i];
        A[i+1]=0;
        A[i]-=B[i]-A[i+1];
      }
      else{
        A[i+1]-=B[i];
        ans+=B[i];
      }
    }
  }
  co(ans)
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int R1; int R2;
	while(~scanf("%d%d", &R1, &R2)) {
		double ans = 1. / (1. / R1 + 1. / R2);
		printf("%.10f\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#   ?????¢??¨?????¢?????°?????????????????´?????¢?????°???????????????????????°??????

#   ??????????????¢????????????????????????
class Dice:
    def __init__(self):
        self.top = 1
        self.front = 2
        self.right = 3
        self.left = 4
        self.back = 5
        self.bottom = 6
    #   2->1->5->6
    def turnSouth(self):
        temp = self.top
        self.top = self.back
        self.back = self.bottom
        self.bottom = self.front
        self.front = temp
        return self
    #   4->1->3->6
    def turnEast(self):
        temp = self.top
        self.top = self.left
        self.left = self.bottom
        self.bottom = self.right
        self.right = temp
        return self
    #   3->1->4->6
    def turnWest(self):
        temp = self.top
        self.top = self.right
        self.right = self.bottom
        self.bottom = self.left
        self.left = temp
        return self

    #   5->1->2->6
    def turnNorth(self):
        temp = self.top
        self.top = self.front
        self.front = self.bottom
        self.bottom = self.back
        self.back = temp
        return self
    #   2->3->5->4
    def turnRight(self):
        temp = self.front
        self.front = self.right
        self.right = self.back
        self.back = self.left
        self.left = temp
        return self
    #   2->4->5->3
    def turnRight(self):
        temp = self.front
        self.front = self.left
        self.left = self.back
        self.back = self.right
        self.right = temp
        return self

#   Dice?????????
myDice = Dice()
#   ?????????????????¶????????\???
myDice.top, myDice.front, myDice.right, myDice.left, myDice.back, myDice.bottom = input().split()
#   ???????????°q????¨??????\???????????????
q = int(input())
#   ?????????????????????????????????????????¨??????
#   ??????????±? ?????´??¢ ???????????????????????????(3)
for i in range(0, q):
    #   ????????????????????? ?????¢(1) ?????¢(2)???
    question = list(input())
    question = "".join(question).split()
    #   ?????¢??????????????????????????????
    for j in range(0, 3):
        if question[0] == myDice.top:
            break
        myDice.turnNorth()
    #   ?????¢??????????????????????????????
    for j in range(0, 3):
        if question[0] == myDice.top:
            break
        myDice.turnEast()
    #   ??£??¢???????????????????????¢????????????????????¢
    for j in range(0, 3):
        if question[1] == myDice.front:
            break
        myDice.turnRight()
    print("{0}".format(myDice.right))

Measured memory_bytes: 7844
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

// O(N^.5)
/// --- divisor {{{ ///
#include <vector>
vector< ll > divisor(ll n) {
  vector< ll > res;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      res.emplace_back(i);
      if(i != n / i) res.emplace_back(n / i);
    }
  }
  return res;
}
/// }}}--- ///


int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  ll n;
  cin >> n;
  auto ds = divisor(n);
  sort(ds.begin(), ds.end());
  ds.pop_back();
  vector<ll> said;
  int ans = 0;
  for(int i = (int) ds.size() - 1; i >= 0; i--) {
    ll x = ds[i];
    int ng = 0;
    for(auto e : said) {
      if(e % x == 0) ng = 1;
    }
    if(!ng) said.push_back(x), ans++;
  }
  
  cout << ans << " " << ds.size() << endl;
  return 0;
}



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

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    int sum[2000];
    for(int i=1;i<=n-1;i++){
        sum[i]=0;
    }
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            int min_dis;
            min_dis=min(j-i,abs(x-i)+1+abs(j-y));
            sum[min_dis]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<sum[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256