akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt(); //机Aに積まれている本
        int M = sc.nextInt(); //机Bに積まれている本
        long K = sc.nextLong(); //合計所要時間

        long[] A = new long[N+1];
        for (int i = 0; i < N; i++) {
            A[i+1] = A[i] + sc.nextLong();
        }

        long[] B = new long[M+1];
        for (int i = 0; i < M; i++) {
            B[i+1] = B[i] + sc.nextLong();
        }

        long count = 0;
        int j = M;
        
        for(int i=0;i <= N;i++){
          	// （最大時間-Aの現在の冊数を読むまでにかかる時間）
          	// で選択可能なBの最大冊数
            long bestB = K - A[i];
            // Bの最大冊数が0→最大時間 < Aの現在の冊数
          	// →もう読めない
            if(bestB < 0) break;
          	// 現時点のAの冊数(最大かもしれない)に対し、
          	// 選択可能なBの冊数
            while(j > 0 && B[j] > bestB) j--;
          	// AとBの合計冊数が一番多くなる組み合わせを
          	// countに代入
            count = Math.max(count, i+j);
        }

//        int aCnt = 0;
//        int bCnt = 0;
//        for (int i = 0; i < (A.length + B.length); i++) {
//            if (aCnt < A.length && bCnt < B.length) {
//                if (A[aCnt] < B[bCnt]) {
//                    if ((K < time)) break;
//                    if((K - time) < A[aCnt]) break;
//                    time += A[aCnt];
//                    aCnt++;
//                    count++;
////                    System.out.println("if1");
//                } else {
//                    if ((K < time)) break;
//                    if((K - time) < B[bCnt]) break;
//                    time += B[bCnt];
//                    bCnt++;
//                    count++;
////                    System.out.println("if2");
//                }
//            } else if (aCnt < A.length) {
//                if ((K < time)) break;
//                if((K - time) < A[aCnt]) break;
//                time += A[aCnt];
//                aCnt++;
//                count++;
////                System.out.println("if3");
//            } else if (bCnt < B.length){
//                if ((K < time)) break;
//                if((K - time) < B[bCnt]) break;
//                time += B[bCnt];
//                bCnt++;
//                count++;
////                System.out.println("if4");
//            } else {
//                break;
//            }
//        }

        System.out.println(count);
    }
}

Measured memory_bytes: 54656
S = gets.chomp
if S.length < 3
    puts "0"
    exit
end
x=S[0..-3].to_i*100
y=S[-2..-1].to_i
num=0
(1..5).reverse_each do |i|
    a=y/i
    b=y%i
    num+=a
    y=b
end
puts x>=num*100 ? "1" : "0"

Measured memory_bytes: 14344
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <stack>

typedef long long ll;

const double EPS = 1e-10;
const double PI  = acos(-1);
const ll     INF = 1 << 30;

ll gdb_exec(ll a, ll b) {
  if (b == 0) return a;
  return gdb_exec(b, a % b);
}

ll gdb(ll a, ll b) {
  if (a < b) std::swap(a, b);
  if (a == 0 || b == 0) return -999999999;
  return gdb_exec(a, b);
}

ll lcm(ll a, ll b) {
  ll gdb_val = gdb(a, b);
  if (a % gdb_val == 0) {
    return (a / gdb_val) * b;
  }
  return (b / gdb_val) * a;
}

int main(int argc, char* argv[])
{
  ll n, m;
  std::cin >> n >> m;

  std::cout << (1900 * m + 100 * (n-m)) * (ll) std::pow(2, m) << std::endl;

  return 0;
}


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


using namespace std;
typedef long long LL;

int main()
{
    int x, y;
    scanf("%d%d", &x, &y);
    LL lcm = 1ll * x * y / __gcd(x, y);
    LL k = lcm / x;
    if(k > 2)
        printf("%lld\n", 1ll * x * (k - 1));
    else if(k == 2)
        printf("%lld\n", 1ll * x * (k + 1));
    else
        printf("-1\n");
    return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Apolloliu
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

using namespace std;

void get() {

}

class ATrain {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, i;
		in >> n >> i;
		out << n - i + 1 << '\n';
	}
};


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ATrain solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 892
#include <cstdio>

