akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
    static short st[30];short tp=0;
    if(x<0) putchar('-'),x=-x;
    do st[++tp]=x%10,x/=10; while(x);
    while(tp) putchar('0'|st[tp--]);
    putchar(ed);
}

template <typename T>
inline void Mx(T &x, T y) { x < y && (x = y); }

template <typename T>
inline void Mn(T &x, T y) { x > y && (x = y); }

int n;
inline void Add(int x, int y, int t) {
    if (t) write(x + n, ' '), write(y + n);
    else write(x, ' '), write(y);
}
int main() {
    read(n); int lim = 1;
    while (lim <= n) {
        if (lim == n) return puts("No"), 0;
        lim <<= 1;
    }
    puts("Yes");
    for (int i = 2;i <= 3; i++)
        Add(i - 1, i, 0), Add(i - 1, i, 1);
    write(n + 1, ' '), write(3);
    for (int i = 4;i < n; i += 2) 
        Add(i, i + 1, 0), Add(i + 1, 1, 0), Add(1, i, 1), Add(i + 1, i, 1);
    if (!(n & 1)) {
        for (int i = 2;i <= n; i++) {
            int tt = n ^ i ^ 1;
            if (i == 3 || tt > n) continue;
            if (tt & 1) swap(tt, i);
            Add(i, n, 0), Add(tt, n, 1);
            return 0;
        }
        return 0;
    }
    return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
    int n,m; cin >> n >> m;
    int maxb=0;
    vector<P> x(m);
    REP(i,m){
        int a,b; cin >> a >> b;
        x[i] = make_pair(b,a);
    }
    sort(all(x));
    int ans= 0;
    REP(i,m){
        P l = x[i];
        int b = l.first;
        int a = l.second;
        if(maxb < a){
            ans++;
            maxb = b-1;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF=1000000000;
typedef pair<int,int> P;
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; }
vector<string> v;
queue<P> Q;
int GCD(int a,int b){return b? GCD(b,a%b):a;}
int main(){
int N,M;
cin>>N>>M;
vector<int> X(M);
for(int i=0;i<M;i++){
    cin>>X.at(i);
}
sort(X.begin(),X.end());
vector<ll> d;
for(int i=1;i<X.size();i++){
   d.push_back(X.at(i)-X.at(i-1));
}
sort(d.begin(),d.end(),greater<ll>());
ll res=X.back()-X.at(0);
for(int i=0;i<min((int)d.size(),N-1);i++){
    res-=d.at(i);
}
cout<<res<<endl;
}

 


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int[] test = new int[N];
		for (int i = 0; i < N; i++) {
			test[i] = input.nextInt();
		}
		System.out.println(JUMP(test));
	}
	public static int JUMP(int[] test) {
		int[] dp = new int[test.length];
		dp[0]=0;
		dp[1]=Math.abs(test[1]-test[0]);
		for (int i = 2; i < test.length; i++) {
			dp[i]=Math.min(dp[i-1]+Math.abs(test[i]-test[i-1]), dp[i-2]+Math.abs(test[i]-test[i-2]));
		}
		return dp[test.length-1];
	}
}

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

int main() {
	long n, a, b, c, resul=0;
	cin >> n >> a >> b;
	c = a + b;
	if (c == 0) {
		resul = 0;
	}
	else {
		resul += a * (long)(n / c);
		if (n % c <= a) {
			resul += n % c;
		}
		else {
			resul += a;
		}
	}
	cout << resul << endl;
	return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

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

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

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vi x, tmp;
  REP(i, n) { x.PB(read()); }
  tmp = x;
  sort(ALL(tmp));
  REP(i, n) {
    if (x[i] <= tmp[n / 2 - 1])
      print(tmp[n / 2]);
    else
      print(tmp[n / 2 - 1]);
  }
}


Measured memory_bytes: 5488
N=int(input())
h=list(map(int,input().split()))
tmp=[]
for i,j in enumerate(h):
  tmp.append([i,j])
tmp=sorted(tmp, key=lambda x: x[1])
a=[]
for i in tmp:
  a.append(i[0]+1)
maped_list = map(str,a) 
mojiretu = ' '.join(maped_list)
print(mojiretu)

