akhauriyash/Code-Regression huggingface dataset:
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = [];
var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line)
});
reader.on('close', () => {
	var n = [...lines[0]]
    var result = 'Good'
    for (var k in n) {
     	if (n[k] === n[k - 1]) {
          result = 'Bad'
          break
        }
    }
	console.log(result)
});

Measured memory_bytes: 7500
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')


N = int(input())

import collections
d = collections.defaultdict(int)

for _ in range(N):
    S = input()
    d[S] += 1

c = collections.Counter(d)
cnt = c.most_common()[0][-1]

a = []
for k, v in collections.Counter(d).most_common():
    if v != cnt:
        break
    a.append(k)

a.sort()
print(*a, sep="\n")

Measured memory_bytes: 68524
import sys
input = sys.stdin.readline


N=int(input())
X=list(map(int,input().split()))
ans = (100*100)**2
for i in range(min(X),max(X)+1):
    kyori = 0
    for j in range(N):
        kyori += (X[j]-i)**2
    ans = min(ans,kyori)
print(ans)


Measured memory_bytes: 9128
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 305
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int h,w,ans;
int dp[N][N],match[N][N];
char s[N][N];

void do_match(int a,int b) {

	for(int i=h;i>=1;i--) {

		for(int j=h;j>=1;j--) {

			match[i][j]=match[i+1][j+1]+(s[i][a]==s[j][b]);

		}

	}

}

int solve(int a,int b) {

	do_match(a,b);

	for(int i=1;i<=h;i++) {

		for(int j=1;j<=h;j++) {

			int topi=max(i-j+1,1),topj=max(j-i+1,1);
			int cuti=topi+min(i,j),cutj=topj+min(i,j);

			int add=match[topi][topj]-match[cuti][cutj];	

			dp[i][j]=min(dp[i-1][j],dp[i][j-1])+add;

		}

	}

	return dp[h][h];

}

int main() {

	scanf("%d %d",&h,&w);

	for(int i=1;i<=h;i++) scanf("%s",s[i]+1);

	for(int i=1;i<w;i++) ans+=solve(i,i+1);

	printf("%d",ans);

}

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

#define ARRAY_MAX 50


void solve(int n, int k, int sticks[]);
int comp(const void *x, const void *y);


int main()
{
  int n, k;
  int sticks[ARRAY_MAX];

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

  solve(n, k, sticks);

  return 0;
}

void solve(int n, int k, int sticks[])
{
  int sum;

  qsort(sticks, n, sizeof(sticks[0]), comp);
  
  sum = 0;
  for (int i = 0; i < k; i++)
    {
      sum += sticks[i];
    }

  printf("%d\n", sum);
}

int comp(const void *x, const void *y)
{
  return *(int *)y - *(int *)x;
}


Measured memory_bytes: 128
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        System.out.println(s.charAt(0) == '9' || s.charAt(1) == '9' ? "Yes" : "No");
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 35596
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
using namespace std;

int main()
{
	ifstream fin("input.txt");
	long long n, power = 1, i = 2, m = 1000000000 + 7;
	cin >> n;
	while (i <= n)
	{
		power=(power*i)%m;
		i++;
	}
	cout << power%m << endl;

}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
total = 0
oldx = 100

for i in range(N):
    x=A[i]-1
#    print(B[x], x, oldx)
    total += B[x]
    if x == oldx +1:
            total += C[x-1]
#            print(C[x-1], "pass")
    oldx = x
#    print(x, oldx)
print(total)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, k, n);
    makev(a, n);
    int d = k + a[0] - a.back();
    for(int i = 1; i < n; ++i){
        d = max(d, a[i] - a[i - 1]);
    }
    cout << k - d;
    return 0;
}

Measured memory_bytes: 1792
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define LINF (LLONG_MAX / 2)
#define EPS (1.0e-8)
const int MGN = 10;
const int ARY_SZ_MAX = (int)1e7;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>;
using vb = vector<bool>; using vvb = vector<vb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using psl = pair<string, ll>;


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


  int N; cin>>N;
  string S; cin>>S;

  int ans = 0;
  for(int ps = 0; ps<1000; ps++) {
    string s = to_string(ps);
    while(s.size()<3) {
      s = "0"+s;
    }
    int d=0;
    REP(i, N) {
      if (s[d] == S[i]) d++;
      if (d>2) break;
    }
    if (d>2) ans++;
  }

  cout << ans << endl;


  return 0;
}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int main()
{
    string s;
    int k;
    cin>>k>>s;
    if(k<s.size())
    {
        s=s.substr(0,k)+"...";
    }
    cout<<s;
}