int main()
{
	char c1,c2,c3;
	scanf("%c %c %c", &c1,&c2,&c3);
	c1=='1' ? c1='9' : c1='1';
	c2=='1' ? c2='9' : c2='1';
	c3=='1' ? c3='9' : c3='1';
	printf("%c%c%c\n", c1,c2,c3);
	
	return 0;
}

Measured memory_bytes: 128
import math

ceil = math.ceil

def main(N, A):
    A.reverse()
    pos = [(A[0], A[0])]
    for i in range(len(A)-1):
        tmpmin = ceil(pos[-1][0]/2) + A[i+1]
        tmpmax = pos[-1][1] + A[i+1]
        pos.append((tmpmin, tmpmax))

    l,r = pos.pop()
    if l > 1:
        return -1
    
    ki = [1]
    A.reverse()
    for j in range(N):
        m = (ki[j]-A[j])*2
        l, r = pos.pop()
        if m < l:
            return -1
        ki.append(min(r, m))
    
    return sum(ki)

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    ans = main(N, A)
    print(ans)


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

int x[20],y[20],p[20];
ll ans[20];
vi dd;
int main()
{
	IOS
	memset(ans,infi,sizeof ans);
	int n,i;
	cin>>n;
	ans[n]=ans[0]=0;
	for(i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>p[i];
		ans[0]+=1LL*p[i]*min(abs(x[i]),abs(y[i]));
		dd.pb(min(abs(x[i]),abs(y[i])));
	}
	
	for(i=1;i<(1<<n);i++)
	{
		int sb=__builtin_popcount(i);
		if(sb == n) continue;
		for(int s=i;;s=(s-1)&i)
		{
			vi d=dd;
			for(int k=0;k<n;k++)
			{
				if(i&(1<<k))
				{
					if(s&(1<<k))
					for(int j=0;j<n;j++)
					d[j]=min(d[j],abs(y[j]-y[k]));
					else
					for(int j=0;j<n;j++)
					d[j]=min(d[j],abs(x[j]-x[k]));
				}
			}
			ll temp=0;
			for(int j=0;j<n;j++)
			temp+=p[j]*1LL*d[j];
			ans[sb]=min(ans[sb],temp);
			if(s==0) break;
		}
	}
	for(i=0;i<=n;i++)
	cout<<ans[i]<<'\n';
}



Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef pair<char,char> P;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int n,q;
string s;
vector<char> t,d;

int func(int x){
	for(int i = 0; i < q; i++){
		if(t[i]==s[x]){
			if(d[i]=='L')x--;
			else x++;
		}
		if(x==-1)return x;
		if(x==n)return x;
	}
	return x;
}