Measured memory_bytes: 32076
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int n, maxCnt = 0;
	cin>>n;
	vector<int> v(n);
	REP(i,n)
		cin>>v[i];
	int i = 0;
	while(i<n)
	{
		int cnt = 0;
		while(i+1<n && v[i]>=v[i+1])
		{
			i++;
			cnt++;
		}
		maxCnt = max(maxCnt, cnt);
		i++;
	}
	cout<<maxCnt<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3716
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var xx = int.Parse(Console.ReadLine());

        var xs = new int[xx];
        xs[0] = 2;
        for (int i = 1; i < xs.Length; ++i)
        {
            xs[i] = (i + 1) * 2 + 1;
        }
        int r = 0;
        int last = xs.Length;
        while (xs[0] < xx)
        {
            for (int i = 1; i < last; ++i)
            {
                var s = xs[i];
                if (s % xs[0] != 0)
                {
                    xs[r++] = s;
                }
            }
            last = r;
            r = 1;
            xs[0] = xs[1];
        }

        Console.WriteLine(xs[0]);
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> v(N+1);
  v.at(0) = 2;
  v.at(1) = 1;
  
  for (int i = 2; i <= N; i++) {
    v.at(i) = v.at(i-2) + v.at(i-1);
  }
  
  cout << v.at(N) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	char a[100][100],b[100][100];
	int h,w,t,i,j;

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

	for(i=0,t=0;i<h;i++){
		scanf("%s",a[t]);
		if(strchr(a[t],'#')!=NULL){
			t++;
		}
	}

	for(i=0;i<w;i++){
		for(j=0;j<t;j++){b[i][j]=a[j][i];}
	}

	for(i=0;i<t;i++){
		for(j=0;j<w;j++){
			if(strchr(b[j],'#')!=NULL){printf("%c",a[i][j]);}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[200000];
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	int k = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == k + 1)k++;
	}
	if (!k)cout << -1 << endl;
	else cout << n - k << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define vv vector<lli>
#define vp vector<pair<lli,lli>>
#define vpp vector<pair<lli,pair<lli,lli>>>
#define lims(w) (w).begin(),(w).end()
#define rlims(w) (w).rbegin(),(w).rend()
#define pb push_back
#define mp make_pair
#define f(i,a,b) for(lli i=a;i<b;i++)
#define ff first
#define ss second
#define sz(a) (lli)(a.size())
lli inf = (1e18 + 2);
lli mod = (1e9 + 7);

int main()
{
	lli n;
	cin>>n;
	lli sum = 0;
	lli a[n+1];
	f(i,0,n)
		cin>>a[i];
	lli s[n+1];
	s[n-1] = a[n-1];

	for(lli i=n-2;i>=0;i--)
		s[i] = (s[i+1] + a[i] + (2*mod)) % mod;
	
	lli prod;

	f(i,0,n-1)
	{
		prod = (a[i] * s[i+1]) % mod;
		sum = (sum + prod) % mod;
	}
	
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 6712
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9
#define LINF = 1e18
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << "=" << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

int main(){

    int n;
    cin >> n;
    int a = n%10;
    if(a == 3)cout << "bon" << endl;
    else if(a == 0 || a == 1 || a == 6 || a == 8)cout << "pon" << endl;
    else cout << "hon" << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
	int n,m;
	vector<int> v;
	cin >> n >> m;
	string s;
	cin >> s;
	int i=n;
	while(i>0){
		bool a=1;
		for(int j=m;j>=1;j--){
			if(i-j<0)continue;
			if(s[i-j]=='0'){
				v.push_back(j);
				i-=j;
				a=0;
				break;
			}
		}
		if(a){
			cout << -1 << endl;
			return 0;
		}
	}

	reverse(all(v));
	FOR(i,v.size()){
		cout << v[i];
		if(i!=(int)v.size()-1)cout << " ";
	}
	cout << endl;
}

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

void judge();
bool rum(int a, int b, int c);

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        judge();
    }
    return 0;
}

void judge()
{
    int nums[9] = {0,1,2,3,4,5,6,7,8}; 
    int numbers[9];
    char colors[9];
    for(int i = 0; i < 9; i++){
        cin >> numbers[i];
    }
    for(int i = 0; i < 9; i++){
        cin >> colors[i];
    }
    int set_num;
    bool flag = false;
    do{
        set_num = 0;
        for(int i = 0; i < 3; i++){
            if(colors[nums[3*i]] == colors[nums[3*i+1]] && colors[nums[3*i+1]] == colors[nums[3*i+2]]){
                if(rum(numbers[nums[3*i]], numbers[nums[3*i+1]], numbers[nums[3*i+2]])){
                    set_num++;
                }
            } else {
                break;
            }
        }
        if(set_num >= 3){
            flag = true;
            break;
        }
    }
    while(next_permutation(nums, nums+9));
    if(flag){
        cout << 1 << endl;
    } else{ 
        cout << 0 << endl;
    }
}

bool rum(int a, int b, int c)
{
    int nums[3] = {a, b, c};
    sort(nums, nums+3);
    bool flag;
    flag = ((nums[0] == nums[1]) && (nums[1] == nums[2])) | ((nums[0] + 1 == nums[1]) && (nums[1] + 1 == nums[2]));
    return flag;
}

Measured memory_bytes: 1180
readlines.each do |l|
	xa,ya,xb,yb,xc,yc,xd,yd = l.split.map(&:to_f)
	puts ((xa-xd)*(xb-xc) <= 0 && (ya-yd)*(yb-yc) <= 0 ? "YES" : "NO")
end

Measured memory_bytes: 6128
n = int(input())
s = input()


count_list = []

prevous_count = s[1:].count("E")
current_min = prevous_count

