akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;


ll N, K;
ll A[200001];



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

	cin >> N >> K;
	FOR(i, 0, N) {
		cin >> A[i];
	}

	FOR(i, K , N) {
		if (A[i] - A[i - K] > 0) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}





	return 0;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
int A[1123], B[1123], S[1123];
int dp[1<<12];

int main() {
	cin >> N >> M;
	REP(i, M) {
		scanf("%d %d", A + i, B + i);
		REP(j, B[i]) {
			int c;
			scanf("%d", &c);
			S[i] |= 1<<(c - 1);
		}
	}
	
	fill(dp, dp + (1<<N), INF);
	dp[0] = 0;
	
	REP(i, M) {
		for (int s = (1<<N)-1; s >= 0; s--) {
			chmin(dp[s | S[i]], dp[s] + A[i]);
		}
	}
	
	int ans = dp[(1<<N)-1];
	if (ans == INF) ans = -1;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define MOD 1000000007
#define int long long
using P = pair<int,int>;
signed main(){
  int student,point;
  cin >> student >> point;
  vint a(student);
  vint b(student);
  vint c(point);
  vint d(point);
  rep(i,student) cin >> a[i] >> b[i];
  rep(i,point) cin >> c[i] >> d[i];
  rep(i,student){
    int ans = INF;
    int key = 0;
    rep(j,point){
      if(ans > abs(a[i]-c[j]) + abs(b[i]-d[j])){
        ans = abs(a[i]-c[j]) + abs(b[i]-d[j]);
        key = j;
      }
    }
    cout << key + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
void swap(int*, int*);
int main() {
  int a, b, ab, x, y, out = 0;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &ab);
  scanf("%d", &x);
  scanf("%d", &y);
  if (x > y) {
    swap(&a, &b);
    swap(&x, &y);
  }
  out += x * ab * 2;
  if (y - x){
    out += (ab * 2 < b) ? (y - x) * ab * 2 : (y - x) * b;
  }
  if (out > a * x + b * y) out = a * x + b * y;
  printf("%d\n", out);
}

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

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = -1;
		for(int i = 1; i <= 10000; i++){
			if(i * 8 / 100 == a){
				if(i * 10 / 100 == b){
					ans = i;
					break;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	int loop;
	for(loop=0;loop<N;loop++){
		cin >> A[loop];
	}
	int multi,count=0,tcut=0;
	for(loop=1;loop<=N;loop++){
		multi=2;
		count=0;
		while((N-loop+1)*multi<=N){
			if(B[(N-loop+1)*multi-1]){
				count++;
			}
			multi++;
		}
		if(count%2!=A[N-loop]){
			B[N-loop]=1;
			tcut++;
		}else{
			B[N-loop]=0;
		}
	}
	cout << tcut << endl;
	for(loop=0;loop<N;loop++){
		if(B[loop]){
			cout << loop+1;
			tcut--;
			if(tcut){
				cout << " ";
			}else{
				cout << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2432
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	s := nextStr()

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

	fmt.Println(cnt)

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1788
import java.util.*;
//import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(a<b) System.out.println("a < b");
        else if(a>b) System.out.println("a > b");
        else System.out.println("a == b");
        sc.close();
    }
}


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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto&& e : a) {
    cin >> e;
  }
  long long sum = accumulate(begin(a), end(a), 0LL);
  long long res = 1e18, l = 0;
  for (int i = 0; i < n; ++i) {
    l += a[i];
    long long r = sum - l;
    res = min(res, abs(l - r));
  }
  cout << res << '\n';
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li x[111];
li y[111];

int main() {
    li a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c + max({a, b, c}) * 9 << endl;

    return 0;
}

Measured memory_bytes: 256
n,q = (int(i) for i in input().split())
s = input()
x = [0,0]
for i in range(1,len(s)):
    if s[i]=="C" and s[i-1]=="A": x.append(x[-1]+1)
    else: x.append(x[-1])
for _ in range(q):
    l,r = (int(i) for i in input().split())
    print(x[r]-x[l])

Measured memory_bytes: 6196
N, A, B, C = map(int, input().split())
S = [input() for _ in range(N)]

A, B, C = min(A, 2), min(B, 2), min(C, 2)
X = [0, A, B, C]  # 1-indexecの方が楽そう
F = {1: 'A', 2: 'B', 3: 'C'}

ans = []
for k, s in enumerate(S):
    if s == 'AB':
        i, j = 1, 2
    elif s == 'BC':
        i, j = 2, 3
    elif s == 'AC':
        i, j = 1, 3

    if X[i] > X[j]:
        X[i] -= 1
        X[j] += 1
        ans.append(j)

    elif X[i] < X[j]:
        X[i] += 1
        X[j] -= 1
        ans.append(i)

    else:
        if (X[i] == X[j] == 1) and (k < N - 1):
            if ((S[k + 1][0] == F[i]) and (S[k + 1][1] == F[i ^ j])) or ((S[k + 1][0] == F[i ^ j]) and (S[k + 1][1] == F[i])):
                X[i] += 1
                X[j] -= 1
                ans.append(i)
            else:
                X[j] += 1
                X[i] -= 1
                ans.append(j)
        else:
            X[i] -= 1
            X[j] += 1
            ans.append(j)

    if any([x < 0 for x in X]):
        print('No')
        exit()

print('Yes')
for a in ans:
    print(F[a])


Measured memory_bytes: 17016
from collections import deque

H, W = map(int, input().split())
grid = [input() for i in range(H)]

# 初期の黒('#')の位置からの距離
dist = [[-1]*W for _ in range(H)]

# '#'の位置をキューに追加（＝今回はこれが複数あるので、複数スタートとなる）
black_cells = deque()
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            black_cells.append((h, w))
            dist[h][w] = 0

def bfs(black_cells, dist):
    d = 0
    while black_cells:
        # キューとして使うのでpop()ではなくpopleft()
        h, w = black_cells.popleft()
        d = dist[h][w]
        for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
            new_h = h + dy
            new_w = w + dx
            if new_h < 0 or H <= new_h or new_w < 0 or W <= new_w:
                continue
            if dist[new_h][new_w] == -1:  # セルが白('.')であるのと同義
                dist[new_h][new_w] = d+1
                black_cells.append((new_h, new_w))
    return d

d = bfs(black_cells, dist)
print(d)

Measured memory_bytes: 115948
#include<stdio.h>

int code(char x){
  if(x=='A')return 0;
  if(x=='B')return 1;
  if(x=='C')return 2;
  return -1;
}

int main(void){
  int cup[3];
  char x,y;
  int tmp;

  cup[0] = 1;
  cup[1] = 0;
  cup[2] = 0;

  while(scanf("%c,%c ",&x,&y)!=EOF){
    tmp = cup[code(x)];
    cup[code(x)] = cup[code(y)];
    cup[code(y)] = tmp;
  }

  if(cup[0])printf("A\n");
  if(cup[1])printf("B\n");
  if(cup[2])printf("C\n");

  return 0;
}

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

using namespace std;
using LL = long long;
const LL LINF = 1e18;
const LL MOD = 1e9+7;


int main(){
    LL L;cin >> L;
    int r = 0;
    LL uku = 1;
    while(L >= uku){
        r++;
        uku *= 2;
    }
    r--;
    vector<pair<pair<int,int>,int>> Edge;
    for(int a = 1;a <= r;a++){
        Edge.push_back(make_pair(make_pair(a,a+1),pow(2,a-1)));
        Edge.push_back(make_pair(make_pair(a,a+1),0));
    }
    for(int t = r;t >= 1;t--){
      //  cout<<t<<" "<<L-pow(2,t-1)<<" "<<pow(2,r)<<endl;
        if(L-pow(2,t-1) >= pow(2,r)){
            
            Edge.push_back(make_pair(make_pair(t,r+1),L-pow(2,t-1)));
            L-=pow(2,t-1);
        }
    }
    cout<<r+1<<" "<<Edge.size()<<endl;
    for(int a = 0;a < Edge.size();a++){
        cout<<Edge.at(a).first.first<<" "<<Edge.at(a).first.second<<" "<<Edge.at(a).second<<endl;
    }
}


Measured memory_bytes: 256
def main():
    n = int(input())
    F = [0 for i in range(n)]
    P = [0 for i in range(n)]


    for i in range(n):
        F[i] = list(map(int,input().split()))

    for i in range(n):
        P[i] = list(map(int,input().split()))

    ans = 0
    Flag = "first"

    for z in range(1,1024):
        ans_list = list(map(int,list(format(z,"010b"))))
        pro = 0

        for i in range(n):
            tmp = 0
            for j in range(10):
                if ans_list[j] == 1 and F[i][j]== 1:
                    tmp += 1

            pro += P[i][tmp]

        if Flag == "first":
            ans = pro
            Flag = False

        ans = max(ans, pro)


    print(ans)


if __name__ == "__main__":
        main()


Measured memory_bytes: 42588
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

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

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

int main()
{
	vector<ll> a(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> a.at(i);
	}

	sort(a.begin(), a.end());

	ull x = (a.at(2) % 2 == 0) ? 0 : a.at(0) * a.at(1);
	cout << x << endl;
}


Measured memory_bytes: 256
# 辞書順なので後ろから当てはまるように探す
# N<=50なので全探索で構わない
s, t = input(), input()
for si in range(len(s) - len(t), -1, -1):
    flag = True
    for ti in range(len(t)):
        if s[si + ti] != t[ti] and s[si + ti] != "?":
            flag = False
            break
    if flag:
        ans = ""
        for i in range(si):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        ans += t
        for i in range(si + len(t), len(s)):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        print(ans)
        exit()
print("UNRESTORABLE")



Measured memory_bytes: 3064
N = int(input())
S = set()
prev = None
flag = 1
for _ in range(N):
    W = input()
    if W in S or (prev is not None and prev[-1] != W[0]):
        flag = 0
    prev = W
    S.add(W)
if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	int s;
    cin>>s;
    
    int tmp;
    bool fl=true;
    for(int i=0;i<3;i++)
    {
    tmp=s%10;
    s/=10;
    if(tmp==s%10)
    {
        fl=false;
        break;
    }
    }
    
    if(fl)
    {
        cout<<"Good"<<endl;
    }
    else
    {
        cout<<"Bad"<<endl;
    }

}

Measured memory_bytes: 256
MOD = 1000000007
s = str(input())
n = len(s)
dp = [[0 for i in range(13)] for j in range(n + 1)]

dp[0][0] = 1
for i in range(n):
    c = -1 if s[i] == "?" else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
    for j in range(13):
        dp[i + 1][j] %= MOD

print(dp[n][5])

Measured memory_bytes: 66780
#pragma GCC optimize(3)
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
//#include<windows.h>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define INF 1e9
#define LLINF 1e18
#define EPS 1e-7
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,b) for(int a=1;a<=b;a++)
#define forr(a,n) for(int a=n;a>0;a--)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define REP(a,m,n) for(int a=m;a<n;a++)
#define REPN(a,m,n,p) for(int a=m;a<n;a+=p)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define iofopen(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define ifopen(a) freopen(a,"r",stdin);
#define ofopen(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
using namespace std;

int n,m,q,r;
int a[100],b[100],c[100],d[100];
int p[20];
int calc(){
	int res=0;
	rep(i,q){
		if(p[b[i]]-p[a[i]]==c[i]){
			res+=d[i];
		}
	}
	return res;
}
void dfs(int x){
	if(x==n-1){
		r=max(r,calc());
		return;
	}
	int f=p[x];
	for(int i=f;i<=m;i++){
		p[x+1]=i;
		dfs(x+1);
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>m>>q;
	rep(i,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;b[i]--;
	}
	p[0]=1;
	dfs(0);
	cout<<r;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <algorithm>
#include <unordered_map>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
// typedef vector<vector<ll>> matrix;
// const ll PRIME = 1e9 + 7;
// typedef pair<int,pair<int,int> >  ppi;

void solve()
{
   int n,d;
   cin>>n>>d;
//    int x[n],y[n];
   int a,b,ans=0;
   fr(i,n)
   {
       cin>>a>>b;
       if(a*a+b*b<=d*d)
       ans++;
   }
   cout<<ans;

}
int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

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

Measured memory_bytes: 3640
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a=0;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3640
package main

import (
	"fmt"
)

func main() {
	var k, a, b int
	fmt.Scan(&k, &a, &b)

	for i := 0; i*k <= 1000; i++ {
		if a <= i*k && i*k <= b {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}


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

//Do not get frustrated over WA. Check for edge cases and runtime errors :)
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 10005
//<<fixed << setprecision(9)
vi G[space],G2[space];
pair<pii,int> edge[space];
int ok[space],visit[space];
void dfs(int n)
{
    ok[n]++;

    for(auto z:G[n])
    {
        if(visit[z]==0)
        {
            visit[z]=1;
            dfs(z);
        }
    }
}
void dfs2(int n)
{
    ok[n]++;

    for(auto z:G2[n])
    {
        if(visit[z]==0)
        {
            visit[z]=1;
            dfs2(z);
        }
    }
}
int main()
{
    int n,i,j,t;
    boost;

    int m,P;

    cin>>n>>m>>P;
    int u,v,w;
    rep(i,0,m)
    {
        cin>>u>>v>>w;
        G[v].pb(u);
        G2[u].pb(v);
        edge[i]={{u,v},P-w};
    }
    visit[n]=1;
    dfs(n);
    memset(visit,0,sizeof(visit));
    visit[1]=1;
    dfs2(1);
    ll dist[n+1];
    dist[1]=0;
    rep(i,2,n+1)dist[i]=LLONG_MAX;
    int flag=0;
    int N=0;
    rep(i,1,n+1)
    {
        if(ok[i]==2)N++;
    }
    vector<pair<pii,int>> vec;
    rep(i,0,m)
    {
        if(ok[edge[i].F.F]==2) vec.pb(edge[i]);
    }
    rep(i,0,N)
    {
        rep(j,0,vec.size())
        {
            if(dist[vec[j].F.F]!=LLONG_MAX)
            {
                if(dist[vec[j].F.S]>dist[vec[j].F.F]+vec[j].S)
                {
                    dist[vec[j].F.S]=max(dist[vec[j].F.F]+vec[j].S,(ll)-1e12);
                    if(i==N-1) flag=1;
                }
            }
        }
    }
    if(flag) cout<<-1;
    else
    {
        cout<<max(-dist[n],(ll)0);
    }
    return 0;
}



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

using namespace std;

int main()
{
    int n;  cin >> n;
    vector <int> dp(3, 0);

    for (int i = 0; i < n; i++)
    {
        vector <int> aux_dp(3, 0), v(3);
        for (int &x: v)
            cin >> x;
        for (int i = 0; i < 3; i++)
            for (int j = 0; j < 3; j++)
                if (i != j)
                    aux_dp[j] = max(aux_dp[j], dp[i] + v[j]);
        dp = aux_dp;
    }
    cout << max(dp[0], max(dp[1], dp[2])) << "\n";
    
}

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

using namespace std;

int main() {
	int N, L;
	cin >> N >> L;
	map<string,int> memo;

	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		memo[s] += 1;
	}


	for (auto x : memo) {
		for (int i = 0; i < x.second; i++) {
			cout << x.first;
		}
	}
	
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
class Test:
  tenboulist = []
  tenboudaiSu = 0
  ways = 0
  goodcount = 0
  jisyo = {}
        
  def __init__(self):
    inp = input()
    inplist1 = inp.split()
    tenboudaiSu = int(inplist1[0])
    ways = int(inplist1[1])
    
    inp2 = input()
    tenboudailiststr = inp2.split()
    work = 1
    for i in range(tenboudaiSu):
      self.jisyo[str(work)] = True
      work += 1
   
    for i in tenboudailiststr:
      self.tenboulist.append(int(i))
    
    inplist2 = [input() for i in range(ways)]
    
    for i in inplist2:
      inwork = i.split()
      froma = int(inwork[0])
      tob = int(inwork[1])
      self.judge(froma , tob)
      
    #print(self.jisyo)
    for i in self.jisyo.values():
      if(i):
        self.goodcount += 1
      
    #print(self.jisyo)
    print(self.goodcount)

  def judge(self,A,B):
    #print("{}と{}を比較".format(self.tenboulist[A-1],self.tenboulist[B-1]))
    if (self.tenboulist[A-1] == self.tenboulist[B-1]):
      self.jisyo[str(A)] = False
      self.jisyo[str(B)] = False
    elif (self.tenboulist[A-1] < self.tenboulist[B-1]):
      self.jisyo[str(A)] = False
    elif (self.tenboulist[A-1] > self.tenboulist[B-1]):
      self.jisyo[str(B)] = False
    #print(self.jisyo)
        
test = Test()



Measured memory_bytes: 39820
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}


struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

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

  UnionFind uf(n);
  rep(i,m) {
    int a,b; cin >> a >> b; --a,--b;
    uf.unite(a,b);
  }
  int ans = 0;
  rep(i,n) umax(ans, uf.size(i));
  cout << ans << endl;
}


Measured memory_bytes: 4040
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	int a,b; cin>>a>>b;
	int c; cin>>c;
	if(a<b && b<c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    lli num1 , num2 , num3 ;
    cin >> num1 >> num2 >> num3 ;
    cout << min({num1 + num2 , num2 + num3 , num1 + num3}) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/

																																																								

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int d[100009];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  sort(d,d+n);
  cout<<d[n/2]-d[n/2-1]<<endl;
  return(0);
}


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

#define st first
#define nd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;

int main(){
	setIO();
	int a,b ;
	cin>>a>>b;
	cout<<a*b<<endl;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
	long long int a, b = 0, c = 0;
	scanf("%lld %lld",&a,&b);
	if (b==0) {
		printf("%lld\n",a);
	}
	if (a%b==0) {
		printf("0");
		return 0;
	}
	if (b/2>a) {
		printf("%lld",a);
		return 0;
	}
	printf("%lld\n",b-(a%b));
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
 static void Main(string[] args)
 {
  List<char> S = Console.ReadLine().ToList();
  S.Sort();
  string u = "No";
  if (new string(S.ToArray()) == "abc") { u = "Yes"; }
  Console.WriteLine("{0}", u);
 }
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, n+1) rep(j, m+1) {
        if ((ll)i*m+j*n-2*i*j == (ll)k) {
            cout << YES << endl;
            return 0;
        }
    }
    cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define NMAX 110000
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
typedef long long int ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll mod = 1e+9+7;

int main()
{	
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);
    for(int i=0; i<m; i++) cin >> a[i];

    vector<bool> safe(n+1, true);
    for(int i=0; i<m; i++) safe[a[i]] = false;

    vector<ll> dp(n+1);
    dp[0] = 1;
    for(ll now=0; now<n; now++){
        for(ll next=now+1; next<=min(n,now+2); next++){
            if(safe[next]){
                dp[next] += dp[now];
                dp[next] %= mod;
            }
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end() 
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;
const ll mod = 1000000007;




int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    int n,i;
    cin>>n;
    bool ar[8];
    memset(ar,false,sizeof(ar));
    int j = 0;
    For(i,0,n){
        int x;
        cin>>x;
        if(x >= 1 && x <= 399) ar[0] = 1;
        else if(x >= 400 && x <= 799 ) ar[1] = 1;
        else if(x >= 800 && x <= 1199) ar[2] = 1;
        else if(x >= 1200 && x <= 1599) ar[3] = 1;
        else if(x >= 1600 && x <= 1999) ar[4] = 1;
        else if(x >= 2000 && x <= 2399) ar[5] = 1;
        else if(x >= 2400 && x <= 2799) ar[6] = 1;
        else if(x >= 2800 && x <= 3199) ar[7] = 1;
        else j++;
    }
    int ans = 0, ol;
    ol = j> 0;
    For(i,0,8) ans += ar[i];
    cout<<max(ans,ol) sp;
    cout<<ans + j;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<algorithm>
#include<vector>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define pr pair<int,int>
	#define FR first
	#define SE second
	#define MP make_pair
	#define PB pushback
	#define vc vector
	void chmax(int &x,const ll y) {x=(x>y?x:y);}
	void chmin(int &x,const ll y) {x=(x<y?x:y);}
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) putchar('-'),num=-num;
		if(num>=10) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	const int MOD=1e9+7;
	void add(ll &a,ll b){a+=b;if(a>=MOD)a-=MOD;if(a<=-MOD)a+=MOD;}
	ll qpower(ll x,int e)
	{
		ll ans=1;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MAX_N=1e6+10;

	void main()
	{
		int n=qread();
		ll ans=0;
		for(int i=1;i<=n;i++) add(ans, invm(qpower(3,i)*n%MOD*(n-i+1)%MOD) );
		write(ans);
	}
};
int main()
{
	// freopen("a.in","r",stdin);
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
    int h, w;
    while (1){
    	cin >> h >> w;
    	if(h == 0 && w ==0 ) break;

        for(int i=0;i<h; i++){
        	for(int j=0;j<w;j++){
        		if((i+j)%2==0)cout << "#";
        		else cout << ".";
        	}
        cout << endl;
    	}
    cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>

using namespace std;

struct Card
{
    char suit;
    int value;
};

void bubbleSort( struct Card card[], int N )
{
    for( int i = 0; i < N; i++)
    {
        for( int j = N - 1; j > i; j--)
        {
            if( card[j].value < card[j - 1].value)
                swap( card[j], card[j-1] );
        }
    }
}

void selectionSort( struct Card card[], int N )
{
    for( int i = 0; i < N; i++)
    {
        int minj = i;
        for( int j = i; j < N; j++)
        {
            if( card[j].value < card[minj].value)
                minj = j;
        }
        swap( card[i], card[minj] );
    }
}

bool isStable( struct Card card1[], struct Card card2[], int N )
{
    for( int i = 0; i < N; i++)
    {
        if( card1[i].suit != card2[i].suit)
            return false;
    }

    return true;
}

int main()
{
    Card card1[100], card2[100];
    int N;

    cin >> N;
    for( int i = 0; i < N; i++ )
    {
        cin >> card1[i].suit >> card1[i].value;
    }

    for( int i = 0; i < N; i++ )
    {
        card2[i] = card1[i];
    }

    bubbleSort( card1, N );
    selectionSort( card2, N );
    
    for( int i = 0; i < N; i++)
    {
        cout << card1[i].suit << card1[i].value;
        if( i == N - 1 )
            cout << endl;
	else
            cout << ' ';
    }
    cout << "Stable" << endl;

    for( int i = 0; i < N; i++)
    {
        cout << card2[i].suit << card2[i].value;
        if( i == N - 1 )
            cout << endl;
	else
            cout << ' ';
    }

    if( isStable( card1, card2, N ) )
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;

    return 0;
}

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

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


Measured memory_bytes: 256
from itertools import combinations_with_replacement


N, M, Q = map(int, input().split())
nums = [list(map(int, input().split())) for _ in range(Q)]
A = list(combinations_with_replacement(range(1, M+1), N))
ans = 0
for i in range(len(A)):
    tmp = 0
    for j in range(Q):
        if A[i][nums[j][1]-1] - A[i][nums[j][0]-1] == nums[j][2]:
            tmp += nums[j][3]
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 21440
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

int gcd(int n, int m) {
    if (n == 0)
        return m;
    return gcd(m % n, n);
}

int bit_count(int i) {
    i = i - ((i >> 1) & 0x55555555);
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
    i = (i + (i >> 4)) & 0x0f0f0f0f;
    i = i + (i >> 8);
    i = i + (i >> 16);
    return i & 0x3f;
}

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    for (size_t i = 0; i < n; i++) {
        cin >> w[i];
    }
    int ans = INT32_MAX;
    for (size_t i = 0; i < n; i++) {
        int s1 = 0, s2 = 0;
        for (size_t j = 0; j <= i; j++) {
            s1 += w[j];
        }
        for (size_t j = i + 1; j < n; j++) {
            s2 += w[j];
        }
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val l = sc.nextInt()
    println(Math.pow(l / 3.0, 3.0))
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 31268
#include<iostream>
using namespace std;
int main(){

    int m[10], temp;
    for(int i = 0; i < 10; i++)
        cin >> m[i];

    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 10; j++){
            if(m[i] < m[j]){
                temp = m[i];
                m[i] = m[j];
                m[j] = temp;
            }
        }
    cout << m[i] << endl;
    }
}

Measured memory_bytes: 1164
/*
  In the name of ALLAH
  Author : Raashid Anwar
*/

#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
const int M1 =  998244353;
const int M2 =  1000000007;
mt19937 rng((uint64_t)chrono::steady_clock::now().time_since_epoch().count());


void solve() {
  int n, m, sx, sy, ex, ey;
  cin >> n >> m >> sx >> sy >> ex >> ey;
  string s[n];
  int dp[n][m];
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      dp[i][j] = M2;
  for(int i = 0; i < n; i++)
    cin >> s[i];
  set <tuple<int, int, int>> si;
  sx--; sy--;
  ex--; ey--;
  if(s[sx][sy] == '#') {
    cout << -1 << "\n";
    return ;
  }
  si.insert({0, sx, sy});
  while(!si.empty()) {
    auto [d, x, y] = *si.begin();
    si.erase(si.begin());
    if(dp[x][y] <= d)
      continue;
    dp[x][y] = d;
    for(int i : {-1, 1}) {
      if(x + i >= 0 && x + i < n && s[x + i][y] == '.')
        si.insert({d, x + i, y});
      if(y + i >= 0 && y + i < m && s[x][y + i] == '.')
        si.insert({d, x, y + i});
    }
    for(int i = x - 2; i <= x + 2; i++)
      for(int j = y - 2; j <= y + 2; j++)
        if(i >= 0 && i < n && j >= 0 && j < m && s[i][j] == '.')
          si.insert({d + 1, i, j});
  }
  if(dp[ex][ey] == M2)
    dp[ex][ey] = -1;
  cout << dp[ex][ey] << "\n";
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
}

Measured memory_bytes: 13436
import numpy as np

L, R = (int(i) for i in input().split()) 

N = int(L/2019)
M = int(R/2019)
l = L%2019
r = R%2019

answer = 0
delta = M - N

if delta == 0:
    for i in range(r-l):
        for j in range(r-l-i):
            k = i + l
            m = j + l + i + 1
            if i == 0 and j == 0:
                answer = (k*m)%2019
            if answer >= (k*m)%2019:
                answer = (k*m)%2019
print(answer)

Measured memory_bytes: 14452
N,A,B = map(int, input().split())

if (B-A)%2 == 0:
    ans = (B-A)//2
elif N-B < A-1:
    ans = N-B + (B-A)//2 + 1
else:
    ans = A-1 + (B-A)//2 + 1
    
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 998244353
#define INF (1<<29)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int mod_pow(Int x, Int a, Int m = MOD){
  if(a == 0)return 1;
  Int res = mod_pow(x, a / 2, m);
  res = res * res % m;
  if(a % 2)res *= x;
  return res % m;
}

Int inv(Int x){
  return mod_pow(x, MOD-2);
}

Int fact[324000], res;

Int nCk(Int n, Int k){
  if(n < k)return 0;
  return fact[n] * inv(fact[k]) % MOD * inv(fact[n-k]) % MOD;
}

int main(){
  fact[0] = 1;
  for(Int i = 1;i < 324000;i++)fact[i] = fact[i-1] * i % MOD;
  Int n, a, b, k;
  cin >> n >> a >> b >> k;
  for(Int i = 0;i <= n;i++){
    Int red = i;
    if((k - red * a) % b)continue;
    Int blue = (k - red*a) / b;
    if(blue > n || blue < 0)continue;
    res += nCk(n, red) * nCk(n, blue) % MOD;res %= MOD;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    ll X;
    cin >> X;
    bool dp[102000];
    fill(dp, dp+102000, false);
    dp[0] = true;
    for(int i = 0; i <= X; i++){
        if(!dp[i]){
            continue;
        }
        for(int j = 0; j <= 5; j++){
            dp[i+100+j] = true;
        }
    }

    cout << (dp[X] ? 1 : 0) << endl;


    return 0;
}




Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define ull  unsigned long long
typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define fi first
#define se second
#define ins insert
#define all(x) (x).begin(), (x).end()
#define fr(i, n) for(int i = 0; i < n; i++)
#define rall(x) (x).rbegin(), (x).rend()
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int INF = 1e9 + 5;
 
 
void solve(){
    string s;
    cin >> s;
    fr(i, s.size()){
        if(s[i] == '7'){
            cout << "Yes";
            return;
        }
    }
    cout << "No";
    
    
}
 
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 3660
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m , k ;
int a[3001][3001] ;
int dp[3001][3001][4] ;
int dfs(int x, int y, int cur){
    if ( x == n && y == m ) {
        return 0 ;
    }
    if ( x == n ) return 0 ;
    if ( y == m ) return 0 ;
    if ( dp[x][y][cur] != -1 ) return dp[x][y][cur] ;
    int ans = 0 ;
    if ( a[x][y] == 0 ) {
        ans = max(dfs(x + 1, y, 0), dfs(x, y + 1, cur)) ;
    }
    else{
        int value = a[x][y] ;
        if ( cur < 3 ) {
            ans = max(ans, value + dfs(x, y + 1, cur + 1)) ; 
            ans = max(ans, value + dfs(x + 1, y, 0)) ;
        }
        ans = max(ans, dfs(x, y + 1, cur)) ;
        ans = max(ans, dfs(x + 1, y, 0)) ;
    }
    return dp[x][y][cur] = ans ;
}
signed main(){
    fastio
    memset(dp, -1, sizeof dp) ;
    cin >> n >> m >> k ;
    for(int i = 0; i < k; i++){
        int x , y , z;
        cin >> x >> y >> z ; 
        x--, y-- ;
        a[x][y] = z ;
    }
    int ans = dfs(0, 0, 0) ;
    cout << ans << endl;
    return 0; 
}

Measured memory_bytes: 355780
#include <iostream>

using namespace std;

int main()
{
    int a[5];

    while (cin >> a[0], a[0]) {
        bool flag[4] = {false};

        flag[a[0]] = true;
        for (int i = 1; i < 5; i++) {
            cin >> a[i];
            flag[a[i]] = true;
        }
        
        if ((flag[1] && flag[2] && flag[3]) ||
            (flag[1] && !flag[2] && !flag[3]) ||
            (!flag[1] && flag[2] && !flag[3]) ||
            (!flag[1] && !flag[2] && flag[3]))
            for (int i = 0; i < 5; i++)
                cout << "3\n";
        else if (flag[1] && flag[2] && !flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 1)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
        else if (flag[1] && !flag[2] && flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 3)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
        else if (!flag[1] && flag[2] && flag[3]) {
            for (int i = 0; i < 5; i++) {
                if (a[i] == 2)
                    cout << "1\n";
                else
                    cout << "2\n";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1124
N = int(input())
A = list(map(int,input().split()))
U1 = list(map(int,input().split()))
U2 = list(map(int,input().split()))
Ut = 0
for j in A:
    Ut += U1[j-1]
i = 0
while i < N-1:
    x = A[i:i+1]+A[i+1:i+2]
    if (x[1] - x[0]) == 1:
        Ut += U2[x[0]-1]
    i += 1
print(Ut)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>








int P,Q,R,x,y,z; 



int main(){



scanf("%d%d%d", &P, &Q, &R);


x = P+Q;

if(P+R <  x ){
 
x = P+R;}

  if ( Q+R < x ){ x = Q+R; }


 


printf("%d",x);

 






//if(str[2]=='a'){printf("yes");}

//printf("%d",x);

   return(0);
} 






Measured memory_bytes: 128