int main()
{
	cin>>n>>q;
	cin>>s;
	t.resize(q),d.resize(q);
	for(int i = 0; i < q; i++){
		cin>>t[i]>>d[i];
	}

	int start=0,end=n-1;
	int left=-1,right=n;
	while(start+1<end){
		int mid=(start+end)/2;
		if(func(mid)==-1)start=mid;
		else end=mid;
	}

	if(func(start)==-1)left=start;
	if(func(end)==-1)left=end;

	start=0,end=n-1;
	while(start+1<end){
		int mid=(start+end)/2;
		if(func(mid)==n)end=mid;
		else start=mid;
	}
	if(func(end)==n)right=end;
	if(func(start)==n)right=start;


	cout<<n-((left+1)+(n-right))<<endl;

	return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main(){
	vector<double> vec(3);
	for(int i = 0; i < 3; ++i)cin>>vec[i];
	sort(vec.begin(), vec.end());
	cout<<(int)((double)(vec[0] / 2) * vec[1])<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s1, s2, checkStr;
		boolean ans = false;
		int s1Length, s2Length;
		s1 = in.readLine();
		s2 = in.readLine();
		s1Length = s1.length();
		s2Length = s2.length();
		/*
		 * System.out .println("s1Length:" + s1Length +
		 * System.getProperty("line.separator") + "s2Length:" + s2Length);
		 */
		for (int i = 0; i < s1Length; i++) {
			if (s1.charAt(i) == s2.charAt(0)) {
				if ((i + 1) + s2Length > s1Length) {
					/*
					 * System.out.println("文字番" + (i + 1));
					 * System.out.println("範囲外文字列" + (s1.substring(i, s1Length)
					 * + s1.substring(0, s2Length - (s1Length - i))));
					 */
					checkStr = s1.substring(i, s1Length)
							+ s1.substring(0, s2Length - (s1Length - i));
				} else {
					/*
					 * System.out.println("文字番" + (i + 1)); System.out
					 * .println("範囲内文字列" + s1.substring(i, i + s2Length));
					 */
					checkStr = s1.substring(i, i + s2Length);
				}
				if (checkStr.matches(s2)) {
					ans = true;
				}
			}
		}
		if (ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 17064
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int x,y,z,k;
	cin >> x >> y >> z >> k;
	vll a(x), b(y), c(z);
	for(int i=0; i<x; i++)cin >> a[i];
	for(int i=0; i<y; i++)cin >> b[i];
	for(int i=0; i<z; i++)cin >> c[i];
	sort(a.rbegin(),a.rend());
	sort(b.rbegin(),b.rend());
	sort(c.rbegin(),c.rend());
	using T = tuple<ll, int,int,int>;
	using T2 = tuple<int,int,int>;
	priority_queue<T>pq;
	set<T2>st;
	pq.emplace(a[0]+b[0]+c[0],0,0,0);
	st.emplace(0,0,0);
	for(int t=0; t<k; t++){
		ll sum; int i,j,kk;
		tie(sum,i,j,kk)=pq.top();
		pq.pop();
		cout << sum << endl;
		if(i<x-1 && !st.count(T2(i+1,j,kk))){
			pq.emplace(a[i+1]+b[j]+c[kk],i+1,j,kk);
			st.emplace(i+1,j,kk);
		}
		if(j<y-1 && !st.count(T2(i,j+1,kk))){
			pq.emplace(a[i]+b[j+1]+c[kk],i,j+1,kk);
			st.emplace(i,j+1,kk);
		}
		if(kk<z-1 && !st.count(T2(i,j,kk+1))){
			pq.emplace(a[i]+b[j]+c[kk+1],i,j,kk+1);
			st.emplace(i,j,kk+1);
		}
	}
	return 0;
}	
	


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

using namespace std ;

const int MAX = 1e5 + 10 ;

int arr[MAX] ;
int n , m ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>m>>n ;
	int x ;
	for(int i = 0 ; i < n ; ++i)
	{
		cin>>x ;
		m -= x ;
	}
	return cout<<max(-1 , m)<<"\n" , 0 ;
}		

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
priority_queue<double>q;
int main(){
	int n;scanf("%d",&n);
	double x;
	for(int i=1;i<=n;++i){
		scanf("%lf",&x);
		q.push(-x);
	}
	while(q.size()>1){
		double w=q.top();q.pop();
		w+=q.top();q.pop();
		q.push(w/2);
	}
	printf("%.6lf",-q.top());
}

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

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

ll n;
ll a[N];

ll f(int g)
{
        ll s = 0, cnt = 0;
        for(int i = 1; i <= n; i++, g ^= 1){
                if(g == 0){
                        s += a[i];
                        cnt += max(0ll, s + 1);
                        s = min(-1ll, s);
                }
                else{
                        s += a[i];
                        cnt += -min(0ll, s - 1);
                        s = max(1ll, s);
                }
        }
        return cnt;
}

void solve()
{
        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        cout << min(f(0), f(1)) << endl;
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(void)
{
   

    ll n,m;
    cin>>n>>m;

    UnionFind friends(n);
    

    rep(i,m)
    {
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if(!friends.issame(a,b))
        {
        friends.merge(a,b);
        }


    }
    ll ans = 0;

    rep(i,n)
    {
        ans =max(ans,friends.size(i));
    }

    cout<<ans<<endl;   
}

Measured memory_bytes: 5976
#include <iostream>
#include <queue>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
const int INF = 100000;
typedef pair<int,int> P;
int main() {
    int h,w;
    cin >> h >> w;
    char maze[h][w];
    int d[h][w];
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> maze[i][j];
        }
    }
    int dx[4] = {0,1,0,-1};
    int dy[4] = {1,0,-1,0};
    queue <P> que;
    que.push(P(0,0));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            d[i][j] = INF;
        }
    }
    d[0][0] = 0;
    while (que.size()) {
        P p = que.front();
        if ((p.first == h - 1)&&(p.second == w - 1)) {
            break;
        }
        que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if ((0 <= nx)&&(nx < h)&&(0 <= ny)&&(ny < w)&&(maze[nx][ny] == '.')&&(d[nx][ny] == INF)) {
                d[nx][ny] = d[p.first][p.second] + 1;
                que.push(P(nx,ny));
            }
        }
    }
    int count = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) { 
            if (maze[i][j] == '.') {
                count++;
            }
        }
    }
    if (d[h-1][w-1] == INF) {
        cout << -1;
    }
    else {
        cout << count - d[h-1][w-1] - 1;
    }
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