for index in range(len(s) - 1):
    add_man = s[index]
    leader = s[index+1]

    if add_man == "W":
        prevous_count += 1
    if leader == "E":
        prevous_count -= 1
    if current_min > prevous_count:
        current_min = prevous_count


print(current_min)



Measured memory_bytes: 3708
#include <iostream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <list>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream>
#include <deque>
using namespace  std;
#define  ll long long
#define  ull unsigned long long
#define mINF(a) memset(a,0x3f3f3f3f,sizeof(a))
#define m0(a) memset(a,0,sizeof(a))
#define mf1(a) memset(a,-1,sizeof(a))
#define lowbit(x) (x&(-x)) 
#define lson i<<1,l,l+r>>1
#define rson i<<1|1,((l+r)>>1)+1,r
#define ALL(x) x.begin(),x.end()
typedef pair<ll,ll>P;
static const ll INF=1e18;
static const ll len=1e5+2;
int main()
{
	ll n;
	while(cin>>n)
	{
		ll ans[len];
		for(ll i=0;i<n;++i)
			scanf("%lld",ans+i);
		sort(ans,ans+n);
		ll sum=ans[0],c=1;
		for(ll i=1;i<n;++i)
		{
			if(sum*2>=ans[i])
			{
				c++;
				sum+=ans[i];
			}
			else
			{
				c=1;
				sum+=ans[i];
			}
		}
		cout<<c<<endl;
	}
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#define MX 200000
int a[MX], n, ln, heap[MX];
void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}
int maxChild(int *ar, int l, int r, int x, int y) {
    if (x < l && ar[r] < ar[x]) r = x;
    if (y < l && ar[r] < ar[y]) r = y;
    return r;
}
void heapify(int *ar, int l, int r) {
    int c = maxChild(ar, l, r, 2 * r + 1, 2 * r + 2);
    if (c != r) {
        swap(&ar[c], &ar[r]);
        heapify(ar, l, c);
    }
}
int getTop(int *ar, int l) {
    int ret = ar[0];
    ar[0] = ar[l];
    heapify(ar, l, 0);
    return ret;
}
void insert(int *ar, int v, int l) {
    ar[l] = v;
    while (l > 0 && ar[(l - 1) / 2] < ar[l]) {
        swap(&ar[(l - 1) / 2], &ar[l]);
        l = (l - 1) / 2;
    }
}
void MRoy() {
    ln = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
        insert(heap, a[i], ln++);
    }
    for(int i = 0;i<n;i++){
        if(heap[0]==a[i]){
            getTop(heap,--ln);
            printf("%d\n",heap[0]);
            insert(heap,a[i],ln++);
        }
        else printf("%d\n",heap[0]);
    }
}
int main() {
    MRoy();
    return 0;
}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    cout << min(a+b,min(b+c,a+c)) << endl;
}


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

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

  int h[n];

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

  int a = 0;
  int b = 0;

  for(int i = 0; i < n-1; ) {
      if(h[i] >= h[i+1]) {
          b++;
          i++;
          if(a < b) {
             a = b;
          }
      } else {
         i++;
         b = 0;
      }
  }

  cout << a << endl;

  /*
    int n;
    cin >> n;

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

    for(int i = 0; i < n; i++) {
        int b = 0;
        for(int j = i; j < n-1; j++) {
            if(h[j] >= h[j+1]) {
                b++;
            } else {
                break;
            }
        }
        if(a < b) a = b;
    }

    cout << a << endl;
*/
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

int N;
int H[20];

