akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	s, t := io.Next(), io.Next()
	count := 0
	for i := range s {
		if s[i] != t[i] {
			count++
		}
	}
	io.Println(count)
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


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

int main() {
    int h, m, s;
    cin >> s;
    h = s / 3600;
    s %= 3600;
    m = s / 60;
    s %= 60;
    cout << h << ":" << m << ":" << s << endl;
    
    return 0;
}


Measured memory_bytes: 3088
n = int(input())
a = list(map(int, input().split()))

if n == 1:
    print(1)
    exit()

mode = 0
ans = 1
for i in range(1, n):
    if mode == 0:
        if a[i] > a[i-1]:
            mode = 1
        elif a[i] < a[i-1]:
            mode = -1
    elif mode == 1:
        if a[i] < a[i-1]:
            ans += 1
            mode = 0
    else:
        if a[i] > a[i-1]:
            ans += 1
            mode = 0

print(ans)

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

int main(){
 long long int x;
  cin>>x;
 int cnt=0;
  long long int i=100;
  while(i<x){
    i=i+i/100;
    cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int A,B,C,D,E,F;
  int temp=0,temp_max=0;
  
  cin>>A>>B>>C>>D>>E>>F;

  temp=(A+B+C+D)-min({A,B,C,D})+max({E,F});

  cout<<temp<<endl;

  return 0;
}



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

int N, A, B, C;
vector<int> V(8);

int calc_mp(int num, int a, int b, int c) {  
  if(num == 8) {
    if(a>0&&b>0&&c>0) {
      int mp = abs(a-A) + abs(b-B) + abs(c-C) - 30;
      return mp;
    } else {
      return 1e9;
    }
  }
  
  int mp1 = calc_mp(num+1, a, b, c);
  int mp2 = calc_mp(num+1, a+V[num], b, c) + 10;
  int mp3 = calc_mp(num+1, a, b+V[num], c) + 10;
  int mp4 = calc_mp(num+1, a, b, c+V[num]) + 10;
  
  return min({mp1, mp2, mp3, mp4});
  
}

int main() {
  cin >> N >> A >> B >> C;
  
  for(int i=0; i<N; i++) {
    cin >> V[i];
  }
    
  int ans = calc_mp(0, 0, 0, 0);
  cout << ans << endl;
  
  return 0;
}

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

int main() {
  int N, K;
  int num = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (num * 2 < num + K) {
      num *= 2;
    } else {
      num += K;
    }
  }
  cout << num << endl;
}


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


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;


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

    rep(i, n){
        ll tmp;
        cin >> tmp;
        if(i == 0) a[i] = tmp;
        else a[i] = tmp + a[i-1]; 
    }

    rep(i, n){
        ll tmp;
        cin >> tmp;
        b[i] = tmp;
    }

    rep(i, n){
        if(i != 0) b[n-1-i] += b[n-i];
    }

    ll m = -INF;
    rep(i, n){
        m = max(m, a[i]+b[i]);
    }

    cout << m;
}

Measured memory_bytes: 256
S=gets.chomp
N=gets.to_i

if S[/^(.)\1*$/]
	p S.size*N/2
	exit
end

a=0
S.scan(/(.)\1+/){
	a+=$&.size/2
}
b=0
if S[0]==S[-1]
	x=S[/^(.)\1*/].size
	y=S[/(.)\1*$/].size
	if x%2==1&&y%2==1
		b+=1
	end
end
p a*N+b*(N-1)


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>

using namespace std;


int main (){
int P;
int Q;
int R;

cin >> P >> Q >> R;

int a;
int b;
int c;

a = P + Q;
b = Q + R;
c = R + P;

int d;

d =  min (a,b);

cout << min (d,c);


}


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int a,b;
int main() {
    scanf("%d%d",&a,&b);
    if((a*b)%2 == 0) puts("Even");
    else  puts("Odd");
    return 0;
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

	READV(N);
	READAR(A,N+1);
	READAR(B,N);
	ll ans=0;
	FORI(i,0,N)
	{
		ll K=min(A[i],B[i]);
		ans+=K;
		A[i]-=K;
		B[i]-=K;
		K=min(A[i+1],B[i]);
		ans+=K;
		A[i+1]-=K;
		B[i]-=K;
	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void) {
	int  i,n,mod;
	long debt=100000;

	scanf("%d",&n);
	for(i=0;i<n;i++) {
		debt*=1.05;
		mod=debt%1000;
		debt+=(mod?(1000-mod):0);
	}
	printf("%ld\n",debt);
	return 0;
}

Measured memory_bytes: 592
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let nums: Vec<i32> = s.trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap()).collect();
    let (mut a, mut b, mut c): (i32, i32, i32) = (nums[0], nums[1], nums[2]);
    let mut _temp: i32;

    if a > b {
        _temp = a;
        a = b;
        b = _temp;
    }

    if b > c {
        _temp = b;
        b = c;
        c = _temp;
    }

    if a > b {
        _temp = a;
        a = b;
        b = _temp;
    }


    println!("{} {} {}", a, b, c);
}



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  string s;cin >>s;
  if(s=="Sunny"){
    cout << "Cloudy";
  } else if(s=="Cloudy"){
    cout << "Rainy";
  } else {
    cout << "Sunny";
  }
  return 0;
}


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

