akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		if(b%a == 0){
			System.out.println(a+b);
		} else {
			System.out.println(b-a);
		}
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const int INF = pow(10, 7);
int main(){
  int n, m;cin>>n>>m;
  vector<int> x(n), y(n);
  ll ans=-1;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i];
  for(int i=0;i<n;i++){
  	for(int j=0;j<i;j++){
      for(int k=0;k<n;k++){
        for(int l=0;l<k;l++){
          int x1=x[i], x2=x[j];
          int y1=y[k], y2=y[l];
          if(x1>x2)swap(x1, x2);
          if(y1>y2)swap(y1, y2);
          int count=0;
          for(int t=0;t<n;t++){
          	if(x1<=x[t]&&x[t]<=x2&&y1<=y[t]&&y[t]<=y2)count++;
          }
          // printf("(%d, %d) to (%d, %d) counts: %d\n", x1, y1, x2, y2, count);
          if(count>=m){
            if(ans==-1)ans=ll(x2-x1)*ll(y2-y1);
            else ans=min(ans, ll(x2-x1)*ll(y2-y1));
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

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

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const ll MAX_N = 100000;
const ll MOD = 1000000007;

ll solve(const int n, const vector<ll> &A) {
    int counter[3] = {0, 0, 0};
    ll acc = 1;
    for (int i = 0; i < n; i++) {
        ll a = 0;
        bool found = false;
        ll x = A[i];

        for (int j = 0; j < (int) (sizeof(counter) / sizeof(counter[0])); j++) {
            if (x == counter[j]) {
                if (!found) {
                    counter[j]++;
                    found = true;
                }
                a++;
            }
        }
        acc = (acc * (a % MOD)) % MOD;
    }
    return acc;
}

int main(void) {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    cout << solve(N, A) << endl;
    
    return 0;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//
//public class atcoder0221_C{
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int[] num = new int[N];
		for(int i =0;i<N;i++) {
			num[i]=-1;
		}
		Map<Integer,Integer> map = new HashMap<Integer,Integer>();
		int result = 0;
		for(int i=0;i<M;i++) {
			int S = scan.nextInt();
			int C = scan.nextInt();
			if(map.get(S)==null){
				map.put(S, C);
			}else if(map.get(S)==C){
            }else{
				result =-1;
			}
		}

		if(result!=-1) {     
			Object[] mapkey = map.keySet().toArray();
			Arrays.sort(mapkey);

			for (Integer nKey : map.keySet())
			{
				num[nKey-1]=map.get(nKey);
			}
			if(num[0]==0&&N>1) {
				result = -1;
			}else {
				int count = 1;
				int j = 1;
				for(int i =1;i<N;i++) {
					j = j*10;
				}
				for(int i:num) {
					if(N==1&&count==1&&i==-1){
						i=0;
					}else if(N>1&&count==1&&i==-1){
						i=1;
					}else if(count!=1&&i==-1){
						i=0;
					}
					result=result+(i*j);
					j=j/10;
                  count++;
				}
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 23764
#解説AC
n=int(input())
a=list(map(int,input().split()))
dp=[[[-1]*(301) for i in range(301)] for j in range(301)]
# dp[a][b][c]=(1個の皿がa枚,2個の皿がb枚,3個の皿がc枚ある時, 全て食べ終わるまでの操作回数の期待値)
# dp[a][b][c]の遷移
#               確率          行先
# 1枚が引かれる  a/N　　　    dp[a-1][b][c]
# 2枚が引かれる  b/N　　　    dp[a+1][b-1][c]
# 3枚が引かれる  c/N　　　    dp[a][b+1][c-1]
# 0枚が引かれる  (N-a-b-c)/N　dp[a][b][c]

#dp[a][b][c]=dp[a-1][b][c]*a/n+dp[a+1][b-1][c]*b/n+dp[a][b+1][c-1]*c/n+dp[a][b][c]*(n-a-b-c)/n+1
#dp[a][b][c]=(dp[a-1][b][c]*a+dp[a+1][b-1][c]*b+dp[a][b+1][c-1]*c+n)/(a+b+c)

def memo(i,j,k):
    if dp[i][j][k]+1:
        return dp[i][j][k]
    ans=n
    if i>0:
        ans+=memo(i-1,j,k)*i
    if j>0:
        ans+=memo(i+1,j-1,k)*j
    if k>0:
        ans+=memo(i,j+1,k-1)*k
    dp[i][j][k]=ans/(i+j+k)
    return ans/(i+j+k)
dp[0][0][0]=0
x,y,z=0,0,0
for i in a:
    if i==1:
        x+=1
    elif i==2:
        y+=1
    else:
        z+=1
print(memo(x,y,z))

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

int N, K;
long a[5000];

int main(){
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> N >> K;
    for(int i=0; i < N; ++i) cin >> a[i];
    sort(a, a + N);

    long s = 0;
    int ans = N;
    for(int i=N-1; i >= 0; --i) {
        if(s + a[i] < K) s += a[i];
        else ans = min(ans, i);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
void max_self(ll &a,ll b){
	a=max(a,b);
}
int main(){
	ll n,Wt;
	cin>>n>>Wt;
	vector<ll>dp(Wt+1);
	for(int item=0;item<n;item++){
		ll w,val;
		cin>>w>>val;
		for(ll wt_al=Wt-w;wt_al>=0;wt_al--){
			ll temp=dp[wt_al];
			max_self(dp[wt_al+w],temp+val);
		}
	}
	ll ans=0;
	for(int i=0;i<=Wt;i++){
		max_self(ans,dp[i]);
	}
	cout<<ans;
}

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

int main(){
    int N,K;
    cin >> N >> K;
    int h, count;
    count=0;
    for(int i=0; i<N; i++){
        cin >> h;
        if( h>=K ){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;
const ll INF = 1061109567;
const double EPS = 1e-10;

int main(){
    int N;
    cin>>N;
    if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9){
        cout<<"hon"<<endl;
    }else if(N%10==0||N%10==1||N%10==6||N%10==8){
        cout<<"pon"<<endl;
    }else{
        cout<<"bon"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;


int main(){
    int n,m,c;cin >> n >> m >> c;
    vector<int> b(m),a(m);
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    LL ans=0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[j];
        }
        LL sum=c;
        for (int j = 0; j < m; j++) {
            sum+=a[j]*b[j];
        }
        if(sum>0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
using namespace std;
int main(void)
{
    long n;
    long a,b;
    a=1;
    b=1;
    long min=10000000000000;
    long distance;
    scanf("%ld",&n);
    for(long i=1;i<sqrt(n)+1;i++)
    {
        if(n%i==0)
        {
            if(min>i+(n/i))
            {
                a=i;
                b=n/i;
                min=a+b;
            }
        }
    }
    distance = a-1+b-1;
    printf("%ld",distance);

     return 0;
}

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

//C++14 (GCC 5.4.1)
int main() {
    int N,K;
    cin >>N>>K;
    K--;

    string S;
    cin >>S;
    if(S[K]=='A')S[K]='a';
    if(S[K]=='B')S[K]='b';
    if(S[K]=='C')S[K]='c';

    cout << S <<endl;
    return (0);
}

Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))

heapq.heapify(a)

for _ in range(m):
    num = heapq.heappop(a)
    heapq.heappush(a, -(-num//2))

print(-sum(a))

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int r; cin >> r;
    cout << r*r << endl;
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int mx=1e6+777;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	vector<bool> flag(mx,true);
	flag[0]=flag[1]=false;
	for (int i=2; i*i<mx; i++)
		if(flag[i])
			for (int j=i; j*i<mx; j++)
				flag[i*j]=false;
	ll n,p; cin>>n>>p;
	map<ll,int> ct;
	for (int i=0; i<mx; i++) {
		if(!flag[i])
			continue;
		while(p%i==0)
			ct[i]++, p/=i;
	}
	ct[p]++, p=1;
	ll ret=1;
	for (auto it : ct)
		for (int i=0; i<it.second/n; i++)
			ret*=it.first;
	cout<<ret<<"\n";
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

// https://onihusube.hatenablog.com/entry/2019/07/23/183851
template<typename Str>
auto regex_searches(Str& str, const std::regex& patern) {
	using std::begin;
	using std::end;
	using str_iterator_t = decltype(begin(str));

	struct wrap_regex_iterator {
	using iterator = std::regex_iterator<str_iterator_t>;

	auto begin() const noexcept -> iterator {
		return first;
	}

	auto end() const noexcept -> iterator {
		return last;
	}

	explicit operator bool() const noexcept {
		return first != last;
	}

	iterator first;
	iterator last;
	};

	return wrap_regex_iterator{{begin(str), end(str), patern}, {}};
}

void solve()
{
	int ans[100000];
	fill(ans, ans + 100000, 0);

	string s;
	cin >> s;

	regex re("R+L+");
    smatch match;
	for (auto&& match : regex_searches(s, re))
	{
		// cout << match[0] << endl;
		int r_cnt = 0;
		int l_cnt = 0;
		for(int i = 0; i < match[0].length(); ++i)
		{
			if (match[0].str()[i] == 'R')r_cnt++;
			else l_cnt++;
		}
		for(int i = 0; i < r_cnt - 1; ++i) cout << "0 ";
		cout << (r_cnt + 1) / 2 +  l_cnt      / 2 << " ";
		cout <<  r_cnt      / 2 + (l_cnt + 1) / 2 << " ";
		for(int i = 0; i < l_cnt - 1; ++i) cout << "0 ";
	}


}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 32400
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define szz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
bool ball[100001];
int main()
{
    int sum=0,N,K;
    scanf("%d %d",&N,&K);
    rep(i,N)
    {
        int num;
        scanf("%d",&num);
        sum+=2*min(num,K-num);
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;

int calc_pcnt(int val) {
  int res = 0;
  while (val != 0) {
    if ((val & 1) == 1) {
      res++;
    }
    val = val >> 1;
  }
  return res;
}

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

  int32_t N;
  cin >> N;
  string X;
  cin >> X;
  int32_t bc = 0;
  for (int i = 0; i < (int) X.size(); i++) {
    if (X[i] == '1') {
      bc++;
    }
  }

  vector<vector<int32_t>> mod_vect(N, vector<int32_t>(2, 0));
  mod_vect[0][0] = bc > 1  ? 1 % (bc - 1) : -1;
  mod_vect[0][1] = 1 % (bc + 1);
  for (int shift = 1; shift < N; shift++) {
    mod_vect[shift][1] = (mod_vect[shift-1][1] << 1) % (bc + 1);
    if (bc > 1) {
      mod_vect[shift][0] = (mod_vect[shift-1][0] << 1) % (bc - 1);
    }
  }

  int32_t base_1st_modp = 0;
  int32_t cur_val = 0;
  int32_t idx = 0;
  while (idx < N && X[idx] == '0') idx++;
  while (idx < N) {
    cur_val = (cur_val << 1);
    if (X[idx] == '1') {
      cur_val += 1;
    }
    if (cur_val >= bc + 1) {
      //cout << "cur_val:" << cur_val << ", idx:" << idx << endl;
      cur_val %= (bc + 1);
    }
    idx++;
  }
  base_1st_modp = cur_val;
  //cout << "base modp: " << cur_val << endl;

  int32_t base_1st_modm = 0;
  if (bc > 1) {
    cur_val = 0;
    idx = 0;
    while (idx < N && X[idx] == '0') idx++;
    while (idx < N) {
      cur_val = (cur_val << 1);
      if (X[idx] == '1') {
        cur_val += 1;
      }
      if (cur_val >= bc - 1) {
        cur_val %= (bc - 1);
      }
      idx++;
    }
    base_1st_modm = cur_val;
  }

  //cout << "base modm: " << cur_val << endl;

  for (int i = 0; i < N; i++) {
    if (X[i] == '0') {
      cur_val = base_1st_modp + mod_vect[N-i-1][1];
      cur_val %= (bc + 1);
    } else {
      if (bc > 1) {
        cur_val = base_1st_modm - mod_vect[N-i-1][0];
        cur_val %= (bc - 1);
        if (cur_val < 0) cur_val += bc - 1;
      } else {
        cout << 0 << endl;    
        continue;
      }
    }
    int32_t cnt = 1;
    int32_t pcnt = 0;
    while (cur_val != 0) {
      pcnt = calc_pcnt(cur_val);
      cur_val %= pcnt;
      cnt++;
    }
    cout << cnt << endl;
  }

  return 0;
}



Measured memory_bytes: 14304
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string S, long long K){
  char p = S[0];
  string Sp = S;
  bool f = true;
  for(int i=1; i<S.size(); i++) {
    if(p!=S[i])
      f = false;
  }
  if(f and S.size()%2!=0) {
    std::cout << K*S.size()/2 << std::endl;
    return;
  }
  ll a=0;
  for(int i=1; i<Sp.size(); i++) {
    if(Sp[i]==p) {
      a++;
      Sp[i] = 'A';
    }
    p=Sp[i];
  }

  string Ss = S+S;
  ll l=0;
  p = Ss[0];
  for(int i=1; i<Ss.size(); i++) {
    if(Ss[i]==p) {
      l++;
      Ss[i] = 'A';
    }
    p=Ss[i];
  }

  std::cout << a+(K-1)*(l-a) << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  long long K;
  scanf("%lld",&K);
  solve(S, K);
  return 0;
}



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

using namespace std;

#define int long long
#define N 100005
#define MOD 1000000007

int ans[N];

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

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


    int maxi = 0;
    int tot = 0;

    if(a==b)
    {
        cout<<0<<endl;
    } 
    else
    {
        maxi = 1e10;
        for(int i=0;i<n;i++)
        {
            if(a[i] > b[i])
                maxi = min(maxi, b[i]);
            tot+=a[i];
        }
        cout<<tot-maxi<<endl;
    }

    return 0;
}

Measured memory_bytes: 512
//string _(){
//    string s;
//    cin >> s;
//    while(!s.empty()){
//        vs words = {"dream","dreamer","erase","eraser"};
//        bool found = false;
//        for(string t : words){
//            if(sz(s) >= sz(t) && s.substr(sz(s)-sz(t)) == t){
//                s.erase(s.end()-sz(t),s.end());
//                found = true;
//                break;
//            }
//        }
//        if(!found)
//            return "NO";
//    }
//    return "YES";
//}
#include <iomanip>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef vector<string> vs;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
string _(){
    string s;
    cin >> s;
    while(!s.empty()){
        vs words = {"dream","dreamer","erase","eraser"};
        bool found = false;
        for(string t : words){
            if(sz(s) >= sz(t) && s.substr(sz(s)-sz(t)) == t){
                s.erase(s.end()-sz(t),s.end());
                found = true;
                break;
            }
        }
        if(!found)
            return "NO";
    }
    return "YES";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


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


int main() {
	string S, T;
	cin >> S >> T;
	T += T;
	if (-1 != T.find(S)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;

constexpr int MAXN = 2e5 + 5, MOD = 1e9 + 7;

template <typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}


int n;
array<int, MAXN> a, b, ans;

struct SegTree {
    SegTree* lson, *rson;
    int l, r;
    int max;
} *root, tree[MAXN << 1];

inline SegTree* newNode(SegTree*& root) {
    static int tot;
    return root = &tree[tot++];
}

inline void update(SegTree* root) {
    root->max = max(root->lson->max, root->rson->max);
}

inline void build(SegTree*& root, int l, int r) {
    newNode(root);
    root->l = l, root->r = r;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(root->lson, l, mid), build(root->rson, mid + 1, r);
}

inline void modify(SegTree* root, int val, int num) {
    if (root->l == val && root->r == val) {
        root->max += num;
        return;
    }
    int mid = (root->l + root->r) >> 1;
    if (val <= mid) modify(root->lson, val, num);
    else modify(root->rson, val, num);
    update(root);
}

int res = 0;
inline void query(SegTree* root, int l, int r) {
    if (l <= root->l && root->r <= r) {
        if (root->max == 0) return;
        if (root->l == root->r) {
            res = max(res, root->l);
            return;
        }
        if (root->lson->max > 0 && root->lson->max >= root->rson->max)
            query(root->lson, l, r);
        else query(root->rson, l, r);
        return;
    }
    int mid = (root->l + root->r) >> 1;
    if (l <= mid) query(root->lson, l, r);
    if (r > mid) query(root->rson, l, r);
}

inline int qpos(SegTree* root, int pos) {
    if (root->l == pos && root->r == pos) {
        return root->max;
    }
    int mid = (root->l + root->r) >> 1;
    if (pos <= mid) return qpos(root->lson, pos);
    else return qpos(root->rson, pos);
}

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    build(root, 1, n);
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        modify(root, b[i], 1);
    }
    for (int i = n; i >= 1; i--) {
        res = 0;
        if (a[i] > 1)
            query(root, 1, a[i] - 1);
        if (a[i] < n && !res)
            query(root, a[i] + 1, n);
        if (!res) {
            cout << "No" << endl;
            return 0;
        }
        modify(root, res, -1);
        ans[i] = res;
    }
    cout << "Yes" << endl;
    for (int i = 1; i <= n; i++)
        cout << ans[i] << " ";
    return 0;
}


Measured memory_bytes: 18504
//https://atcoder.jp/contests/dp/tasks/dp_v
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int N,M;
vector<int> g[112345];
LL ret[112345];
vector<LL> LtoR[112345];
vector<LL> RtoL[112345];
void dfs(int v,int p){
    LtoR[v].resize(g[v].size()+2);
    RtoL[v].resize(g[v].size()+2);
    LtoR[v].front()=1;
    RtoL[v].back()=1;

    for(int u:g[v]){
        if(u==p)continue;
        dfs(u,v);
    }
    for(int e:range(g[v].size())){
        int u = g[v][e];
        LtoR[v][e+1]=LtoR[v][e];
        if(u==p)continue;
        LtoR[v][e+1]*=(LtoR[u].back()+1);
        LtoR[v][e+1]%=M;
    }
    for(int re:range(g[v].size())){
        int e=g[v].size()-re-1;
        int u = g[v][e];
        RtoL[v][e+1]=RtoL[v][e+2];
        if(u==p)continue;
        RtoL[v][e+1]*=(LtoR[u].back()+1);
        RtoL[v][e+1]%=M;
    }
    LtoR[v].back()=RtoL[v].front()=RtoL[v][1];
}
void solve(int v,int p,LL k){
    ret[v]=k*LtoR[v].back()%M;
    //cout<<v<<" "<<k<<endl;
    for(int e:range(g[v].size())){
        int u = g[v][e];
        if(u==p)continue;
        LL x = LtoR[v][e]*RtoL[v][e+2]%M;
        solve(u,v,(k*x+1)%M);
    }

}
int main(){
    cin>>N>>M;
    for(int i:range(N-1)){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,0);
    solve(0,0,1);
    for(int i:range(N)){
        cout<<ret[i]<<endl;
    }
    //cout<<RtoL[0][2]<<endl;
    return 0;
}

Measured memory_bytes: 28800
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        
        double ans = (double)W*(double)H/2.0;
        
        if(W==x*2 && H==y*2){
            System.out.println(ans+" "+1);
        }else{
            System.out.println(ans+" "+0);
        }
    }
}

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

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

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

    int N; cin >> N;
    int cnt4 = 0, cnt2 = 0, cnt = 0;
    int A;

    for (int i = 0;i < N;i++){
        cin >> A;
        if(A%4 == 0) cnt4++;
        else if(A%2 == 0) cnt2++;
        else cnt++;
    }

    if(cnt2 != 0 && cnt4 < cnt){ cout << "No" << endl; return 0;}
    if(cnt2 == 0 && cnt4+1 < cnt){ cout << "No" << endl; return 0;}
    if(cnt4 == 0 && cnt > 0){ cout << "No" << endl;}
    else cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
    int cnt, taro=0, hanako=0;
    string taro_s, hanako_s;
    cin >> cnt;
    for (int i=0; i<cnt; i++){
        cin >> taro_s >> hanako_s;
        if (taro_s == hanako_s){
            taro++;
            hanako++;
        } else if (taro_s > hanako_s){
            taro += 3;
        } else {
            hanako += 3;
        }
    }
    cout << taro << " " << hanako << endl;
    return 0;
}


Measured memory_bytes: 3120
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll a, b, n, ans;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>a>>b>>n;
    ll x = min(b - 1, n);
    ans = a * x / b - a * (x / b);
    cout<<ans;
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


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

int main() {
  while(true) {
    string s;
    cin >> s;
    if(s == "-") break;
    int m, h = 0;
    cin >> m;
    for(int i = 0; i < m; i++) {
      int hi;
      cin >> hi;
      h += hi;
    }
    int shikiri = 0;
    shikiri = h % s.size();
    if(shikiri == 0) cout << s << "\n";
    else {
      cout << s.substr(shikiri, s.size() - shikiri) << s.substr(0, shikiri) << "\n";
    }
  }
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	vector<vector<int>>dp(s.size()+1,vector<int>(t.size()+1,0));
	for(int i=0;i<s.size();++i){
		for(int j=0;j<t.size();++j){
			if(s.at(i)==t.at(j))dp.at(i+1).at(j+1)=dp.at(i).at(j)+1;
			else dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j),dp.at(i).at(j+1));
		}
	}
	string ans;
	for(int i=s.size(),j=t.size();i>=0&&j>=0;--i,--j){
		int cur=dp.at(i).at(j);
		if(!cur)break;
		while(dp.at(i-1).at(j)==cur)--i;
		while(dp.at(i).at(j-1)==cur)--j;
		ans+=s.at(i-1);
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n"s;
}


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

#define SIZE 16

typedef struct node {
    char elem;
    struct node *next;
} node;

void push(node **first, char elem) {
    node *new = (node *)malloc(sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

char pop(node **first) {
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}

int main() {
    char input[SIZE] = {'\0'};
    char output[SIZE] = {'\0'};
    char *ptr_i, *ptr_o;
    node *first = NULL;
    
    scanf("%s", input);
    ptr_i = input;
    while(*ptr_i != '\0') {
        if(*ptr_i == 'B' && first != NULL) {
            pop(&first);
        } else if(*ptr_i == '0' || *ptr_i == '1') {
            push(&first, *ptr_i);
        }
        ptr_i++;
    }

    ptr_o = output;
    while(first != NULL) {
        *ptr_o = pop(&first);
        ptr_o++;
    }
    for(int i = SIZE - 1; i >= 0; i--) {
        if(output[i] == '\0') continue;
        printf("%c", output[i]);
    }
    printf("\n");

    return 0;
}


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

using namespace std;

int main(){

  int a,b;

  cin >> a >> b;

  if(a + b < 0)cout << -1 << endl;

  else if(!(a + b))cout << 0 << endl;

  else cout << 1 << endl;

  return 0;

}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
    int n,l;
    cin >> n>>l;
    vector<int>a(n);
    for(int i =0;i<n;i++){
        a[i]+= l;
        l++;
    }
    
    
    int bited = 1000;
    
    for(int i = 0;i<n;i++){
        bited = min(abs(a[i]),bited);
        
    }
    int sum =0;
    for(int i =0;i<n;i++){
        if(abs(a[i])!=bited){
            sum+=a[i];
        }
    }
    cout << sum;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i = 2; i <= n; i++)
        while (n % i == 0){
            res[i]++;
            n /= i;
        }
    return res;
}

bool is_prime(ll n){
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) return false;
    }
    return true;
}

int main(void)
{
    ll A,B;
    cin >> A >> B;
    // auto a = prime_factor(A);
    // auto b = prime_factor(B);

    set<ll> a;
    for (ll i = 1; i*i <= A; i++) {
        if(A%i==0) {
            a.insert(i);
            if(i*i != A) a.insert(A/i); //Nが平方数である時の対策
        }
    }

    set<ll> b;
    for (ll i = 1; i*i <= B; i++) {
        if(B%i==0) {
            b.insert(i);
            if(i*i != B) b.insert(B/i); //Nが平方数である時の対策
        }
    }


    int ans = 0;
    for(auto &&ai : a){
        if(b.count(ai) > 0){
            if(is_prime(ai)) ans++;
        }
    }
    pr(ans);
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<int> v(N);
  rep(i,N)cin >> v[i];
  int ans = 1e9;
  repp(x,1,101){
    int sum = 0;
    rep(i,N){
      sum += (v[i] - x)*(v[i] - x);
    }
    ans = min(ans,sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char ch;

	while ((ch = getchar()) != EOF) {
		if (96 < ch && ch < 123) {
			printf("%c", ch-32);
		}
		else if (64 < ch && ch < 92) {
			printf("%c", ch+32);
		}
		else {
			printf("%c", ch);
		}
	}

	return 0;
}


Measured memory_bytes: 2448
def solve():
    n = int(input())
    rolls = [list(map(int,input().split())) for i in range(n)]
    for i in range(n-2):
        if rolls[i][0]==rolls[i][1] and rolls[i+1][0]==rolls[i+1][1] and rolls[i+2][0]==rolls[i+2][1]:
                return True

    return False

print("Yes" if solve() else "No")

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

using namespace std;

int main()
{
    int n;
    string s;
    cin>>n>>s;
    if(n%2)
        cout<<"No";
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[n/2+i])
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
    }
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>



#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=1e6+100;
const int N=2e5+10;
const int M=1e6+10;
const ll mm=(1LL<<32);

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

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll a[N];
int main()
{
#ifdef local
      freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;cout.tie(0);
    int n;cin>>n;
    rep1(i,n) cin>>a[i];
    sort(a+1,a+1+n,greater<int>());
    ll sum=a[1];
    for(int i=3;i<=n;++i)
    {
        sum+=a[(i+1)/2];
    }
    cout<<sum<<endl;
    return 0;
}


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

using namespace std;

const int t[10][10] = {
	{3, 2, 6, 1, 5, 4},
	{4, 2, 1, 6, 5, 3},
	{2, 6, 3, 4, 1, 5},
	{5, 1, 3, 4, 6, 2}

};

int main()
{
	int d[10], a[10], k[200];
	string s;
	k['W'] = 0, k['E'] = 1, k['N'] = 2, k['S'] = 3;
	
	for(int i = 0; i<6; i++)
	{
		cin >> d[i];	
	}
	cin >> s;
	
		for(int i = 0; i< s.size(); i++)
	{
		for(int j = 0; j < 6; j++)	
		{
			a[j] = d[t[k[s[i]]][j]-1];
		}
		for(int j = 0; j < 6; j++)	
		{
			d[j] = a[j];
		}		
	}
	cout << d[0] << endl;
	return 0;


	


	
 } 



Measured memory_bytes: 3208
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;

int main(void)
{
    double a, b, x, y, theta;

    cin >> a >> b >> x;

    if((x/a) > a*b/(double)2){
        y = (double)2 * (a*b-(x/a)) / a / a;

        theta = atan(y) * (double)180 / M_PI;
    }

    else{
        y = b * b / (double)2 / (x/a);

        theta = atan(y) * (double)180 / M_PI;
    }

    cout << setprecision(10) << theta << endl;

    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc145/tasks/abc145_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

const int MOD = 1e9 + 7;

template <int N, typename T, T M> struct factorial_mod {
    T mod[N + 1];
    T inv_mod[N + 1];

    constexpr factorial_mod() : mod(), inv_mod() {
        mod[0] = 1;
        for (int i = 0; i < N; ++i) {
            mod[i + 1] = (mod[i] * (i + 1)) % M;
        }
        inv_mod[N] = power(mod[N], M - 2);
        for (int i = N - 1; i >= 0; --i) {
            inv_mod[i] = (inv_mod[i + 1] * (i + 1)) % M;
        }
    }

    constexpr T power(T a, T b) {
        T r = 1;
        while (b > 0) {
            if ((b & 1) != 0)
                r = (r * a) % M;
            a = (a * a) % M;
            b >>= 1;
        }
        return r;
    }

    constexpr T comb(T n, T r) {
        return (((mod[n] * inv_mod[r]) % M) * inv_mod[n - r]) % M;
    }
};
factorial_mod<1000000, long long, MOD> facmod;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int X, Y;
    cin >> X >> Y;
    int x = X, y = Y;
    if ((x + y) % 3 != 0) {
        cout << "0\n";
        return 0;
    }
    int n = (x + y) / 3;
    x -= n;
    y -= n;
    if (x < 0 || y < 0) {
        cout << "0\n";
        return 0;
    }
    cout << facmod.comb(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod  = 1e9 + 7;
const ll N = 1e3 + 5;

int n,m,sx,sy,ex,ey;
int vis[N][N];
char a[N][N];

struct node{
	int x,y,z;
	bool operator <(const node &T) const{
		return z>T.z;
	}
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>sx>>sy>>ex>>ey;
    for(int i=1;i<=n;i++) cin>>a[i]+1;
    priority_queue<node> q;
    memset(vis,-1,sizeof(vis));
    vis[sx][sy]=0;
    q.push({sx,sy,0});
    while(q.size()){
    	node t=q.top();q.pop();
    	if(t.z>=vis[ex][ey] and vis[ex][ey]!=-1) break;
    	// if(vis[ex][ey]!=-1) break;
    	int x=t.x,y=t.y,z=t.z;
    	for(int i=-2;i<=2;i++){
    		for(int j=-2;j<=2;j++){
    			int tx=x+i;
    			int ty=y+j;
    			int tz=z;
	    		if(abs(tx-x)+abs(ty-y)>1) tz++;
    			if(tx>=1 and tx<=n and ty>=1 and ty<=m and a[tx][ty]=='.' and (vis[tx][ty]==-1 || tz<vis[tx][ty])){
	    			vis[tx][ty]=tz;
	    			q.push({tx,ty,tz});
	    		}
    		}
    	}
    }
    cout<<vis[ex][ey]<<'\n';
    return 0;
}

Measured memory_bytes: 8652
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string A, B, C;
	cin >> A >> B >> C;
	int ans = 0;
	REP(i, N) {
		bool ab = A[i] == B[i];
		bool bc = B[i] == C[i];
		bool ca = C[i] == A[i];
		if (ab && bc && ca)continue;
		else if (ab || bc || ca)ans++;
		else ans += 2;
	}
	cout << ans << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 504
#include <iostream>

int main() {
  int n;
  std::cin >> n;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    int j = i;
    int keta = 0;
    while (j > 0) {
      j /= 10;
      keta++;
    }
    if (keta % 2 != 0)
      cnt++;
  }
  std::cout << cnt << std::endl;
}


Measured memory_bytes: 3104
// Arrays.sortの第二引数にコンパレータを定義した場合
// 参考 -> #4529481

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] AB = new int[n][2];

        for (int i = 0; i < n; i++) {
            AB[i][0] = sc.nextInt();
            AB[i][1] = sc.nextInt();
        }

        Arrays.sort(AB, (x, y) -> Integer.compare(x[0], y[0]));

        long totalPrice = 0;
        int totalCnt = 0;
        for (int i = 0; i < n; i++) {
            long price = AB[i][0];
            int count = AB[i][1];

            if (count >= m - totalCnt) {
                totalPrice += (m - totalCnt) * price;
                break;
            } else {
                totalPrice += count * price;
                totalCnt += count;
            }
        }

        System.out.println(totalPrice);
    }
}

Measured memory_bytes: 92232
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=1250;i++)
    {
        int x=i*0.08;
        int y=i*0.1;
        if(x==a && y==b)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;
ll A, B, n, ans, i;
int a[5];

int main()
{
	while(cin >> A >> B)
	{
		ans = 0;
		for(i = A; i <= B; i++)
		{
			a[0] = i / 10000;
			a[1] = i / 1000 % 10;
			a[2] = i % 1000 / 100;
			a[3] = i % 100 / 10;
			a[4] = i % 10;
			if(a[0] == a[4] && a[1] == a[3]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n, p = 0, ret = 0;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    rep(i, n){
        ++ret;
        p = a[p] - 1;
        if(p == 1){
            cout << ret << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


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

int main(){
  int A, B ;
  cin >> A >> B ;
  if(A %3 == 0 || B %3 == 0 || (A+B) %3 == 0 ){
    cout << "Possible" << endl;
  }
  else
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("needed");
            //2 5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("atcoder");
            //-1 -1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("ABCBA");
            //2 4
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string S = InputList[0];

        //始点のループ
        int UB = S.Length - 1;
        for (int I = 0; I <= UB; I++) {
            char StaChar = S[I];

            int Ind1 = I + 1;
            int Ind2 = I + 2;
            if (Ind1 <= UB && S[Ind1] == StaChar) {
                Console.WriteLine("{0} {1}", I + 1, Ind1 + 1);
                return;
            }
            if (Ind2 <= UB && S[Ind2] == StaChar) {
                Console.WriteLine("{0} {1}", I + 1, Ind2 + 1);
                return;
            }
        }
        Console.WriteLine("-1 -1");
    }
}

//始点をループさせつつ、
//始点の文字をA、A以外の文字をXとして
//下記の3通りに場合分けしてます

//場合1 AA
//場合2 AXA
//場合3 AXX

//場合1と場合2は、解となることが確定
//
//場合3は、
//Aが1文字、A以外の文字が2文字で、
//文字列の中にA以外の文字のほうが多いので、
//これ以上終点を右に移動させるよりも、
//4文字目を始点としたほうが、Aが半分超えとなる文字列を見つけやすい
//ということで、探索打ち切り


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int B=50,N=B*2;
int c[N][N],n,p;
ll x;

int main(){
	read(n);
	rep(i,1,n){
		char ch=getchar();
		while(!isdigit(ch)){
			ch=getchar();
		}
		x=0;
		while(isdigit(ch)){
			x=x*10+ch-'0';
			ch=getchar();
		}
		p=0;
		if(ch=='.'){
			while(!isdigit(ch)){
				ch=getchar();
			}
			while(isdigit(ch)){
				x=x*10+ch-'0';
				ch=getchar();
				p++;
			}
		}
		int c2=0,c5=0;
		while(x%2==0){
			c2++,x/=2;
		}
		while(x%5==0){
			c5++,x/=5;
		}
		//cout<<c2-p<<" "<<c5-p<<endl;
		c[c2-p+B][c5-p+B]++;
	}
	ll ans=0;
	REP(i,N) REP(j,N) if(i+j>=2*B){
		REP(x,N) REP(y,N) if(x+y>=2*B){
			if(mp(i,x)<mp(j,y)) ans+=(ll)c[i][x]*c[j][y];
			else if(i==j&&x==y) ans+=(ll)c[i][x]*(c[i][x]-1)/2;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;

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

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

    ll t = 1900 * m + 100 * (n - m);
    ll inv_p = 1 << m;
    cout << t * inv_p << endl;

    return 0;
}


Measured memory_bytes: 256