akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

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

  ll sumf[N] = {A[0]};
  ll sumb[N] = {A[N-1]};
  rep(i, N-1) sumf[i+1] = A[i+1] + sumf[i];
  rep(i, N-1) sumb[i+1] = A[N-i-2] + sumb[i];

  ll ans = sumf[N-1];
  repi(nbc, 2, N-1){
    ll nb, nd;
    ll halfbc = lower_bound(sumf, sumf + nbc, sumf[nbc-1] / 2) - sumf;
    if(halfbc == 0) nb = 1;
    else if(sumf[nbc-1] / 2 - sumf[halfbc-1] < sumf[halfbc] - sumf[nbc-1] / 2)
      nb = halfbc;
    else nb = halfbc + 1;

    ll halfde = lower_bound(sumb, sumb + N - nbc, sumb[N-nbc-1] / 2) - sumb;
    if(halfde == 0) nd = 1;
    else if(sumb[N-nbc-1] / 2 - sumb[halfde-1] < sumb[halfde] - sumb[N-nbc-1] / 2)
      nd = halfde;
    else nd = halfde + 1;

    ll P = sumf[nb-1], Q = sumf[nbc-1] - sumf[nb-1];
    ll R = sumb[nd-1], S = sumb[N-nbc-1] - sumb[nd-1];
    ll diff = max(max(P, Q), max(R, S)) - min(min(P, Q), min(R, S));
    ans = min(diff, ans);
    // printf("%lld %lld %lld %lld\n", P, Q, R, S);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
  
using namespace std;
  
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
  
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
  
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
  
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
  
long long ans = 0;
  
void work(long long x, long long y)
{
    if (x < y)
    {
        ans += (y / x) * x * 2 - x;
        if (y % x == 0)
            return;
        ans += x;
        work(x, y % x);
    }
    else
    {
        ans += (x / y) * y * 2 - y;
        if (x % y == 0)
            return;
        ans += y;
        work(y, x % y);
    }
}
  
int main()
{
    long long N, X;
    cin >> N >> X;
    ans += N;
    work(X, N - X);
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve(input_s):
    length = len(input_s)
    ans = []
    
    def func(i, n):
        if i == length-1:
            ans.append(sum(map(int, n.split("+"))))
        else:
            func(i+1, n+"+"+input_s[i+1])
            func(i+1, n+input_s[i+1])

    func(0, input_s[0])
    return sum(ans)

if __name__ == "__main__":
    input_s = input()
    print(solve(input_s))


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

#define el '\n'

vector<int> adj[100005];
int dis[100005];
int in[100005];
bool vis[100005];

void dfs(int u){
  if(vis[u]) return;
  vis[u] = true;
  for(int v: adj[u]){
    dis[v] = max(dis[v], dis[u]+1);
    in[v]--;
    if(in[v]==0){
      dfs(v);
    }
  }
}

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

  int n, m;
  cin >> n >> m;
  while(m--){
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    in[v]++;
  }
  for(int i = 1; i <= n; i++){
    if(in[i]==0){
      adj[0].push_back(i);
      in[i]++;
    }
  }
  dfs(0);
  int ans = 0;
  for(int i = 1; i <= n; i++){
    ans = max(ans, dis[i]);
  }
  ans--;
  cout << ans << el;
  
  return 0;
}

Measured memory_bytes: 9728
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var nums []int = make([]int, n)

	for i := range nums {
		sc.Scan()
		nums[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Sort(sort.IntSlice(nums))
	fmt.Println(nums[n/2] - nums[(n/2)-1])
}


Measured memory_bytes: 2048
"use strict";
main(require("fs").readFileSync("/dev/stdin", "utf8").replace(/\r?\n$/, "").split(/\r?\n/));

function main(lines){
	var p = lines[0].split(" ").map(Number);
	console.log(Math.sqrt(Math.pow(p[0]-p[2],2)+Math.pow(p[1]-p[3],2)));
}

Measured memory_bytes: 15816
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int p,q,r;cin>>p>>q>>r;
    cout<<min({p+q,p+r,q+r})<<endl;;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int H, W, K, k, ans{};
  cin >> H >> W >> K;
  vector<vector<bool>> c(H,vector<bool>(W));
  string S;
  for (int i = 0; i != H; ++i) {
    cin >> S;
    for (int j = 0; j != W; ++j) {
      c[i][j] = S[j] == '#';
    }
  }

  for (int I = 0, M = 1 << H; I != M; ++I) {
    for (int J = 0, N = 1 << W; J != N; ++J) {
      k = 0;
      for (int i = 0; i != H; ++i) {
        if (I & (1 << i)) continue;
        for (int j = 0; j != W; ++j) {
          if (J & (1 << j)) continue;
          if (c[i][j]) ++k;
        }
      }
      if (k == K) ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[90];
int main()
{
	cin>>n;
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;++i)
		a[i]=a[i-1]+a[i-2];
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define pb(x) push_back(x)
#define HAYAKU_HAYAKU ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    HAYAKU_HAYAKU; 
    int n;
    cin>>n;
    vi a(n),b(n),c(n);
    for(int i = 0; i < n; i++)
        cin>>a[i];
    for (int i = 0; i < n; i++)
        cin>>b[i];
    for (int i = 0; i < n; i++)
        c[i] = i+1;
    int x = 0,y = 0,i = 1;
    while (next_permutation(c.begin(),c.end()))
    {
        if(c == a)
            x = i;
        if(c == b)
            y = i;
        i++;
        if(x > 0 && y > 0)
            break;
    }
    cout<<abs(x-y);
}

Measured memory_bytes: 3652
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [a for a in A if a <K]
N = len(A)
#dpm = [+1) for _ in range(N+1)]
dpm = [0]*(N+1)
dpm[0] = 1<<(K-1)
for i, a in enumerate(A):
    dpm[i+1] = dpm[i] | (dpm[i] >> a)

r = 0
dp2 = 1
for i, a in enumerate(A[::-1]):
    for j in range(a):
        if dp2 & dpm[N-i-1]:
            break
        dpm[N-i-1] >>= 1
    else:
        r += 1
    dp2 |= dp2<<a
    dp2 &= (1<<K)-1
print(r)


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

int main()
{
    long long int ans, a, b, c, d, e, i, j, k, n, m, x, y, z;
    cin>>a>>b>>c>>d;
    if(c == 1 || d == 1)
        ans = 0;
    else if(c == d)
    {
        ans = b - a + 1;
        i = b / c;
        j = a / c;
        n = i - j;
        if(a % c == 0)
            n++;
        ans = ans - n;
    }
    else
    {
        ans = b - a + 1;
        i = b / c;
        j = a / c;
        n = i - j;
        if(a % c == 0)
            n++;
        i = b / d;
        j = a / d;
        m = i - j;
        if(a % d == 0)
            m++;
        x = (c * d) / __gcd(c, d);
        i = b / x;
        j = a / x;
        z = i - j;
        if(a % x == 0)
            z++;
        ans = ans - n - m + z;
    }
    cout<<ans;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var t="0"+sc.S;
		int p=0,ans=0;
		for(int i = t.Length-1;i>=0;i--) {
			int c=t[i]-'0'+p;
			if((c==5&&t[i-1]-'0'>=5)||c>5){
				p=1;
				ans+=10-c;
			}
			else{
				p=0;
				ans+=c;
			}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 18912
n=int(input())
s=[int(input()) for i in range(n)]
s.sort()
S=sum(s)
ans=0
if S%10!=0:
  print(S)
else:
  for i in range(n):
    if (S-s[i])%10!=0:
      ans=max(S-s[i],ans)
  print(ans)

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

int main() {
  int N,X,T;
  cin>>N>>X>>T;
  int ans=0, hold=0;
  hold=N/X;
  if(N%X != 0){
    hold=hold+1;
  }
  ans = hold*T;
  cout<<ans<<endl;
  
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 2e5 + 100;
int n;
int a[N];
map<ll, ll> mmp;

int main() {
    scanf("%d", &n);
    ll answer = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        answer += mmp[i - a[i]];
        mmp[i + a[i]]++;
    }
    printf("%lld\n", answer);
    return 0;
}

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

int n,q;
std::string s;
std::vector<std::pair<int,int>> query;
std::vector<int> ac; //どれだけACがあったか

void input(){
    std::cin>>n>>q;
    std::cin>>s;
    query.resize(q);
    ac.resize(n+1);

    for(int i=0;i<q;i++){
        int a,b;
        std::cin>>a>>b;
        a--;b--;
        query[i] = {a,b};
    }

    int cnt = 0;
    for(int i=1;i<n+1;i++){
        if(s[i-1]=='A' && s[i]=='C')cnt++;
        ac[i+1]=cnt;
    }
}

int main(){
    input();
    for(int i=0;i<q;i++){
        int l = query[i].first;
        int r = query[i].second;
        std::cout<<ac[r+1] - ac[l+1]<<std::endl;
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    string res;
    res += string(tx - sx, 'R');
    res += string(ty - sy, 'U');
    res += string(tx - sx, 'L');
    res += string(ty - sy + 1, 'D');
    res += string(tx - sx + 1, 'R');
    res += string(ty - sy + 1, 'U');
    res += "LU";
    res += string(tx - sx + 1, 'L');
    res += string(ty - sy + 1, 'D');
    res += 'R';
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//#define int long long
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];

    int limit = 2000000;
    int cnt[limit+1];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        cnt[a[i]]++;
    }
    int type = 0;
    int Max = -(1 << 30);
    int maxi = -1;
    vector<int> mini;
    int Min = (1 << 30);
    vector<int> v;
    for (int i = 0; i <= limit; i++) {
        if(cnt[i] != 0) {
            type++;
            v.push_back(i);
        }
        if(Max < cnt[i] && cnt[i] != 0) {
            Max = cnt[i];
            maxi = i;
        }
        if(Min > cnt[i] && cnt[i] != 0 && maxi != i) {
            mini.clear();
            Min = cnt[i];
        }
        if(Min == cnt[i]) mini.push_back(i);
    }

    int ans = 0;
    vector<int> er;
    while(true) {
        if(type <= k) break;
        if (mini.size() != 0) {
            if (Max == 1) {
                ans += v.size() - k;
                break;
            } else {
                int tmp = mini[0];
                mini.erase(mini.begin());
                ans += cnt[tmp];
                cnt[maxi] += cnt[tmp];
                cnt[tmp] = 0;
                type--;
            }
        } else {
            Min = (1 << 30);
            for (int i = 0; i < v.size(); i++) {
                if(cnt[v[i]] == 0) er.push_back(i);
                if(Min > cnt[v[i]] && cnt[v[i]] != 0 && maxi != v[i]) {
                    mini.clear();
                    Min = cnt[v[i]];
                }
                if(Min == cnt[v[i]]) mini.push_back(v[i]);
            }
            for(int i = er.size()-1; i >= 0; i--) {
                v.erase(v.begin() + er[i]);
            }
            er.clear();

        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10612
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main()
{
    int n; cin>>n;
    vector<long> x(n), y(n);

    map<pair<long, long>, int> s;
    for(int i=0; i<n; ++i) {
        cin>>x[i]>>y[i];
        s[make_pair(x[i], y[i])]=i;
    }

    int res=n;
    for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) if (i!=j) {
        long p=x[i]-x[j];
        long q=y[i]-y[j];
        vector<bool> used(n, false);
        int cnt=0;
        for(int k=0; k<n; ++k) if (!used[k]) {
            used[k]=true;
            for(long a=x[k]-p, b=y[k]-q; s.count(make_pair(a, b)); a-=p, b-=q)
                used[s[make_pair(a, b)]]=true;
            for(long a=x[k]+p, b=y[k]+q; s.count(make_pair(a, b)); a+=p, b+=q)
                used[s[make_pair(a, b)]]=true;
            ++cnt;
        }
        res=min(res, cnt);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
import numpy as np
import sys
input = sys.stdin.readline
N, K = map(int,input().split())
A = np.sort(list(map(int,input().split())))
F = np.sort(list(map(int,input().split())))[::-1]
mul = A*F
if K >= sum(A)*N:
    print(0)
    exit()

ma = 2**40
mi = 0
while ma != mi:
    tgt = (ma + mi)//2
    tmp = np.ceil((mul-tgt)/F)
    num = np.sum(tmp[tmp>0])
    if num <= K:
        ma = mi + (ma - mi)//2
    else:
        mi = mi + (ma - mi)//2+1
print(ma)

Measured memory_bytes: 37240
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n,x;
  cin>>n>>x;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i],x-=a[i];
  sort(a.begin(),a.end());
  cout<<n+(x/a[0])<<endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
l = [int(i) for i in input().split()]
  
f = True
for i in l:
  if i % 2 == 0:
    if not (i % 3 == 0 or i % 5 ==0):
      f = False
      break
      
if f:
  print('APPROVED')
else:
  print('DENIED')

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

using namespace std;
class Edge {
public:
    Edge(){};
    Edge(int s, int t, int w) : s {s}, t {t}, w {w} {};
    int s;
    int t;
    int w;
};

class UnionFindTree {
public:
    UnionFindTree(int n) : ps {vector<int>()}, rs {vector<int>(n, 0)} {
        for(int i = 0; i < n; ++i){
            ps.push_back(i);
        }
    };
    void unite(int x, int y){
        int px = find(x);
        int py = find(y);
        if(px == py){
            return;
        }
        if(rs[x] < rs[y]){
            ps[px] = py;
        } else if(rs[y] < rs[x]){
            ps[py] = px;
        } else {
            ps[px] = py;
            ++rs[py];
        }
    };
    int find(int x){
        return (x == ps[x]) ? x : (ps[x] = find(ps[x]));
    };
private:
    vector<int> ps;
    vector<int> rs;
};
int kruskal(int v, vector<Edge> es){
    auto uft = UnionFindTree(v);
    sort(es.begin(), es.end(), [](Edge a, Edge b){
            return a.w < b.w;
         });
    int n = 0;
    int sum = 0;
    for(auto it = es.begin(); it != es.end(); ++it){
        Edge e = *it;
        if(uft.find(e.s) == uft.find(e.t)){
            continue;
        }
        uft.unite(e.s, e.t);
        sum += e.w;
        ++n;
        if(n == v){
            break;
        }
    }
    return sum;
}

int main(){
    int v, e;
    cin >> v >> e;
    auto es = vector<Edge>();
    int s, t, w;
    for(int i = 0; i < e; ++i){
        cin >> s >> t >> w;
        es.push_back(Edge(s, t, w));
    }
    cout << kruskal(v, es) << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define REP(i,first,last) for(int i=first;i<=last;++i)
#define DOW(i,first,last) for(int i=first;i>=last;--i)
using namespace std;
inline int Read()
{
	int x(0),f(1);
	char c(getchar());
	while(c<'0'||'9'<c)
	{
		if(c=='-')
		{
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return f*x;
}
void Write(int x)
{
	if(x<0)
	{
		printf("-");
		x=-x;
	}
	if(9<x)
	{
		Write(x/10);
	}
	putchar(x%10+'0');
}
inline void Writeln(int x)
{
	Write(x);
	puts("");
}
struct Point
{
	double x,y;
	Point(double fx=0,double fy=0)
	{
		x=fx;
		y=fy;
	}
	void Read()
	{
		scanf("%lf%lf",&x,&y);
	}
	void Write(int len=2)
	{
		printf("%.9lf %.9lf",x,y);
	}
	double operator ^(Point const b)const
	{
		return x*b.x+y*b.y;
	}
	double operator |(Point const b)const
	{
		return x*b.y-b.x*y;
	}
	double operator ==(Point const b)const
	{
		return sqrt((x-b.x)*(x-b.x)+(y-b.y)*(y-b.y));
	}
	Point operator *(double const b)const
	{
		return Point(x*b,y*b);
	}
	Point operator +(Point const b)const
	{
		return Point(x+b.x,y+b.y);
	}
	Point operator -(Point const b)const
	{
		return Point(x-b.x,y-b.y);
	}
};
Point Symmetrical(Point a,Point m=Point(0,0))
{
	return Point(m.x*2-a.x,m.y*2-a.y);
}
/**
 *      /
 *   a /
 *    m
 *   / b
 */
struct Vector
{
	Point a,b;
	Vector(Point f=Point(0,0),Point e=Point(0,0))
	{
		a=f;
		b=e;
	}
	double operator ^(Vector const c)const
	{
		return (a.x-b.x)*(c.a.x-c.b.x)+(c.a.y-c.b.y)*(a.y-b.y);
	}
	double operator |(Vector const c)const
	{
		return (a.x-b.x)*(c.a.y-c.b.y)-(c.a.x-c.b.x)*(a.y-b.y);
	}
};
Point p0,p1,p2;
const int MAXN=1e5+5;
void Work()
{
	p0.Read();
	double b=Vector(p1,p0)^Vector(p1,p2);
	double c=b;
	b/=(p1==p2)*(p1==p2);
	Point answer=(p2-p1)*b+p1;
	Symmetrical(p0,answer).Write();
	puts("");
}
int main()
{
	p1.Read();
	p2.Read();
	int q;
	scanf("%d",&q);
	REP(i,1,q)
	{
		Work();
	}
	return 0;
}


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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};

ll gcd(ll p, ll q){
    if(q==0) return p;
    else return gcd(q, p%q);
}

int main() {
    string s;
    cin >> s;
    ll a = 0, ad = 0;
    for(auto c : s){
        if(c == '(') break;
        else if(c == '.') ad = 1;
        else{
            a = a*10 + c-'0';
            ad *= 10;
        }
    }
    if(s.find('(') != s.npos){
        ll b = 0, bd = 1;
        bool f = false;
        for(int i=s.find('.')+1;s[i]!=')';i++){
            if(s[i] == '(') f = true;
            else{
                if(f) b = b*10+s[i]-'0';
                bd *= 10;
            }
        }
        int l = s.find(')')-s.find('(')-1;
        b *= pow(10,l);
        bd *= (ll(pow(10,l))-1);
        ll gb = gcd(b, bd);
        b /= gb;
        bd /= gb;
        a = a*bd + b*ad;
        ad *= bd;
    }
    ll ga = gcd(a, ad);
    a /= ga;
    ad /= ga;
    cout << a << "/" << ad << endl;
    return 0;
}



Measured memory_bytes: 3364
#include<bits/stdc++.h>
#define int long long
using namespace std;



int32_t main(){
	
	int a;cin>>a;
	int x=1;
	if(a%2==0){
		x=a/2;
		x*=(a-1);
	}
	else{
		x=(a-1)/2;
		x*=a;
	}
	cout<<x<<endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		int h = sc.nextInt();
		int s = sc.nextInt();
		int d = sc.nextInt();
		long n = sc.nextLong() * 4;
		sc.close();

		Tea[] arr = new Tea[4];
		arr[0] = new Tea(q, 1);
		arr[1] = new Tea(h, 2);
		arr[2] = new Tea(s, 4);
		arr[3] = new Tea(d, 8);
		Arrays.parallelSort(arr);

		long ans = 0;
		int i = 0;
		while (n > 0) {
			long a = n / arr[i].m;
			ans += arr[i].p * a;
			n %= arr[i].m;
			i++;
		}
		System.out.println(ans);
	}

	static class Tea implements Comparable<Tea> {
		int p, m;

		public Tea(int p, int m) {
			this.p = p;
			this.m = m;
		}

		public int compareTo(Tea o) {
			return p * 8 / m - o.p * 8 / o.m;
		}
	}
}


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

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

    string s;
    cin >> s;
    
    long sum = 0;

    long cr = 0, cg = 0, cb = 0;
    for (int i = 0; i < s.size(); i++){
        if (s.at(i) == 'R'){
            cr++;
        }
        else if (s.at(i) == 'G'){
            cg++;
        }
        else{
            cb++;
        }
    }    
    sum = cr * cg * cb;

    for (int i = 1; i <= n; i++){
        for (int j = 0; j <= n; j++){
            if (j - i < 0 || j + i >= n){
                continue;
            }
            if (s.at(j - i) != s.at(j) && s.at(j - i) != s.at(j + i) && s.at(j) != s.at(j + i)){
                sum--;
            }
        }
    }

cout << sum << endl;
}


Measured memory_bytes: 3632
N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
li = [[] for _ in range(N)]
for i in range(M):
    for ma in s[i]:
        li[ma - 1].append(i)
ans = 0
for i in range(2 ** N):
    l = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            for r in li[j]:
                l[r] ^= 1
    if l == p:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int n;
	cin >> n;
	int cur = 0;
	int maxi = 0;
	rep(i, n) {
		int x, y;
		cin >> x >> y;
		if (x == y) cur++;
		else cur = 0;
		chmax(maxi, cur);
	}
	puts(maxi >= 3 ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3632
N , M = map(int,input().split())

Lmax = 0
Rmin = 10**5 + 1

for i in range(M) :
    L , R = map(int,input().split())

    Lmax = max(Lmax,L)
    Rmin = min(Rmin,R)


if Lmax <= Rmin :
    print(int(Rmin - Lmax + 1))
else :
    print(0)

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

int main(){

    int N;
    cin >> N;

    int d[N];
    for(auto& temp:d){
        cin >> temp;
    }

    int sum=0;

    for (size_t i = 0; i < N; i++)
    {
        for (size_t j = 0; j < N; j++)
        if(i!=j)sum+=d[i]*d[j];
    }
    
    cout << sum/2 <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main() {
  int a,b,q;cin>>a>>b>>q;int s[100000], t[100000];rep(i,a)cin>>s[i];rep(i,b)cin>>t[i];
  rep(i,q){
    int x;cin>>x;
    auto itrs = lower_bound(s,s+a,x), itrt = lower_bound(t,t+b,x);
    int ps = *(itrs-1), ns = *itrs, pt = *(itrt-1), nt = *itrt;
    //cout << ps << " " << ns << " " << pt << " " << nt << endl;
    int ans = 1000000000000;
    if(itrs-s && itrt-t)ans = min(ans,max(abs(ps-x),abs(pt-x)));
    if(itrs != s+a && itrt != t+b)ans = min(ans,max(abs(ns-x),abs(nt-x)));
    if(itrs-s && itrt != t+b)ans = min(ans,abs(ps-x) * 2 + abs(nt-x));
    if(itrs-s && itrt != t+b)ans = min(ans,abs(ps-x) + abs(nt-x) * 2);
    if(itrs != s+a && itrt-t)ans = min(ans,abs(ns-x) * 2 + abs(pt-x));
    if(itrs != s+a && itrt-t)ans = min(ans,abs(ns-x) + abs(pt-x) * 2);
    cout << ans << endl;
  }
}


Measured memory_bytes: 2816
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int main() {
        map<int, int> m;
        int a;
        for (int i = 0; i < 3; i++) {
                cin >> a;
                m[a]++;
        }
        cout << m.size() << endl;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int r,c;
	cin >> r >> c;
	int a[r+1][c+1];
	for(int i=0;i<r;i++){
		int b = 0;
		for(int j=0;j<c;j++){
			cin >> a[i][j];
			b += a[i][j];
		}
		a[i][c] = b;
	}
	for(int j=0;j<=c;j++){
		int b = 0;
		for(int i=0;i<r;i++) b += a[i][j];
		a[r][j] = b;
	}
	for(int i=0;i<=r;i++){
		for(int j=0;j<c;j++) cout << a[i][j] << " ";
		cout  << a[i][c] << endl;
	}
}

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


int main() {
	char s;
	cin >> s;
	if (s == 'A')cout << 'T';
	else if (s == 'T') cout << 'A';
	else if (s == 'C')cout << 'G';
	else cout << 'C';
	return 0;

}


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

int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    long long ans = 0;
    vector<long long> rec;
    char last = s[0];
    long long num = 1;
    for(int i = 1; i < n; i++){
        if(s[i] == last){
            num++;
        }else{
            rec.push_back(num);
            num = 1;
            last = s[i];
        }
    }
    rec.push_back(num);

    if(rec.size() == 1){
        cout << rec[0] * k / 2 << endl;
        return 0;
    }

    for(int t : rec) ans += t/2;
    ans *= k;

    if(s[0] == s[n-1]){
        long long a = rec[0];
        long long b = rec[rec.size()-1];
        ans -= (k-1) * (a/2 + b/2 - (a+b)/2);
    }

    cout << ans << endl;
}

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

// 基本テンプレート
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// 型
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// 定数
#pragma region CONST_VAL
constexpr int PI = (2*acos(0.0));
constexpr int EPS = (1e-9);
constexpr int MOD = (int)(1e9+7);
constexpr int INF = 100000000;
#pragma endregion

#define int long long


signed main()
{
    int n;
    cin >> n;
    int res = 0;
    while(n--) {
        int a;
        cin >>a;
        if(a%2==1) res++;
    }
    if(res%2==1) cout << "NO" << endl;
    else cout << "YES" << endl;

    return 0;
}



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

Measured memory_bytes: 256
comp = 0
def m(L, R):
    global comp
    j = 0
    for l in L:
        while j < len(R) and R[j] < l:
            yield R[j]
            j += 1
        yield l
    while j < len(R):
        yield R[j]
        j += 1
    comp += len(L) + len(R)
def merge(A):
    global comp
    if len(A) == 1:
        return A
    if len(A) == 2:
        comp += 2
        a, b = A
        return A if a < b else (b, a)
    mid = len(A) // 2
    A[:] = m(merge(A[:mid]), merge(A[mid:]))
    return A

n, *A = map(int, open(0).read().split())
B = merge(A)
print(*B)
print(comp)

Measured memory_bytes: 63012
class FordFulkerson
  class Edge
    attr_accessor :to, :cap, :rev
    def initialize(to, cap, rev)
      @to, @cap, @rev, @pos = to, cap, rev
    end
  end

  def initialize(n)
    @N = n
    @g = Array.new(n) {[]} # 隣接リスト表現
    @used = Array.new(n) # dfsですでに調べたかのフラグ
  end
  
  def add_edge(from, to, cap)
    @g[from] << Edge.new(to, cap, @g[to].size)
    @g[to] << Edge.new(from, 0, @g[from].size-1)
  end

  def dfs(v, t, f) # v: 調べる始点, t: 終点, f:
    return f if v == t
    @used[v] = true
    @g[v].size.times do |i| # vから行ける各点について
      edge = @g[v][i] # vから伸びてるある辺
      if !@used[edge.to] && edge.cap > 0
        d = dfs(edge.to, t, [f, edge.cap].min)
        if d > 0
          edge.cap -= d # d流す（残容量をd減らす）
          @g[edge.to][edge.rev].cap += d
          return d
        end
      end
    end
    return 0
  end

  def max_flow(s, t)
    flow = 0
    while true
      @used = Array.new(@N)
      f = dfs(s, t, 10**10) # inf
      return flow if f == 0
      flow += f
    end
  end
end


N = gets.to_i
g = FordFulkerson.new(2*N+2)
s = 2*N
t = s + 1

red = {}
blue = {}

N.times do |i|
  g.add_edge(s, i, 1)
  red[i] = gets.split.map(&:to_i)
end
N.times do |i|
  g.add_edge(N+i, t, 1)
  blue[N+i] = gets.split.map(&:to_i)
end
N.times do |i|
  N.times do |j|
    if red[i][0] < blue[N+j][0] && red[i][1] < blue[N+j][1]
      g.add_edge(i, N+j, 1)
    end
  end
end

puts g.max_flow(s, t)

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

int main(){
  int W, H, x, y, r;

  cin >> W >> H >> x >> y >> r;

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

  return 0;
}



Measured memory_bytes: 3100
import sys
import itertools
input = sys.stdin.readline

S = list(input().strip())
T = list(input().strip())
s = set()

for i in range(len(S) - len(T) + 1):
    p = S[i:i+len(T)]
    f = True
    for j in range(len(T)):
        if p[j] != T[j] and p[j] != "?":
            f = False
        
    if f:
        s.add("".join(S[0:i] + T + S[i+len(T):]))

    if p == ["?"] * len(T):
        s.add("".join(S[0:i] + T + S[i+len(T):]))
        
if len(s) == 0:
    print("UNRESTORABLE")
else:
    l = list(s)
    for i in range(len(s)):
        l[i] = l[i].replace("?", "a")
        
    l.sort()
    print(l[0])

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

typedef long long ll;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  std::vector< ll > va(3);
  std::cin >> va[0] >> va[1] >> va[2];

  std::sort(va.begin(), va.end());

  ll ans = 0;
  if (va[0] % 2 == 0 || va[1] % 2 == 0 || va[2] % 2 == 0) {
    ans = 0;
  } else {
    ans = va[0] * va[1];
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll ar[M];
map<ll,ll> mp;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll i,n,ans = 0;
	cin >> n;
	for(i=1;i<=n;++i)
		cin >> ar[i];
	for(i=1;i<=n;++i)
	{
		ans += mp[i-ar[i]];
		mp[ar[i]+i]++;
	}
	cout << ans << endl;
}

	

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

using namespace std;

#define LOG(...) fprintf(stderr, __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(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

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 N = 123456 * 2;
bool sieve[N + 1];
int number[N + 1];

int main() {
  int cnt = 0;
  FOR(i, 2, N + 1){
    number[i] = cnt;
    if (sieve[i]) continue;
    number[i] = ++cnt;
    for(int j = i * 2; j < N  + 1; j += i) {
      sieve[j] = true;
    }
  }

  int n;
  while(cin >> n, n) {
    cout << number[2 * n] - number[n] << endl;
  }
}

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

int main () {
  int i, N, judge=0;
  
  cin >> N;
  
  rep(i,N/7+1){
    if((N-7*i)%4==0) {
      judge=1;
      break;
    }
  }
  
  if(judge) cout << "Yes";
  else cout << "No";
}






Measured memory_bytes: 3596
#include<stdio.h>	
int main(void)
{
	int k,a,b,c,d;
	scanf("%d %d %d",&k,&a,&b);
	c=0;
	while(1){
		c=k*d;
		d++;
		if(c>b) {
			printf("NG\n");
			break;
		}
		else if(c>=a&&c<=b){
			printf("OK\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1624
import sys
sys.setrecursionlimit(10**6)


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def main(input, print):
    n = int(input())
    ans = 0
    ret = factorization(n)
    if ret[0][0] == 1:
        print('0')
        return
    for i in range(len(ret)):
        cnt = 0
        while ret[i][1] > 0:
            cnt += 1
            ret[i][1] -= cnt
            ans += 1
        if ret[i][1] < 0:
            ans -= 1

    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 63504
inpl = lambda: list(map(int,input().split()))

H, W = inpl()
A = []
for _ in range(H):
    A.append(inpl())

def pos(n):
    q, m = divmod(n, W)
    if q % 2:
        m = (W-1) - m
    return q, m

ans = []
f = 0
hn, wn = 0, 0
for n in range(H*W-1):
    h, w = hn, wn
    hn, wn = pos(n+1)
    if (f+A[h][w]) % 2:
        ans.append([h+1,w+1,hn+1,wn+1])
        f = 1
    else:
        f = 0

print(len(ans))
for rec in ans:
    print(rec[0],rec[1],rec[2],rec[3])

Measured memory_bytes: 30284
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define int long long
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
    const int MAX =200005;
const int MOD =1000000007;

signed main(){
  int n;
  cin>>n;
  pair<int,int> p[n];
  int x,y[n];
  for(int i=0;i<n;i++){
    cin>>x>>y[i];x--;y[i]--;
    p[i]={x,y[i]};
  }
  sort(p,p+n);
  dsu d(n);
  priority_queue<int,vector<int>,greater<int>> que;
  bool used[n]={};
  for(int i=0;i<n;i++){
    while(!que.empty()&&que.top()<p[i].second){
        int j=que.top();
        que.pop();
        cerr<<j<<' '<<i<<endl;
        while(!used[j]&&j<p[i].second){
          used[j]=true;
          d.merge(j,j+1);
          j++;
        }
    }
    que.push(p[i].second);
  }
  for(int i=0;i<n;i++)cout<<d.size(y[i])<<endl;
}


Measured memory_bytes: 10036
function Main(input){
  const Input = input.split(" ");
  const long = Input[0];
  const time = Input[1];
  const speed = Input[2];
  
  if(long / speed <= time){
    console.log("Yes");
  }
  else{
    console.log("No");
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,m;
  scanf("%lld %lld",&n,&m);
  struct edge{
    Int from,to,cost;
    edge(Int from,Int to,Int cost):from(from),to(to),cost(cost){}    
  };
  vector<edge> es,v;
  vector<char> ss;
  for(Int i=1;i<n;i++){
    // p[0] <= p[i]
    // p[0] - p[i] <= 0
    es.emplace_back(i,0,0);
  }
  for(Int i=0;i<m;i++){
    Int a,b,d;
    char c,s;
    scanf("%lld%c",&a,&c);
    if(c!='*') scanf("=");
    scanf("%lld%c%lld",&b,&s,&d);
    //cout<<a<<" "<<c<<" "<<b<<" "<<s<<" "<<d<<endl;
    a--;b--;
    if(c=='>') swap(a,b);
    if(c=='*'){
      v.emplace_back(a,b,d);
      ss.emplace_back(s);
      continue;
    }
    // p[a] <= p[b]
    // p[a] - p[b] <= 0
    es.emplace_back(b,a,0);
    if(s=='+'){
      // p[a] + d <= p[b]
      // p[a] - p[b] <= -d 
      es.emplace_back(b,a,-d);
    }else{
      // p[a] + d >= p[b]
      // p[b] - p[a] <= d	
      es.emplace_back(a,b,d);
    }
  }
  const Int INF = 1e15;
  auto calc=
    [&]()->Int{
      vector<Int> dp(n,INF);
      dp[0]=0;
      Int flg=0;
      for(Int i=0;i<n*3;i++){
	flg=0;
	for(auto e:es){
	  if(dp[e.from]+e.cost<dp[e.to]){
	    dp[e.to]=dp[e.from]+e.cost;
	    flg=1;
	  }	     
	}
      }
      if(flg) return -1;
      Int res=0;
      for(Int i=0;i<n;i++) chmax(res,dp[i]);
      return res;
    };
  Int ans=-1;
  
  Int k=v.size();
  for(Int bit=0;bit<(1<<k);bit++){
    for(Int i=0;i<k;i++){
      Int a=v[i].from,b=v[i].to,d=v[i].cost;
      char s=ss[i];
      if((bit>>i)&1) swap(a,b);
      es.emplace_back(b,a,0);
      if(s=='+'){
	// p[a] + d <= p[b]
	// p[a] - p[b] <= -d 
	es.emplace_back(b,a,-d);
      }else{
	// p[a] + d >= p[b]
	// p[b] - p[a] <= d	
	es.emplace_back(a,b,d);
      }
    }
    chmax(ans,calc());
    for(Int i=0;i<k;i++){
      es.pop_back();      
      es.pop_back();
    }
  }
  if(ans==INF) puts("inf");
  else printf("%lld\n",ans);
  return 0;
}



Measured memory_bytes: 3304
#include<iostream>
using namespace std;
int n,a[10000],q,r1,r2,sum;
int main(){
	cin>>n;for(int i=1;i<=n;i++){cin>>a[i];sum+=a[i];}
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>r1>>r2;cout<<sum+(r2-a[r1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<algorithm>
using namespace std;
int a[4];
int ans=0;
int main()
{
	for(int i=1;i<=3;i++)scanf("%d",a+i);
	sort(a+1,a+4);
	ans=a[3]-a[1];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int k=0,n=0,sum=0,max=0,temp=0,sub=0;
    int array[200001]={};

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

    for(int i=0;i<n;i++){
        sub=array[i+1]-array[i];
        sum+=sub;
        if(sub>max){
            max=sub;
            temp=i;
        }
    }
    sum-=array[temp+1]-array[temp];

    printf("%d",sum);

    return 0;
}


Measured memory_bytes: 2516
import collections

N = int(input())
A = list(map(int, input().split()))
A = collections.Counter(A)
B = []
C = []
for i in A:
    if A[i] == 1:
        B.append(i)
    else:
        C.append(i)
B = sorted(B)
if len(B) == 0:
    print(0)
    exit()
mb = 1000000
ok = [True] * (mb+1)

if len(C) > 0:
    C = sorted(C)
    for c in C:
        if not ok[c]:
            continue
        k = 2
        while k*c <= mb:
            ok[k*c] = False
            k += 1

for b in B:
    if not ok[b]:
        continue
    k = 2
    while k*b <= mb:
        ok[k*b] = False
        k += 1

ans = 0
for b in B:
    if ok[b]:
        ans += 1

print(ans)


Measured memory_bytes: 40448
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#define LL long long
using namespace std;

int a, b, c;

int main() 
{
	cin >> a >> b >> c;
	for(int i = 1; i <= b; i++)
		if(a * i % b == c)
		{
			cout << "YES" << endl;
			return 0;
		}
	cout << "NO" << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <sstream>
#include <string>
using namespace std;
typedef long long lint;
int cn[20];
int main()
{
	lint L;
	while(cin>>L,L){
		int k = 0;
		for(int i = 2; (lint)i*i <= L; i++){
			if(L%i == 0){
				cn[k] = 0;
				while(L%i == 0){
					L /= i;
					cn[k]++;
				}
				k++;
			}
		}
		if(L>1) cn[k++] = 1;
		lint ans = 1;
		for(int i = 0; i < k; i++){
			ans *= (2*cn[i]+1);
		}
		cout<<(ans/2+1)<<endl;
	}
	return 0;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll> T;
long long euclid(long long x,long long y){
    long long a=max(x,y);
    long long b=min(x,y);
    if(a%b==0)return b;
    else{
        return euclid(b,a%b);
    }
}
long long ruijou(long long x, long long y){
    if(y==0) return 1;
    else if(y%2==0) return ruijou(x*x%mod,y/2);
    else return x*ruijou(x,y-1)%mod;
}


ll i,j,k;

int main(){
   ll N;
   cin>>N;
   ll ans=0;
   for(ll i=2;i*i<=N;i++){
       
       if(N%i==0){
           ll cnt=0;
           

           while(N%i==0){
               N/=i;
               cnt++;
           }
           ll kotae=(-1+sqrt(1+8*cnt))/2;
           ans+=kotae;
       }
   }
   if(N!=1)ans++;
   cout<<ans<<endl;
}

Measured memory_bytes: 3676
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
#include <numeric>
typedef long long ll;
using namespace std;

int main(void){
  const ll BIG = 1LL << 60;

  int n, i;
  cin >> n;
  n++;

  if(n==1){
    ll x;
    cin >> x;
    if(x==1){
      cout << 1 << endl;
    }
    else{
      cout << -1 << endl;
    }
    return 0;
  }

  vector<ll> a(n), max(n);
  for(i=0;i<n;i++){
    cin >> a[i];
  }

  max[0] = 1;
  if(a[0]!=0){
    cout << -1 << endl;
    return 0;
  }
  for(i=1;i<n-1;i++){
    max[i] = max[i-1] * 2 - a[i];
    if(max[i]<1){
      cout << -1 << endl;
      return 0;
    }
    if(max[i]>BIG) max[i] = BIG;
  }
  max[n-1] = max[n-2] * 2 - a[n-1];
  if(max[n-1]<0){
    cout << -1 << endl;
    return 0;
  }

  ll tmp = a[n-1], ans = a[n-1];
  for(i=n-2;i>0;i--){
    if(max[i]<tmp){
      tmp = max[i] + a[i];
      ans += tmp;
    }
    else{
      tmp = tmp + a[i];
      ans += tmp;
    }
  }
  ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4792
n=int(input())
h=list(map(int,input().split()))
ans=0
temp=[0]*n
while True:
  a=0
  b=1
  cnt=1
  for i in range(n):
    if h[i]!=temp[i]:
      temp[i]=temp[i]+1
      a=1
      b=0
    elif a==1:
      cnt=cnt+1
      a=0
      b=1
  if b==1:
    cnt=cnt-1
  ans=ans+cnt
  if sum(temp)==sum(h):
    break
print(ans)

Measured memory_bytes: 3064