akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}

const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int MY_COM(int n, int k) {
	int x=1, y=1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

bool b[105];

signed main() {
	int a[3][3];
	rep(i, 3) {
		rep(j, 3) {
			cin >> a[i][j];
		}
	}
	int n;
	cin >> n;
	rep(i, n) {
		int x;
		cin >> x;
		b[x] = true;
	}
	rep(i, 3) {
		int check = true;
		rep(j, 3) {
			if (!b[a[i][j]]) check = false;
		}
		if (check) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	rep(i, 3) {
		int check = true;
		rep(j, 3) {
			if (!b[a[j][i]]) check = false;
		}
		if (check) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	if (b[a[0][0]] && b[a[1][1]] && b[a[2][2]]) {
		cout << "Yes" << endl;
		return 0;
	}
	if (b[a[2][0]] && b[a[1][1]] && b[a[0][2]]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

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

struct node{
    int key;
    node *p,*l,*r;
};

int n;
node *N;

void tree_insert(node *z){
    node *y=NULL;
    node *x=N;
    while(x!=NULL){
        y=x;
        if(x->key>z->key)x=x->l;
        else if(x->key<z->key)x=x->r;
    }
    z->p=y;
    if(y==NULL)N=z;
    else if(y->key<z->key)y->r=z;
    else y->l=z;
}

node *find_num(int num){
    node *x=N;
    while(x!=NULL){
        if(x->key==num){
            return x;
        }
        if(x->key>num)x=x->l;
        else x=x->r;
    }
    return x;
}

void tree_find(int num){
    node *x=find_num(num);
    if(x!=NULL)cout<<"yes"<<endl;
    else cout<<"no"<<endl;
}

void in(node *x){
    if(x->l!=NULL)in(x->l);
    cout<<" "<<x->key;
    if(x->r!=NULL)in(x->r);
}

void pre(node *x){
    cout<<" "<<x->key;
    if(x->l!=NULL)pre(x->l);
    if(x->r!=NULL)pre(x->r);
}

node* successor(node *z){
    node *x;
    x=z->r;
    while(x->l!=NULL)x=x->l;
    return x;
}

void tree_delete(node *z){
    node *y;
    if(z->l==NULL||z->r==NULL)y=z;
    else y=successor(z);
    node *x;
    if(y->l!=NULL)x=y->l;
    else x=y->r;
    if(x!=NULL)x->p=y->p;

    if(y->p==NULL) N=x;
    else if(y==y->p->l)y->p->l=x;
    else y->p->r=x;

    if(y!=z) z->key=y->key;
    delete(y);
}

void print(){
    node *x=N;
    in(x);
    cout<<endl;
    pre(x);
    cout<<endl;
}

int main()
{
    N=NULL;
    cin>>n;
    int i;
    for(i=0;i<n;i++){
        string s;
        cin>>s;
        if(s=="insert"){
            int num;
            cin>>num;
            node *z=new node();
            z->key=num;z->l=z->r=z->p=NULL;
            tree_insert(z);
        }
        if(s=="find"){
            int num;
            cin>>num;
            tree_find(num);
        }
        if(s=="print"){
            print();
        }
        if(s=="delete"){
            int num;
            cin>>num;
            node *z=find_num(num);
            tree_delete(z);
        }
    }
    return 0;
}

Measured memory_bytes: 21808
using System;
using System.Linq;

namespace AtCoder.Question
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();

            if (s.Length + 1 == t.Length && t.StartsWith(s) && 'a' <= t.Last() && t.Last() <='z')
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 26388
import sys
sys.setrecursionlimit(10000000)


def main():
    N = int(input())
    min_ = N - 1
    for i in range(1, int(N ** 0.5) + 1):
        if N % i != 0:
            continue
        else:
            j = N // i
            min_ = min(min_, i + j - 2)
    print(min_)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;

const long long mod = 998244353;

int main(){
  int n;
  cin >> n;
  vector<pair<long long, long long> > a(n + 1);
  for(int i = 0; i < n; ++i){
    cin >> a[i].first >> a[i].second;
    a[i].second += a[i].first;
  }
  a[n].first = a[n].second = 1e18;
  sort(a.begin(), a.end());
  vector<long long> d(n + 1);
  d[n] = 1;
  stack<long long> s;
  s.push(n);
  for(int i = n - 1; i >= 0; --i){
    while(a[i].second > a[s.top()].first)
       s.pop();
    d[i] = (d[i + 1] + d[s.top()]) % mod;
    s.push(i);
  }
  cout << d[0];
}

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

int main(){
    int n;
    int k;
    cin >> n >> k;
    vector<int> h(n);
    long long ans= 0;
    for (int i = 0; i < n; i++)
    {
        cin >> h[i] ;
    }
    sort(h.begin(),h.end());

    for (int i = 0; i < n-k; i++)
    {
        ans += h[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
int main(){
  int D;
  cin >> D;
  if (D == 25) {
    cout << "Christmas" << endl;
  }
  else if (D == 24) {
    cout << "Christmas" << " " << "Eve" << endl;
  }
  else if (D == 23) {
    cout << "Christmas" << " " << "Eve" << " " << "Eve" << endl;
  }
  else {
    cout << "Christmas" << " " << "Eve" << " " << "Eve" << " " << "Eve" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
s = input()
mod = 1000000007
alphacnt = [0]*26
ans = 0
for c in s[::-1]:
    idx = ord(c)-ord("a")
    alphacnt[idx] += 1
    cnt = 1
    for i in range(26):
        if i == idx: continue
        cnt = (cnt*(alphacnt[i]+1))%mod
    ans = (ans+cnt)%mod
print(ans)

Measured memory_bytes: 9216
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
using namespace std;

#define N 200002

vector<int >edge[N];

char s[N];
int vis[N][4];
char t[4] ={'A','A','B','B'};
bool dfs(int node,int ord) {
  if(vis[node][ord]==2) {
    return false;
  }
  else if(vis[node][ord]==1) {
    return true;
  }
  vis[node][ord] = 1;
  char tt = t[(ord+1)%4];
  for(int i=0;i<edge[node].size();++i) {
    int ch = edge[node][i];
    char g = s[ch];
    if(tt==g) {
      if(dfs(ch,(ord+1)%4)) {
        return true;
      }
    }
  }
  vis[node][ord] = 2;
  return false;
}
void solve() {
  int n,m;scanf("%d %d",&n,&m);
  scanf(" %s",s+1);
  for(int i=m;i;--i) {
    int a,b;scanf("%d %d",&a,&b);
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i=1;i<=n;++i) {
    if(!vis[i][0] && s[i]=='A') {
      if(dfs(i,0)) {
        printf("Yes\n" );
        return;
      }
    }
  }
  printf("No\n");
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
#define ll long long
const ll inf = 1e9;
const int mod = 1e9 + 7;
using namespace std;
int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    ll b[100005];
    int k, n, a[100005];
    cin>>n>>k;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
    }
    b[0] = 0;
    b[1] = 0;
    for(int i = 2; i <= n; i++){
        ll mn = 10000 * inf;
        for(int j = 1; j <= k; j++){
            if(i - j > 0)
                mn = min((ll)abs(a[i] - a[i - j]) + b[i - j], mn);
        }
        b[i] = mn;
    }
    cout<<b[n]<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e5;
int main(){
  int N; cin >> N;
  vector<vector<int>> to(N,vector<int>(N,0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      char c; cin >> c; int d = c-'0'; 
      if( d == 0 ){ d = INF;} 
      if( i == j ){ d = 0;}
      to[i][j] = d;}}
  
  vector<int> color(N,0); //0が未到達、1が白、２が黒
  
  queue<int> Q; Q.push(0); color[0] = 1;
  bool flag = true;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    for(int i = 0; i < N; i++){ 
      if( to[p][i] == 1 ){ //隣接しているところに進む
        if( color[i] == 0){ 
          if(color[p] == 1){ color[i] = 2;}
          else{ color[i] = 1;}
          
          Q.push(i);
        }
        else{
          if( color[i] == color[p]){ //二部じゃない
            flag = false; break;}
        }
      }
    }
      if(!flag){ break;}
  }
    
  if(!flag){ cout << -1 << endl; return 0;}
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        to[i][j] = min(to[i][j], to[i][k]+to[k][j]);
      }
    }
  }
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      ans = max(ans, to[i][j]);
    }
  }
  
  cout << ans+1 << endl; return 0;
}
  

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

#include <iostream>
using namespace std;
int main() {
  const int num_elements = 9;
  vector<int> A(num_elements);
  vector<bool> B(num_elements, false);
  for (int i = 0; i < num_elements; ++i) {
    if (i % 3 == 0) {
      cin >> A[i] >> A[i + 1] >> A[i + 2];
    }
  }
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    int b;
    cin >> b;
    for (int j = 0; j < num_elements; ++j) {
      if (b == A[j]) {
        B[j] = true;
      }
    }
  }
  bool bingo = false;
  for (int i = 0; i < 3; ++i) {
    if (B[i * 3] && B[i * 3 + 1] && B[i * 3 + 2]) {
      bingo = true;
    }
    if (B[i] && B[i + 3] && B[i + 6]) {
      bingo = true;
    }
  }
  if (B[0] && B[4] && B[8]) {
    bingo = true;
  }
  if (B[2] && B[4] && B[6]) {
    bingo = true;
  }

  if (bingo) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define pb push_back
#define ins insert

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<string> vec(3);
  rep(i,3) cin >> vec[i];
  int cost = 0;
  rep(i,n) {
    set<char> S;
    rep(j,3) S.insert(vec[j][i]);
    int s = S.size();
    if( s == 3 ) cost += 2;
    else if( s == 2 ) cost += 1;
  }
  cout << cost << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	ll x;
	cin >> n >> x;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,n-1){
		if(a[i]+a[i+1] > x){
			ll add = a[i] + a[i+1] - x;
			a[i+1] = max(0LL, a[i+1]-add);
			ans += add;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
bool T[200];
vector<int> tarou,hanako;
int main() {
	int n;
	while(scanf("%d",&n),n) {
		tarou.clear();
		hanako.clear();
		memset(T,0,sizeof(T));
		for(int i=0;i<n;i++) {
			int card;
			scanf("%d",&card);
			T[card-1]=true;
		}
		for(int i=0;i<2*n;i++) {
			if(T[i]) tarou.push_back(i+1); else hanako.push_back(i+1);
		}
		int field=0,turn=1;
		while(tarou.size()&&hanako.size()) {
			if(turn) {
				int fnd=-1;
				 for(int i=0;i<tarou.size();i++) {
					 if(field<tarou[i]) {fnd=i;break;}
				 }
				 if(fnd==-1) field=0;
				 else field=tarou[fnd],tarou.erase(tarou.begin()+fnd);
			}else {
				int fnd=-1;
				 for(int i=0;i<hanako.size();i++) {
					 if(field<hanako[i]) {fnd=i;break;}
				 }
				 if(fnd==-1) field=0;
				 else field=hanako[fnd],hanako.erase(hanako.begin()+fnd);
			}
			turn^=1;
		}
		int t_point=0,h_point=0;
		for(int i=0;i<hanako.size();i++) t_point++;
		for(int i=0;i<tarou.size();i++) h_point++;
		printf("%d\n%d\n",t_point,h_point);
	}
}

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

// main.cpp

int main() {
  std::int_fast64_t N;
  std::cin >> N;

  static constexpr std::array<std::int_fast64_t, 12> options = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
  std::vector<std::int_fast64_t> dp(N + 1, std::numeric_limits<std::int_fast64_t>::max());
  dp[0] = 0;
  for (std::int_fast64_t i = 0; i <= N; ++i) {
    for (const std::int_fast64_t& option : options) {
      if (i + option <= N) dp[i + option] = std::min(dp[i + option], dp[i] + 1);
    }
  }

  std::cout << dp[N] << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<string> S(n);
    int N = 0;
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
        N = max(N, (int) S[i].length());
    }

    vector<vector<int>> T(N + 1);

    vector<int> reqs(n, 0);
    vector<int> chgs(n, 0);
    for (int i = 0; i < n; ++i) {
        int bal = 0;
        auto& s = S[i];
        int m = s.length();
        for (int j = 0; j < m; ++j) {
            bal += s[j] == '(' ? 1 : -1;
            reqs[i] = max(reqs[i], -bal);
        }
        chgs[i] = bal;
        T[reqs[i]].push_back(i);
    }

    string res;
    int BAL = 0;
    int cnt = 0;
    for (int i = 0; i <= BAL && i <= N; ++i) {
        for (auto x : T[i]) {
            if (chgs[x] >= 0) {
                BAL += chgs[x];
                res += S[x];
                ++cnt;
            }
        }
    }

    priority_queue<pair<int,int>> pq;
    for (int i = 0; i < n; ++i) {
        if (chgs[i] < 0) {
            pq.emplace(reqs[i] + chgs[i], i);
        }
    }

    while (!pq.empty()) {
        int x = pq.top().second;
        if (BAL < reqs[x]) {
            break;
        }
        pq.pop();
        BAL += chgs[x];
        res += S[x];
        ++cnt;
    }

    if (cnt == n && BAL == 0) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 53488
# -*- coding: utf-8 -*-

X = int(input())

num = X // 100
reminder = X % 100
if reminder == 0:
    print("1")
    exit()

for i in range(num+1):
    for j in range(num+1):
        if i+j > num:
            continue
        for k in range(num+1):
            if i+j+k > num:
                continue
            for l in range(num+1):
                if i+j+k+l>num:
                    continue
                for m in range(num+1):
                    if i+j+k+l+m>num:
                        continue

                    res = i*1+j*2+k*3+l*4+m*5
                    if res == reminder:
                        print("1")
                        exit()

print("0")


Measured memory_bytes: 9200
n=int(input())
d=list(map(int,input().split()))
m=int(input())
t=list(map(int,input().split()))
dic={}
for i in range(n):
    if d[i] in dic:
        dic[d[i]]+=1
    else:
        dic[d[i]]=1
for i in range(m):
    if not t[i] in dic:
        print("NO")
        exit()
    if dic[t[i]]==0:
        print("NO")
        exit()
    dic[t[i]]-=1
print("YES")

Measured memory_bytes: 43984
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int h, n, a, asum = 0;
  cin >> h >> n;
  REP(i, n) {
    cin >> a;
    asum += a;
  }
  if (h > asum) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

int main() {
  // ここにプログラムを追記
  int ans = 0;
  string s;
  
  cin >> s;
  
  for(int i = 0;i < 3;i++){
    if(s[i] == '1'){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;

int main()
{
    int n, m;
    cin >> n >> m;
if(n == 1 && m == 0){
    cout << 0 << endl;
    return 0;
}
    int s, c;
    vi ans(n, -1);
    rep(i, m)
    {
        cin >> s >> c;
        if (ans[s - 1] == -1)
        {
            ans[s - 1] = c;
        }
        else if (ans[s - 1] != c)
        {
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, n)
    {
        if (ans[i] == -1)
        {
            if (i == 0)
            {
                ans[i] = 1;
            }
            else
            {
                ans[i] = 0;
            }
        }
    }
    if (n == 2 && ans[0] == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    if (n == 3 && ans[0] == 0)
    {
        cout << -1 << endl;
        return 0;
    }
    rep(i, n)
    {
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
int h, w, ch, cw, dh, dw;
vector<vector<char>> s;
vector<vector<int>> dist;

bool judge(pii coord, int d) {
  int x = coord.first, y = coord.second;

  return x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.' &&
         (dist[x][y] == -1 || dist[x][y] > d);
}

bool aiueo(int i, int j) {
  bool flag = false;
  for (int k = 0; k < 4; k++) {
    if (i == dx[k] && j == dy[k]) flag = true;
  }
  return flag;
}
int main() {
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--;
  cw--;
  dh--;
  dw--;
  s.resize(h, vector<char>(w));
  dist.resize(h, vector<int>(w, -1));

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

  deque<pii> que;

  que.push_front(make_pair(ch, cw));
  dist[ch][cw] = 0;

  while (!que.empty()) {
    pii temp = que.front();
    que.pop_front();

    /* for (int i = 0; i < 4; i++) {
      int tmpx = temp.first + dx[i], tmpy = temp.second + dy[i];
      if (judge({tmpx, tmpy})) {
        que.push_front(make_pair(tmpx, tmpy));
        dist[tmpx][tmpy] = dist[temp.first][temp.second];
      }
    } */

    for (int i = -2; i <= 2; i++) {
      for (int j = -2; j <= 2; j++) {
        int tmpx = temp.first + i, tmpy = temp.second + j;
        int d = dist[temp.first][temp.second];
        if (judge({tmpx, tmpy}, d)) {
          if (aiueo(i, j)) {
            que.push_front({tmpx, tmpy});
            dist[tmpx][tmpy] = dist[temp.first][temp.second];
          } else {
            que.push_back({tmpx, tmpy});
            dist[tmpx][tmpy] = dist[temp.first][temp.second] + 1;
          }
        }
      }
    }
  }

  cout << dist[dh][dw] << endl;
}

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

int main()
{
	string a, b;
	cin >> a >> b;
	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
	}
	else if (a.size() < b.size()) {
		cout << "LESS" << endl;
	}
	else {
		for (int i = 0; i < a.size(); i++) {
			if (a[i] > b[i]) {
				cout << "GREATER" << endl;
				return 0;
			}
			if (a[i] < b[i]) {
				cout << "LESS" << endl;
				return 0;
			}
		}
		cout << "EQUAL" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    //let n = read::<usize>();
    //let n = read::<u32>();
    let v = read_vec::<u32>();

    let a = v[0];
    let b = v[1];
    let c = v[2];

    let mut count = 0;
    for i in a..b + 1 {
        if c % i == 0 {
            count += 1;
        }
    }
    println!("{}", count);
}



Measured memory_bytes: 5024
#include <iostream>
#include <cmath>

using namespace std;
typedef long long LL;

int main() {
    LL X, cnt = 0, s = 100;
    cin >> X;
    while (s < X) {
        s = s + s * 0.01;
        cnt += 1;
    }
    cout << cnt << endl;
    return 0;
}

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

#define inf 1000*1000

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	string s;
	cin >> n >> m >> s;

	// start from n, work backwards greedily
	vector<int> prev(n+1, -1);
	for(int i = n; i >= 0; i--) {
		if(s[i] == '1') {
			prev[i] = s[i+1] == '0' ? i+1 : prev[i+1];
		}
	}
	
	vector<int> ans;
	bool ok = true;
	int cur = n;
	while(cur > 0) {
		int jump = min(cur, m);
		int next = cur - jump;
		if(s[next] == '1') {
			next = prev[next];
			if(next == cur) {
				ok = false;
				break;
			}
			jump = cur - next;
		}
		
		ans.push_back(jump);
		cur = next;
	}
	
	reverse(ans.begin(), ans.end());
	int sz = ans.size();
	if(ok) {
		for(int i = 0; i < sz; i++) {
			cout << ans[i] << " \n"[i==sz-1];
		}
	} else {
		cout << -1 << endl;
	}
}


Measured memory_bytes: 1480
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
	ll k; cin >> k;
	ll a[k];
	for(ll i = 0; i < k; i++) cin >> a[i];
	ll ana = 2, bi = 2;
	for(ll i = k - 1; i >= 0; i--){
		ana = ana / a[i] * a[i] + !!(ana % a[i]) * a[i];
		bi = bi / a[i] * a[i] + a[i] - 1;
		if(ana > bi){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ana << " " << bi << endl;
	return 0;
}

Measured memory_bytes: 1024
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	h, a := nextInt(), nextInt()
	if h % a == 0 {
		fmt.Println(h/a)
	} else {
		fmt.Println(h/a + 1)
	}
}

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

const int N = 2e5 + 10, MOD = 1e9 + 7;
int p3[N], n, t = 1, ans;
string s;

int mul(int a, int b){
	return 1LL * a * b % MOD;
}
int sum(int a, int b){
	int c = a + b;
	if(c >= MOD)
		c -= MOD;
	return c;
}

int main(){	
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> s;
	n = s.size();
	
	p3[0] = 1;
	for (int i = 1; i < N; i++)
		p3[i] = mul(p3[i - 1], 3);
	
	for (int i = 0; i < n; i++){
		if(s[i] == '0')
			continue;
		ans = sum(ans, mul(t, p3[n - i - 1]));
		
		t = mul(t, 2);
	}
	ans = sum(ans, t);
	cout << ans;
}

Measured memory_bytes: 1360
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<int> iter_for_win(N, 0);
  for (int i = 0; i < N; i++) {
    int gain = i + 1;
    while (gain < K) {
      iter_for_win[i]++;
      gain *= 2;
    }
  }
  long double ans = 0.0;
  for (int i = 0; i < N; i++) {
    ans += (long double)powl((long double)0.5, (long double)iter_for_win[i]);
  }
  ans *= (long double)1.0 / (long double)N;
  cout << fixed << setprecision(12) << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <numeric>
using ll = long long;
using namespace std;

string S;

int main() {
	cin >> S;
	size_t n = S.size();
	int ans = (n + 1) / 2;
	const int c = S[ans - 1];
	for (size_t i = 0; i < n / 2; i++)
	{
		if (S[n - 1 - ans] != c || S[ans] != c)
			break;
		ans++;
	}
	cout << ans << endl;
}

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

int main()
{
	int N, M;
	long long K;
	cin >> N >> M >> K;
	vector<long long> A( N );
	for( int i = 0; i < N; i++ ) {
		cin >> A[i];
	}
	vector<long long> B( M );
	for( int i = 0; i < M; i++ ) {
		cin >> B[i];
	}

	vector<long long> asum( N + 1 );
	for( int i = 0; i < N; i++ ) {
		asum[i + 1] = asum[i] + A[i];
	}
	vector<long long> bsum( M + 1 );
	for( int i = 0; i < M; i++ ) {
		bsum[i + 1] = bsum[i] + B[i];
	}
	int l = -1;
	int r = N + M + 1;
	while( r - l > 1 ) {
		int m = (l + r) / 2;
		long long k = INT64_MAX / 2;
		for( int i = 0; i <= m; i++ ) {
			if( i > N ) continue;
			if( m - i > M ) continue;
			k = min( k, asum[i] + bsum[m - i] );
		}
		if( k <= K ) l = m;
		else r = m;
	}
	int ans = l;

	cout << ans << endl;
}


Measured memory_bytes: 9576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ld long double
const int maxn = 1e5 + 10 , mod = 1e9 + 7;

int a, b, c;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> a >> b >> c;
	cout << (a + b >= c ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>


int main() {


    int N, X;
    std::cin >> N >> X;

    std::vector<int> ls;

    for (int i = 0; i < N; i++) {
        int v;
        std::cin >> v;
        ls.push_back(v);
    }

    std::vector<int> ds;

    ds.push_back(0);

    for (int i = 1; i <= N; i++) {
        int d = ds[i - 1] + ls[i - 1];
        ds.push_back(d);
    }

    int cnt = 0;

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

        if (ds[i] <= X) {
            cnt += 1;
        }

    }

    std::cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
####################
def pri(n):
  i = 2
  X = {}
  while i * i <= n:
    while n % i == 0:
      n //= i
      if i in X:
        X[i] = X[i] + 1
      else:
        X[i] = 1
    i += 1
  if n > 1:
    X[n] = 1
  return X
####################


N,X = list(map(int, input().split()))

x = list(map(int, input().split()))
x.append(X)

x.sort()

d = []
for i in range(N):
  dif = x[i+1] - x[i]
  if dif not in d:
    d.append(dif)

d.sort()

if len(d) == 1:
  print(d[0])
  exit()

m = d[0]
P = pri(d[0])
for i in range(1,len(d)):
  if d[i] % m != 0:
    t = pri(d[i])
    m = 1
    for j in list(P):
      if j in t:
        P[j] = min(P[j], t[j])
        m *= j ** P[j]
      else:
        del P[j]
print(m)


Measured memory_bytes: 14228
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    string s,t,u; cin>>s>>t>>u;
    cout << s[0] << t[0] << u[0] << endl;
    return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    FOR(i, 1, n + 1) {
        cin >> a[i];
    }
    vector<int> b(n + 1, 0);
    for (int i = n; i > 0; i--) {
        int c = 0;
        for (int j = i * 2; j <= n; j += i) {
            c += b[j];
        }
        if (c % 2 == 0 && a[i] == 1) {
            b[i] = 1;
        } else if (c % 2 == 1 && a[i] == 0) {
            b[i] = 1;
        }
    }

    int c = 0;    
    FOR(i, 1, n + 1) {
        if (b[i] == 1) {
            c++;
        }
    }
    cout << c << endl;
    if (c == 0) {
        return 0;
    }
    FOR(i, 1, n + 1) {
        if (b[i] == 1) {
            cout << i << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 2432
#include<stdio.h>
#include<algorithm>

using namespace std;

long long ans,kloter,mini,x,n;

int main(){
    mini = 1000000000000000000;
    scanf("%lld",&n);
    for(int i =0;i<5;i++){
        scanf("%lld",&x);
        mini = min(mini,x);
    }
    kloter = n/mini;
    if(n%mini) kloter++;
    ans = 5+kloter-1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cstring>
#include <bits/stdc++.h>
#include <search.h>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include<stack>
#include <utility>
using namespace std;
int main()
{
int n,step=0,maxx=0;
long long int arr[100000];
cin>>n;
for(int i=0;i<n;++i){
        cin>>arr[i];
        if(i!=0){
          if(arr[i]<=arr[i-1]) step++;
          else step=0;
        }
        if(step>maxx) maxx=step;
}
cout<<maxx;
return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


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

    vector<int>cnt(n);
    x--;
    y--;

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int MIN=min(j-i,1+abs(j-y)+abs(x-i));
            cnt[MIN-1]++;
        }
    }

    rep(i,n-1)cout<<cnt[i]<<endl;


}


Measured memory_bytes: 256
// abc142_e
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    vector<int> A(M), C(M);
    REP(i, M){
        cin >> A[i];
        int b; cin >> b;
        REP(j, b) {
            int c; cin >> c;
            C[i] |= 1 << (--c);
        }
    }

    vector<int> dp(1<<N, INF);
    dp[0] = 0;

    REP(i, M){
        REP(n, 1<<N){
            dp[n | C[i]] = min(dp[n | C[i]], dp[n] + A[i]);
        }
    }

    int ans = dp[(1<<N) - 1] != INF ? dp[(1<<N) - 1] : -1;
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
LL n, ans = 0;

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

	cin >> n;
	FOR(i, n)
		ans += (n-1)/i;
	
	cout << ans << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> P(N);
    ll easy = 0, med = 0, hard = 0;
    Rep (i, N) {
        cin >> P[i];
        if (P[i] <= A) easy++;
        else if (P[i] <= B) med++;
        else hard++;
    }

    cout << min({easy, med, hard}) << "\n";


}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int m = Math.max(a,b);
                m = Math.max(b,c);
		if(m==a){
			for(int i=0; i<k; i++){
				a = 2*a;
			}
		}
		else if(m==b){
			for(int i=0; i<k; i++){
				b = 2*b;
			}
		}
		else if(m==c){
			for(int i=0; i<k; i++){
				c = 2*c;
			}
		}
		System.out.println(a+b+c);
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
void ABC110(void);
void ABC111(void);
void ABC112(void);
void ABC113(void);
void ABC114(void);
void ABC115(void);
void ABC116(void);
void ABC117(void);
void ABC118(void);
void ABC119(void);

int main(void){
    ABC112();
}

void ABC112(){
    int n,a,b;
    cin>>n>>a>>b;
    if(n==1)cout<<"Hello World"<<endl;
    else cout<<a+b<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

int in() { int x; scanf("%d", &x); return x; }

int main() {
  int N = in();


  if (N < 1000) {
    printf("ABC\n");
  } else {
    printf("ABD\n");
  }
  return 0;
}



Measured memory_bytes: 256
using System;

namespace ABC128
{
    class Program
    {
        static int Main(string[] args)
        {
            Program.problemA();
            return 0;
        }

        static void problemA()
        {
            string[] input = Console.ReadLine().Split(' ');
            int apple = int.Parse(input[0]);
            int piece = int.Parse(input[1]);

            piece = piece + 3 * apple;

            Console.WriteLine(piece / 2);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c=0;
  cin>>a>>b;
  if(a>=b){
    c+=a;
    a--;
  }
  else{
    c+=b;
    b--;
  }
  if(a>=b){
    c+=a;
    a--;
  }
  else{
    c+=b;
    b--;
  }
  cout<<c<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,H;
vector<pll> katana;
void input(){
    fast_io();
    cin >> N >> H;
    for (int i = 0; i < N; i++)
    {
        ll a,b; cin >> a >> b;
        katana.emplace_back(a,b);
    }
    
}

int solve(){
    sort(katana.begin(),katana.end());
    ll A = katana.back().first;
    sort(katana.begin(),katana.end(),[](pll a,pll b){return a.second>b.second;});
    ll ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(katana[i].second>=A){
            H -= katana[i].second;
            ans++;
            if(H<=0) break;
        }
    }
    if(H>0){
        ans += (H+A-1)/A;
    }
    cout << ans << endl;
    return 0;
}   

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

Measured memory_bytes: 2420
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[h,w]=i2()
s=[]
for i in range(h):
 s.append(list(input()))
for i in range(h):
 ss=""
 for j in range(w):
   a=0
   if s[i][j]==".":
      if i>0 and s[i-1][j]=="#":
         a+=1
      if j>0 and s[i][j-1]=="#":
         a+=1
      if i>0 and j>0 and s[i-1][j-1]=="#":
         a+=1
      if i<h-1 and s[i+1][j]=="#":
         a+=1
      if j<w-1 and s[i][j+1]=="#":
         a+=1
      if i<h-1 and j<w-1 and  s[i+1][j+1]=="#":
         a+=1
      if i>0 and j<w-1 and s[i-1][j+1]=="#":
         a+=1
      if i<h-1 and j>0 and s[i+1][j-1]=="#":
         a+=1
      ss+=str(a)
   else:
      ss+="#" 
 print(ss)

Measured memory_bytes: 41452
n = int(input())
a = list(map(int,input().split()))
mx = max(a)
mn = min(a)
ans = []
if abs(mx)>=abs(mn):
    mx_ind = a.index(mx)
    for i in range(n):
        a[i] += mx
        ans.append([mx_ind+1,i+1])
    for i in range(1,n):
        a[i] += a[i-1]
        ans.append([i,i+1])
else:
    mn_ind = a.index(mn)
    for i in range(n):
        a[i] += mn
        ans.append([mn_ind+1,i+1])
    for i in range(n-1,0,-1):
        a[i-1] += a[i]
        ans.append([i+1,i])
print(len(ans))
for x,y in ans:
    print(x,y)

Measured memory_bytes: 38384
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    S = input()

    count = {}

    for s in S:
        if s not in count.keys():
            count[s] = 1
        else:
            count[s] += 1
    flag = 0
    if len(count) == 2:
        for v in count.values():
            if v != 2:
                flag = -1
                break
    else:
        flag = -1
    
    if flag == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int n, s[30000], ans = 0;
  scanf("%d", &n);
  s[0] = 3; s[1] = 5; s[2] = 7;
  for (size_t i = 1; i < 9841; i++) {
    s[3*i] = s[i-1] * 10 + 3;
    s[3*i+1] = s[i-1] * 10 + 5;
    s[3*i+2] = s[i-1] * 10 + 7;
  }
  for (size_t j = 12; j < 29523; j++) {
    int cn3 = 0, cn5 = 0, cn7 = 0;
    if (s[j] > n) {
      break;
    }
    while (s[j] != 0) {
      s[j] % 10 == 3 ? cn3++ :
      s[j] % 10 == 5 ? cn5++ :
      cn7++;
      s[j] /= 10;
    }
    if (cn3 > 0 && cn5 > 0 && cn7 > 0) {
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
map<ll,ll>cnt;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,a,b,c,l,r,q;
    cin>>k>>n;
    for(i=1; i<=n; i++)
    {
        cin>>r;
        cnt[r]++;
    }
    vector<pair<ll,ll>>v;
    x=k;
    while(1)
    {
        if(cnt[x]==0)
        {
            v.pb(x,x-k);
            break;
        }
        x++;
    }
    y=k;//cout<<cnt[5];
    while(1)
    {
        if(cnt[y]==0)
        {
            v.pb(y,k-y);
            break;
        }
        y--;
    }
  //  cout<<y<<'\n';
    if(v[0].second==v[1].second)
        cout<<v[1].first<<'\n';
    else if(v[0].second<v[1].second)
        cout<<v[0].first<<'\n';
    else
        cout<<v[1].first<<'\n';
}






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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X;
    --Y;
    
    vector<int> ans(N, 0);
    for (int i = 0; i < N; ++i) {
        int I = 0;
        if (i <= X) I = 0;
        if (X < i && i < Y) I = 1;
        if (Y <= i) I = 2;
        for (int j = i + 1; j < N; ++j) {
            
            int J = 0;
            if (j <= X) J = 0;
            if (X < j && j < Y) J = 1;
            if (Y <= j) J = 2;
            
            if (I == 0 && J == 0) ++ans[j - i];
            if (I == 2 && J == 2) ++ans[j - i];
            if (I == 0 && J == 2) ++ans[(X - i) + (j - Y) + 1];
            if (I == 0 && J == 1) {
                if (2 * j <= X + Y + 1) ++ans[j - i];
                else ++ans[(X - i) + (Y - j) + 1];
            }
            if (I == 1 && J == 2) {
                if (X + Y - 1 <= 2 * i) ++ans[j - i];
                else ++ans[(j - Y) + (i - X) + 1];
            }
            if (I == 1 && J == 1) {
                int l = min(i - X, Y - i + 1);
                int r = min(Y - i, i - X + 1);
                ++ans[ min(min(j - X + l, Y - j + r), j - i) ];
            }
        }
    }
    
    for (int i = 1; i < N; ++i) cout << ans[i] << endl;
    return 0;
}

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

using namespace std;
#define ll long long
const long double EPS = 1e-8;
const long double PI = acos(-1);
const int N = 1e5 + 9;
int n, m;

vector<int> adj[N];
int mem[N];

int dfs(int node) {
    if (~mem[node])return mem[node];
    mem[node] = 0;
    for (auto child:adj[node]) {
        mem[node] = max(mem[node], 1 + dfs(child));
    }
    return mem[node];
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u - 1].push_back(v - 1);
    }
    memset(mem, -1, sizeof mem);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, dfs(i));
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7424
#include <iostream>
#include <cstring>
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int a[26];
ll f[21];

ll calc_f (int n )
{
	if (n == 0 ) return 1LL;

	return ((ll)n*calc_f (n-1));
}

int main()
{
	memset (f, 0LL, sizeof (f ) );
	memset (a, 0, sizeof (a ) );
	rep (i, 21 )
		f[i] = calc_f (i );

	string s = "";
	cin >> s;
	int len = s.length();
	bool even = (len % 2 == 0 ? true : false );
	
	rep (i, len )
		a[s[i] - 'a']++;
	ll res = 0LL;

	if (even ){
		rep (i, 26 ){
			if (a[i] == 0 ) continue;
			else
			if (a[i] % 2 != 0 ){
				cout << 0 << endl;
				return 0;
			} // end if
		} // end rep
		res = f[len/2];
		rep (i, 26 ){
			if (a[i] == 0 || a[i] == 2 ) continue;
			res /= f[a[i]/2];
		} // end rep
		cout << res << endl;
	}else{
		int od = 0, ev = 0;
		rep (i, 26 ){ 
			if (a[i] == 0 ) continue;
			else
			if (a[i] % 2 == 0 ) ev++;
			else
				od++;
		} // end rep
		if (od != 1 ){
			cout << 0 << endl;
			return 0;
		} // end if
		res = f[(len-1)/2];
		rep (i, 26 ){
			if (a[i] == 0 || a[i] == 1 || a[i] == 2 ) continue;
			res /= f[a[i]/2];
		} // end rep
		cout << res << endl; 
	} // end if

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
	
	char input[9];
	int h, w;
	int i, j;
	
	while (1){
		
		fgets(input, sizeof(input), stdin);
		h = atoi(strtok(input," "));
		w = atoi(strtok(NULL, " "));
		
		if (h == 0 || w == 0){
			break;
		}
		
		for (i = 1; i <= h; i++){
			
			if ((i % 2) == 1){
				for (j = 1; j <= w / 2; j++){
					printf("#.");
				}
				if (w % 2){
					printf("#");
				}
			}else{
				for (j = 1; j <= w / 2; j++){
					printf(".#");
				}
				if (w % 2){
					printf(".");
				}
			}
			
			printf("\n");
		}
		
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 524
import functools

def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
    
def gcd(nums):
    return functools.reduce(euclid, nums)
sn =0
N = int(input())
N +=1
for x in range(1,N):
    for y in range(x,N):
        for z in range(y,N):
            if x ==y and y ==z:
                sn +=gcd([x,y,z])
            elif x ==y or y == z or z==x:
                sn +=gcd([x,y,z])*3
            else: sn +=gcd([x,y,z])*6
print(sn)

Measured memory_bytes: 9628
import math
 
S = int(input())
 
 
X1 = 0
Y1 = 0
X2 = 10 ** 9
X3 = 1
 
Y3 = math.ceil(S / (10 ** 9))
Y2 = X2 * Y3 - S
 
print(X1, Y1, X2, Y2, X3, Y3)

Measured memory_bytes: 3060
import java.util.Scanner;

class Main{
 public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   String s = sc.next();
   String t = sc.next();
   int a = sc.nextInt();
   int b = sc.nextInt();
   String u = sc.next();

   if(u.equals(s)) {System.out.print((a-1) +" "+ b);}
	else {System.out.print(a +" "+ (b-1));}
 }
}


Measured memory_bytes: 21588
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

A,B,C,D = LI()

lcm = C * D // math.gcd(C,D)

# 下側は切り上げ
# tmp = (B//C)-math.ceil(A/C)+1 + (B//D)-math.ceil(A/D)+1 - (B//lcm - math.ceil(A/lcm) + 1)
tmp = (B//C)-((A-1)//C)+1 + (B//D)-((A-1)//D)+1 - (B//lcm - ((A-1)//lcm) + 1)
# 4-2+1, 3-2+1, 1-1+1
ans = B-(A-1)+1 - tmp
print(ans)


Measured memory_bytes: 26804