Problem p02640 (python)

Fixed submission:
#getting input from user
#cranes and turtle already give the information
#condition yes or no 
X,Y= map(int,input().split())
cranes= 2 # assign 2 to cranes
turtles= 4 # assign 4 to turtle
ans="No"
for i in range(X+1): 
    b=X-i
    if cranes*i + turtles*b == Y:
        ans = "Yes"
print(ans)

# Time complixity O(X)

Buggy submission (verdict: Runtime Error):
X,Y = map(input().split()) #input number of animals and legs

crane_legs = 2
turtle_legs = 4

answer = "No"

for i in range(X+1): #X+1 because it will only consider 0,1,2
    remaining=X-i #
    if crane_legs*i + turtle_legs*remaining == Y:
        answer = "Yes"
#Loop to check combinations of animals is correct

print(answer)

Buggy submission (verdict: Runtime Error):
X,Y = map(input().split()) #input number of animals and legs

crane_legs = 2
turtle_legs = 4

answer = "No"

for i in range(X+1): #X+1 because it will only consider 0,1,2
    remaining=X-i #
    if crane_legs*i + turtle_legs*remaining == y:
        answer = "Yes"
#Loop to check combinations of animals is correct

print(answer)

Buggy submission (verdict: Runtime Error):
animals= input()
legs= input()

for i in range (len(animals)):

    if int(legs) % 2 ==0: #to check if it's even then there is a possibility of combination
        print ("yes")
    elif int(legs) % 4 ==0:
        print ("yes")
    elif int(legs) % 2 !=0:
        print ("no")
    elif int(legs) % 4 !=0:
        print ("no")

Buggy submission (verdict: Runtime Error):
C,D=input().split('')
C=int(C)
D=int(D)

numb=4*C
if D>numb:
    print("No.")
else:
    print("Yes.")

Buggy submission (verdict: Runtime Error):
X,Y=input().split(' ')

X=int(X)
Y=int(Y)

num=4*A

if B>num:
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int n,m,k;
int main(){
	fast
	cin>>n>>m>>k;
	int sx,sy,ex,ey;
	cin>>sx>>sy>>ex>>ey;
	pii came[n][m];
	sx--;sy--;ex--;ey--;
	char a[n][m];
	FOR0(n){
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	int vis[n][m];
	mem(vis,-1);
	queue<pair<int,int> >q;
	vis[sx][sy]=0;
	q.push({sx,sy});
	mem(came,-1);
	came[sx][sy]={-1,-1};
	while(!q.empty()){
		pii f=q.front();
		q.pop();
		int x=f.ff,y=f.ss;
		for(int i=1;i<=k;i++){
			int yy=y+i;
			if(yy>=m) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int yy=y-i;
			if(yy<0) break;
			if(a[x][yy]=='@') break;
			else if(vis[x][yy]==-1){
				vis[x][yy]=vis[x][y]+1;
				q.push({x,yy});
				came[x][yy]={x,y};
			}
			else if(came[x][yy]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x+i;
			if(xx>=n) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
		for(int i=1;i<=k;i++){
			int xx=x-i;
			if(xx<0) break;
			if(a[xx][y]=='@') break;
			else if(vis[xx][y]==-1){
				vis[xx][y]=vis[x][y]+1;
				q.push({xx,y});
				came[xx][y]={x,y};
			}
			else if(came[xx][y]==came[x][y]) break;
		}
	}
	cout<<vis[ex][ey];
}