Measured memory_bytes: 3640
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    def main():
        if s[0] != 'A' or s[2:-1].count('C') != 1:
            return 'WA'
        for i in s[2:-1]:
                if i != 'C' and i.isupper():
                    return 'WA'
        if s[1].isupper() or s[-1].isupper():
            return 'WA'
        return 'AC'
    print(main())
resolve()

Measured memory_bytes: 3060
#include "bits/stdc++.h"

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

using namespace std;
const long long INF = 1LL << 61;

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

	cout << (N + 2 * D) / (2 * D + 1);
}

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

int main() {
  int n;
  int sum;
  cin >> n;
  if(n<10) 
    sum = n;
  else if(n<100)
    sum = 9;
  else if(n<1000) 
    sum = n-90;
  else if(n<10000) 
    sum = 909;
  else if(n<100000) 
    sum =n-9090;
  else
    sum = 90909;
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
lis = []
for i in range(n):
    lis.append(list(map(int, input().split())))

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        t = 0
        for k in range(d):
            t += (abs(lis[i][k] - lis[j][k]))**2
            
        if (t**0.5).is_integer():
            cnt += 1
            
print(cnt)

Measured memory_bytes: 3188
#include<stdio.h>
int main(void){
	int H[1000],W[1000];
	int n,h,w,k;

	for(n=0;;n++){
		scanf("%d %d",&H[n],&W[n]);
		if (H[n]==0 && W[n]==0 ) {
			break;
		}
	}

	for(k=0;k < n;k++){
		for (h = 0; h < H[k]; h++) {
			for (w = 0; w < W[k]; w++) {
				if ( h==0 || w==0 || w==W[k]-1 || h==H[k]-1 ) {
					printf("#");
				}else{
					printf("." );
				}
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}



Measured memory_bytes: 1920
#include<iostream>
#include<utility>

using namespace std;

int main() {
	int h, w, res = 0;
	char s[20][20]; 

	cin >> h >> w;
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++)
			cin >> s[i][j];
	pair<int, int> ind[20][20];
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++) {
			ind[i][j] = make_pair(i,j);
		}
	for(int i = 0; i < h; i++)
		for(int j = 0; j < w; j++) {
			int d[20][20];
			// initilize d with -1s, not visited
			for(int k = 0; k < h; k++)
				for(int l = 0; l < w; l++)
					d[k][l] = -1;
			// start from (i, j)
			if (s[i][j] == '#') continue;
			d[i][j] = 0;
			pair<int, int> ps1[400] = {ind[i][j]}, ps2[400], *ps, *pss, *psst;
			int cur_num = 0, next_num = 1;
			ps = ps1; pss = ps2;
			while(next_num != 0) {
				cur_num = next_num;
				next_num = 0;
				for(int t = 0; t < cur_num; t++) {
					int x = ps[t].first, y = ps[t].second;
					if (x < h-1 
					    && s[x+1][y] == '.'
					    && d[x+1][y] == -1) {
						int u = d[x][y] + 1;
						d[x+1][y] = u;
						pss[next_num] = ind[x+1][y];
						next_num++;
						if (u > res) res = u;
					}
					if (0 < x 
					    && s[x-1][y] == '.'
					    && d[x-1][y] == -1) {
						int u = d[x][y] + 1;
						d[x-1][y] = u;
						pss[next_num] = ind[x-1][y];
						next_num++;
						if (u > res) res = u;
					}
					if (y < w-1 
					    && s[x][y+1] == '.'
					    && d[x][y+1] == -1) {
						int u = d[x][y] + 1;
						d[x][y+1] = u;
						pss[next_num] = ind[x][y+1];
						next_num++;
						if (u > res) res = u;
					}
					if (0 < y 
					    && s[x][y-1] == '.'
					    && d[x][y-1] == -1) {
						int u = d[x][y] + 1;
						d[x][y-1] = u;
						pss[next_num] = ind[x][y-1];
						next_num++;
						if (u > res) res = u;
					}
				}
				psst = ps; ps = pss; pss = psst;
			}
		}
	cout << res << endl;
	return 0;
}








	


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n;
  cin>>n;
  vll a(n);
  int cnt=0;
  ll min_a=INF;
  bool flg=false;
  rep(i,n) {
    ll b; cin>>b;
    if(b<0){
      b*=-1;
      cnt++;
    }else if(b==0) flg=true;
    a[i]=b;
    chmin(min_a,b);
  }
  ll summary=0;
  rep(i,n){
      summary+=a[i];
  }
  if(flg){
    cout<<summary<<endl;
    return 0;
  }
  if(cnt%2!=0)summary-=(min_a*2);
  cout<<summary<<endl;
}


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

struct UnionFind {
  UnionFind(size_t size) : v(size, -1) {}
  vector<int> v;

  int root(int x) {
    return (v[x] < 0 ? x : v[x] = root(v[x]));
  }

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

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (v[x] > v[y]) swap(x, y);
      v[x] += v[y];
      v[y] = x;
    }
  }

  int size(int x) {
    return -v[x];
  }
};

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

  UnionFind uf(n);
  while (q--) {
    int c, x, y;
    scanf("%d %d %d", &c, &x, &y);
    if (c) {
      cout << uf.same(x, y) << endl;
    } else {
      uf.unite(x, y);
    }
  }
}

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

