akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

constexpr int MAX=25;
constexpr int NIL=-1;

struct Node{
   int left;
   int right;  
   int parent;
};

Node node[MAX];
int dep[MAX], height[MAX];

void setdepth(int u, int d){
   if(u==NIL) return;
   dep[u]=d;
   setdepth(node[u].left, d+1);
   setdepth(node[u].right, d+1);
}

int setheight(int u){
   int h1=0, h2=0;
   if(node[u].left!=NIL)
      h1=setheight(node[u].left) + 1;
   if(node[u].right!=NIL)
      h2=setheight(node[u].right) + 1;
   return height[u]=(h1 > h2 ? h1:h2);
}

int getsibling(int u){
   if(node[u].parent==NIL) return NIL;
   if(node[node[u].parent].left!=u && node[node[u].parent].left!=NIL) 
      return node[node[u].parent].left;
   if(node[node[u].parent].right!=u && node[node[u].parent].right!=NIL) 
      return node[node[u].parent].right;
   return NIL;
}

int main(){
   int n;
   int id, left, right;
   cin >> n;
   for(int i=0; i<n; i++) node[i].left=node[i].right=node[i].parent=NIL;
   for(int i=0; i<n; i++){
      cin >> id >> left >> right;
      node[id].left=left;
      node[id].right=right;
      if(left!=NIL) node[left].parent=id;
      if(right!=NIL) node[right].parent=id;
   }

   int root;
   for(int i=0; i<n; i++) if(node[i].parent==NIL) root=i;
   
   setdepth(root, 0);
   setheight(root);

   for(int i=0; i<n; i++){
      cout << "node " << i << ": ";
      cout << "parent = " << node[i].parent << ", ";
      cout << "sibling = " << getsibling(i) << ", ";
      cout << "degree = ";
      int deg=0;
      if(node[i].left!=NIL) deg++;
      if(node[i].right!=NIL) deg++;
      cout << deg;
      cout << ", ";
      cout << "depth = " << dep[i] << ", ";
      cout << "height = " << height[i] << ", ";
      if(node[i].parent==NIL) cout << "root" << endl;
      else if(node[i].left==NIL && node[i].right==NIL)
         cout << "leaf" << endl;
      else cout << "internal node" << endl;
   }
}