int main() {
    cin >> N;
    rep(i, N) cin >> H[i];

    int ans = 0;
    int max = 0;
    rep(i, N) {
        if (max <= H[i]) {
            ans++;
            max = H[i];
        }
    }

    cout << ans << endl;
}

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

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

	rep(i, 1, b + 1) {
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

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

int main()
{
	int n;
	while (cin >> n, n) {
		string MD, hm, e, p;
		int flag = 0, tmp;
		vector<int> time(1000), start(1000);
		for (int i = 0; i < n; i++) {
			cin >> MD >> hm >> e >> p;
			if (p == "000") {
				if (flag) {
					for (int i = 0; i < 1000; i++) {
						if (start[i]) {
							time[i] += stoi(hm.substr(0, 2)) * 60 + stoi(hm.substr(3, 2)) - max(tmp, start[i]);
						}
					}
					tmp = 0;
				}
				else {
					tmp = stoi(hm.substr(0, 2)) * 60 + stoi(hm.substr(3, 2));
				}
				flag = 1 - flag;
			}
			else if (e == "I") {
				start[stoi(p)] = stoi(hm.substr(0, 2)) * 60 + stoi(hm.substr(3, 2));
			}
			else {
				int id = stoi(p);
				if (flag && start[id]) {
					time[id] += stoi(hm.substr(0, 2)) * 60 + stoi(hm.substr(3, 2)) - max(tmp, start[id]);
				}
				start[id] = 0;
			}
		}
		int res = 0;
		for (int i = 0; i < 1000; i++) {
			res = max(res, time[i]);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
n = gets.chomp
l = Array.new
stk = Array.new
ls = Array.new

k = 0
n.length.times { |i|
	if n[i] == "\\"
		stk.push(i)
		ls[k] = i
	elsif n[i] == "/"
		j = stk.pop
		if j != nil
			if l[k] == nil
				l[k] = 0
			end
			l[k]+=1
			l[k]+=i-j-1
			while k != 0 && ls[k-1] > j
				l[k-1]+=l[k]
				l.pop
				k-=1
			end
			ls[k] = j
			k+=1
		end
	end
}

a = 0
k.times { |i|
	a += l[i]
}

puts a
if k != 0
	print(k," ",l.join(" "),"\n")
else
	puts k
end

Measured memory_bytes: 9128
N,M=map(int,input().split())
x=[0 for i in range(M)]
y=[0 for i in range(M)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1
    y[i]-=1
a=[0 for i in range(N)]
a[0]=1
b=[1 for i in range(N)]
for i in range(M):
    b[x[i]]-=1
    b[y[i]]+=1
    if a[x[i]]==1:
        a[y[i]]=1
    if b[x[i]]==0:
        a[x[i]]=0
print(sum(a))


Measured memory_bytes: 12584
// https://beta.atcoder.jp/contests/abc067

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

i64 sum[2 * 100000];

int main() {
    int n;
    cin >> n;
    i64 a;
    for (int i = 0; i < n; ++i) {
        cin >> a;

        sum[i] = a;
        if (i == 0) continue;
        sum[i] += sum[i - 1];
    }

    i64 ans = numeric_limits<i64>::max();
    for (int i = 0; i < n - 1; ++i) {
        i64 su = sum[i];
        i64 ara = sum[n - 1] - sum[i];
        i64 score = abs(su - ara);
        ans = min(ans, score);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define mod 1000000007
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector< pi >
ll d[100010];
int main()
{
	int n;
	cin>>n;
	int a[n+10],b[n+10],c[n+10];
	//map<int,int> m,mm;
	//m.clear();mm.clear();
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) 
	{
		cin>>b[i];
		//m[b[i]]+=1;
	}
	for(int i=0;i<n;i++) 
	{
		cin>>c[i];
		//mm[c[i]]+=1;
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	int i=0,j=0;
	while(i<n&&j<n)
	{
		while(j<n&&c[j]<=b[i]) j++;
		d[i]=n-j;
		i++;
	}
	for(i=n-2;i>=0;i--) d[i]+=d[i+1];
		ll res=0;
	i=0;j=0;
	while(i<n&&j<n)
	{
		while(j<n&&b[j]<=a[i]) j++;
		if(j<n)
		res+=d[j];
	i++;
	}
	cout<<res;

	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<queue>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int sum = 0;
	for (int i = 0;i < s.length();i++)
		if (s[i] != t[i])sum++;
	cout << sum;
}

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

int main() {
  int N,K,Sum,x;
  cin>>N>>K;
  Sum=0;
 rep(i, N){
   cin>>x;
     if(x>K-x){Sum+=2*(K-x);}else{Sum+=2*x;}}
  cout<<Sum<<endl;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto nxt = readln.split.to!(int[]);
    auto N = nxt[0];
    auto X = nxt[1];
    auto T = nxt[2];
    writeln((N + X - 1) / X * T);
}

Measured memory_bytes: 2748
from bisect import bisect_right


def main():
    s = list(input())
    t = list(input())

    table = {ss: [] for ss in set(s)}
    for i, ss in enumerate(s):
        table[ss].append(i)

    cnt = 1
    cur = -1
    for tt in t:
        if tt not in table:
            print(-1)
            return
        tl = table[tt]
        idx = bisect_right(tl, cur)
        # if idx == len(tl) or tl[idx] <= cur:
        if idx == len(tl):
            idx = 0
            cnt += 1
        cur = tl[idx]
    print(len(s) * (cnt - 1) + cur + 1)


main()


Measured memory_bytes: 60432
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

mod = 10**9+7

class PERM_COMB_MOD():
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def perm(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * self.finv[n-k] % self.mod % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

    def h(self, n, k):
        if n == k == 0:
            return 1
        return self.comb(n+k-1, k)

n,k = map(int, input().split())
PCM = PERM_COMB_MOD()
if k > n:
    k = n

ans = 0
for i in range(min(k, n-1)+1):
    ans += PCM.comb(n,i)*PCM.comb(n-1,n-i-1)
    ans %= mod
print(ans)



Measured memory_bytes: 51952
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,k] <- getIntList
    as <- getIntList
    let g = foldl1' gcd as 
    let m = maximum as
    putStrLn $ if m >= k && k `mod` g == 0 then "POSSIBLE" else "IMPOSSIBLE"

Measured memory_bytes: 13916
function Main(input) {
	//SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict modeになってしまうため
	"use strict"
	
	const inputStrings = input.split(' ');
	const verifyNum = parseInt(inputStrings[0] + inputStrings[1]);
	
	let answer = 'No';
	for(let i = 1; i <= 100100; i++){
		if((i * i) === verifyNum){
			answer = 'Yes';
			break;
		}
	}
	console.log(answer);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
n = gets.to_i
l = gets.split.map(&:to_i).sort
ans=0
n.times do |i|
    for j in i+1..n-2
        x=l[i]+l[j]
        bi=l.bsearch_index{|c|x<=c}
        bi=n if bi.nil?
        ans += bi-j-1
    end
end
puts ans

Measured memory_bytes: 14316
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> ivv;


int main()
{
	int m,nmin,nmax;
	
	while(cin >> m >> nmin >> nmax,m)
	{
		int score[m];
		REP(i,m)
		{
			cin >> score[i];
		}
		
		int ans = 0,maxgap = 0;
		
		for(int i = nmin-1;i <= nmax-1;i++)
		{
			if(maxgap <= score[i] - score[i+1])
			{
				ans = i+1;
				maxgap = score[i] - score[i+1];
			}
		}
		
		cout << ans << endl;
		
	}
	
	
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int len=S.size();
  int i=0;
  int ans=0;
  string tmp="a9pi8rytno";
    string p;
  while(i<len){
    p=S.substr(i,1);
    if(p==tmp) {
      p=S.substr(i,2);
    	if(i+2>len) break;
    }
    i += p.size();
    //cout<<p<<" "<<tmp<<endl;
    tmp =p;
    ans++;
    
  }
  //if(p==tmp) ans--;
 
cout<<ans<<endl;
}


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

int main() {
  long long dp[30];
  dp[0] = 1;
  dp[1] = 2;
  dp[2] = 4;
  for (int i = 3; i < 30; i++) {
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
  }
  int a[30];
  for (int i = 0; i < 30; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      break;
    }
    else {
      int x = a[i];
      long long y = dp[x-1]/3650+1;
      cout << y << endl;
    }
  }
}


Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

int cnt = 0;

void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1], R[n2];
    for(int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1] = 1000000000;
    R[n2] = 1000000000;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++) {
        cnt++;
        if(L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        } else { 
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int A[], int left, int right) {
  if(left + 1 < right) {
      int mid;
      mid = (left + right) / 2;
      mergeSort(A, left, mid);
      mergeSort(A, mid, right);
      merge(A, left, mid, right);
  }
  return;
}

int main() {
    int n;
    int S[600000];
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> S[i];
    }
    mergeSort(S, 0, n);
    for(int i = 0; i < n; i++) {
        if( i != 0 ) cout << " ";
        cout << S[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int cnt[50][50];


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

    int n; cin >> n;
    vi two(n), five(n);
    forn(i,n) {
        double f; cin >> f;
        f *= 1e9;
        ll x = round(f);
        while (x % 2 == 0) {
            two[i]++;
            x /= 2;
        }
        while (x % 5 == 0) {
            five[i]++;
            x /= 5;
        }
        cnt[two[i]][five[i]]++;
    }
    ll ans = 0;
    forn(i,50) forn(j,50) forn(k,50) forn(l,50) if (i + k >= 18 && j+l >= 18) {
        ll a = cnt[i][j];
        cnt[i][j]--;
        ll b = cnt[k][l];
        ans += a*b;
        cnt[i][j]++;
    }
    assert(ans%2 == 0);
    cout << ans/2 << '\n';

    return 0;
}


Measured memory_bytes: 4764
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 100000000
typedef long long ll;

int main(void) {
    double a, b;
    cin >> a >> b;
    printf("%.7f\n", a*b/3.305785);
    return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
const int N = 8200;
const int MAX_VAL = 8000;

int n, to_x, to_y, dis_x, dis_y, sum_x, sum_y;
int x[N], y[N], tot_x = 0, tot_y = 0;
bool fx[N], fy[N];
string s;

int main()
{
	cin>> s; n = s.length();
	scanf( "%d%d", &to_x, &to_y );
	
	int now = 0;
	while( s[now] == 'F'&& now < n )
		now ++;
	dis_x = to_x - now; dis_y = to_y;
		
	int cur = 1, sum = 0; now++;
	// 0 : x, 1 : y
	while( now < n ) 
	{
		if( s[now] == 'F' ) {
			sum ++; now++; continue;
		}
		
		if( cur == 1 )
			y[++tot_y] = sum;
		else x[++tot_x] = sum;
		sum = 0; cur ^= 1; now++;
	}
	if( cur == 1 ) 
		y[++tot_y] = sum;
	else x[++tot_x] = sum;
	
	memset( fx, false, sizeof( fx ) );
	memset( fy, false, sizeof( fy ) );
	fx[0] = true; fy[0] = true;
	
	for( int i = 1; i <= tot_x; i ++ )
		for( int j = MAX_VAL; j >= x[i]; j -- )
			if( !fx[j] ) fx[j] = fx[j-x[i]]; 
	
	for( int i = 1; i <= tot_y; i ++ )
		for( int j = MAX_VAL; j >= y[i]; j -- )
			if( !fy[j] ) fy[j] = fy[j-y[i]];
			
	for( int i = 1; i <= tot_x; i ++ )
		sum_x += x[i];
	for( int i = 1; i <= tot_y; i ++ )
		sum_y += y[i];
		 
//	printf( "sum_x:%d, sum_y:%d\n", sum_x, sum_y );
//	printf( "dis_x:%d, dis_y:%d\n", dis_x, dis_y );
		 
	sum_x -= dis_x; sum_y -= dis_y;
	if( sum_x % 2 == 1 || sum_y % 2 == 1 ) {
		puts( "No" ); return 0;
	}
	
//	printf( "sum_x:%d, sum_y:%d\n", sum_x, sum_y );
	
	if( sum_x < 0 || sum_y < 0 ) {
		puts( "No" ); return 0;
	}
	
	sum_x /= 2; sum_y /= 2;
	if( !fx[sum_x] || !fy[sum_y] ) 
		puts( "No" ); 
	else puts( "Yes" );
		
	return 0;
}

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

unsigned int gcd(unsigned int a, unsigned int b)
{
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}

int main()
{
  unsigned int a, b;


  while (cin >> a >> b)
  {
    if (a < b)
    {
      int t = a;
      a = b;
      b = t;
    }

    int g = gcd(a,b);
    int l = a * (b / g);

    cout << g << ' ' << l << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
package main

import (
  "bufio"
  "fmt"
  "os"
  "sort"
  "strconv"
  "strings"
)

func main() {
  io := IO{bufio.NewReaderSize(os.Stdin,100),bufio.NewWriterSize(os.Stdout,100)}
  n := io.NextInt()
  a := io.NextIntArray()
  b := io.NextIntArray()
  pa := make(Pairs,n)
  pb := make(Pairs,n)
  for i:=0;i<n;i++ {
    pa[i] = Pair{a[i],i}
    pb[i] = Pair{b[i],i}
  }
  sort.Sort(pa)
  sort.Sort(pb)
  p := make([]int,n)
  for i:=0;i<n;i++ {
    if pa[i].x > pb[i].x { fmt.Println("No");return }
    p[pa[i].y] = pb[i].y
  }
  for i:=1;i<n;i++ {
    if pa[i].x <= pb[i-1].x { fmt.Println("Yes");return }
  }
  s := make(map[int]struct{})
  for i,m:=0,0;i<n;i++ {
    s[m] = struct{}{}
    m = p[m]
  }
  if len(s) < n { fmt.Println("Yes");return }
  fmt.Println("No")
}

type Pair struct { x,y int }
type Pairs []Pair
func(p Pairs) Len() int { return len(p) }
func(p Pairs) Swap(i,j int) { p[i],p[j] = p[j],p[i] }
func(p Pairs) Less(i,j int) bool {
  if p[i].x == p[j].x { return p[i].y < p[j].y }
  return p[i].x < p[j].x
}

type IO struct {
  reader *bufio.Reader
  writer *bufio.Writer
}
func(io *IO) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := io.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(io *IO) Println(a ...interface{}) (int,error) {
  return fmt.Fprintln(io.writer,a...)
}
func(io *IO) Flush() error {
  return io.writer.Flush()
}
func(io *IO) NextInt() int {
  n,_ := strconv.Atoi(io.NextLine())
  return n
}
func(io *IO) NextIntArray() []int {
  s := strings.Fields(io.NextLine())
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

Measured memory_bytes: 9728
nums = [2,5,5,4,5,6,3,7,6]

n,m = map(int,input().split())

digits = list(map(int,input().split()))

dp = [-1]*(n+10)
dp[0] = 0
for i in range(n+1):
   if(dp[i] == -1):
       continue
   else:
       for digit in digits:
           dp[i+nums[digit-1]] = max(dp[i+nums[digit-1]], dp[i]*10+digit)
           

print(dp[n])


Measured memory_bytes: 14692
#include<bits/stdc++.h> 
using namespace std;
bool is_prime(int x){
    if(x <= 1) return false; 
    for(int i = 2; i*i <= x; i++)
    if(x%i==0)
    return false; 
    return true;  
    }
	int main(){
    int X;
    cin >>X;
    int p = X;
	while(!is_prime(p)) p++;
	cout<< p <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class T1, class T2> void sortA_L(int N, T1 a[], T2 b[], void *mem = wmem){
  int i;
  pair<T1, T2> *arr=(pair<T1, T2> *) mem;
  for(i=0;i<N;i++){
    arr[i].first = a[i];
    arr[i].second = b[i];
  }
  sort(arr, arr+N);
  for(i=0;i<N;i++){
    a[i] = arr[i].first;
    b[i] = arr[i].second;
  }
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
char memarr[96000000];
int A;
int B;
int Q;
long long S[100000];
long long T[100000];
long long X[100000];
int ind[100000];
long long res[100000];
int main(){
  int a, b, i, j, k;
  long long tmp;
  wmem = memarr;
  rd(A);
  rd(B);
  rd(Q);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<A;Lj4PdHRW++){
      rd(S[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY;
    for(KL2GvlyY=0;KL2GvlyY<B;KL2GvlyY++){
      rd(T[KL2GvlyY]);
    }
  }
  {
    int Q5VJL1cS;
    for(Q5VJL1cS=0;Q5VJL1cS<Q;Q5VJL1cS++){
      rd(X[Q5VJL1cS]);
    }
  }
  for(i=0;i<Q;i++){
    ind[i] = i;
  }
  sortA_L(Q, X, ind);
  a = b = 0;
  for(k=0;k<Q;k++){
    tmp = 4611686016279904256LL;
    while(a<A && S[a]<X[k]){
      a++;
    }
    while(b<B && T[b]<X[k]){
      b++;
    }
    for(i=a-1;i<a+1;i++){
      if(0 <= i  &&  i < A){
        for(j=b-1;j<b+1;j++){
          if(0 <= j  &&  j < B){
            chmin(tmp,min_L(abs(X[k]-S[i]), abs(X[k]-T[j]))+ abs(S[i]-T[j]));
          }
        }
      }
    }
    res[ind[k]] = tmp;
  }
  for(i=0;i<Q;i++){
    wt_L(res[i]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int A, B, Q;
// ll S[1d5], T[1d5], X[1d5];
// int ind[1d5]; ll res[1d5];
// {
//   int i, j, k, a, b;
//   ll tmp;
//   rd(A,B,Q,S(A),T(B),X(Q));
//   rep(i,Q) ind[i] = i;
//   sortA(Q, X, ind);
// 
//   a = b = 0;
//   rep(k,Q){
//     tmp = ll_inf;
//     while(a<A && S[a]<X[k]) a++;
//     while(b<B && T[b]<X[k]) b++;
//     rep(i,a-1,a+1) if(0 <= i < A) rep(j,b-1,b+1) if(0 <= j < B){
//       tmp <?= min(abs(X[k]-S[i]), abs(X[k]-T[j])) + abs(S[i]-T[j]);
//     }
//     res[ind[k]] = tmp;
//   }
// 
//   rep(i,Q) wt(res[i]);
// }


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  int n; cin >> n;
  vector<ll> h(n);
  RPT(i,0,n) cin >> h[i];
  int  d=0; int ans = 0;
  for(;d<n-1;){
    int cnt=0;
    while(d<n-1){
      ++d;
      if(h[d-1]<h[d]) break;
      cnt++;
    }
    ans = max(ans, cnt);
    cnt = 0;
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

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

    int x = abs(a - c);
    int y = abs(b - d);

    int g = gcd(x, y);
    int x2 = x / g;
    int y2 = y / g;

    int ans = (x2 + y2 - 1) * g;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <stack>
using namespace std;

int InsertionSort(int *array, int size, int span);
string JoinWith(int *array, int size, const char *joiner);

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

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

	// Start shell sort.
	stack<int> span_stack;
	for (int i = 1; i < n; i = 3 * i + 1) {
		span_stack.push(i);
	}
	if (span_stack.empty()) {
		span_stack.push(1);
	}

	int times_of_inssort = span_stack.size();
	int spans[times_of_inssort];
	int index = 0;
	int count = 0;
	while(!span_stack.empty()) {
		int span = span_stack.top();
		span_stack.pop();
		count += InsertionSort(array, n, span);
		spans[index++] = span;
	}

	cout << times_of_inssort << endl;
	cout << JoinWith(spans, times_of_inssort, " ") << endl;
	cout << count << endl;
	cout << JoinWith(array, n, "\n") << endl;
	return 0;
}

int InsertionSort(int *array, int size, int span) {
	int count = 0;
	for (int i = span; i < size; i++) {
		int current = array[i];
		int j = i - span;
		while (j >= 0 && array[j] > current) {
			array[j + span] = array[j];
			j -= span;
			count++;
		}
		array[j + span] = current;
	}
	return count;
}

string JoinWith(int *array, int size, const char *joiner) {
	ostringstream oss;
	for (int i = 0; i < size - 1; i++) {
		oss << array[i] << joiner;
	}
	oss << array[size - 1];
	return oss.str();
}

Measured memory_bytes: 25196
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int T,E;
	cin>>T>>E;
	vector<double> v1(T),v2(T);
	rep(i,T){
		cin>>v1[T-1-i];
	}
	double b;
	cin>>b;
	rep(i,T){
		cin>>v2[i];
	}
	double a=v1[T-1];
	double c=v2[T-1];
	for(int i=T-2;i>=0;i--){
		int s=T-i;
		if(v1[i]>=a){
			a=(v1[i]+a*(s-1))/(s);
		}
		else{
			a=v1[i];
		}
		if(v2[i]>=c){
			c=(v2[i]+c*(s-1))/(s);
		}
		else{
			c=v2[i];
		}
	}
	double ans1=max(E/b,(double)E*(T+1)/(T*(a+c)+b));
	cout<<LDcout(ans1,10)<<endl;
}


signed main() {
	ios_base::sync_with_stdio(false);
  	// cout<<fixed<<setprecision(10);
    mainmain();
}

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


int main(void) {
  vector<vector<int>> c(3, vector<int>(3));
  rep(i, 3) {
    rep(j, 3) {
      cin >> c[i][j];
    }
  }

  vector<int> a(3, 0);
  vector<int> b(3, 0);
  a[0] = 0;
  rep(i, 3) b[i] = c[0][i] - a[0];
  rep(i, 3) a[i] = c[i][0] - b[0];

  bool ok = true;
  rep(i, 3) {
    rep(j, 3) {
      if (c[i][j] != a[i] + b[j]) {
        ok = false;
      }
    }
  }
  
  if (ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3580
#include<iostream>
#include<string>
using namespace std;
int main(int argc, char const *argv[])
{
	int k;cin>>k;
	string str;cin>>str;
	if(str.length()<=k){
		cout<<str<<'\n';
	}
	else{

		for(int i=0;i<k;++i){
			cout<<str[i];
		}
		cout<<"..."<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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

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

    cout << ((a + b + c) >= 22 ? "bust" : "win") << endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; cin >> n;
  while (n) {
    if (n % 10 == 7) return puts("Yes"), 0;
    n /= 10;
  }
  puts("No");

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a,b,c;
int main()
{
	cin>>a>>b>>c;
	if (a%2==0 || b%2==0 || c%2==0)
	{
		puts("0");
		return 0;
	}
	ll ans=2e18;
	ans=min(a*b,b*c);
	ans=min(ans,c*a);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define oo 1000000000000000000LL
using namespace std;


void _sol(){
    int n,ac=0,wa=0,tle=0,re=0; cin >> n;
    forr(i,n){
        string v; cin >> v;
        if(v[0]=='A' && v[1]=='C') ac++;
        else if( v[0]=='W' && v[1]=='A' ) wa++;
        else if( v[0]=='R') re++;
        else tle++;
    }
    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1; //cin >> t;
    while(t--) _sol();
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;

int main() {
    ll n, ans = 0;
    cin >> n;
    for(ll l = 1; l <= n; ) {
        ll r = n/ (n/l);
        ll x = n / r;
        // cout << l << " " << r << endl;
        for(ll q = max(1LL, (n-x)/r - 1); q <= max(1LL, (n-x)/l + 1); q++) {
            ll t = (n - x) / q;
            if((n - x) % q == 0 && t >= l && t <= r && n / t == n % t) {
                // cout << l << " " << r << " > " << t << endl;
                ans += t;
            }
        }
        l = r + 1;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	int A[3][3],AA[3][3];
		rep(i, 3) {
		rep(j, 3) {
			cin >> AA[i][j];
		}
	}

	int  N;
	cin >> N;
	vector<int> b(N);
	rep(i, N) {
		cin >> b[i];
		rep(j, 3) {
			rep(k, 3) {
				if (b[i]==AA[j][k])A[j][k]=1;
			}
		}
	}
	int a=0;
	rep(i, 3) {
		if (A[i][1] ==1 && A[i][2]==1 && A[i][0]==1)a++;
		if (A[1][i] ==1&& A[2][i] ==1&& A[0][i] ==1)a++;
	}
	if (A[0][0]==1&& A[1][1]==1 && A[2][2]==1)a++;
	if (A[0][2] == 1 && A[1][1] ==1&& A[2][0]==1)a++;

	if (a == 0)cout << "No";
	else cout << "Yes";
		}

Measured memory_bytes: 256
import collections

n = int(input())
x = list(map(int, input().split()))

c = collections.Counter(x)
li = []
for i in c.values():
    li.append(i)

li.sort(reverse=True)

for j in range(2):
    for i in range(len(li) - 1):
        if li[i] >= 3 and li[i] % 2 == 0:
            li[i] = 2
        elif li[i] >= 3 and li[i] % 2 != 0:
            li[i] = 1

        if li[i + 1] == 2 and li[i] == 2:
            li[i + 1] = 1
            li[i] = 1
    li.sort(reverse=True)
    if len(li) > 1 and li[0] == 2 and li[1] == 1:
        li[0] -= 1
        li.pop(-1)


print(len(li))




Measured memory_bytes: 18648
n,m = map(int,input().split())
sc = [[i for i in map(int,input().split())] for j in range(m)]
start = 0
goal = 0
if n==1:
  start = 0
  goal = 9
elif n==2:
  start = 10
  goal = 99
elif n==3:
  start = 100
  goal = 999

flag = 1
ans = -1
for num in range(start,goal+1):
  flag = 1
  for i in range(m):
    if str(num)[sc[i][0]-1] != str(sc[i][1]): #両辺ともちゃんとstrで変換
      flag = 0
  if flag == 1:
    ans = num
    break

print(ans)

Measured memory_bytes: 3064