using namespace std;

const int MAXN = 100005;

vector<int> G[MAXN];

int vis[MAXN];

int n, m, x, y, z, res = 0;

void dfs(int u)
{
    vis[u] = 1;
    for (auto v : G[u])
        if (!vis[v])
            dfs(v);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> x >> y >> z;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    for (int i = 1; i <= n; i++)
        if (!vis[i])
            ++res, dfs(i);
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 9216
s = input()
x, y = map(int, input().split())
l = s.split("T")
#print(l)
x -= len(l[0])
ys = []
xs = []
if len(l) == 1:
  if x == 0 and y == 0:
    print("Yes")
  else:
    print("No")
  exit(0)
for i in range(len(l)):
  if i == 0:
    continue
  if i % 2:
    ys.append(len(l[i]))
  else:
    xs.append(len(l[i]))
#移動しうるマスの総数はなんとか全列挙できるレベル
#先頭からi番目まで見たとき、移動可能であるマス
#何x何のDPなら追いつくのか考える
#bitDPするよりずっと現実的
#集合を使うと無駄なカウントがない
dpx = set()
dpx.add(0)
for i in range(len(xs)):
  nextset = set()
  for j in dpx:
    nextset.add(j + xs[i])
    nextset.add(j - xs[i])
  dpx = nextset
dpy = set()
dpy.add(0)
for i in range(len(ys)):
  nextset = set()
  for j in dpy:
    nextset.add(j + ys[i])
    nextset.add(j - ys[i])
  dpy = nextset
if x in dpx and y in dpy:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 49116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int f[2],large,a,b,c,k,i,d;
	for(int i=0;i<=2;i++)
	{
		cin >> f[i];
	}
	large=max(f[1],f[2]);
	b=max(large,f[0]);
	cin >> k;
	d=b*pow(2,k)+f[0]+f[1]+f[2]-b;
	cout <<d;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n, d, x, ans;
	cin >> n >> d >> x;
	for (int i = 0; i < n; i++) {
		int a, j = 0;
		cin >> a;
		while (j * a + 1 <= d) {
			ans += 1;
			j++;
		}
	}
	cout << ans + x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int A, B;
	cin >> A >> B;
	if (A <= 9 && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    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: usize,
    hs: [i32; n]
  }
  let mut cost = vec![1<<30; n];
  cost[0] = 0;
  for i in 1..n {
    cost[i] = cmp::min(cost[i], cost[i-1] + (hs[i] - hs[i-1]).abs());
    if i > 1 {
      cost[i] = cmp::min(cost[i], cost[i-2] + (hs[i] - hs[i-2]).abs());
    }
  }
  println!("{}", cost[n-1]);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    char S = '#' ,G = '.';
    while(1){
        int e = 1;
        cin>>H>>W;
        for(int a = 0;a<H;a++){
            for(int b = 0;b<W;b++){
               if(W%2){
                  if(e%2) cout<<S;
                  else  cout<<G;
                }else{
                    if(a%2){
                        if(e%2) cout<<G;
                        else cout<<S;
                    }  
                    else{
                    if(e%2)cout<<S;
                    else cout<<G;
                 }
                    } e++;
                }
               
                cout<<endl;
            }
                   
        if(W ==0|| H==0)break;
    cout<<endl;
    
            }
       
    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
unsigned long long  mod=998244353LL, ans;
unsigned long long countt[100005], x, ok=1, n;
unsigned long long powe(unsigned long long a, unsigned long long b){
	unsigned long long sol=1;
	while (b){
		if (b&1) sol*=a;
		a*=a; b>>=1; 
		a%=mod; sol%=mod;
	}
	return sol;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=0; i<n; i++){
	cin >> x; if (i==0 and x!=0) ok=0; 
	countt[x]++;
}
	if (countt[0]!=1) ok=0; bool kk=1;
	for (int i=1; i<n; i++){
		if (countt[i]==0) kk=0;
		if (kk==0 and countt[i]) ok=0;
	}
	if (ok){
		ans=1; 
		for (int i=1; i<n; i++){ans*=powe(countt[i-1], countt[i]); ans%=mod;}
		cout << ans;
	}
	else cout << "0";
return 0;
}