def bubble_sort(A, N):
    C = list(A)
    for i in xrange(N):
        for j in reversed(xrange(i+1, N)):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C

def selection_sort(A, N):
    C = list(A)
    for i in xrange(N):
        minj = i
        for j in xrange(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

def is_stable(a, c, n):
    for i in xrange(n-1):
        if c[i][1] == c[i+1][1]:
            if a.index(c[i]) > a.index(c[i+1]):
                print "Not stable"
                return False
    print "Stable"
    return True

def print_c(c):
    print " ".join(map(lambda c:c[0] + str(c[1]), c))

def main():
    n = input()
    c = map(lambda c:(c[0], int(c[1:])), raw_input().split())
    bubble = bubble_sort(c, n)
    selection = selection_sort(c, n)
    print_c(bubble)
    is_stable(c, bubble, n)
    print_c(selection)
    is_stable(c, selection, n)

main()

Measured memory_bytes: 6500
# 2020/09/18
# AtCoder Beginner Contest 150 - B

# Input
n = int(input())
s = input()
cnt = 0
abc = 'ABC'

# Calc
for i in range(n-2):
    for j in range(3):
        if s[i+j] != abc[j]:
            break
        if j == 2:
            cnt = cnt + 1

# Output
print(cnt)


Measured memory_bytes: 9152
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll a,b;
 	cin>>a>>b;
 	cout<<a*b<<endl;
    return 0;
}

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

void solve(int a, int b){
    int n = 3;
    vector<bool> lis(n, false);
    lis[a-1] = true;
    lis[b-1] = true;
    for(int i=0; i<n; i++){
        if (lis[i] == false){
            cout << i+1 << endl;
            return;
        }
    }
}

int main(){
    int a, b;
    cin >> a >> b;
    solve(a,b);
} 

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n;
  if(n % 1000 == 0) cout << 0 << endl;
  else cout << 1000 - (n % 1000) << endl;
  
  
}

Measured memory_bytes: 3628
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec; 
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define ff first
#define ss second
#define P pair<ll,ll>
#define N 100005
#define LG 20
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main()
{
      FAST;
      
      map<string,ll> m;
      
      ll n;
      cin>>n;
      
      ll mx=0;      
      for(int i=0;i<n;i++)
      {
            string s;
            cin>>s;
            m[s]++;
            mx=max(mx,m[s]);
      }
      
      set<string> s;
      
      for(auto X:m)
      {
            if(X.ss==mx)
                  s.insert(X.ff);
      }
      
      for(auto X:s)
            cout<<X<<"\n";
      
      
}

Measured memory_bytes: 33280
//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
using namespace std;

#define ios ios::sync_with_stdio(false)
#define ll long long
#define pa pair<int,int>
#define mk make_pair
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define of(i, a, b) for(int i = a; i >= b; i--)
#define mem(a, b) memset(a, b, sizeof a)
#define copy(a,b) memcpy(a, b, sizeof b)
#define pi acos(-1)
#define in freopen("input.in", "r", stdin);
#define out freopen("output.out", "w", stdout);

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 10;
const ll M = 1e4 + 10;
const double eps = 1e-10;