Measured memory_bytes: 3116
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String judge = "OK";
    int N = sc.nextInt();
    for(int i = 0;i < N;i++){
      int A = sc.nextInt();

      if(A % 2 == 0){
        if(A % 3 == 0){
          judge = "OK";
        }else if(A % 5 == 0){
          judge = "OK";
        }else {
          judge = "NG";
          break;
        }
      }
    }
    if(judge == "OK"){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");}
  }
}

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

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

    vector<int>dl(10);
    rep(i,0,k){
        int d;
        cin>>d;
        dl[d]++;
    }

    for (int i=n;i<100000;i++) {
        int x=i;
        bool jdg=true;
        while(x>0){
            if(dl[x%10]==1){
                jdg=false;
            }
            if(jdg==false){
                break;
            }
            x/=10;
        }
        if(jdg){
            cout<<i<<endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

int N, M;
vector<int> a(51, 0), b(51, 0), c(51, 0), d(51, 0);

int main(void){
    
    scanf("%d %d", &N, &M);
    for(int i = 0; i < N; ++i) scanf("%d %d", &a[i], &b[i]);
    for(int i = 0; i < M; ++i) scanf("%d %d", &c[i], &d[i]);
    
    for(int i = 0; i < N; ++i){
        int dist = INT_MAX, num = 0;
        for(int j = 0; j < M; ++j){
            int mat = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dist > mat) dist = mat, num = j + 1; 
        }
        printf("%d\n", num);
    }
    
    return 0;
}

Measured memory_bytes: 256
def solve(n, c, k, t):
    t = list(sorted(t))
    ans = 0
    i = 0
    while i < n:
        num = 0
        threshold = t[i] + k
        while (i < n) and (t[i] <= threshold) and (num < c):
            num += 1
            i += 1
        ans += 1
    return ans

n, c, k = map(int, input().split())
t = [int(input()) for i in range(n)]
print(solve(n, c, k, t))

Measured memory_bytes: 8664
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef struct point
{
    int x,y;
    bool operator < (const struct point & t)const
    {
        return x==t.x?y<t.y:x<t.x;
    }
}POINT,*PPOINT;
POINT a[200002];
int h,w;
long long f[200002],inv[200002],fac[200002];
void init()
{
    int i;
    fac[0]=fac[1]=inv[0]=inv[1]=1;
    for(i=2;i<=h+w-2;i++)
        inv[i]=-MOD/i*inv[MOD%i]%MOD;
    for(i=2;i<=h+w-2;i++)
    {
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=inv[i-1]*inv[i]%MOD;
    }
}
long long C(int n,int m)
{
    return fac[n]*inv[n-m]%MOD*inv[m]%MOD;
}
int main()
{
    int n,i,j;
    scanf("%d%d%d",&h,&w,&n);
    for(i=0;i<n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    a[n].x=h;
    a[n].y=w;
    sort(a,a+n+1);
    init();
    for(i=0;i<=n;i++)
    {
        f[i]=C(a[i].x+a[i].y-2,a[i].x-1);
        //printf("%lld\n",f[i]);
        for(j=0;j<i;j++)
        {
            if(a[j].y<=a[i].y)
                f[i]=f[i]-f[j]*C(a[i].x-a[j].x+a[i].y-a[j].y,a[i].x-a[j].x)%MOD;
        }
        f[i]=(f[i]+MOD)%MOD;
    }
    printf("%lld",(f[n]+MOD)%MOD);
    return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
int main() {
    int N, K, tmp, min_cost;
    cin >> N >> K;
    vector<int> h(N), dp(N, 0);
    rep(i, N) cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    rep2(i, 2, N){
        min_cost = 999999999;
        rep2(j, 1, min(i, K)+1){
            tmp = dp[i-j] + abs(h[i] - h[i-j]);
            min_cost = min(min_cost, tmp);
        }
        dp[i] = min_cost;
    }
    cout << dp[N-1] << endl;
    return 0;
}

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

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

int main() {
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int ans=0;
	for(int i=0;i<=a;++i){
		for(int j=0;j<=b;++j){
			for(int k=0;k<=c;++k){
				int total=500*i+100*j+50*k;
				if(total==x)++ans;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
X,N=list(map(int,input().split()))
P=list(map(int,input().split()))
if not X in P:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    if not A in P:
        print(A)
        sys.exit()
    if not B in P:
        print(B)
        sys.exit()

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
int main()
{
    fast;
    map<long long ,long long> m;
    long long n;
    cin>>n;
    long long sum=0;
    for(long long i=0;i<n;i++)
    {
        long long a;
        cin>>a;
        sum+=a;
        m[a]++;
    }
    long long q;
    cin>>q;
    while(q--)
    {
        long long b,c;
        cin>>b>>c;
        long long diff=m[b];
        m[b]=0;
        m[c]+=diff;
        sum-=diff*b;
        sum+=diff*c;
            cout<<sum<<'\n';
    }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

template<class T>
class SegmentTree {

public:
    /**
     * @param N size
     * @param e identity element
     * @param operation operation for query
     * @param updater operation for update
     */
    SegmentTree(size_t N, T e, function<T(T, T)> operation, function<T(T, T)> updater)
            : e(e), operation(std::move(operation)), updater(move(updater)) {
        n = 1;
        while (n < N) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, e);
    }

    /**
     * iの値をxに更新
     * @param i index ( 0-indexed )
     * @param x  value
     */
    void update(int i, T x) {
        i += n - 1;
        data[i] = updater(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    /**
     * [a, b)の区間でクエリを実行
     */
    T query(int a, int b) {
        return query(a, b, 0, 0, n);
    }

    /**
     * 添字でアクセス
     * @param i index ( 0-indexed )
     */
    T operator[](int i) {
        return data[i + n - 1];
    }

private:
    int n;
    vector<T> data;
    T e;
    function<T(T, T)> operation;
    function<T(T, T)> updater;

    T query(int a, int b, int k, int l, int r) {
        // 交差しない
        if (r <= a || b <= l) return e;
        // 区間 [a, b) に l, r が含まれる
        if (a <= l && r <= b) return data[k];
        // 左の子
        T c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
        // 右の子
        T c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return operation(c1, c2);
    }
};

void Main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> items;
    rep(i, M) {
        ll l, r, c;
        cin >> l >> r >> c;
        l--;
        r--;
        items.push_back(vector<ll>{l, r, c});
    }
    sort(items.begin(), items.end());
    SegmentTree<ll> segmentTree(N + 1, INF, [](ll a, ll b) { return min(a, b); }, [](ll a, ll b) { return min(a, b); });
    vector<ll> dp(N + 1, INF);

    dp[0] = 0;
    segmentTree.update(0, 0);
    rep(i, M) {
        ll l = items[i][0];
        ll r = items[i][1];
        ll c = items[i][2];
        ll tmp = segmentTree.query(l, r) + c;
        dp[r] = min(dp[r], tmp);
        segmentTree.update(r, dp[r]);
    }
    ll ans = dp[N - 1];
    if (ans == INF) {
        cout << -1 << '\n';
    } else {
        cout << ans << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 8752
#include<stdio.h>
int abs(int n)
{
	if (n < 0)
		n *= -1;
	return n;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	int t[100005], x[100005], y[100005];
	for (i = 1; i <= n; i++)
		scanf("%d %d %d", &t[i], &x[i], &y[i]);
	t[0] = x[0] = y[0] = 0;
	int dt, dx, dy;
	for (i = 0; i < n; i++)
	{
		dt = t[i + 1] - t[i];
		dx = abs(x[i] - x[i + 1]);
		dy = abs(y[i] - y[i + 1]);
		if (dt < dx + dy)
		{
			printf("No\n");
			return 0;
		}
		if ((dt - dx - dy) % 2 > 0)
		{
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

void solve(int n, int prev, const string &str){
  if(n == 0){
    puts(str.c_str());
    return;
  }
  for(int i=0; i < n; i++){
    if(n - i > prev) continue;
    char buff[8];
    sprintf(buff, "%d", n-i);
    string spc = (str == "" ? "" : " ");
    string tmp = str + spc + string(buff);
    solve(i, n-i, tmp);
  }
}

int main(){
  int n;
  string s;
  while(scanf("%d",&n),n)
    solve(n,INT_MAX,s);
  return 0;
}

Measured memory_bytes: 940
#include <stdio.h>

int a,b;

int main () 
{
	scanf("%d %d",&a,&b);
	while (a!=0||b!=0)
	{
		for (int i=1;i<=a;i++)
		{
			for (int j=1;j<=b;j++)
			{
				if (i==1||i==a||j==1||j==b)
				{
					printf("#");
				} else 
				{
					printf(".");	
				}
			}
			printf("\n");
		}
		scanf("%d %d",&a,&b);
		printf ("\n");	
	}
}


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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

int main() {
    ll num[10][10] = {};
    ll N;
    cin >> N;
    ll po = 1;
    REP(i,1,N+1) {
        if(i%(po*10)==0) po*=10;
        num[i/po][i%10]++;
    }
    ll ans = 0;
    REP(i,1,10){
        REP(j,1,10){
            ans += num[i][j] * num[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = min(b-1, n);
  int ans = (a*x/b) - a*(x/b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3596
kab = gets.split(" ").map{|a|a.to_i}
k = kab[0]
a = kab[1]
b = kab[2]
if a+2 >= b then
answer = 1+k
elsif a+1 > k then
  answer = 1+k
elsif (k-a-1)%2==0 then
  answer = b+((k-a-1)/2)*(b-a)
elsif (k-a-1)%2==1 then
  answer = b+((k-a-2)/2)*(b-a)+1
end
puts answer


Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int N;
    std::cin >> N;
    
    double d = 0.0;
    for (int i = 0; i < N; i++) {
        int p;
        std::cin >> p;
        d += 1.0 / p;
    }
    
    std::cout << std::fixed << std::setprecision(5) << 1.0 / d << std::endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(void)
{
    int i, cnt;
    char w[11], s[1001];
    scanf("%s", w);
    cnt = 0;
    while (1) {
        scanf("%s", s);
        
        if ( strcmp(s, "END_OF_TEXT") == 0)
            break;
        
        for(i = 0; s[i] != '\0'; i++)
            s[i] = tolower(s[i]);

        if ( strcmp(s, w) == 0)
            ++cnt;
    }
    printf("%d\n", cnt);
    
    return 0;
}


Measured memory_bytes: 2096
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int count = 0;
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		for(int i = a;i <= b;i++)
		{
			if(c%i==0)
			{
				count+=1;
			}
		}
		System.out.println(count);
	}
}



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

int main(){
  int N;
  cin >> N;
  
  vector<int> L(N);
  for (int i = 0 ; i < N; i++) cin >> L.at(i);
  
  sort(L.begin(), L.end());
  long cnt = 0; int k = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      k = lower_bound(L.begin(), L.end(), L.at(i) + L.at(j)) - L.begin();
  cnt += max(k - (j + 1), 0);
    }
  }
  cout << cnt;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;class Main {
    public void yatary() {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt(); 
        int W = sc.nextInt();
        int H2 = H; 
        int W2 = W;   
        int H3 = H - 2;
        while(H != 0 || W != 0){ 
            while(0 < H){ 
                if(H == 1 || H == H2){
                    for(int i = 1; i <= W; i++){
                        System.out.print("#");
                    } 
                    System.out.println(); 
                }else{
                    while(0 < H3){ 
                        System.out.print("#");
                        for(int i = 1; i <= W2 - 2; i++){ 
                            System.out.print("."); 
                        } 
                        System.out.println("#");
                        H3--;  
                    }  
                }  
                H--;   
            }     
            System.out.println(); 
            H = sc.nextInt(); 
            W = sc.nextInt();
            H2 = H;     
            W2 = W;     
            H3 = H - 2;    
        }      
    }    
    public static void main(String[] args) { 
        new Main().yatary();
    } 
}

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


#define DEFAULTSIZE 1024


int comp_int(const void*a, const void*b)
{
  return *(int*)a-*(int*)b;
}

typedef struct TPair Pair;
struct TPair {
  int fValue;
  int fCount;
};

int comp_pair(const void*a, const void*b)
{
  return ((Pair*)b)->fCount - ((Pair*)a)->fCount;
}


int main(){
  /* The mode value is the element which occurs most frequently */

  int n;
  int *p;
  int used;
  int size;
  int i,j;
  int last;
  int count;
  Pair *q;

  size = DEFAULTSIZE * sizeof(int);

  used = 0;
  p = (int*)malloc(size);

  while(scanf("%d", &n)==1){
    p[used] = n;
    used+=1;
    if(used >= size){
      size = size*2;
      p = (int*)realloc(p, size);
    }
  }
  qsort(p, used, sizeof(int), comp_int);

  q = (Pair*)malloc(sizeof(Pair)*used);

  last = *p;
  count = 1;
  j = 0;
  for(i = 1; i<used; i++){
    if(*(p+i)==last){
      count +=1;
    }else{
      (q+j)->fCount = count;
      (q+j)->fValue = last;
      j++;
      last = *(p+i);
      count = 1;
    }
  }
  (q+j)->fCount = count;
  (q+j)->fValue = last;
  j++;

  qsort(q, j, sizeof(Pair), comp_pair);

  last = q->fValue;
  count = q->fCount;
  for(i=1; i < j ; i++){
    if((q+i)->fCount==count){
      printf("%d\n", last);
      last = (q+i)->fValue;
      count = (q+i)->fCount;
    }else{
      printf("%d\n", last);
      break;
    }
  }

  return 0;
}

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

int main() {
  int a , b;
  cin >> a >> b ;
  int c = a * b ;
  if ( c % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}
template<typename T> bool chmin(T& a, const T& b) {
  if (a > b) return a = b, true; else return false;
}

template<typename T> bool chmax(T& a, const T& b) {
  if (a < b) return a = b, true; else return false;
}


void solve(){
  int N, K, R, S, P;
  cin >> N  >> K >> R >> S >> P;

  string T;
  cin >> T;

  ll score = 0;

  bool get[100000 + 5] = {};
  rep(i, T.size()){
    if(i-K >= 0 && T[i-K] == T[i] && get[i-K])
      continue;
    get[i] = true;
    if(T[i] == 'r')
      score += P;
    else if(T[i] == 's')
      score += R;
    else if(T[i] == 'p')
      score += S;
  }

  cout << score << endl;
}

int main(){
// FastIO
//ios_base::sync_with_stdio(false);
cin.tie(NULL);
  solve();
  return 0;
}

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

void insertionsort(vector<int> &A, int n, int g){
    for (int i=g; i < n; i++){
        int v = A.at(i);
        int j = i - g;
        while (j >= 0 && A.at(j) > v){
            A.at(j+g) = A.at(j);
            j = j - g;
            cnt += 1;
        }
        A.at(j+g) = v;
    }
    return;
}
void shellsort(vector<int> &A, vector<int> &G, int n){
    cnt = 0;
    for (int w=1; ; ){
        if (w > n)break;
        G.push_back(w);
        w = 3*w + 1;
    }
    for (int i=G.size()-1; i >= 0; i--){
        insertionsort(A, n, G.at(i));
    }
    return;
}

int main(){
    int n;
    cin >> n;
    vector<int> G;
    vector<int> Ai(n);
    for (int i=0; i<n; i++){
        cin >> Ai.at(i);
    }
    shellsort(Ai, G, n);
    cout << G.size() << endl;
    for (int j=G.size()-1; j>=0; j--){
        cout << G.at(j);
        if (j != 0) cout << " ";
        else cout << endl;
    }
    cout << cnt << endl;
    for (int i=0; i<n; i++){
        cout << Ai.at(i) << endl;
    }
    return 0;
}


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

using namespace std;

int main(){
    int N,M;
    string S,T;
    cin >> S >> T;
    N = S.size(); M = T.size();
    for(int i = 0 ; i <= N-M ; i++){
        bool ok = 1;
        for(int j = 0 ; j < M ; j++){
            if(T[j] != S[i+j]){
                ok = 0;
                break;
            }
        }
        if(ok){
            cout << i << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1188
<?php
list($n) = ints();
$a = ints();
$l = strlen(decbin(max($a)));
$aor = 0;
for ($i = 0; $i < $n; ++$i) $aor = $aor ^ $a[$i];
for ($i = 0; $i < $n; ++$i) $b[$i] = $a[$i] ^ $aor;
echo implode(' ', $b);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 43300
#include <iostream>
using namespace std;
int main(){
	int i,j,n,m;
	while(cin>>n>>m,n){
		int f=0,q,p[100]={0};
		for(j=n;j--;) for(i=0;i<m;p[i++]+=q)cin>>q;
		for(j=n+1;j--;)for(i=0;i<m;i++) if(p[i]==j)cout<<(f++?" ":"")<<i+1;
		cout<<endl;
	}
}

Measured memory_bytes: 868
from collections import deque
count = 0

def merge(A,left,mid,right):
    L = deque(A[left:mid])
    R = deque(A[mid:right])
    L.append(float("inf"))
    R.append(float("inf"))
    
    global count
    
    for k in range(left,right):
        count +=1
        if L[0] <= R[0]:
            A[k] = L.popleft()
 
        else:
            A[k] = R.popleft()

            
def mergeSort(A,left,right):
    if left + 1 < right:
        middle = (left + right) //2
        mergeSort(A,left,middle)
        mergeSort(A,middle,right)
        merge(A,left,middle,right)
        
input()
l = list(map(int,input().split()))
mergeSort(l,0,len(l))
print(*l)
print(count)            
        

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

int main(){
    string s,t,u;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    cin>>u;
    if(s.compare(u)){
        cout<<a<<" "<<b-1;
    }else if(t.compare(u)){
        cout<<a-1<<" "<<b;
    }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String in =sc.next(); 
		
		int a = Integer.parseInt(in.substring(0, 1));
		int b = Integer.parseInt(in.substring(1, 2));
		int c = Integer.parseInt(in.substring(2, 3));
		
		System.out.println(a+b+c);
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
  int a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  bool ans=true;
  rep(i,0,s.size()){
   if(i<a){
     if(s[i]<'0'||s[i]>'9')ans=0;
   }
   else if(i==a){
    if(s[i]!='-')ans=false; 
   }
    else{
      if(s[i]<'0'||s[i]>'9'){
        ans=0; 
        //cout<<1<<endl;
      }
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#define F first
#define S second
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define all(n) n.begin(),n.end()
using namespace std;
bool used[3010][3010];
static const short dy[] = {0,1,0,-1};
static const short dx[] = {1,0,-1,0};
int h,w;
typedef pair<int,int> P;
 
int main(){
  int n;
  while(true){
    cin >> w >> h;
    if(w+h == 0)break;
    cin >> n;
    int x1[n],x2[n],y1[n],y2[n];
    vector<int> x,y;
    for(int i=0;i<n;i++){
      cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
      x.pb(x1[i]);y.pb(y1[i]);x.pb(x2[i]);y.pb(y2[i]);
    }
    x.pb(0); x.pb(w); y.pb(0); y.pb(h);
     
    sort(all(x)); sort(all(y));
    x.erase(unique(all(x)),x.end()); y.erase(unique(all(y)),y.end());
    
    int limx = x.size(),limy = y.size();
    rep(i,3010)rep(j,3010)used[i][j] = false;
    
    rep(i,n){
      x1[i] = find(all(x),x1[i])-x.begin();
      //cout << "x1[i] = " << x1[i];
      y1[i] = find(all(y),y1[i])-y.begin();
      //cout << ", y1[i] = " << y1[i];
      x2[i] = find(all(x),x2[i])-x.begin();
      //cout << ", x2[i] = " << x2[i];
      y2[i] = find(all(y),y2[i])-y.begin();
      //cout << ", y2[i] = " << y2[i] << endl;
    
    
    }
    int cnt = 0;
    rep(i,limy)rep(j,limx)used[i][j] = i==limy-1||j==limx-1;
    queue<P> que;

    rep(i,n)for(int k=x1[i];k<x2[i];k++){
    for(int j=y1[i];j<y2[i];j++)used[j][k] = true;
      }
     
    rep(i,limy){
      rep(j,limx){
    if(!used[i][j]){
      que.push(P(j,i));
      cnt++;
      used[i][j] = true;
      while(!que.empty()){
        P p = que.front(); que.pop();
        rep(k,4){
          int nx = p.F+dx[k],ny = p.S+dy[k];
          if(0<=nx && nx <limx-1 && 0<= ny && ny <limy-1 && !used[ny][nx]){
        used[ny][nx] = true;
        que.push(P(nx,ny));
          }
        }
 
      }
    }
      }
    }
   
 
 
    cout << cnt << endl;
 
 
 
 
 
  }
  return 0;
}

Measured memory_bytes: 10088
#include<iostream>
using namespace std;
#define INFTY 2000000000

int A[500000];
int cnt;

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

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

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

Measured memory_bytes: 6924
function Main(input) {
  input = input.split("\n");
  var H = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  input.shift();
  var S = input.map(i => i.split(""));
  S.splice(H,S.length-H);
  var dp1=new Array(H);
  var dp2=new Array(H);
  for(var i=0;i<H;i++){
    var tmp1=new Array(W).fill(1);
    var tmp2=new Array(W).fill(1);
    dp1[i]=tmp1;
    dp2[i]=tmp2;
  }
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(j==0){
        if(S[i][j]=="#"){
          dp1[i][j]=0;
        }
      }else{
        if(S[i][j]=="."){
          dp1[i][j]=dp1[i][j-1]+1;
        }else{
          dp1[i][j]=0;
        }
      }
    }
  }
  for(var i=0;i<H;i++){
    for(var j=W-2;j>=0;j--){
      if(S[i][j]=="."){
        if(dp1[i][j+1]!=0){
          dp1[i][j]=dp1[i][j+1];
        }
      }
    }
  }
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(i==0){
        if(S[i][j]=="#"){
          dp2[i][j]=0;
        }
      }else{
        if(S[i][j]=="."){
          dp2[i][j]=dp2[i-1][j]+1;
        }else{
          dp2[i][j]=0;
        }
      }
    }
  }
  for(var i=H-2;i>=0;i--){
    for(var j=0;j<W;j++){
      if(S[i][j]=="."){
        if(dp2[i+1][j]!=0){
          dp2[i][j]=dp2[i+1][j];
        }
      }
    }
  }
  var ans=0;
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      ans=Math.max(ans,dp1[i][j]+dp2[i][j]-1);
    }
  }
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 123508
#include<bits/stdc++.h>
#define mx 100000
#define pb push_back
#define print(a) printf("%d",a)
#define sc1(a) scanf("%d",&a)
using namespace std;

typedef unsigned long  ull;
typedef long long int lli;

int main()
{
 	lli x,coin=0;
 	cin>>x;
 	if (x>=500)
 	{
 		coin=(x/500)*1000;
 		x%=500;		
	}
	if (x>=5)
	{
		coin+=(x/5)*5;
	}
	cout<<coin<<endl;	


 return 0;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep_ll(i,n) for(ll i = 0; i < (ll)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;

const long double PI = (acos(-1));
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

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

  int n;
  cin >> n;

  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int ans = 0;
  int cnt=0;
  rep(i,n-1){
    if(h[i]>=h[i+1]) cnt++;
    else {
      ans = max(ans, cnt);
      cnt=0;
    }
  }
  ans = max(ans, cnt);

  cout << ans;
  
  return 0;
}

Measured memory_bytes: 640
int main()
{
	int m,d,n,i;

	while(1){
		scanf("%d %d",&m,&d);
		if(m==0&&d==0) break;
		n=0;
		for(i=1;i<m;i++){
			if(i==4||i==6||i==9||i==11) n+=30;
			else if(i==2) n+=29;
			else n+=31;
		}
		switch((d+n)%7){
		case 0:
			printf("Wednesday\n");
			break;
		case 1:
			printf("Thursday\n");
			break;
		case 2:
			printf("Friday\n");
			break;
		case 3:
			printf("Saturday\n");
			break;
		case 4:
			printf("Sunday\n");
			break;
		case 5:
			printf("Monday\n");
			break;
		case 6:
			printf("Tuesday\n");
			break;
		}
	}
	return 0;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class BCraneAndTurtle {
public:
	void solve(std::istream& in, std::ostream& out) {
        ll x,y;
        in>>x>>y;
        for (int i = 0; i <= x; ++i) {
            if(i*2 + (x-i)*4==y) {
                out<<"Yes"<<endl;
                return;
            }
        }
        out<<"No"<<endl;
	}
};


int main() {
	BCraneAndTurtle solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3124
def isOdd(n):
    return n % 2 == 1


def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


A, B, C = li()

cnt = 0
ABC = []
flag = False
while True:
    if flag:
        break
    if isOdd(A) or isOdd(B) or isOdd(C):
        break
    ABC.append([A, B, C])
    A2 = A // 2
    B2 = B // 2
    C2 = C // 2
    A = B2 + C2
    B = A2 + C2
    C = A2 + B2
    cnt += 1

    for i in range(len(ABC)):
        if ABC[i] == [A, B, C]:
            cnt = -1
            flag = True
            break

print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const ll INF=INT64_MAX>>3;
int main(){
    ios::sync_with_stdio(false);
    int S,W;
    cin >> S >> W;
    if(S > W) cout << "safe\n";
    else cout << "unsafe\n";
}

Measured memory_bytes: 3648
#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>;

// mint
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> s, t;
	rep(i,n) {
		cin >> a[i];
		if (a[i] < 0) t.push_back(a[i]);
		else s.push_back(a[i]);
	}

	int S = s.size();
	int T = t.size();
	bool ok = false;
	if (S > 0) {
		if (n == k) ok = (T%2 == 0);
		else ok = true;
	} else {
		ok = (k%2 == 0);
	}

	mint ans = 1;
	if (!ok) {
		sort(a.begin(),a.end(), [](int x, int y) {
				return abs(x) < abs(y);
			});
		rep(i,k) ans *= a[i];
	} else {
		// 昇順 小さい順
		sort(s.begin(),s.end());
		sort(t.rbegin(),t.rend());
		if (k%2 == 1) {
			// 後ろからとる 大きい順
			ans *= s.back();
			s.pop_back();
		}
		vector<ll> p;
		while(s.size() >= 2) {
			ll x;
			x = s.back();s.pop_back();
			x *= s.back();s.pop_back();
			p.push_back(x);
		}
		while(t.size() >= 2) {
			ll x;
			x = t.back();t.pop_back();
			x *= t.back();t.pop_back();
			p.push_back(x);
		}
		sort(p.rbegin(),p.rend());
		rep(i,k/2) ans *= p[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6380
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n>>k;
    vector<int>sunuke(n);
    for(int i=0;i<k;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int a;
            cin >> a;
            sunuke[a-1]++;
        }
    }
    int ans =0;
    for(int i=0;i<n;i++){
        if(sunuke[i] == 0)ans ++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << x2+y1-y2 <<" "<< y2+x2-x1 <<" "<< x1+y1-y2 <<" "<< y1+x2-x1 <<endl;
}

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

int main() {
  int H,W;
  cin >>H>>W;
  vector<char> F(W+2,'#');
  vector<char> T(W);
  for(int i=0;i<W+2;i++){
    cout<<F.at(i);
  }
  cout<<endl;
  for(int i=0;i<H;i++){
    cout<<'#';
    for(int u=0;u<W;u++){
      cin>>T.at(u);
      cout<<T.at(u);
    }
      cout<<'#'<<endl;
  }
    for(int i=0;i<W+2;i++){
    cout<<F.at(i);
  }
  cout<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2**20)
n = int(input())
NIL = -1
class node:
    def __init__(self,parent,left,right):
        self.parent = parent
        self.left = left
        self.right = right
T = [node(NIL,NIL,NIL) for _ in range(n)]
firstid = 0
for _ in range(n):#入力の一例
    A = list(map(int,input().split()))
    id = A[0]
    if n == 1:
        firstid = id
    k = A[1]
    if k != 0:
        chil = A[2:2+k]
        T[id].left = chil[0]
        for i in range(k):
            if i != k-1:
                T[chil[i]].right = chil[i+1]
                T[chil[i]].parent = id
            else:
                T[chil[i]].parent = id            
D = [0]*n
def setDepth(u,p):#uはノードの番号、pはノードpの深さ。
    D[u] = p      #uより右下にあるノードの深さをDに保存し、かえす
    if T[u].right != NIL:
        setDepth(T[u].right,p)
    if T[u].left != NIL:
        setDepth(T[u].left,p+1)
    return D
def getDepth(u):
    d = 0
    while T[u].parent != NIL:
        u = T[u].parent
        d += 1
    return d
def findroot(u): #根をみつける
    while T[u].parent != NIL:
        u = T[u].parent
    return u
def printChildren(u):#番号uのノードの子供をlistでかえす
    child = []
    if T[u].left != NIL:
        c = T[u].left
        while c != NIL:
            child.append(c)
            c = T[c].right
    return child
def ppp():
	for i in range(n):
  		ccc = T[i]
  		print(i,ccc.parent,ccc.left,ccc.right)
#ここからもんだいによってかわる
r = findroot(firstid)
D = setDepth(r,0)
for i in range(n):
    nod = T[i]
    d = getDepth(i)
    s = "internal node"
    if nod.parent == NIL:
        s = "root"
    elif nod.left == NIL:
        s = "leaf"
    child = printChildren(i)
    print(f'node {i}: parent = {nod.parent}, depth = {d}, {s}, {child}')


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

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

	vector<int> count(n);
	for (int i = 0; i < m; i++)
	{
		int a, b;
		cin >> a >> b;
		count.at(a - 1)++;
		count.at(b - 1)++;
	}

	for (auto item : count)
	{
		cout << item << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const ll MOD = 1e9 + 7;

int main() {
    ll a, v, b, w ,t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;

    ll dx  = b -a;
    ll dv =  v - w;
    if (dv > 0) {
        if (dx < 0) dx *= - 1;
        ll t1 = (dx + dv - 1) / dv;
        if (t1 > 0 && t1 <= t) {
            cout << "YES" << endl;
            return 0;
        }

    } 
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

/**
 * @author author
 *
 */
public class Main {

  /**
   * @param args int a = Integer.parseInt(sc.next());
   * 
   */
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int p = Integer.parseInt(sc.next());

    System.out.println((a * 3 + p) / 2);
    
  }

}


Measured memory_bytes: 22608
//BY: YASH JAIN, CF: yashjain0333
#include <bits/stdc++.h>
using namespace std;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MOD 1000000007
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 200005

void solve(){
    int n; cin>>n;
    vector<pair<int,int>> a(n);
    for(int i=0;i<n;i++) cin>>a[i].f>>a[i].s;
    pair<int,int> c1,c2,c3,c4;
    int r1 = -INF, r2 = -INF, r3 = -INF, r4 = -INF;
    for(int i=0;i<n;i++){
        int dist = a[i].f+a[i].s;
        if(dist>r1){
            r1 = dist;
            c1 = {a[i].f,a[i].s};
        }
    }
    for(int i=0;i<n;i++){
        int dist = a[i].f-a[i].s;
        if(dist>r2){
            r2 = dist;
            c2 = {a[i].f,a[i].s};
        }
    }
    for(int i=0;i<n;i++){
        int dist = -a[i].f+a[i].s;
        if(dist>r3){
            r3 = dist;
            c3 = {a[i].f,a[i].s};
        }
    }
    for(int i=0;i<n;i++){
        int dist = -a[i].f-a[i].s;
        if(dist>r4){
            r4 = dist;
            c4 = {a[i].f,a[i].s};
        }
    }
    int res = max({abs(c1.f-c2.f)+abs(c1.s-c2.s),abs(c1.f-c3.f)+abs(c1.s-c3.s),abs(c1.f-c4.f)+abs(c1.s-c4.s),abs(c2.f-c3.f)+abs(c2.s-c3.s),abs(c2.f-c4.f)+abs(c2.s-c4.s),abs(c3.f-c4.f)+abs(c3.s-c4.s)});
    cout<<res;
}

int32_t main(){
    May_the_fork_be_with_you
    int t = 1; 
    // cin>>t;
    while (t--) {
        solve();
	}
}

Measured memory_bytes: 6368
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;

    input!{
        a: usize,
        b: usize,
    }
    let mut ans = a + b;
    ans = (ans + (ans & 1))/2;
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long int li;
int main(){
  int n,k=0;li s=1; cin >>n;
  rep(i,n){
    int a; cin >>a;
    if(2*k==a){
      (s*=k+1)%=MOD;
      k--;
    }
    k++;
  }
  while(k>0){
    (s*=k--)%=MOD;
  }
  printf("%ld",s);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,p;
  cin >> s >> p;
  s=s+s;//この行が何を表しているのかわからない
  if(s.find(p)!=-1) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
#define fast_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll dp[1005][1005];
string b[1005];
char a[1005][1005];
bool vis[N],vis1[N];
vector<ll>v[N];
ll mem[10005][10005];
pair<ll,ll>p[N],p1[N];
set<int>s;
map<string,ll>mp;
queue<ll>q;
ll mod=1e9+7,n,m;
/*ll dp(ll i,ll j)
{
    if(a[i][j]=='#')
        return 0;
    if(i==n&&j==m)
        return 1;
        ll p1=0,p2=0;
        ll &ret=mem[i][j];
        if(ret!=-1)
            return ret%mod;
    if(i+1<=n)
        p1=dp(i+1,j)%mod;
    if(j+1<=m)
    p2=dp(i,j+1)%mod;
    return (p1+p2)%mod;

}*/
main()
{
    fast_IO
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        cin>>b[i];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
            a[i][j]=b[i][j-1];
    }

    dp[1][1]=1;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            if(a[i][j]=='#')
                continue;
            if(i==1&&j==1)
                continue;

            else
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;

        }
    }
    cout<<dp[n][m];


}










Measured memory_bytes: 18248
x,k,d=map(int,input().split())

jump=abs(x//d)

if jump >= k:
        print(abs(x)-d*k)
else:
        x=abs(x%d)
        k-=jump
        if k%2==0:
                print(abs(x))
        else:
                print(abs(x-d))
                

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
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;}

void find_divisor(ll N, vector<ll>& divisor) {
  for(int i=1; i<=sqrt(N); i++) {
    if(N % i == 0)
      divisor.push_back(i);
  }
  int n = divisor.size();
  for(int i=n-1; i>=0; i--) {
    if(N != (ll)pow(divisor[i], 2))
      divisor.push_back(N / divisor[i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n; cin >> n;
  vector<ll> div;
  find_divisor(n, div);
  ll ans = longinf;
  for(ll d: div) {
    chmin(ans, d+n/d-2);
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <cassert>

int digit_sum(int n){
    assert(1 <= n);
    assert(n <= 10000);

    int sum = 0;
    int x = n;
    for(;;){
        sum += (x % 10);
        if(x / 10 == 0) return sum;
        x  = x / 10;
    }
}

int main(int argc, char **argv)
{
    int N, A, B;

    std::cin >> N >> A >> B;

    int sum = 0;
    for(int i = 1; i <= N; i++){
        int v = digit_sum(i);
        if(A <= v && v <= B){
            sum += i;
        }
    }
    std::cout << sum << std::endl;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    while (b != 0) {
        ll x = a, y = b;
        a = y; b = x % y;
    }
    return a;
}

int main()
{
    ll n; cin >> n;
    ll num; cin >> num;
    REP(i, n-1) {
        ll _num; cin >> _num;
        num = gcd(num, _num);
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int x=0,y=0,z=0,a=0,b=0;
	while(scanf("%d,%d,%d",&x,&y,&z)!=EOF){
		if( x*x+y*y == z*z && x!=y){
			a++;
		}
		if( x*x+y*y != z*z && x==y){
			b++;
		}
	}
	printf("%d\n%d\n",a,b);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
long long int gcd(long long int a, long long int b){
  long long int t;
  if(a > b){
    t = b;
    b = a;
    a = t;
  }
  long long int  r = -1;
  while(r != 0){
    r = b % a;
    b = a;
    a = r;
  }
  return b;
}

int main(){
  int N;
  cin >> N;
  
  vector<long long int> A(N);
  
  for(int i = 0; i < N; i++) cin >> A[i];
  
  long long int d = A[0];
  for(int i = 0; i < N; i++){
    d = gcd(d,A[i]);
  }
  cout << d;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

ll Pow(ll n, ll p) {
	if (p == 0)return 1;
	if (p == 1)return n;
	ll t = Pow(n, p / 2);
	if (p & 1) return (t * t % MOD) * n % MOD;
	else return t * t % MOD;
}

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

	ll ans = 0;
	if (!(k & 1)) {//k is even
		ll cnt = 0;
		repe(i, 1, n) {
			if (i % k == k / 2)cnt++;
		}
		//ans = Pow(cnt, 3);
		ans += cnt * cnt*cnt;
	}

	ll cnt = 0;
	repe(i, 1, n) {
		if (i % k == 0)cnt++;
	}
	//ans += Pow(cnt, 3);
	ans += cnt * cnt*cnt;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
// ABC_158_B

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

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

	ll ans = (n / (a + b)) * a + min(a, n % (a + b));
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256