Measured memory_bytes: 1024
/*
USER: caoash3
LANG: JAVA
TASK: 
*/

import java.io.*;
import java.util.*;

public class Main {

	static final boolean stdin = true;
	static final String filename = "";
	static FastScanner br;
	static PrintWriter pw;

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

		if (stdin) {
			br = new FastScanner();
			pw = new PrintWriter(new OutputStreamWriter(System.out));
		}

		else {
			br = new FastScanner(filename + ".in");
			pw = new PrintWriter(new FileWriter(filename + ".out"));
		}

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(FastScanner br, PrintWriter pw) throws IOException {
			
			long MOD = (long) (1e9+7);
			
			int N = br.nextInt();
			int M = br.nextInt();
			
			boolean[][] grid = new boolean[N][M];
			
			for(int i = 0; i < N; i++) {
				String s = br.nextToken();
				for(int j = 0; j < M; j++) {
					grid[i][j] = (s.charAt(j) == '#');
				}
			}
			
			long[][] dp = new long[N][M];
			
			dp[0][0] = 1;
			
			for(int i = 1; i < N; i++) {
				if(grid[i][0]) {
					dp[i][0] = 0;
					continue;
				}
				dp[i][0] = dp[i-1][0];
			}
			for(int i = 1; i < M; i++) {
				if(grid[0][i]) {
					dp[0][i] = 0;
					continue;
				}
				dp[0][i] = dp[0][i-1];
			}
			
			for(int i = 1; i < N; i++) {
				for(int j = 1; j < M; j++) {
					if(grid[i][j]) {
						dp[i][j] = 0;
						continue;
					}
					dp[i][j] = (long) (dp[i-1][j] + dp[i][j-1]) % MOD;
					
				}
			}
			
			pw.println(dp[N-1][M-1]);
			
			pw.close();
		}

	}

	//fastscanner class
	public static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

}
 



Measured memory_bytes: 36656
#define R register
#define ll long long
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;

int n, curr;
int a[maxn];
ll s[maxn], ans;
map<ll, int> cnt;

int main()
{
	scanf("%d", &n);
	for (R int i = 1; i <= n; ++i) scanf("%d", &a[i]), s[i] = s[i - 1] + a[i], cnt[s[i]] = 0;
    for (R int i = n; i >= 1; --i)
    {
        if(s[i] == 0) ++ans;
        ans += cnt[s[i]];
        cnt[s[i]] += 1;
    }
	printf("%lld", ans);
}

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

int main(){
    int n;
    cin >> n;
    int w[n];
    for(int i=0;i<n;i++){
        cin >> w[i];
    }
    vector<int> a;
    a.push_back(w[0]);//9
    vector<int> b;
    b.push_back(w[n-1]);//1
    n-=2;//7
    for(int i=1;i<=n;){
        while(accumulate(a.begin(),a.end(),0)<=accumulate(b.begin(),b.end(),0)&&i<=n){
            a.push_back(w[i]);//11,15
            i++;//2,3
        }
        while(accumulate(a.begin(),a.end(),0)>accumulate(b.begin(),b.end(),0)&&i<=n){
            b.push_back(w[n]);//2,5,9,14,15
            n--;//6,5,4,3,2
        }
    }
    cout << abs(accumulate(a.begin(),a.end(),0)-accumulate(b.begin(),b.end(),0)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph=vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

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

	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n)
	{
		cin >> s[i];
	}

	vector<pair<ll, string>> ans;
	sort(all(s));
	pair<ll, string> tmp;
	tmp.first = 1;
	tmp.second = s[0];
	ans.push_back(tmp);
	ll nv = 0;

	for (int i = 1; i < n; i++)
	{
		if (s[i] == tmp.second)
			ans[nv].first++;
		else
		{
			tmp.first = 1; tmp.second = s[i];
			ans.push_back(tmp);
			nv++;
		}
	}

	sort(ans.begin(), ans.end(),greater<pair<ll,string>>());
	vector<string> st;
	ll nu = ans[0].first;
	for (ll i = 0; i <= nv; i++)
	{
		if (ans[i].first == nu)
			st.push_back(ans[i].second);
		else
			break;
	}
	reverse(st.begin(), st.end());
	for (int i = 0; i < st.size(); i++)
	{
		cout << st[i] << endl;
	}
	return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll A,B,C,K;
  cin>>A>>B>>C>>K;

  if(K%2==1)cout<<B-A<<endl;
  else cout<<A-B<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,i,ara[100000];
    for(i=1;;i++)
    {
        scanf("%d",&ara[i]);
        if(ara[i]==0)
        {
            break;
        }
        printf("Case %d: %d\n",i,ara[i]);
    }
    return 0;
}