int main() {
    ll h;cin>>h;
    ll ans=0;
    ll num=1;
    while (h) {
        h/=2;
        ans+=num;
        num*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100009

void swap(int *,int *);
int partition(int,int);

int A[MAX];
int n;

int main(){
  int i;
  int q;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

    q=partition(0,n-1);
    for(i=0;i<n;i++){
      if(i)printf(" ");
      if(i==q)printf("[");
      printf("%d",A[i]);
      if(i==q)printf("]");
      }
      printf("\n");

return 0;
}

int partition(int p,int r){
  int x;
  int i,j;
  int t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}

void swap(int *a,int *b){
  int v;
  v=*a;
  *a=*b;
  *b=v;
}

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

int main(){
    long N;
    cin >> N;
    long long power = 1.0;

    for(double i = 1; i <= N; ++i){
        power = fmod(power * i, (pow(10.0,9.0) + 7));
    }
    cout << power << endl;
    return 0;
}

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

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())


using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

const ll mod = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k; cin>>n>>k;
    vector<ii> segs;
    for0(i, k){
        int l, r; cin>>l>>r;
        segs.pb({l, r});
    }
    vector<ll> dp(n), presum(n);
    dp[0] = 1;
    presum[0] = 1;
    for1(i, n-1){
        for(auto [l, r]: segs){
            if(i - l < 0) continue;
            if(i - r <= 0){
                dp[i] = (dp[i] + presum[i - l]) % mod;
            }
            else{
                dp[i] = (dp[i] + presum[i - l] - presum[i - r - 1] + mod) % mod;
            }
        }
        presum[i] = presum[i-1] + dp[i];
    }
    cout<<dp[n-1]<<endl;
}



Measured memory_bytes: 6360
#include <bits/stdc++.h>
#include <set> 
#include <iterator> 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)


int main()
{
  
    fastio();
    int n,k;
    cin>>n>>k;
    int a[n];
    cn(a,n);
    int dp[k+1]={0};
    for(int i=0;i<a[0];i++)
    {
        dp[i]=2;
    }
    for(int i=a[0];i<=k;i++)
    {
        int f=2;
        for(int j=0;j<n;j++)
        {
            if(i-a[j]>=0)
            {
                if(dp[i-a[j]]==2)
                    f=1;
            }
          	else
              break;
        }
        dp[i]=f;
    }
    string s = "First";
    if(dp[k]==2)
        s="Second";
    cout<<s<<endl;
}


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