ll fpow(ll a, ll b, ll p)
{
	ll res = 1;
	a %= p;
	while (b)
	{
		if (b & 1)
			res = res * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return res;
}

ll C(ll n, ll m, ll p)
{
	m = min(m, n - m);
	ll res = 1;
	for (int i = 0; i < m; i++)
		res = res * (n - i) % p * fpow(i + 1, p - 2, p)  % p;
	return res;
}

ll lucas(ll n, ll m, ll p)
{
	if (n < p && m < p)
		return C(n, m, p);
	return C(n % p, m % p, p) % p * lucas(n / p, m / p, p) % p;
}

int main()
{
	ll x, y;
	cin >> x >> y;
	if (2 * y - x < 0 || (2 * y - x) % 3 != 0 || 2 * x - y < 0 || (2 * x - y) % 3 != 0)
		puts("0");
	else
	{
		ll a = (2 * y - x) / 3, b = (2 * x - y) / 3;
		cout << C(a + b, b, mod) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int a,b;cin>>a>>b;

    if(b==1){
        cout<<0<<endl;
    }
    else {
        cout<<a-b<<endl;
    }

}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    a=inpl()
    dic={}
    ans=0
    for i in range(n):
        if a[i] not in dic:
            dic[a[i]]=1
            ans+=1
    if ans%2==0:
        ans-=1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 61420
#include<stdio.h>
#include<stdlib.h>
struct n{
  char s[101];
};
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  struct n c[a];
  for(int i=0; i<a; i++){
    scanf("%s",c[i].s);
  }
  for(int i=0; i<a; i++){
    printf("%s\n%s\n",c[i].s,c[i].s);
  }
  return 0;}


Measured memory_bytes: 128
S = input()
S_len = len(S)
if S_len % 2 != 0:
    print("No")
else:
    set_num = int(S_len // 2)
    for i in range(set_num):
        if S[i*2] != "h" or S[i*2 +1] != "i":
            hitachi = False
            break
        else:
            hitachi = True
    if hitachi == False:
        print("No")
    elif hitachi  == True:
        print("Yes")


Measured memory_bytes: 2940
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    ll x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>

unsigned long long n ,t ,ti ,on 	,ans	,i ;

int main()
{
	scanf( "%lld %lld %lld" ,&n ,&t ,&on ) ;

	ans = t ;

	for( i = 1 ; i < n ; i++ )
	{
		scanf( "%lld" ,&on ) ;

		on -= ti ;
		ti += on ;

		if( t > on )
		{
			ans += on ;
		}
		else
		{
			ans += t ;
		}
	}

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

	return 0 ;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int main() {
	string s; cin >> s;
	int ans = 1;
	string tmp = s.substr(0, 1);
	int i = 1;
	while (1) {
		if (tmp == s.substr(i, 1)) {
			if (i + 1 < s.size()) tmp = s.substr(i - 1, 2);
			i += 2;
		} else {
			if (i < s.size()) tmp = s.substr(i, 1);
			i++;
		}
		if (i > s.size()) break;
		ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int length;
    int array[101];
    int i;
    
    scanf("%d", &length);
    for(i = (length - 1); i >= 0; i--){
        scanf("%d", &array[i]);
    }
    
    for(i = 0; i < length; i++){
        if(i) printf(" ");
        printf("%d", array[i]);
    }
    printf("\n");
    
    return 0;
    
}


Measured memory_bytes: 2096
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(){
	char a[101],b[101];
	scanf("%s",a);
	scanf("%s",b);
	int n=strlen(a),i,j;
	for(i=0;i<n;i++){
		if(strstr(a,b)!=NULL){
			printf("Yes\n");
			return 0;
		}
		else{
			char temp=a[0];
			for(j=1;j<n;j++){
				a[j-1]=a[j];
			}
			a[j-1]=temp;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 524
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> Heap;

inline void Max_Heapify(int node)
{
	int l = node * 2;
	int r = node * 2 + 1;

	int largest;

	if (l < Heap.size())
	{
		if (Heap[node] < Heap[l])
		{
			largest = l;
		}
		else
		{
			largest = node;
		}
	}
	else
	{
		largest = node;
	}

	if (r < Heap.size())
	{
		if (Heap[largest] < Heap[r])
		{
			largest = r;
		}
	}

	if (largest != node)
	{
		swap(Heap[largest], Heap[node]);

		Max_Heapify(largest);
	}
}

int main()
{
	int N; scanf("%d", &N); Heap.push_back(0);

	int tmp;

	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &tmp);

		Heap.push_back(tmp);
	}

	for (int i = N / 2; i >= 1; i--)
	{
		Max_Heapify(i);
	}

	for (int i = 1; i <= N; i++)
	{
		printf(" %d", Heap[i]);
	}

	printf("\n");
	
	return 0;
}

Measured memory_bytes: 4408
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 1e5;
const int inf = 1<< 30;
typedef long long LL;
int main(){
	int n;
	cin >> n;
	int sum = 0,m = n;
	while(m){
		sum += m%10;
		m/=10;
	}
	if(n%sum == 0)
		printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

int threemax(int a, int b, int c) {
	if (a >= b && a >= c) {
		return a;
	}
	else if (b >= a && b >= c) {
		return b;
	}
	else {
		return c;
	}
}

int threemin(int a, int b, int c) {
	if (a <= b && a <= c) {
		return a;
	}
	else if (b <= a && b <= c) {
		return b;
	}
	else {
		return c;
	}
}

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  ll N;
  string S;
  ll ans=1;
  cin >> N >> S;
  map<char,int> moji;
  for (int i=0;i<N;i++){
    moji[S[i]]++;
  }
  for(auto i:moji){
    ans*=(1+i.second);
    ans%=MOD;
  }
  cout << (ans-1)%MOD;
}

Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main() {
	string s;
	cin >> s;
	
	int ans = 0;
	for (char e : s) {
		if (e == '+') {
			ans ++;
		} else {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 888
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string a,b,c;int n,m;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	cin>>a;
	for(int i=0;i<a.size();i++)
	cout<<'x';
	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

int main(){
    llong n;
    llong cnt_25=0;
    llong cnt_10=0;
    llong cnt_5=0;
    llong cnt_1=0;

    cin >> n;
    cnt_25 = n/25;
    n = n-cnt_25*25;

    cnt_10 = n/10;
    n = n-cnt_10*10;

    cnt_5  = n/5;
    n = n-cnt_5*5;

    cnt_1  = n;
    cout << cnt_25+cnt_10+cnt_5+cnt_1 << endl;
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    int K;
    cin >> N >> K;

    vi A(N);
    for (int i=0;i<N;i++) {
        cin >> A[i];
    }
    
    vi nA(N+1);
    for (int i=0;i<K;i++) {
        for (int j=0;j<=N;j++) nA[j] = 0;
        for (int j=0;j<N;j++) {
            int left = max(j - A[j], 0);
            int right = min(j + A[j] + 1, N);
            nA[left]++;
            nA[right]--;
        }
        for (int j=1;j<=N;j++) nA[j] += nA[j-1];

        int tot = 0;
        for (int j=0;j<N;j++) {
            if (nA[j] == N) tot++;
            A[j] = nA[j];
        }
        if (tot == N) break;
    }

    for (int a : A) cout << a << " ";
    cout << endl;

    return 0;
}


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

using namespace std;

const int N = 1e5 + 8;
int a[N] , cnt[5][N] , n , mx1 , mx0 , nx , nx1 , x;
vector<int> v1 , v0;

int main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i++)
	{
		cin >> a[i];
		if(i % 2 == 0)
		{
			cnt[0][a[i]]++;
			mx0 = max(mx0 , cnt[0][a[i]]);
		}
		else
		{
			cnt[1][a[i]]++;
			mx1 = max(mx1 , cnt[1][a[i]]);
		}
	}
	for(int i = 1 ; i < n ; i++)
	{
		if(i % 2 == 0)
		{
			if(cnt[0][a[i]] == mx0)
				v0.push_back(a[i]);
		}
		else
		{
			if(cnt[1][a[i]] == mx1)
				v1.push_back(a[i]);
		}
	}
	for(int i = 0 ; i < v0.size() ; i++)
		for(int j = 0 ; j < v1.size() ; j++)
			if(v0[i] != v1[j])
			{
				x = n / 2;
				cout << x - mx0 + x - mx1;
				return 0;
			}
	for(int i = 0 ; i < n ; i++)
	{
		if(i % 2 == 0 && cnt[0][a[i]] != mx0)
			nx = max(nx , cnt[0][a[i]]);
		else if(i % 2 == 1 && cnt[1][a[i]] != mx1)
			nx1 = max(nx1 , cnt[1][a[i]]);
	}
	cout << min(n - mx1 - nx , n - mx0 - nx1);
}

Measured memory_bytes: 2044
#include <stdio.h>
#include <iostream>
using namespace std;
int n, t;

int main() {
	cin >> n >> t;
	int tmp; cin >> tmp;
	int tmp2;
	int ans = 0;
	for(int i=2;i<=n;++i) {
		scanf("%d",&tmp2);
		if(tmp2 - tmp + 1 <= t) ans += tmp2 - tmp;
		else ans += t;
		tmp = tmp2;
	}
	ans += t;
	cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
int sum(int n){return n * (n + 1)/ 2;}
int tax(int per,int yen) {return yen * (100 +per) / 100;}
void main(){
	int x,y,s;
	while(read(x,y,s),x|y|s){
		int ans ;
		//auto taxed = new int [s];
		//foreach(int i,ref t;taxed)t = tax(x,i);
		auto taxed= iota(s).map!(i => tax(x,i));
		foreach(i;1..s/2+1){
			foreach(j;i..s){
				if (taxed[i] + taxed[j] == s ){
					ans = max(ans,tax(y,i) + tax(y,j));break;
				}
			}
		}
		ans.writeln;
	}
}
//[(0,0),(0,1),..]
/*		iota(1,s)
.permutations.writeln;
.map!(a => Tuple!(a,iota(1,s)))
.filter!(a => tax (x,a[0]) + tax (x,a[1]) == s)
.map!(a => tax (y,a[0]) + tax(y,a[1]))
.reduce!(max);
*/

Measured memory_bytes: 2356
class UnionFind:
    """素集合を木構造として管理する。"""
    def __init__(self, n):
        self.parent = [-1] * n
        self.n = n
        self.cnt = n

    def root(self, x):
        """要素xの代表元を求める。O(α(N))"""
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def merge(self, x, y):
        """要素xを含む集合と要素yを含む集合を併合する。O(α(N))"""
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return False
        if self.parent[x] > self.parent[y]:
            x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
        self.cnt -= 1
        return True

    def is_same(self, x, y):
        """要素x, yが同じ集合に属するかどうかを求める。O(α(N))"""
        return self.root(x) == self.root(y)

    def size(self, x):
        """要素xを含む集合の要素数を求める。O(α(N))"""
        return -self.parent[self.root(x)]

    def count(self):
        """集合の個数を求める。O(1)"""
        return self.cnt

    def groups(self):
        """集合を列挙する。list[list[int]]で返す。O(N)"""
        res = [[] for _ in range(self.n)]
        for i in range(self.n):
            res[self.root(i)].append(i)
        return [group for group in res if group]


n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(m)]

uf = UnionFind(n)
for a, b in info:
    a -= 1
    b -= 1
    uf.merge(a, b)
print(uf.count() - 1)


Measured memory_bytes: 89816
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=998244353
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b,c,d=map(int,input().split())
MAX=3050
dp=[[0]*MAX for _ in range(MAX)]
dp[a][b]=1
for i in range(a,c+1):
    for j in range(b,d+1):
        dp[i][j]+=dp[i][j-1]*i+dp[i-1][j]*j-dp[i-1][j-1]*(i-1)*(j-1)
        dp[i][j]%=MOD
print(dp[c][d])

Measured memory_bytes: 133920
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };
const int dx2[] = { 0,1,1,0,-1,-1 }; const int dy2[] = { 1,0,-1,-1,-1,0 };
struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int sx, sy, gx, gy, n;
	cin >> sx>> sy>> gx>> gy>> n;
	set<pii> jama;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		jama.insert({ a, b });
	}
	int lx, ly;
	cin >> lx >> ly;
	int ans = -1;
	priority_queue<pair<int, pair<pii, int>>> Q;//musi x,y,t
	Q.push({ 0,{{sx,sy},0} });
	vector<vvi> G(lx * 2 + 1, vvi(ly * 2 + 1, vi(6, 1e9)));
	G[sx + lx][sy + ly][0] = 0;
	while (!Q.empty()) {
		pair<int, pair<pii, int>> q = Q.top();Q.pop();
		int ignore = -q.first;
		int qx = q.second.first.first;
		int qy = q.second.first.second;
		int time = q.second.second;
		int dir = abs(qx*qy*time) % 6;
		if (qx == gx&&qy == gy) {
			ans = ignore;
			break;
		}
		REP(i, 6) {
			int nx = qx + dx2[i];
			int ny = qy;
			if (i == 0)
				ny++;
			if (abs(qx) % 2 == 0) {
				if (i == 2 || i == 4)
					ny--;
			}
			if (abs(qx) % 2 == 1) {
				if (i == 1 || i == 5)
					ny++;
			}
			if (i == 3)
				ny--;
			if (abs(nx) > lx || abs(ny) > ly)
				continue;
			if (jama.find({ nx,ny }) != jama.end())
				continue;
			if (dir == i) {
				if (G[nx + lx][ny + ly][(time + 1) % 6] > ignore) {
					G[nx + lx][ny + ly][(time + 1) % 6] = ignore;
					Q.push({ -ignore,{{nx,ny},(time + 1) % 6 } });
				}
			}
			else {
				if (G[nx + lx][ny + ly][(time + 1) % 6] > ignore + 1) {
					G[nx + lx][ny + ly][(time + 1) % 6] = ignore + 1;
					Q.push({ -ignore - 1,{ { nx,ny },(time + 1) % 6 } });
				}
			}
		}
		if (G[qx + lx][qy + ly][(time + 1) % 6] > ignore + 1) {
			G[qx + lx][qy + ly][(time + 1) % 6] = ignore + 1;
			Q.push({ -ignore - 1,{ { qx,qy },(time + 1) % 6 } });
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5068
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,j,n,ans=0;
	int y[15][15]={};
	cin>>n;
	for(i=0;i<n;i++){
		int A;cin>>A;
		while(A--){
			int X,Y;cin>>X>>Y;X--;
			y[i][X]=Y+1;
		}
	}
	//0? 1x 2o
	for(int bi=0;bi<(1<<n);bi++){
		int gen=0;
		for(i=0;i<n;i++){
			if(!(bi&(1<<i))){continue;}
			gen++;
			for(j=0;j<n;j++){
				if(y[i][j]==1&&(bi&(1<<j))>0){gen=-999;}
				if(y[i][j]==2&&(bi&(1<<j))==0){gen=-999;}
			}
		}
		maxeq(ans,gen);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define IOS ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define AfterDecimal(n) cout << fixed << setprecision(n);
#define pb push_back
#define pp(a, b) pair <a, b>
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define pi pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
#define itr iterator
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
#define int ll
#define endl "\n"
 
using namespace __gnu_pbds;
using namespace std;
 
template <class T> T printr(T p) { cout << p << '\n'; return 0; }
template <class T> T printe(T p) { cout << p << '\n'; exit(0); }
template <class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
 
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << "# "<< name << " = " << arg1 << '\n';
}
template<typename Arg1, typename... Args>
void __f(const char* names, Arg1 && arg1, Args &&... args){
        const char* comma = strchr(names + 1 ,',');
        cout << "# ";
        cout.write(names, comma - names)<< " = " << arg1 << " | ";
        __f(comma + 1, args...);
}
#else
#define debug(...) 36
#endif
 
ll power(ll x, ll y, ll p){ 
   ll res = 1;
   x = x % p;  
   while (y > 0) {
      if (y & 1) 
         res = (res * x) % p; 
      y = y >> 1;
      x = (x * x) % p; 
   }
   return res;
}
 
const ll INF = (ll)(8e18);
const ll MOD = 1e9 + 7;
 
const int M = 1e12;

int32_t main()
{
    IOS;
    #ifndef ONLINe5E_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif

    int n;
    cin >> n;

    int a[n];
    fori(n) cin >> a[i];

    int dp[n];
    dp[0] = 0;

    fori(n) {
        if(i==0)continue;
        else if(i==1) dp[i] = dp[i-1] + abs(a[i] - a[i-1]);
        else dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
    }
    
    cout << dp[n-1] << endl;
    
    #ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}

//g++ -DLOCAL -DDEBUG -std=c++17 -Wshadow -Wall -o "c" "icpc.cpp" -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, std::vector<long long> A)
{
  vector<LL> lower(N, 0);
  vector<LL> upper(N, 0);

  for (int i = 0; i < N; i++)
  {
    int pl = i + A[i];
    int mn = i - A[i];
    if (pl < N)
      lower[pl]++;
    if (mn >= 0)
      upper[mn]++;
  }
  LL ans = 0;
  for (int i = 0; i < N; i++)
    ans += lower[i] * upper[i];
  cout << ans << endl;
}

int main()
{
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 8016