Measured memory_bytes: 2028
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<tgmath.h>
#include<stdlib.h>
#include<assert.h>
#include<stdio.h>



#define ll long long


/*
_
_._ _..._ . - ',     _.._(`))
'-. `     ' / -._. - '    ', /
)         \            '.
/ _    _ | \
| a    a    /              |
\   . - .;
'-('' ).-', '       ;
'-;           |      .'
\           \    /
| 7.__  _. - \   \
| |  |  ``/ / `  /
/, _|  |   /, _/   /
/, _ / '`-'
*/
using namespace std;

int bin_search(int ele, vector<pair<int,int> > arr)
{
    int l = 0, r = arr.size()-1 , mid=0;
    while (l <= r) {
        mid = l + (r - l) / 2;
        if (arr[mid].first == ele) {
            return arr[mid].second;
        }
        else if (arr[mid].first > ele) {
            r = mid - 1;
        }
        else {
            l = mid + 1;
        }
    }
    return mid;
}

int main()
{
    int n;
    cin >> n;
    if (n % 2 == 0) {
        cout << n / 2;
    }
    else {
        cout << n / 2 + 1;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    pair<long long,long long> d[n];
    for(int i=0;i<n;i++)cin >> d[i].first >> d[i].second;
    sort(d,d+n);
    long long sum=0;
    for(int i=0;m>0;i++){
        if(m>=d[i].second){
            sum+=d[i].second*d[i].first;
            m-=d[i].second;
        }
        else{
            sum+=m*d[i].first;
            m=0;
        }
    }
    cout << sum;
}

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

using namespace std;

int main()
{
	int a[1005], t[1005];
	unsigned long long t_temp = 1, a_temp = 1;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) 
		cin >> t[i] >> a[i];

	for (int i = 0; i < n; i++) {
	    if(t_temp % t[i] != 0) {
			t_temp = (t_temp / t[i] + 1) * t[i];
	    }
	    if(a_temp % a[i] != 0) {
			a_temp = (a_temp / a[i] + 1) * a[i];
	    }
 
	    unsigned long long ans1, ans2;
	    ans1 = t_temp / t[i];
	    ans2 = a_temp / a[i];
 
	    if(ans1 <= ans2)
	    	t_temp = t[i] * ans2;
	    else 
	    	a_temp = a[i] * ans1;
	}
	cout << a_temp + t_temp << endl;

	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <map>

using namespace std;

const int W = 4, H = 5;
int ans;
map<string, bool> memo;

int next(int pos, int dy, int dx)
{
    if (dy == 0 && dx == 0)
        return -1;
    int x = (pos % W) + dx, y = (pos / W) + dy;
    if (x < 0 || y < 0 || x >= W || y >= H)
        return -1;
    return y * W + x;
}

void Rec(string s)
{
    if (memo.end() != memo.find(s))
        return ;
    ans = min(ans, (int)s.size());
    memo.insert(map<string, int>::value_type(s, true));

    for (int i = 0; i < s.size(); ++i) {
        for (int dy = -1; dy <= 1; ++dy) {
            for (int dx = -1; dx <= 1; ++dx) {
                int nx = next(i, dy, dx);
                if (nx == -1 || nx >= s.size())
                    continue;
                if (s[i] != s[nx])
                    continue;

                string tmp;
                for (int l = 0; l < s.size(); ++l)
                    if (l != i && l != nx)
                        tmp.push_back(s[l]);

                Rec(tmp);
            }
        }
    }
}

int main()
{
    int N;

    cin >> N;
    while (N--) {
        // Input
        char ch;
        string card;

        for (int i = 0; i < H * W; ++i) {
            cin >> ch;
            card += ch;
        }
        // Solve
        ans = H * W;
        memo.clear();

        Rec(card);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1292
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

const long waru = 1000000007;

long pow3(int n)
{
    long res = 1;
    int i = n;
    for(; i>40; i -= 40)
    {
        res *= (3486784401L) % waru * 3486784401L % waru;
        res %= waru;
    }

    for(; i>0; i--)
    {
        res *= 3;
        res %= waru;
    }
    return res;
}

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

    long a[100001] = {};
    long c[100001] = {};
    long h[100001] = {};
    for(int i=0; i<s.length(); i++)
    {
        //int cIdx = s.length() - 1 - i;
        //cout << a[i] << " " << c[cIdx] << endl;
        if(i != 0)
        {
            a[i] += a[i-1];
            c[i] += c[i-1];
            h[i] += h[i-1];
        }

        if(s[i] == 'A') a[i]++;
        if(s[i] == 'C') c[i]++;
        if(s[i] == '?') h[i]++;
    }

    long ans = 0;

    for(int i=1; i<s.length()-1; i++)
    {
        if(s[i] == 'B' || s[i] == '?')
        {
            int lh = h[s.length()-1] - h[i];
            int lc = c[s.length()-1] - c[i];

            // 1
            if(a[i-1] > 0 && lc > 0)
            {
                ans = (ans + a[i-1] * lc * pow3(h[i-1] + lh)) % waru;
            }

            // 2
            if(h[i-1] > 0 && lc > 0)
            {
                ans = (ans + h[i-1] * lc * pow3(h[i-1] - 1 + lh)) % waru;
            }

            // 3
            if(a[i-1] > 0 && lh > 0)
            {
                ans = (ans + a[i-1] * lh * pow3(h[i-1] + lh - 1)) % waru;
            }

            // 4
            if(h[i-1] > 0 && lh > 0)
            {
                ans = (ans + h[i-1] * lh * pow3(h[i-1] - 1 + lh - 1)) % waru;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

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


int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    //int n=3;
    cin>>s;
    int cnt=0;
    int ans;
    for(int i=0;i<3;i++)
	{
			if(s[i]=='R')
				cnt++;
			else
			{
				ans=max(ans,cnt);
				cnt=0;
			}
	}
	ans=max(ans,cnt);
	cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 3616
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, A, B = [int(x) for x in input().split()]

    if A > B:
        print(0)
        return
    if N == 1 and A != B:
        print(0)
        return

    mi = A + B + (N - 2) * A
    ma = A + B + (N - 2) * B
    print(ma - mi + 1)

    

if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#define INF 300000

using namespace std;

typedef pair<int, int> p;

int w, h, n, result;
int visited[1000][1000];
bool map[1000][1000];
p start, last_start, goal, cur, cheese[10];
queue<p> myqueue;

void init(int in){
    start = last_start;

    while(!myqueue.empty()) myqueue.pop();

    for(int i=0; i<w; ++i){
        for(int j=0; j<h; ++j){
            if(map[i][j] == false){
                visited[i][j] = -1;
            }else{
                visited[i][j] = INF;
            }
            goal = cheese[in];
        }
    }
    return ;
}

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

    char input;
    for(int i=0; i<w; ++i){
        for(int j=0; j<h; ++j){
            cin >> input;
            if(input == 'X') map[i][j] = false;
            else             map[i][j] = true;
            if(input == 'S')
                last_start = make_pair(i, j);
            if(input != 'X' && input != 'S' && input != '.'){
                cheese[input-'0'] = make_pair(i, j);
            }
        }
    }


    result = 0;
    for(int i=1; i<=n; ++i){
        init(i);
        myqueue.push(start);
        visited[start.first][start.second] = 0;

        while(!myqueue.empty()){

            cur = myqueue.front();
            myqueue.pop();

            if(cur == goal)break;

            int x = cur.first, y = cur.second;
            if(x-1 >= 0 && visited[x-1][y]==INF){
                myqueue.push(make_pair(x-1, y));
                visited[x-1][y] = visited[x][y]+1;
            }
            if(y-1 >= 0 && visited[x][y-1]==INF){
                myqueue.push(make_pair(x, y-1));
                visited[x][y-1] = visited[x][y]+1;
            }
            if(x+1 < w && visited[x+1][y]==INF){
                myqueue.push(make_pair(x+1, y));
                visited[x+1][y] = visited[x][y]+1;
            }
            if(y+1 < h && visited[x][y+1]==INF){
                myqueue.push(make_pair(x, y+1));
                visited[x][y+1] = visited[x][y]+1;
            }
        }

        result += visited[goal.first][goal.second];
        last_start = goal;
    }
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 8004
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void)
{
  int N , K;
  cin >> N >> K;
  vector<bool> sunuke(N,true);
  int tmp;
  for(int i = 0 ; i < K ; i++)
  {
    vector<int> d(K);
    cin >> d.at(i);
    for(int j = 0; j < d.at(i); j++)
    {
      cin >> tmp;
      sunuke.at(tmp-1) = false;
    }
  }
  int ans = 0;
  for(int i = 0 ; i < N ; i++)
  {
    if(sunuke.at(i))ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
    double x1, y1, x2, y2, dis;
    cin >> x1 >> y1 >> x2 >> y2;
    dis = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
    cout << fixed << setprecision(4) << dis << endl;
    return 0;
}


Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
void solve()
{
    int n;
    cin>>n;
   int ans=0;
   int mx=pow(10,6);
   int rem=0;
   set<int> s;
   for(int i=0;i<mx;i++)
   {
       rem*=10;
       rem+=7;
       rem%=n;
       if(rem==0)
       {
           cout<<i+1<<endl;
           return;
       }
       if(s.find(rem)!=s.end())
       {
           cout<<-1<<endl;
           return;
       }
       s.insert(rem);
   }
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


Measured memory_bytes: 50516
// Aizu 2752: Finger Counting
// 2017.9.24 bal4u@uu

#include <stdio.h>

int main()
{
	int k;
	long long a;

	scanf("%lld", &a);
	k = 0;
	while (a > 0) a >>= 1, k++;
	printf("%d\n", k);
	return 0;
}

Measured memory_bytes: 1844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



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

  ll n, m;
  cin >> n >> m;
  ll left=1, right=n;
  ll l, r;
  rep(i, 0, m) {
    cin >> l >> r;
    left = max(left, l);
    right = min(right, r);
  }    
  
  cout << max(0LL, right-left+1) << "\n";

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int build[4][3][10]={0};
	
	int i ,j ,p ;
	
	for( i=0 ; i<4 ;i++)
	{
		for(j =0 ; j<3 ;j++)
		{
			for(p=0 ;p<10 ;p++)
			{
					build[i][j][p]=0;
			}
		}
	}
	int n =0;
	scanf("%d",&n);
	while(n--)
	{
		int b ,f ,r ,v;
		
		scanf("%d %d %d %d",&b ,&f ,&r ,&v);
		build[b-1][f-1][r-1]+=v;
	}
	for(i=0 ; i<4 ;i++)
	{
		for(j=0;j<3;j++)
		{
			for(p=0;p<10;p++)
			{
				
				printf(" %d",build[i][j][p]);
				
			}
			printf("\n");
		}
		if(i!=3)
		{
			printf("####################\n");
		}
	}
}



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

int main(){
	int N, K, i, j, ans=0;
	cin >> N >> K;
	int d[K+1], count[N+1]={0};
	int A[K+1][N+1]={0};
	for(i=1; i<=K; i++){
		cin >> d[i];
		for(j=1; j<=d[i]; j++){
			cin >> A[i][j];
		}
	}
	
	for(i=1; i<=K; i++){
		for(j=1; j<=d[i]; j++){
			count[A[i][j]]++;
		}
	}
	for(i=1; i<=N; i++){
		if(count[i]==0)	ans++;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_I_O ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7 , INF = 1e9 ,  mx = 100005 ;
main()
{
    fast_I_O;
    int i,j,n,m,x,y,sum=0,p=0,l,k;
    string s,t;
    cin>>s>>t;
    for(i=0;i<s.length();i++)
    {
        if(s[i]!=t[i]) ++p;
    }
    cout<<p;
    return 0;
}

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

int main(){
  long long n; cin >> n;
  long long ans = 0;
  for(int i = 1; i < n+1; i++){
  	if(i%3!=0 && i%5!=0) ans += i;
  }
  cout << ans << endl;
}


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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

ll fn(ll n, ll m) {
  ll maxVal = max(n, m);
  ll minVal = min(n, m);
  while (minVal != 0) {
    ll tmp = maxVal % minVal;
    maxVal = max(tmp, minVal);
    minVal = min(tmp, minVal);
  }
  return maxVal;
}

int main() {
  ll n, x;
  cin >> n >> x;

  vector<ll> a(n, 0);
  for (long i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    a.at(i) = abs(tmp - x);
  }

  ll ans = a.at(0);
  for (long i = 1; i < n; i++) {
    ans = fn(a.at(i), ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4024
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a.size()>80||b.size()>80)
			cout<<"overflow"<<endl;
		else{
			int t;
			int c[100]={0};
			if(a.size()>=b.size())
				t=a.size();
			if(a.size()<b.size())
				t=b.size();
			for(int j=0;j<t;j++){
				if(j<a.size())
					c[j]+=a[a.size()-j-1]-'0';
				if(j<b.size())
					c[j]+=b[b.size()-j-1]-'0';
				if(c[j]>=10){
					c[j]-=10;
					c[j+1]=1;
				}
			}
			bool h=true;
			if(c[t]==1){
				if(t==80){
					cout<<"overflow"<<endl;
					h=false;
				}
				else
				    cout<<"1";
			}
			if(h==true){
			for(int j=t-1;j>=0;j--)
				cout<<c[j];
			cout<<endl;
			}
		}
	}
	return 0;
}

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

int main(void){
  int n,k,g;
  char c,cl;
  
  cin >> n >> k;
  cl = '\0';
  for (int i=0; i<n; i++){
    cin >> c;
    if (c!=cl) g++;
    cl = c;
  }
  // グループ数をどこまで減らせるか。
  // O(1)にもできるけど分岐が複雑だしO(k)で十分なのでこうする
  for (; k>0 && g>1; k--){
//    cout << g << endl;
    g -= (g>2?2:1);
  }
//  cout << g << endl;
  cout << (n-g) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

void solve()
{
	int n, S;
	while(cin >> n >> S, n || S)
	{
		vector<int> r(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> r[i];
		}
		sort(r.begin(), r.end(), greater<int>());
		int sum = 0;
		for(int i = 0; i < n; ++i)
		{
			if(r[i] >= S)
			{
				sum += n - i - 1;
				continue;
			}
			else
			{
				for(int j = i + 1; j < n; ++j)
				{
					if(r[i] + r[j] > S)
					{
						++sum;
					}
					else
					{
						break;
					}
				}
			}
		}
		cout << sum << endl;
	}
}

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

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

int main()
{
   
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    
        int r;
        cin >> r;
        
        double ans = (double)(2) * PI * (double)(r);

        cout << setprecision(10) << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3780
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] A = in.ii(N);
        int[] l = new int[N];
        int[] r = new int[N];

        l[0] = A[0];
        for (int i = 0; i < N - 1; i++) {
            l[i + 1] = gcd(l[i], A[i]);
        }

        r[N - 1] = A[N - 1];
        for (int i = N - 1; i > 0; i--) {
            r[i - 1] = gcd(r[i], A[i]);
        }

        l[0] = r[0];
        r[N - 1] = l[N - 1];

        int ans = 0;
        for (int i = 0; i < N; i++) {
            ans = Math.max(ans, gcd(l[i], r[i]));
        }

        out.println(ans);
    }

    static int gcd(int a, int b) {
        int r;
        while ((r = a % b) != 0) {
            a = b;
            b = r;
        }
        return b;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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

int main(){
  int h, w; cin >> h >> w;
  vector<vector<int>> mp(h, vector<int>(w));
  vector<int> x1, x2, y1, y2;
  int cnt = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> mp[i][j];
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w-1; j++){
      if(mp[i][j] % 2){
        mp[i][j]--;
        mp[i][j+1]++;
        y1.push_back(i+1); x1.push_back(j+1);
        y2.push_back(i+1); x2.push_back(j+2);
        cnt++;
      }
    }
  }
  for(int i = 0; i < h-1; i++){
    if(mp[i][w-1] % 2){
      mp[i][w-1]--;
      mp[i+1][w-1]++;
      y1.push_back(i+1); x1.push_back(w);
      y2.push_back(i+2); x2.push_back(w);
      cnt++;
    }
  }
  cout << cnt << endl;
  for(int i = 0; i < cnt; i++){
    cout << y1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
  }
}

Measured memory_bytes: 6260
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
//#define int ll

const int N = 2e5 + 10;
int a[N], b[N];

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  n = 2 * n - 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }  
  int l = 1, r = n + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    for (int i = 1; i <= n; i++) {
      b[i] = (a[i] >= mid ? 1 : 0);
    }
    pair<int, int> best = {n + 1, -1};
    int ps = (n + 1) / 2;
    for (int i = 1; i < n; i++) {
      if (b[i] == b[i + 1]) {
        best = min(best, make_pair(abs(ps - i), b[i]));
        best = min(best, make_pair(abs(ps - (i + 1)), b[i]));
      }
    }
    if (best.F == n + 1) {
      if (b[1] == 1) {
        l = mid;
      }
      else {
        r = mid;
      }
    }
    else {
      if (best.S == 1) {
        l = mid;   
      }
      else {
        r = mid;
      }
    } 
  }
  cout << l << '\n'; 
} 

Measured memory_bytes: 1920