int main(){
    string s;
    cin >> s;
    for(int i=0;i<s.size();++i){
        if(s[i]=='9'){
            cout << '1';
        }else{
            cout << '9';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e5+9;
int x,y,a,b,c;
multiset<ll> p,q;
ll P[sz],Q[sz],R[sz];
priority_queue<ll> r;
ll t;
ll ans;

int main(){
	cin>>x>>y>>a>>b>>c;
	for(int i=0;i<a;i++){
		cin>>t;
		P[i]=t;
	}	
	for(int i=0;i<b;i++){
		cin>>t;
		Q[i]=t;
	}		
	for(int i=0;i<c;i++){
		cin>>t;
		R[i]=t;
		r.push(t);
	}	
	sort(P,P+a,greater<ll>());
	sort(Q,Q+b,greater<ll>());
	for(int i=0;i<x;i++){
		p.insert(P[i]);
		ans+=P[i];
	}
	for(int i=0;i<y;i++){
		q.insert(Q[i]);
		ans+=Q[i];
	}
	while(!r.empty()){
		t=r.top();
		ll pm,qm;
		if(p.empty()) pm=1e18;
		else pm=*(p.begin());
		if(q.empty()) qm=1e18;
		else qm=*(q.begin());
		if(t<=min(pm,qm)) break;
		r.pop();
		ans+=t;
		if(pm<qm){
			p.erase(p.begin());
			//p.insert(t);
			ans-=pm;
		}else{
			q.erase(q.begin());
			//q.insert(t);
			ans-=qm;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 11764
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    h2 = int(S[:2])
    t2 = int(S[2:])
    hm = False
    tm = False
    if 1 <= h2 <= 12:
        hm = True
    if 1 <= t2 <= 12:
        tm = True

    if hm and tm:
        return 'AMBIGUOUS'
    elif hm:
        return 'MMYY'
    elif tm:
        return 'YYMM'
    return 'NA'


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7772
//テンプレートを最初から描いてみる
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;

namespace ABC{
    public class Program{
        public static void Main(){
            //出力を高速化する用
            var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
            Console.SetOut(sw);
            //実行時間計測する用
            var watch = new Stopwatch();
            bool isTest = false;
            watch.Start();
            //ファイルから読み込む用
            TextReader reader;
            var filename = "";
            if(filename == String.Empty){
                reader = Console.In;
            }else{
                reader = new StreamReader(filename);
            }

            watch.Stop();
            if(isTest){
                System.Console.WriteLine($"実行時間{watch.ElapsedMilliseconds}ミリ秒");
            }

            var N = int.Parse(reader.ReadLine());
            var K = int.Parse(reader.ReadLine());
            var X = int.Parse(reader.ReadLine());
            var Y = int.Parse(reader.ReadLine());
            //最初のK泊はX円
            int ans;
            if(K<N){
                ans = K*X + (N-K)*Y;
            }else{
                ans = N*X;
            }
            Console.WriteLine(ans);
            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	ll n,p;

	cin>>n>>p;

	ll o=1;
	ll d=0;
	if(n==1){
		cout<<p<<endl;
		return 0;
	}

	for(ll i=1000000; i>=2; i--){
		d=1;
		for(ll j=1; j<n+1; j++){
			d*=i;
			if(d>p){
				break;
			}
			if(p%d>0){
				break;
			}
		}
//		cout<<d<<endl;
//		if(d>p){
//			break;
//		}else{
			if(p%d==0){
				o=i;
				cout<<o<<endl;
				return 0;
			}
//		}

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


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <bitset>
#include <cmath>
#define ff first
#define ss second
#define MAXN 300005
#define INF 1000000001000000001LL
#define int long long

using namespace std;

const int mod = 998244353; //1000000007;
int n, q, i, sum[MAXN], ans[MAXN];
vector <int> g[MAXN];

int dfs(int v, int p = -1, int sm = 0){
    int i, to;

    ans[v] = sum[v] + sm;

    for(i = 0; i < g[v].size(); i++){
        int to = g[v][i];

        if(to == p)
            continue;

        dfs(to, v, sum[v] + sm);
    }
}

main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base :: sync_with_stdio(false);
    cin.tie();
    cin >> n >> q;

    for(i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    while(q--){
        int v, x;
        cin >> v >> x;
        v--;
        sum[v] += x;
    }

    dfs(0);

    for(i = 0; i < n; i++)
        cout << ans[i] << " ";

    return 0;
}







Measured memory_bytes: 31872
/**
*    author:  yuya1234
*    created: 16.07.2020 15:10:29
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long double eps = 1.0E-14;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>T lcm(T a,T b){return gcd(a,b)*(a/gcd(a,b))*(b/gcd(a,b));}

ll f(ll n, ll mod){return n==1 ? 1 : (n*f(n-1,mod))%mod;}


int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

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

  ll MOD=pow(10,9)+7;
  ll ans=0;

  if(abs(n-m)==1)
  {
   ans=(f(n,MOD)*f(m,MOD))%MOD;
  }
  else if(n==m)
  {
    ans=(2*f(n,MOD)*f(m,MOD))%MOD;
    
  }
  
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 6776
#include<cstdio>
using namespace std;
char query[6];
class Dice{
  private :
    int up;
    int front;
    int right;
    int left;
    int back;
    int bottom;
    int cnt;
  public :
    Dice(){
      cnt = 1;
      up = 1;
      front = 2;
      right = 3;
      left = 4;
      back = 5;
      bottom = 6;
    }
    int get(){
      return cnt;
    }
    void North(){
      int tmp = up;
      up = front;
      front = bottom;
      bottom = back;
      back = tmp;
      cnt += up;
    }
    void East(){
      int tmp = up;
      up = left;
      left = bottom;
      bottom = right;
      right = tmp;
      cnt += up;
    }
    void West(){
      int tmp = up;
      up = right;
      right = bottom;
      bottom = left;
      left = tmp;
      cnt += up;
    }
    void South(){
      int tmp = up;
      up = back;
      back = bottom;
      bottom = front;
      front = tmp;
      cnt += up;
    }
    void Right(){
      int tmp = front;
      front = right;
      right = back;
      back = left;
      left = tmp;
      cnt += up;
    }
    void Left(){
      int tmp = front;
      front = left;
      left = back;
      back = right;
      right = tmp;
      cnt += up;
    }
};
int main(){
  int n;
  while(true){
    scanf("%d",&n);
    if(n == 0)
      break;
    Dice d;
    for(int i = 0 ; i < n ; i++){
      scanf("%s",query);
      switch(query[0]){
        case 'N' : d.North(); break;
        case 'E' : d.East(); break;
        case 'W' : d.West(); break;
        case 'S' : d.South(); break;
        case 'R' : d.Right(); break;
        case 'L' : d.Left(); break;
      }
    }
    printf("%d\n",d.get());
  }
}



Measured memory_bytes: 2692
n, x, y = map(int,input().split())

d = [0]*n
for i in range(1, n+1):
    for j in range(i+1, n+1):
        a = min(j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))
        d[a] += 1

for i in range(1, n):
    print(d[i])

Measured memory_bytes: 3444
N = int(input())
A = [int(x) for x in input().split()]

def GCD(m, n):
  if m == 0:
    return n
  elif n == 0:
    return m
  a = max(m, n)
  b = min(m, n)
  while b > 0:
    r = a % b
    if r == 0:
      return b
    a = b
    b = r  

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
  L[i + 1] = GCD(L[i], A[i])
  R[N - i - 1] = GCD(R[N - i], A[N - i - 1])
M = [GCD(L[i], R[i+1]) for i in range(N)]
print(max(M))

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

#define rep(i, j, k) for(int i = (int) j; i < (int) k; ++i)
#define sz(x) ((int) (x).size())
#define ll long long
#define mp make_pair
#define pii pair<int, int >
#define fi first
#define se second
#define pb push_back
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define zero(x) memset((x), (0), sizeof (x))
#define zerox(x, y) memset((x), (y), sizeof (x))

using namespace std;
const int N = 100007;
const ll mo = (ll)1e9+7;

ll inv[N], f[N], fv[N];

void count() {
	inv[0] = inv[1] = f[0] = f[1] = fv[0] = fv[1] = 1;
	rep(i, 2, N) {
		inv[i] = mo - mo/i * inv[mo%i] % mo;
		f[i] = f[i-1] * i % mo;
		fv[i] = fv[i-1] * inv[i] % mo;
	}
}

ll CNM(int n, int m) {
	if(n < m) return 0;
	return f[n] * fv[m] % mo * fv[n-m] % mo;
}

int n;
int a[N];

int main()
{
#ifdef PIT
//freopen(".in", "r", stdin);
//freopen(".out", "w", stdout);
#endif //PIT

	ios_base::sync_with_stdio(false); cin.tie(0);
	
	count();
	cin >> n;
	int x, pre = -1, suf = -1;
	zero(a);
	rep(i, 1, 2+n) {
		cin >> x;
		if(a[x]) pre = a[x]-1, suf = 1+n-i;
		a[x] = i;
	}
	rep(i, 1, 2+n) {
		ll ans = (CNM(1+n, i) - CNM(suf+pre, i-1) + mo) % mo;
		cout << ans << endl;
	}

	
#ifdef PIT
flush(cout);
cerr << endl << "Time: " << (clock() / double(CLOCKS_PER_SEC)) << endl;
#endif //PIT
	return 0;
}


Measured memory_bytes: 3968
n = int(input())
a = list(map(int, input().split()))

def calc(sgn):
    ans = 0
    sum = 0
    for ai in a:
        sum += ai
        sgn *= -1
        if sum == 0:
            ans += 1
            sum = sgn
        elif sum * sgn < 0:
            ans += abs(sum) + 1
            sum = sgn
    return ans

print(min(calc(1), calc(-1)))


Measured memory_bytes: 14332
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

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

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

    ll N;
    cin >> N;

    if (N == 3) {
        cout << "2 5 63\n";
        return 0;
    } else if (N == 4) {
        cout << "2 5 20 63\n";
        return 0;
    }

    vec ans = {2, 3, 4, 6, 9};
    N -= 5;
    ll k = 6;
    while (N > 1 and k < 30000) {
        ans.push_back(k+2);
        ans.push_back(k+4);
        k += 6;
        N -= 2;
    }

    k = 18;
    while (N > 1 and k < 30000) {
        ans.push_back(k-3);
        ans.push_back(k+3);
        k += 12;
        N -= 2;
    }

    k = 12;
    while (N--) {
        ans.push_back(k);
        k += 6;
    }

    ll check = 0;
    for (ll e : ans) {
        cout << e << " ";
        check += e;
    }
    cout << endl;
    // for (ll e : ans) {
    //     if (gcd(e, check) == 1) {
    //         cout << "There is a number whose gcd is 1\n";
    //         break;
    //     }
    // }

    // cout << "ans.size():" << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b, c*d) << endl;
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i=0; i<N; i++)
    cin >> x[i];
  int g=0;
  
  for(int j=0; j<N; j++) {
    if(K-x[j]<x[j]) 
      g += (K-x[j])*2;
    else
      g += x[j]*2;
  }
  
  cout << g << endl;
}

Measured memory_bytes: 3592
#104B
s = input()
c_list = []
c_count = 0
answer = "WA"
for i in range(2,len(s)-1):
    if s[i] == "C":
        c_list.append(i)
    if s[i].islower() == False:
        c_count += 1
if s[0]=="A" and s[1].islower()==True and s[-1].islower()==True and len(c_list)==1 and c_count==1:
    answer="AC"
print(answer)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	while(1){
		int a,b,c;
		cin >> a >> b >> c;
		if(a==0&&b==0&&c==0)return 0;
		int N; cin >> N;
		V<int> x(a,2),y(b,2),z(c,2),s(N),t(N),u(N),v(N);
		for(int i = 0; i < N; ++i){
			cin >> s[i] >> t[i] >> u[i] >> v[i];
			s[i] -= 1;
			t[i] -= 1 + a;
			u[i] -= 1 + a + b;
			if(v[i]) x[s[i]] = y[t[i]] = z[u[i]] = 1;
		}
		for(int i = 0; i < N; ++i){
			if(v[i]) continue;
			if(x[s[i]] == 1 && y[t[i]] == 1) z[u[i]] = 0;
			if(y[t[i]] == 1 && z[u[i]] == 1) x[s[i]] = 0;
			if(z[u[i]] == 1 && x[s[i]] == 1) y[t[i]] = 0;
		}
		for(int i = 0; i < a; ++i) cout << x[i] << endl;
		for(int i = 0; i < b; ++i) cout << y[i] << endl;
		for(int i = 0; i < c; ++i) cout << z[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3072
#include <iostream>
using namespace std;
int main() {
    long k,a,b,result;
    cin >> k >> a >> b;
    if (a+2 >= b){
        result = k+1;
    }else{
        k = k - (a-1);
        if (k%2 == 0){
            result = k/2 * (b - a) + a;
        }else{
            result = (k/2) * (b - a) + 1 + a;
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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 ll INF = 1LL << 60;
//const int INF = 1001001001;


int main(void){
    int n;ll k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    
    vector<int> s;
    vector<int> ord(n+1,-1);
    int c=1, l=0;
    {
        int v=1;
        while(ord[v]==-1){
            ord[v]=s.size();
            s.push_back(v);
            v=a[v-1];
        }
        c=s.size()-ord[v];
        l=ord[v];
    }
    if(k<l) cout << s[k] << endl;
    else{
        k-=l;
        k%=c;
        cout << s[l+k] << endl;
    }

    return 0;
}

Measured memory_bytes: 5888
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  int x[101],y[101],h[101];
  for ( int i = 0; i < N; i++ ) cin >> x[i] >> y[i] >> h[i];

  for ( int posY = 0; posY <= 100; posY++ ) {
    for ( int posX = 0; posX <= 100; posX++ ) {
      vector<int>data;      
      for ( int i = 0; i < N; i++ ) {
	data.push_back(h[i]+abs(posX-x[i])+abs(posY-y[i]));
      }
      for ( int d = 0; d < data.size(); d++ ) {
	bool f= true;
	for ( int i = 0; i < N; i++ ) {
	  int dist = abs(posX-x[i])+abs(posY-y[i]);
	  if ( max(data[d] - dist,0) != h[i]) f = false;
	}
	if(f) {
	  cout << posX << " " << posY << " " << data[d] << endl;
	  return 0;
	}
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
//B - Checkpoints:
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, m, mini, dst, ans;
    cin >> n >> m;
    vector<ii> students(n), check(m);
    loop(i, 0, n) cin >> students[i].fi >> students[i].se;
    loop(i, 0, m) cin >> check[i].fi >> check[i].se;
    loop(i, 0, n) {
        mini = INF;
        loop(j, 0, m) {
            dst = abs(students[i].fi - check[j].fi) + abs(students[i].se - check[j].se);
            //cout << dst << "--\n";
            if(dst < mini) {
                mini = dst;
                ans = j;
            }
        }
        cout << ans+1 << "\n";
    }
}

Measured memory_bytes: 256
h, w = map(int, input().split())
graph = [[0 for _ in range(w)] for _ in range(h)]
ans_graph = []
for i in range(h):
  w_g = input()
  for j in range(w):
    graph[i][j] = w_g[j]

pop_row_list = []
pop_ar_list = []
for i in range(h):
  flag = True
  for j in range(w):
    if graph[i][j] != '.':
      flag = False
  if flag == True:
    pop_row_list.append(i)

for j in range(w):
  flag = True
  for i in range(h):
    if graph[i][j] != '.':
      flag = False
  if flag == True:
    pop_ar_list.append(j)

ans_graph = []

for i in range(h):
  if i in pop_row_list:
    continue
  ans_graph.append([])
  for j in range(w):
    if j in pop_ar_list:
      continue
    ans_graph[-1].append(graph[i][j])

for i in range(len(ans_graph)):
  print("".join(ans_graph[i]))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
const int maxn=2010;
int k,n,dis[maxn];
vector<int> a[maxn];
bool vis[maxn];
int bfs(int st,int nxt){
    queue<int> q;
    for(int i=1;i<=n;i++)
        dis[i]=maxn;
    dis[st]=0;
    dis[nxt]=0;
    q.push(st);
    q.push(nxt);
    while(!q.empty()){
        int top=q.front();
        q.pop();
        for(int i:a[top]){
            if(dis[i]==maxn){
                dis[i]=dis[top]+1;
                q.push(i);
            }
        }
    }
    int ct=0;
    for(int i=1;i<=n;i++){
        if(dis[i]>k/2)ct++;
    }
    return ct;
}

int main(){
    int u,v;
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
    }
    int ans=2010;
    if(k%2){
        for(int i=1;i<=n;i++){
            for(int j:a[i]){
                ans=min(ans,bfs(i,j));
            }
        }
    }
    else{
        for(int i=1;i<=n;i++){
            ans=min(ans,bfs(i,i));
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    // Your code here!
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    if(n>k) printf("%d\n",x*k+y*(n-k));
    else printf("%d\n",x*n);
}


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

int main() {
	string s;
	cin >> s;
	if (s.size() == 6) {
		if (s[2] == s[3] && s[4] == s[5]) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
}


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

const long long INF = 1LL << 60;

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

	long long max_h = 0;
	for (int i = 0; i < N; i++) max_h = max(max_h, h[i]);

	long long top = (max_h - 1) / B + 1;
	long long bottom = 0;
	long long middle = (top + bottom) / 2;

	long long ans = INF;
	long long cnt_one;
	bool flag = false;
	while (1) {
		cnt_one = 0;
		for (int i = 0; i < N; i++) {
			if (h[i] - middle*B - 1 >= 0) {
				cnt_one += (h[i] - middle*B - 1)/ (A - B) + 1;
			}
		}
		ans = min(ans, max(cnt_one, middle));

		if (cnt_one >= middle)
			bottom = middle;
		else
			top = middle;

		if (middle == (top + bottom) / 2)
			if (!flag) {
				flag = true;
				middle++;
			}
			else
				break;
		else
			middle = (top + bottom) / 2;
	}
	cout << ans << endl;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    cin >> n;

    vector<int> a(n);
    for (int &x : a)
        cin >> x;

    sort(a.rbegin() , a.rend());

    long long ans = a.front();
    for (int i = 1 , j = 2 ;j < n ;j += 2 , i++) {
        if (j + 1 < n)
            ans += 2 * a[i];
        else
            ans += a[i];
    }

    cout << ans;
}

Measured memory_bytes: 3976
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    int ps[s.length()];
    ps[0] = 0;
    for (int i = 1; i < s.length(); i++) {
        ps[i] = ps[i-1];
        if (s[i-1] == 'A' && s[i] == 'C') {
            ps[i]++;
        }
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << ps[r-1] - ps[l-1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
  int T[5], Tm[5];
  for(int i=0; i<5; i++) cin >> T[i];
  for(int i=0; i<5; i++) Tm[i]=(T[i]%10==0?T[i]:T[i]-T[i]%10+10);
  int S[5]={0};
  for(int i=0; i<5; i++){
    for(int j=0; j<5; j++){
      if(i!=j) S[i]+=Tm[j];
    }
  }
  for(int i=0; i<5; i++) S[i]+=T[i];
  int min=-1;
  for(int i=0; i<5; i++){
    if(min==-1||min>S[i]) min=S[i];
  }
  cout << min << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


int main()
{
	int sub[31] = {0}, i, num;

	for(i=1; i<=28; i++){
		scanf("%d", &num);
		sub[num] = 1;
	}
	for(i=1; i<=30; i++){
		if(sub[i] == 0)
			printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int qsz=1e6;int qLen,qHead,Q[1000000];
static inline void PUSH(int n){Q[(qHead+qLen)%qsz]=n;qLen++;}
static inline int POP(void){int q=Q[qHead];qLen--;qHead=(qHead+1)%qsz;return q;}
int H,W,grid[1000][1000];
static inline int f(int x,int y){return W*x+y;}
static inline void DFS(int x,int y)
{
  if(x>=0&&x<H&&y>=0&&y<W&&!grid[x][y])
  {
    grid[x][y]=1;
    PUSH(f(x,y));
    DFS(x+1,y);
    DFS(x-1,y);
    DFS(x,y+1);
    DFS(x,y-1);
  }
}
int main(void)
{
  int C[2],D[2],step=0;H=IN(),W=IN(),C[0]=IN()-1,C[1]=IN()-1,D[0]=IN()-1,D[1]=IN()-1;
  rep(i,H){char str[1001];if(!scanf("%s",str)){return -1;}rep(j,W){grid[i][j]=(str[j]=='#');}}
  PUSH(f(C[0],C[1]));
  while(qLen)
  {
    int size=qLen;
    while(size--){int x=POP();DFS(x/W,x%W);}
    size=qLen;
    while(size--)
    {
      int z=POP(),x=z/W,y=z%W;
      if(x==D[0]&&y==D[1]){return OUT(step),0;}
      for(int i=-2;i<=2;i++)
      {
        for(int j=-2;j<=2;j++)
        {
          int nx=x+i,ny=y+j;
          if(nx>=0&&nx<H&&ny>=0&&ny<W&&!grid[nx][ny]){PUSH(f(nx,ny));}
        }
      }
    }
    step++;
  }
  return puts("-1"),0;
}

Measured memory_bytes: 9020
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

    string s, t;
    cin >> s >> t;

    if (s[0] == t[2] && s[2] == t[0] && s[1] == t[1])
        cout << "YES\n";
    else
        cout << "NO\n";

    int a;
    cin >> a;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
#define per(i , j , n) for(long long i = j ; i >= n ; i--)

const ll N = 123456;
const ll mod = 998244353;
const ld eps = 1e-5;

ld a[N];
ld dp[3333][3333];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cout << fixed;
    int n;
    cin >> n;

    rep(i , 1 , n) cin >> a[i - 1];

    ld ans = 0;

    dp[0][0] = 1 - a[0];

    dp[0][1] = a[0];

    rep(i , 1 , n - 1) {
        rep(j , 0 , i + 1) {
            if(j > 0 && j < i + 1) {
                dp[i][j] = dp[i - 1][j - 1] * a[i] + dp[i - 1][j] * (1.0 - a[i]);
            }
            else if(j == 0) {
                dp[i][j] = dp[i - 1][j] * (1.0 - a[i]);
            }
            else if(j == i + 1) {
                dp[i][j] = dp[i - 1][j - 1] * a[i];
            }
        }
    }


    rep(i , n / 2 + 1 , n) ans += dp[n - 1][i];

    cout << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 158208
#include<bits/stdc++.h>
//#define int long long
#define PB push_back
#define MP make_pair
#define F first
#define S second
using namespace std;

int n, t, s, a[3010], b[3010];
int dp[3010][3010];

signed main()
{
	cin >> n >> t >> s;
	for(int i = 1; i <= n; i++){
		cin >> a[i] >> b[i];
	}
	
	for(int i = 1; i <= t; i++){
		for(int j = 1; j <= n; j++){
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if(0 <= i - b[j] && i <= s || s <= i - b[j]){
				dp[i][j] = max(dp[i][j], dp[i - b[j]][j - 1] + a[j]);
			}
		}
	}
	
	cout << dp[t][n] << endl;
	return 0;
}

Measured memory_bytes: 38404
#include <stdio.h>

int main() {
    int x1, x2, x3, x4, x5;
    scanf("%d%d%d%d%d", &x1, &x2, &x3, &x4, &x5);
    
    if(x1 == 0)
        printf("1");
    if(x2 == 0)
        printf("2");
    if(x3 == 0)
        printf("3");
    if(x4 == 0)
        printf("4");
    if(x5 == 0)
        printf("5");
        
    return 0;
}

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

using namespace std;

const int MAX = 1e9 + 10;
vector< set<int> > c(30);
int b[30000],k;

int main()
{
    int n,m,i,j,l,r,t;
    string s;
    char x;
    cin >> n;
    cin >> s;
    for(i = 0; i < 26; i ++) c[i].insert(MAX);
    for(i = 0; i < n; i ++) c[s[i]-'a'].insert(i);
    cin >> m;
    for(i = 0; i < m; i ++)
    {
        cin >> t;
        if(t == 1)
        {
            cin >> l >> x;
            l --;
            c[s[l]-'a'].erase(l);
            s[l] = x;
            c[x-'a'].insert(l);
        }
        else
        {
            cin >> l >> r;
            l --,r --;
            for(j = 0; j < 26; j ++)
            {
                if(*c[j].lower_bound(l) <= r) b[k]++;
            }
            k++;
        }
    }
    for(i = 0; i < k; i ++)
    {
        cout << b[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 24324
#include<iostream>
#include<string>
using namespace std;
int main(){
    string a,b;
    int n,s1=0,s2=0;
    cin>>n;
    while(n--){
        cin>>a>>b;
        if(a>b) s1+=3;
        else if(a<b) s2+=3;
        else s1++,s2++;
    }
    cout<<s1<<" "<<s2<<endl;
    return 0;
}


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

int power(int64_t x, int64_t i) {
  return (x * i)%1000000007;
}

int main() {
  int64_t ans=1,n;
  cin >>n;
  for (int i=1;i<=n;i++) ans=power(ans,i);
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int score[100][100];
int sum[100];
int tmp[100];
int f[100];
int rank[100];

int main(){
	int n;
	
	cin >> n;
	
	int game = n*(n-1)/2;
	
	REP(i,game){
		int a, b, c, d;
		
		cin >> a >> b >> c >> d;
		
		a--; b--;
		
		if (c > d){
			score[a][b] = 3;
			score[b][a] = 0;
		}
		else if (c < d){
			score[a][b] = 0;
			score[b][a] = 3;
		}
		else {
			score[a][b] = 1;
			score[b][a] = 1;
		}
	}
	
	int ma = 0;
	
	REP(i,n){
		REP(j,n){
			sum[i] += score[i][j];
		}
		tmp[i] = sum[i];
	}
	
	sort(tmp,tmp+n);
	
	REP(i,n){
		REP(j,n){
			if (f[j] == 0 && tmp[n-i-1] == sum[j]){
				f[j] = 1;
				rank[j] = i+1;
			}
		}
	}
	
	REP(i,n){
		cout << rank[i] << endl;
	}
	
	return 0;
}

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

int main() {
  int n,t;
  int64_t ans=0;
  cin >> n >> t;
  vector<int>ti(n);
  rep(i,n) cin>> ti.at(i);
  rep(i,n-1) ans+=min(t,ti.at(i+1)-ti.at(i));
  ans+=t;
  cout << ans << endl; 
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
 
int main()
{
int n,m[50],i;
bool f;
while(cin>>n,n){
 for(i=0;i<n;i++)cin>>m[i];
 f=false;
 cout<<m[0];
 for(i=1;i<n;i++){
  if(m[i]==m[i-1]+1){
   f=true;
  }else{
   if(f)cout<<"-"<<m[i-1];
   f=false;
   cout<<" "<<m[i];
  }
 }
 if(f)cout<<"-"<<m[n-1];
 cout<<endl;
}
}

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

int n, a[100000];
int cnt = INF;
int ans;

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


Measured memory_bytes: 3872