akhauriyash/Code-Regression huggingface dataset:
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val h = sc.nextLong
  
  def loop(div: Long, attackCnt: Long = 0, loopCnt: Long = 0): (Long, Long) = {
    if (div == 1) (attackCnt, loopCnt)
    else loop(div / 2, attackCnt + math.pow(2, loopCnt).toLong, loopCnt + 1)
  }
  
  val (attackCnt, loopCnt) = loop(h)
  
  println(attackCnt + math.pow(2, loopCnt).toLong)
}

Measured memory_bytes: 25672
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define N 1000005
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
vector<int> dig(int n){
	vector<int> ans;
	while(n){
		ans.pb(n%10);
		n/=10;
	}
	return ans;
}
int power(int x, unsigned int y, unsigned int m)
{
    if (y == 0)
        return 1;
    int p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}
int dfs(vector<int> v, int i, bool f){
	if(i==sz(v)-1) return 1;
	if(f){
		return 10*dfs(v,i+1,f);
	}
	else{
		return dfs(v,i+1,1)+v[i]*dfs(v,i+1,0);
	}
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		int ans = 0;
		rep(a,1,n+1){
			int last = a%10;
			int first = a/power(10,(int)log10(a),INF);
			// trace(a,last,first);
			if(first == last && first<=n) {
				ans++;
			}
			if(last==0) continue;
			int i = 1;
			int cur = 10*last+first;
			while(cur<=n){
				// trace(a,cur,last,first);
				int lo = 0, hi = power(10,i-1,INF)-1;
				while(lo<=hi){
					int mid = (lo+hi)/2;
					if(mid*10+cur<=n){
						lo = mid+1;
					}
					else{
						hi = mid-1;
					}
				}
				ans += lo;
				i++;
				cur = power(10,i,INF)*last+first;
			}
		}
		cout<<ans;
	}
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
const ll MOD = 1e9 + 7;
struct mint {
    long long x;
    mint(long long _x=0):x((_x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint modpow(long long t) const {
        if (!t) return 1;
        mint a = modpow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return modpow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
    friend std::ostream& operator<<(std::ostream& os, const mint& a){
        os << a.x;
        return os;
    }
};


int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> s(2e5,0), f(2e5,0);
    vector<ll> A;
    ll cntz = 0, cntpl = 0, cntmi = 0;
    rep(i,N){
        ll a;
        cin >> a;
        A.push_back(abs(a));
        if(a == 0)cntz++;
        if(a > 0){
            s.push_back(a);
            cntpl++;
        }
        if(a < 0){
            f.push_back(abs(a));
            cntmi++;
        }
    }
    sort(all(A));
    sort(all(s), greater<>());
    sort(all(f), greater<>());
    mint ans = 1;
    if(N == K){
        rep(i,K)ans *= A[i];
        if(cntmi & 1)ans = -ans;
        cout << ans << endl;
        return 0;
    }
    // K < N;
    ll idx[] = {0,0};
    if(K&1){
        if(cntpl > 0)ans *= s[idx[0]++];
        else{
            rep(i,K)ans *= A[i];
            ans = -ans;
            cout << ans << endl;
            return 0;
        }
    }
    // 残りの偶数個を決めていく
    ll len = K / 2;
    while(len--){
        ll tmp[2];
        tmp[0] = s[idx[0]] * s[idx[0]+1];
        tmp[1] = f[idx[1]] * f[idx[1]+1];
        if(tmp[0] < tmp[1]){
            ans *= tmp[1];
            idx[1] += 2;
        }
        else{
            ans *= tmp[0];
            idx[0] += 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 13016
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int maxn = 5e5+10;
char w[maxn];
int len;
int pre_next[maxn],suf_next[maxn];
void get_next(){
    pre_next[0]=pre_next[1]=0;
    int j=0;
    for(int i=2;i<=len;i++){
        while(j&&w[i]!=w[j+1])j=pre_next[j];
        if(w[j+1]==w[i])++j;
        pre_next[i]=j;
    }
    reverse(w+1,w+len+1);
    suf_next[0]=suf_next[1]=0;
    j=0;
    for(int i=2;i<=len;i++){
        while(j&&w[i]!=w[j+1])j=suf_next[j];
        if(w[j+1]==w[i])++j;
        suf_next[i]=j;
    }
}
bool pre_check(int i){
    return !pre_next[i]||i%(i-pre_next[i]);
}
bool suf_check(int i){
    return !suf_next[i]||i%(i-suf_next[i]);    
}
int main(){
    scanf("%s",w+1);
    len=strlen(w+1);
    get_next();
    if(pre_check(len)){
        printf("1\n1\n");
    }
    else if(len-pre_next[len]==1){
        printf("%d\n1\n",len);
    }
    else {
        int ans=0;
        for(int i=1;i<=len;i++){
            if(pre_check(i)&&suf_check(len-i))
                ans++;
        }
        printf("2\n%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4608
n, m, l = map(int, input().split())
mc = [[0 for j in range(l)] for i in range(n)]
ma = [list(map(int, input().split())) for i in range(n)]
mb = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    for j in range(l):
        for k in range(m):
            mc[i][j] += ma[i][k] * mb[k][j]

for row in range(n):
    print("%d" % mc[row][0], end="")
    for col in range(1, l):
        print(" %d" % mc[row][col], end="")
    print()



Measured memory_bytes: 7068
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=a.index(1)
ans=m//(k-1)+(n-m-1)//(k-1)
kk=m%(k-1)+(n-m-1)%(k-1)+1
if m!=0 and m!=n-1:
  if kk>1:
    ans+=1+(kk>k)
else:
  ans+=(ans*(k-1)+1<n)
print(ans)

Measured memory_bytes: 13880
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

typedef vector<vector<char>> Line;
typedef vector<Line> Block;

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

int h, n;
int ans;

Block getMovedBlock(const Block& b, int dir){
	Block res(2, Line(2, vector<char>(2, '.')));
	rep(i,2){
		rep(j,2){
			rep(k,2){
				if(b[i][j][k] == '#'){
					int ny = j + dy[dir];
					int nx = k + dx[dir];
					if(ny < 0 || ny >= 2 || nx < 0 || nx >= 2) return Block();
					res[i][ny][nx] = '#';
				}
			}
		}
	}
	return res;
}

bool canDown(const vector<Line>& m, const Block& b, int h){
	rep(i,2){
		if(h == m.size() and i == 1) break;
		rep(j,2){
			rep(k,2){
				if(m[h - 1 + i][j][k] == '#' and b[i][j][k] == '#') {
					return false;
				}
			}
		}
	}
	return true;
}

void output(Block d){
	show("JI")
	rep(i,2){
		rep(j,2){
			rep(k,2){
				cout << d[i][j][k];
			}
		cout << endl;
		}
	}
	show("JI")
}

void dfs(vector<Line>& m, const vector<Block>& d, int idx, int cnt){
	if(idx == n){
		ans = max(ans, cnt);
		return;
	}

	//show(idx)
	const auto& b = d[idx];
	//output(b);

	vector<Line> save = m;
	rep(dir,9){
		Block moved = getMovedBlock(b, dir);
		//show(dir)
		if(moved.empty()) continue;

		//output(moved);

		int h = 1;
		for(int i = m.size(); i >= 1; i--){
			if(not canDown(m, moved, i)){
				h = i + 1;
				break;
			}
		}

		if(h == m.size() + 1){
			m.emplace_back(moved[0]);
			m.emplace_back(moved[1]);
		}else if(h == m.size()){
			rep(j,2){
				rep(k,2){
					if(moved[0][j][k] == '#') m[h - 1][j][k] = '#';
				}
			}
			m.emplace_back(moved[1]);
		}else{
			rep(i,2){
				rep(j,2){
					rep(k,2){
						if(moved[i][j][k] == '#') m[h - 1 + i][j][k] = '#';
					}
				}
			}
		}

		int deleteLine = 0;
		for(auto it = next(m.begin(), 1); it != m.end();){
			Line& tmp = *it;
			if(tmp[0][0] == '#' and tmp[0][1] == '#' and tmp[1][0] == '#' and tmp[1][1] == '#'){
				it = m.erase(it);
				deleteLine++;
			}else{
				it++;
			}
		}

		//rep(i,m.size()){ rep(j,2){ rep(k,2){ cout << m[i][j][k]; } cout << endl; } }

		dfs(m, d, idx + 1, deleteLine + cnt);
		m = save;
	}
}

int main(){
	while(cin >> h >> n, h||n){
		vector<Line> m;
		m.emplace_back(Line(2, vector<char>(2, '#')));

		rep(i,h){
			Line a(2, vector<char>(2));
			rep(i,2){
				rep(j,2){
					cin >> a[i][j];
				}
			}
			m.emplace_back(a);
		}

		vector<Block> d;
		rep(i,n){
			Block a(2, Line(2, vector<char>(2)));
			rep(i,2){
				rep(j,2){
					rep(k,2){
						cin >> a[i][j][k];
					}
				}
			}
			d.emplace_back(a);
		}

		ans = 0;
		dfs(m,d,0,0);
		cout << ans << endl;
	}
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define Nmax 1005

using namespace std;

const long long INF=1e18l;
ifstream f("1.in");
ofstream g("1.out");

//double dp[3004], p;
int n;

int main()
{
    scanf("%d", &n);
    vector <double> dp(n+1);

    dp[0]=1;

    for (int coin = 0; coin < n; coin++)
    {
        double p;
        scanf("%lf", &p);
        for (int i = coin+1; i >= 0; i--)
            dp[i] = (i == 0 ? 0 : dp[i-1]*p)+dp[i]*(1-p);
    }

    double ans=0;
    for (int h = 0; h <= n; h++)
    {
        int t=n-h;
        if(h>t) ans+=dp[h];
    }
    cout << fixed << setprecision(9) <<  ans;

    return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long int li;

int main(){
    ll ans=0;
    ll n,m,c;
    cin >> n >> m >> c;
    int a[n][m];
    int b[m];
    for(ll i = 0; i < m;i++){
            cin >> b[i];
    }
    for(ll i = 0; i < n;i++){
        for(ll j = 0; j < m;j++){
            cin >> a[i][j];
        }
    }
    for(ll i = 0; i < n;i++){
        int x=0;
        for(ll j = 0; j < m;j++){
            x += (a[i][j]*b[j]);
        }
        x+=c;
        if(x>0)ans++;
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

const long MOD = 998244353;
long lu[200000], ld[200000], ru[200000], rd[200000];

typedef pair<int, int> P;
P p[200000];

template <typename T>
struct bit{
    int n;
    vector<T> data;

    bit(int n_){
        n = 1;
        while(n < n_) n *= 2;
        data = vector<T>(n+1);
        for(int i = 0; i <= n; i++) data[i] = 0;
    }
    
    T sum(int i){
        T ret = 0;
        while(i > 0){
            ret += data[i];
            i -= i&-i;
        }
        return ret;
    }

    void add(int i, T x){
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
};

long pow2[200001];

void init(){
    pow2[0] = 1;
    for(int i = 1; i <= 200000; i++){
        pow2[i] = pow2[i-1]*2;
        pow2[i] %= MOD;
    }
}

int main(){
    init();
    int N;
    int x[200000],y[200000];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < N; i++){
        p[i] = P(x[i], i);
    }
    sort(p, p+N);
    for(int i = 0; i < N; i++){
        x[p[i].second] = i+1;
    }
    for(int i = 0; i < N; i++){
        p[i] = P(y[i], i);
    }
    sort(p, p+N);
    for(int i = 0; i < N; i++){
        y[p[i].second] = i+1;        
    }
    
    for(int i = 0; i < N; i++){
        p[i] = P(x[i], y[i]);
    }
    sort(p, p+N);
    bit<int> bl(N), br(N);
    for(int i = 0; i < N; i++){
        bl.add(p[i].second, 1);
        int m = bl.sum(p[i].second);
        ld[i] = m-1;
        lu[i] = i-m+1;
    }
    for(int i = N-1; i >= 0; i--){
        br.add(p[i].second, 1);
        int m = br.sum(p[i].second);
        rd[i] = m-1;
        ru[i] = (N-i)-m;
    }
    long ans = 0;
    for(int i = 0; i < N; i++){
        //cout << lu[i] << ' ' << ld[i] << ' ' << ru[i] << ' ' << rd[i] << endl;
        long tmp;
        ans += pow2[N-1];
        ans += (((pow2[lu[i]]-1)*(pow2[rd[i]]-1))%MOD);
        ans %= MOD;
        ans += (((pow2[ld[i]]-1)*(pow2[ru[i]]-1))%MOD);
        ans %= MOD;
        ans += (((pow2[ld[i]]-1)*(pow2[lu[i]]-1))%MOD)*(((pow2[rd[i]]-1))%MOD);
        ans %= MOD;
        ans += (((pow2[ld[i]]-1)*(pow2[lu[i]]-1))%MOD)*(((pow2[ru[i]]-1))%MOD);
        ans %= MOD;
        ans += (((pow2[ld[i]]-1)*(pow2[rd[i]]-1))%MOD)*(((pow2[ru[i]]-1))%MOD);
        ans %= MOD;
        ans += (((pow2[lu[i]]-1)*(pow2[rd[i]]-1))%MOD)*(((pow2[ru[i]]-1))%MOD);
        ans %= MOD;
        ans += (((((pow2[ld[i]]-1)*(pow2[lu[i]]-1))%MOD)*(((pow2[rd[i]]-1)*(pow2[ru[i]]-1))%MOD))%MOD);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    set<int>sad;
    int n,m;
    cin>>n;
    while(n--)
    {
        cin>>m;
        sad.insert(m);
    }
    cout<<SZ(sad)<<NL;
    return 0;
}


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

using namespace std;

#define pb push_back
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) FOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

const double eps = 1e-10;
const int MOD = 1000000007;

void printv(vector<auto> const& s) {
  REP(i, s.size()) {
    cout << s[i] << endl;
  }
}

void print(auto const s) {
  cout << s << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int a, b, c; cin >> a >> b >> c;
  map<int, bool> m;
  int now = a % b;
  m[now] = true;
  while(1) {
    if(now == c) {
      cout << "YES" << endl;
      return 0;
    }
    now = (now + a) % b;
    if(m[now] == true) {
      cout << "NO" << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
    int f[N2];
    int space;
    string path;
    
    bool operator < ( const Puzzle &p ) const {
        
        for (int i = 0 ; i<N2 ; i++) {
            if (f[i]==p.f[i]){
                continue;
                
            }
            return f[i] > p.f[i];
        }
        return false;
    }
};

bool isTarget(Puzzle p){
    
    for (int i =0 ; i<N2 ; i++){
        if (p.f[i]!=(i + 1)){
            return false;
        }
    }
    return true;
}

static const char dir[4] = {'u', 'l', 'd', 'r'
};
static const int dx[4] = {-1, 0, 1, 0
};
static const int dy[4] = {0, -1, 0, 1
};

string bfs(Puzzle s) {
    queue<Puzzle> Q;
    map<Puzzle, bool> V;
    Puzzle u, v;
    s.path = "";
    Q.push(s);
    V[s] = true;
    
    while( !Q.empty()) {
        u = Q.front();
        Q.pop();
        if ( isTarget(u)) return u.path;
        int sx = u.space / N;
        int sy = u.space % N;
        for (int r = 0; r < 4; r++) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;
            swap(v.f[u.space], v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if ( !V[v]) {
                V[v] = true;
                v.path += dir[r];
                Q.push(v);
            }
        }
    }
    
    return "unsolvable";
}

int main() {
    Puzzle in;
    
    for (int i =0 ; i<N2 ; i++){
        cin >> in.f[i];
        if (in.f[i]==0) {
            in.f[i] = N2;
            in.space = i;
        }
    }
    
    string ans = bfs(in);
    cout << ans.size() << endl;
    
    return 0;
}



Measured memory_bytes: 30680
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll H, W;
    cin >> H >> W;
    vector<vector<ll>> A(H, vector<ll>(W));
    rep(i, H) rep(j, W) cin >> A[i][j];

    vector<pair<P,P>> ans;
    rep(i, H) rep(j, W - 1){
        if(A[i][j] % 2 == 0) continue;
        else{
            ans.pb({{i, j}, {i, j + 1}});
            --A[i][j];
            ++A[i][j + 1];
        }
    }

    rep(i, H - 1){
        if(A[i][W-1] % 2 == 0) continue;
        else{
            ans.pb({{i, W - 1}, {i + 1, W - 1}});
            --A[i][W-1];
            ++A[i + 1][W - 1];
        }
    }

    print(len(ans));
    for(auto p : ans){
        cout << p.first.first + 1 << " " << p.first.second + 1 << " ";
        cout << p.second.first + 1 << " " << p.second.second + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 8432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string S;
    cin >> S;
    reverse(ALL(S));
    ll count = 0;
    int where = 0;
    REP(i,S.size()){
        if(S[i] == 'B'){
            count += i - where;
            where++;
        }
    }
    cout << count << "\n";
}

Measured memory_bytes: 720
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int A[200000];
vi poss,num;
int pp[200000];
vi adjList[200000];
int visited[200000],parent[200000],depth[200000];
vpii vv;
int doDFS(int u,int p,int d) {
    int i;
    visited[u] = 1,parent[u] = p,depth[u] = d;
    for (i = 0; i < adjList[u].size(); i++) {
        int v = adjList[u][i];
        if (v != p) doDFS(v,u,d+1);
    }
    return 0;
}
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&A[i]),poss.pb(A[i]);
    sort(poss.begin(),poss.end());
    poss.resize(unique(poss.begin(),poss.end())-poss.begin());

    int ans = 0;
    num.resize(poss.size());
    for (i = 0; i < N; i++) num[lower_bound(poss.begin(),poss.end(),A[i])-poss.begin()]++;
    for (i = 0; i < poss.size(); i++) {
        int b = 0;
        while ((1 << b) <= poss[i]) b++;
        int z = (1 << b)-poss[i];
        int p = lower_bound(poss.begin(),poss.end(),z)-poss.begin();
        if ((p != poss.size()) && (poss[p] == z)) {
            if (i != p) adjList[i].pb(p),adjList[p].pb(i);
            else pp[i] = 1;
        }
    }
    for (i = 0; i < poss.size(); i++) {
        if (!visited[i]) doDFS(i,-1,0);
    }
    for (i = 0; i < poss.size(); i++) vv.pb(mp(depth[i],i));
    sort(vv.begin(),vv.end());
    for (i = (int) vv.size()-1; i >= 0; i--) {
        int u = vv[i].second;
        if (parent[u] != -1) {
            int x = min(num[u],num[parent[u]]);
            ans += x,num[u] -= x,num[parent[u]] -= x;
        }
        else if (pp[u]) ans += num[u]/2;
    }
    printf("%d\n",ans);

    return 0;
}



Measured memory_bytes: 19916
nm = input().split()
n = int(nm[0])
m = int(nm[1])

load = []
load_roomn = {}

for i in range(m):
  l = list(map(lambda x:int(x), input().split()))
  load.append(l)
  #print(l)
  if l[0] in load_roomn:
    load_roomn[l[0]].append(i)
  else:
    load_roomn[l[0]] = [i]
  if l[1] in load_roomn:
    load_roomn[l[1]].append(i)
  else:
    load_roomn[l[1]] = [i]
    
#print(load)
#print(load_roomn)

visitCost = [10^5+1]*(n+1)#部屋が10^5個しかないのでこれがinfでいいはず

marker = [-1]*(n+1)
marker[1] = 0
visitable = [1]
visited = []
visitednum = 1

#count = 0
while visitednum < n:
  #count += 1
  #最短で行ける場所確認
  visiting = visitable.pop(0)
  #print("visit from " + str(visiting))
  for i in load_roomn[visiting]:
    if load[i][0] == visiting:
      if marker[load[i][1]] == -1:
        visitable.append(load[i][1])
        marker[load[i][1]] = visiting
        visitednum += 1
        #print("visit" + str(load[i][1]))
    elif load[i][1] == visiting:
      if marker[load[i][0]] == -1:
        visitable.append(load[i][0])
        marker[load[i][0]] = visiting
        visitednum += 1
        #print("visit" + str(load[i][0]))
    else:
      print("error")

print("Yes")
for i in range(2,n+1):
  print(marker[i])

Measured memory_bytes: 71016
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;

const int N = 101, W = 1e5 + 1;
const ll inf = 1e18;
ll dp[N][W];
int n, w, weight[N], value[N];

int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.precision(10);
   cout << fixed;
   cin >> n >> w;
   for (int i = 0; i < n; ++i){
      cin >> weight[i] >> value[i];
   }

   for (int i = 1; i <= w; ++i)
      dp[0][i] = -inf;
   
   for (int i = 0; i < n; ++i){
      for (int j = 0; j <= w; ++j){
         dp[i + 1][j] = dp[i][j];
         if (j > 0) dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - 1]);
         if (j >= weight[i]){
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - weight[i]] + value[i]);
         }
      }
   }
   cout << dp[n][w] << '\n';
   return 0;
}

Measured memory_bytes: 79232
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int i,j,len,ans=0;
	char s[105];
	scanf("%s",s);
	len=strlen(s);
	i=0,j=len-1;
	while(i<=j)
	{
		if(s[i]==s[j])
		{
			i++;
			j--;
		}			
		else
		{
			ans++;
			i++;
			j--;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,a,b,x;
  cin>>n>>a>>b;
  if(a>=b){
    x=b;
  }
  else if(a<b){
    x=a;
  }
  int y;
  if(n>a+b){
    y=0;
  }
  else if(n<=a+b){
    y=a+b-n;
  }
  cout<<x<<" "<<y<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

signed main() {

    int k;

    cin >> k;

    queue<ll> que;

    for(int i = 1; i < 10; i++) que.push(i);
    ll t;
    for(int i = 0; i < k; i++) {
        t = que.front();
        que.pop();
        if(t%10 != 0) que.push(10 * t + t%10 - 1);
        que.push(10 * t + t%10);
        if(t%10 != 9) que.push(10 * t + t%10 + 1);
    }
    
    cout << t << endl;
  
    return 0;
}



Measured memory_bytes: 1792
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        long j = 0 ;
        List<Character> ls = new LinkedList<>();
        for(char c: s.toCharArray())
            ls.add(c);

        System.out.println(ls.stream().distinct().map(e -> solve.apply(e,s)).min(Comparator.naturalOrder()).get());


    }



    static BiFunction<String,Character,String> step = (before,c) -> {
        String s1,s2;
        StringBuilder sb = new StringBuilder();
        if(before !=  null && before.length() > 0) {
            s1 = before.substring(0, before.length() - 1);
            s2 = before.substring(1,before.length());
            for(int i = 0;i < before.length() -1;i++)
            {
                if(c.equals(s1.charAt(i)) || c.equals(s2.charAt(i)))
                {
                    sb.append(c);
                }
                else
                    sb.append(s1.charAt(i));
            }
            return sb.toString();
        }
        else
            return "";
    };

    static Predicate<String> check = s -> {
        List<Character> ls = new LinkedList<>();
        for(char c: s.toCharArray())
            ls.add(c);
        if(ls.stream().distinct().count() == 1)
            return true;
        else
            return false;
    };
    static BiFunction<Character,String,Integer> solve = (c,s) -> {
        for (int i = 0; ; i++) {
            if (check.test(s))
                return i;
            else
                s = step.apply(s,c);
        }
    };
}


Measured memory_bytes: 34756
#include<iostream>
using namespace std;
 
int main()
{
	int age,price;
	cin >> age >> price;
	if (age >= 13)
		cout << price << endl;
	else if (age <= 12 && age>=6)
		cout << price / 2 << endl;
	else
		cout << 0 << endl;
	return 0;
}

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

using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class T> ostream& operator<<(ostream &os, set<T> S){os << "{ "; for(auto s:S) os<<s<<" "; return os<<"}";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {os << "{ "; for(auto m:M) os<<"("<<m.first<<":"<<m.second<<") "; return os<<"}";}
#ifdef np
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "<<arg1<<endl;}
template<typename Arg1, typename ... Args>void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,','); cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif


int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
	
	int a ,b ;
	cin >> a >> b;
    cout<< 6-(a+b) << endl;
    

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


Measured memory_bytes: 256
def main():
  M=10**9+7
  n,k,*a=map(int,open(0).read().split())
  dp=[[1]+[0]*k]
  for b,i in zip(dp,a):
    t,d=0,[]
    for v in b[:i+1]:
      t+=v
      t%=M
      d+=t,
    for w,v in zip(b,b[i+1:]):
      t+=v-w
      t%=M
      d+=t,
    dp+=d,
  print(t)
main()

Measured memory_bytes: 398224
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    s = input()
    q = int(input())
    ans = deque()
    swap = False
    for i in range(len(s)):
        ans.append(s[i])

    for i in range(q):
        #print(ans, swap)
        inp = input()
        if len(inp) == 1:
            hoge = int(inp)
            if swap:
                swap = False
            else:
                swap = True
        else:
            # print(tuple(inp))
            fi, ci = tuple(inp)[2], tuple(inp)[4]
                       
            if int(fi) == 1:
                if not swap:
                    ans.appendleft(ci)
                else:
                    ans.append(ci)
            if int(fi) == 2:
                if not swap:
                    ans.append(ci)
                else:
                    ans.appendleft(ci)
    s_ans = str()
    ans = list(ans)
    if swap:
        for i in range(len(ans)-1,-1, -1):
            s_ans += ans[i]
    else:
        for i in range(len(ans)):
            s_ans += ans[i]
    
    print(s_ans)
                
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 10236
#include <iostream>

using namespace std;

int main() {
  int x, y;
  cin >> x >> y;
  int a = (y - 2 * x) / 2;
  int b = x - a;
  if (0 <= a && 0 <= b && a + b == x && 4 * a + 2 * b == y)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 3600
'use strict';
(function(stdin) {

  var inputs  = stdin.toString().trim().split('\n');
  var cols = inputs[0].split(' ');
  var colsNumber = cols.map(Number);

  var Ascending_order = colsNumber.sort(function f(a, b){
        if( a < b ) return -1;
        if( a > b ) return 1;
        return 0;
})
  console.log(Ascending_order.join(' '));

}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15536
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = 1000000007;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solutionA(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solutionA(String[] args) throws Exception{
		int N = nextInt();
		String s = nextString();

		StringBuffer sb = new StringBuffer();
		ArrayDeque<Character> stack = new ArrayDeque<>();
		for(int i=0;i<N;i++) {
			if(s.charAt(i)==')') {
				sb.append(")");
				if(!stack.isEmpty()&&stack.peek()=='(') {
					stack.poll();
				}else {
					sb.insert(0,"(");
				}
			}else {
				stack.push('(');
				sb.append("(");
			}
		}
		while(!stack.isEmpty()) {
			char c = stack.poll();
			if(c=='(') {
				sb.append(")");
			}else {
				sb.insert(0,"(");
			}
		}
		pw.println(sb.toString());

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 22612
#include <stdio.h>

int main(void){

	int i,j;
	char str[21];
	char ptr[21]={0};

	scanf("%s", &str);
	
	/*文字数*/
	i=0;
	while(str[i]) i++;

	for( j=0; i>0 ; i--, j++)
		ptr[j] = str[i-1];

		printf("%s\n" , ptr);



	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int a, b, c, d;

int lcm(int a, int b){
   return a*(b/__gcd(a, b));
}

int solve(int x){
   return x/c + x/d - (x/lcm(c, d));
}

int32_t main(){_

   cin>>a>>b>>c>>d;   

   int t = solve(b);
   int x = solve(a-1);

   tr(x, t);

   cout<< (b-a+1) - (t-x);


   return 0;
}


Measured memory_bytes: 256
{
  const Main = (input: string) => {
    const [a,b,x] = input.trim().split(" ").map(BigInt)
    if (a === 0n) {
      console.log((b / x + 1n).toString())
    } else {
      console.log((b / x - (a - 1n) / x).toString())
    }
  };

  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
}


Measured memory_bytes: 29624
#include<cstdio>
#include<algorithm>
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	int a[n]={};
	int q;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]==1)q=i;
	}
	printf("%d\n",(n-2)/(k-1)+1);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const long long INF = 1LL << 60;

int k,n;
int p[1010];

int main()
{
  cin >> n >> k;
  rep(i,n) cin >> p[i];
  
  sort(p, p+n);
  
  int res = 0;
  rep(i,k) res += p[i];
  
  cout << res << endl;
}

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

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

void solve(long long N, std::string S, std::string T) {
    string ans = "";
    rep(i, N) {
        ans.push_back(S[i]);
        ans.push_back(T[i]);
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(N, S, T);
    return 0;
}


Measured memory_bytes: 3676
s = str(input())
moji = 'abcdefghijklmnopqrstuvwxyz'
dic = {}
for i in range(len(moji)):
    dic.setdefault(moji[i],0)
for i in range(len(s)):
    dic[s[i]] += 1
isNone = True
for i in range(len(moji)):
    if dic[moji[i]]==0:
        print(moji[i])
        isNone = False
        break
if isNone:
    print('None')

Measured memory_bytes: 9056
/**
 *    author:  FromDihPout
 *    created: 2020-08-25
**/

#include <bits/stdc++.h>
using namespace std;

const int N = 3010;
const long long INF = 1e18;
long long dp[N][N][4];
int val[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w, k;
    cin >> h >> w >> k;
    for (int i = 0; i < k; i++) {
        int r, c, v;
        cin >> r >> c >> v;
        val[r-1][c-1] = v;
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 4; k++) {
                dp[i][j][k] = -INF;
            }
        }
    }
    dp[0][0][0] = 0;
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 2; k >= 0; k--) {
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + val[i][j]);
            }
            
            for (int k = 0; k < 4; k++) {
                if (i + 1 < h) {
                    dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
                }
                if (j + 1 < w) {
                    dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
                }
            }
        }
    }
    
    long long ans = -INF;
    for (int k = 0; k < 4; k++) {
        ans = max(ans, dp[h-1][w-1][k]);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 321076
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int k, t;
    cin >> k >> t;

    vector<int> a(t);
    rep(i, t) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    int ans = max( (a[t-1] - 1) - (k - a[t-1]), 0);

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

Measured memory_bytes: 256
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int X = sc.nextInt();

		int map[] = new int[N+1];
		int degs[] = new int[N+1];


		for(int n=0;n<N;n++){
			map[n] = sc.nextInt();
		}
		map[N] = X;

		for(int n=1;n<N+1;n++){
			degs[n] = Math.abs(map[n-1] - map[n]);
		}
		degs[0] = Math.abs(map[N] - map[0]);

		int gcd=-1;
		for(int n=0;n<N+1;n++){
			if(n==0) gcd = degs[0];
			else gcd = GCD(gcd,degs[n]);
		}	

		System.out.println(gcd);


	}

	private static int GCD( int a, int b ) {
        if( a < b ) { int temp = a; a = b; b = temp; }
        if( b < 1 ) return -1; 

        if( a % b == 0 ) return b;
        return GCD( b, a % b );
    }
}

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define long long int ll
#define endl '\n'


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


const int MOD = 1000000007;

vector<int> graph[210000];
int ans[210000];
int t[210000];

void dfs(int a, int b, int c) {

    ans[a] = c + t[a];
    for(int i = 0; i < graph[a].size(); i++) {

        if(graph[a][i] == b) continue;
        dfs(graph[a][i], a, c + t[a]);
    }
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n,q;
  cin >> n >> q;

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

    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

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

    int a, b;
    cin >> a >> b;
    a--;
    t[a] += b;
  }

  dfs(0, -1, 0);

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

    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;



}



Measured memory_bytes: 30592
# F - Knapsack for All Segments
# https://atcoder.jp/contests/abc159/tasks/abc159_f

MOD = 998244353

n, s = map(int, input().split())
A = list(map(int, input().split()))

# dp[i][j] = i 番目までの選択をして、1 つめの選択肢を選んだ k に対する ak の和が j であるような場合の数
dp = [[0] * (s + 1) for _ in range(n + 1)]

for i in range(n):
  dp[i + 1][0] = 1
  if A[i] <= s:
     dp[i + 1][A[i]] = 1
  for j in range(s + 1):
    dp[i + 1][j] += dp[i][j] 
    dp[i + 1][j] %= MOD
    if j + A[i] <= s:
      dp[i + 1][j + A[i]] += dp[i][j]
      dp[i + 1][j + A[i]] %= MOD

print(sum(i[-1] for i in dp) % MOD)

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  int A=S.size();
  vector<char>alphabet_numbers(26);
  if(N==0){
    cout << S << endl;
  }
  else{
    for(int i=0;i<A;i++){
      char c=S.at(i);
      int d;
      for(int j=0;j<N;j++){
        if(j==0){
          d=alphabet_numbers[c];
          d=c+1;
        }
        else{
          d++;
        }
      }
      if(d>=91){
        cout << (char)(d-26);
      }
      else{
        cout << (char)d;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
void doStuff(int * , int);
int main(){
    string str;
    getline(cin,str);
    int a[str.length()+1]={0};
    a[str.length()-1] = str.at(str.length()-1) -48;
    int temp=1;
    for (int i=str.length()-2;i>=0;i--){
        temp = (temp*10)%2019;
        a[i] = (a[i+1] + temp * (str.at(i)-48))%2019;
        //cout<<"temp="<<temp<<endl;
        //cout << a[i]<< endl;
    }
    sort(a, a+str.length()+1);
    for (int i =0;i < str.length()+1;i++){
        //cout << a[i]<< endl;
    }
    doStuff(a, str.length()+1);
    
}




void doStuff(int* a, int n){
    ll res=0;
    ll temp = a[0];
    ll mx =1;
    for (int i=1; i< n;i++) {
        if (temp == a[i]){
            mx ++;
        }else {
            res += (mx * (mx-1))/2;
            mx = 1;
            temp = a[i];
        }
    }
    res += mx * (mx-1)/2;
    cout << res;
}

Measured memory_bytes: 4496
#include <iostream>
 
int main(int argc, char *argv[]) {
    int a, b;
    std::cin >> a >> b;
    if (a > b) std::cout << "a > b" << std::endl;
    else if (a < b) std::cout << "a < b" << std::endl;
    else std::cout << "a == b" << std::endl;
    return 0;
}

Measured memory_bytes: 1156
#coding=UTF-8


s=input()
K=int(input())

num_s=[]

for moji in s:
    num_s.append(ord(moji)-ord('a'))

#a にしたら優勝
ans=''
for idx in range(0,len(num_s)-1,1):
    if num_s[idx]==0:
        ans=ans+'a'
    elif K >= (26 - num_s[idx]):
        K=K-(26 - num_s[idx])
        ans=ans+'a'
    else:
        #回せないと不利になる一方
        ans=ans+s[idx]

#残りは最後に
ans=ans+chr( (num_s[len(num_s)-1] + K)%26 + ord('a'))

print(ans)


Measured memory_bytes: 4340
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

typedef long long int ll;

//ll num[50];
//ll num2[50];
ll num[10];
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<string,ll>::iterator iter;
//deque<char> deq;

int main(void)
{
    //double ans=0.0,d,d1,d2;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1=0,a2=0,a3=0;
    string s;
    char c,c1;
    a=a1=a2=a3=0;
    cin>>n>>m;
    a=n*m;
    if(n==1 || m==1) cout<<1;
    else
    {
        if(a%2==0) cout<<a/2;
        else cout<<a/2+1;
    }
    return 0;
}





Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int takahashi = (c-1)/b+1;
  int aoki = (a-1)/d+1;
  if(takahashi > aoki) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

const i32 mod = 1000003;

#define ADD(x, a) do{(x) += (a); if ((x) >= mod) (x) -= mod;} while (0)
#define SUB(x, a) do{(x) += mod - (a); if ((x) >= mod) (x) -= mod;} while (0)

i32 inv (i32 a) {
  i32 t = 1;
  while (a > 1) {
    t = (i64) t * (mod - mod / a) % mod;
    a = mod % a;
  }
  return t;
}

i32 mod_pow (i32 r, i32 n) {
  i32 t = 1;
  i32 s = r;
  while (n > 0) {
    if (n & 1) t = (i64) t * s % mod;
    s = (i64) s * s % mod;
    n >>= 1;
  }
  return t;
}

i32 *fact = NULL;
i32 *iFact = NULL;
void init_fact (const i32 n) {
  fact = (i32 *) calloc (n + 1, sizeof (i32));
  fact[0] = 1;
  for (i32 i = 1; i <= n; ++i) {
    fact[i] = (i64) i * fact[i - 1] % mod;
  }
  iFact = (i32 *) calloc (n + 1, sizeof (i32));
  iFact[n] = inv (fact[n]);
  for (i32 i = n - 1; i >= 0; --i) {
    iFact[i] = (i64) (i + 1) * iFact[i + 1] % mod;
  }
}

i32 perm (i32 n, i32 k) {
  if (!(0 <=k && k <= n)) return 0;
  return (i64) fact[n] * iFact[n - k] % mod;
}

i32 comb (i32 n, i32 k) {
  if (!(0 <= k && k <= n)) return 0;
  return (i64) fact[n] * iFact[k] % mod * iFact[n - k] % mod;
}

i32 calc (i32 x, i32 d, i32 n) {
  if (d == 0) return mod_pow (x, n);
  if (x == 0) return 0;
  i32 y = (i64) x * inv (d) % mod;
  if (y + n - 1 >= mod) return 0;
  return (i64) fact[y + n - 1] * iFact[y - 1] % mod * mod_pow (d, n) % mod;
}

void run (void) {
  i32 q;
  scanf ("%" SCNi32, &q);
  init_fact (mod - 1);
  for (i32 i = 0; i < q; ++i) {
    i32 x, d, n;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &x, &d, &n);
    printf ("%" PRIi32 "\n", calc (x, d, n));
  }
}

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


Measured memory_bytes: 8576