output
stringlengths 52
181k
| instruction
stringlengths 296
182k
|
---|---|
#include <bits/stdc++.h>
using namespace std;
string str;
string sub[3] = {"1", "14", "144"};
bool fign = false;
void dfs(int i, int j) {
if (j == str.length()) {
fign = true;
} else if (i == 2 && j != str.length()) {
fign = false;
}
for (int i = 0; i < 3; i++) {
string temp = str.substr(j, i + 1);
if (temp == sub[i] && !fign) {
dfs(i, j + i + 1);
}
}
}
int main() {
while (cin >> str) {
fign = false;
dfs(0, 0);
if (fign) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string str;
string sub[3] = {"1", "14", "144"};
bool fign = false;
void dfs(int i, int j) {
if (j == str.length()) {
fign = true;
} else if (i == 2 && j != str.length()) {
fign = false;
}
for (int i = 0; i < 3; i++) {
string temp = str.substr(j, i + 1);
if (temp == sub[i] && !fign) {
dfs(i, j + i + 1);
}
}
}
int main() {
while (cin >> str) {
fign = false;
dfs(0, 0);
if (fign) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
;
long long int count = 0, i;
string s;
string a = "1", b = "14", c = "144";
cin >> s;
for (i = 0; i < s.size(); i++) {
string m, n, p;
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
count += 3;
i += 2;
} else if (s[i] == '1' && s[i + 1] == '4') {
count += 2;
i++;
} else if (s[i] == '1') {
count++;
}
}
if (count == s.size())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
;
long long int count = 0, i;
string s;
string a = "1", b = "14", c = "144";
cin >> s;
for (i = 0; i < s.size(); i++) {
string m, n, p;
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
count += 3;
i += 2;
} else if (s[i] == '1' && s[i + 1] == '4') {
count += 2;
i++;
} else if (s[i] == '1') {
count++;
}
}
if (count == s.size())
cout << "YES" << endl;
else
cout << "NO" << endl;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;
int main() {
int n;
cin >> n;
int k = n;
string s = "";
while (k) {
s += ('0' + (k % 10));
k /= 10;
}
reverse(s.begin(), s.end());
for (int i = 0; i + 2 < s.size(); i++) {
string h = s.substr(i, 3);
if (h == "144") {
for (int k = i, j = 0; j < 3; j++, k++) s[k] = 'x';
}
}
for (int i = 0; i + 1 < s.size(); i++) {
string h = s.substr(i, 2);
if (h == "14") {
for (int k = i, j = 0; j < 2; j++, k++) s[k] = 'x';
}
}
for (int i = 0; i < s.size(); i++) {
string h = s.substr(i, 1);
if (h == "1") {
for (int k = i, j = 0; j < 1; j++, k++) s[k] = 'x';
}
}
bool ok = true;
for (int i = 0; i < s.size(); i++)
if (s[i] != 'x') ok = false;
if (ok)
puts("YES");
else
puts("NO");
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 1 << 30;
int main() {
int n;
cin >> n;
int k = n;
string s = "";
while (k) {
s += ('0' + (k % 10));
k /= 10;
}
reverse(s.begin(), s.end());
for (int i = 0; i + 2 < s.size(); i++) {
string h = s.substr(i, 3);
if (h == "144") {
for (int k = i, j = 0; j < 3; j++, k++) s[k] = 'x';
}
}
for (int i = 0; i + 1 < s.size(); i++) {
string h = s.substr(i, 2);
if (h == "14") {
for (int k = i, j = 0; j < 2; j++, k++) s[k] = 'x';
}
}
for (int i = 0; i < s.size(); i++) {
string h = s.substr(i, 1);
if (h == "1") {
for (int k = i, j = 0; j < 1; j++, k++) s[k] = 'x';
}
}
bool ok = true;
for (int i = 0; i < s.size(); i++)
if (s[i] != 'x') ok = false;
if (ok)
puts("YES");
else
puts("NO");
return 0;
}
```
|
#include <bits/stdc++.h>
char ch[15];
int main() {
int i, j, len;
while (gets(ch)) {
len = strlen(ch);
for (i = 0; i < len; i++) {
if (ch[i] != '1' && ch[i] != '4')
break;
else if (!(ch[i] == '1' || (ch[i] == '4' && i > 0 && ch[i - 1] == '1') ||
(ch[i] == '4' && i > 1 && ch[i - 1] == '4' &&
ch[i - 2] == '1')))
break;
}
if (i != len)
puts("NO");
else
puts("YES");
memset(ch, 0, sizeof(ch));
}
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
char ch[15];
int main() {
int i, j, len;
while (gets(ch)) {
len = strlen(ch);
for (i = 0; i < len; i++) {
if (ch[i] != '1' && ch[i] != '4')
break;
else if (!(ch[i] == '1' || (ch[i] == '4' && i > 0 && ch[i - 1] == '1') ||
(ch[i] == '4' && i > 1 && ch[i - 1] == '4' &&
ch[i - 2] == '1')))
break;
}
if (i != len)
puts("NO");
else
puts("YES");
memset(ch, 0, sizeof(ch));
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flag = 0;
if (s[0] != '1')
cout << "NO" << endl;
else {
for (int i = 0; i < s.length(); i++) {
if (s[i] != '1' && s[i] != '4') {
flag++;
cout << "NO" << endl;
break;
} else if (s.find("444") != s.npos) {
flag++;
cout << "NO" << endl;
break;
}
}
if (!flag) cout << "YES" << endl;
}
}
|
### Prompt
Create a solution in CPP for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flag = 0;
if (s[0] != '1')
cout << "NO" << endl;
else {
for (int i = 0; i < s.length(); i++) {
if (s[i] != '1' && s[i] != '4') {
flag++;
cout << "NO" << endl;
break;
} else if (s.find("444") != s.npos) {
flag++;
cout << "NO" << endl;
break;
}
}
if (!flag) cout << "YES" << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool solve(int x) {
if (x == 0) return true;
if (x % 1000 == 144) {
return solve(x / 1000);
} else if (x % 100 == 14) {
return solve(x / 100);
} else if (x % 10 == 1) {
return solve(x / 10);
}
return false;
}
int main() {
int x;
cin >> x;
if (solve(x))
cout << "YES\n";
else
cout << "NO\n";
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool solve(int x) {
if (x == 0) return true;
if (x % 1000 == 144) {
return solve(x / 1000);
} else if (x % 100 == 14) {
return solve(x / 100);
} else if (x % 10 == 1) {
return solve(x / 10);
}
return false;
}
int main() {
int x;
cin >> x;
if (solve(x))
cout << "YES\n";
else
cout << "NO\n";
}
```
|
#include <bits/stdc++.h>
int main() {
long long int n, i, k, a;
scanf("%lld", &n);
k = n;
for (i = 0; i < 10; i++) {
a = k % 10;
k = k / 10;
if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (k == 0 && a != 1) {
printf("NO\n");
break;
}
if (a == 1) {
continue;
} else if (a == 4) {
a = k % 10;
k = k / 10;
if (a == 4) {
a = k % 10;
k = k / 10;
if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (a == 1) {
continue;
} else {
printf("NO\n");
break;
}
} else if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (a == 1) {
continue;
} else {
printf("NO\n");
break;
}
} else {
printf("NO\n");
break;
}
}
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
long long int n, i, k, a;
scanf("%lld", &n);
k = n;
for (i = 0; i < 10; i++) {
a = k % 10;
k = k / 10;
if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (k == 0 && a != 1) {
printf("NO\n");
break;
}
if (a == 1) {
continue;
} else if (a == 4) {
a = k % 10;
k = k / 10;
if (a == 4) {
a = k % 10;
k = k / 10;
if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (a == 1) {
continue;
} else {
printf("NO\n");
break;
}
} else if (k == 0 && a == 1) {
printf("YES\n");
break;
} else if (a == 1) {
continue;
} else {
printf("NO\n");
break;
}
} else {
printf("NO\n");
break;
}
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return (a < b) ? a : b; }
int main() {
long long int n;
int len = 0;
cin >> n;
while (n != 0) {
if (n % 10 == 4) {
if ((n % 100) / 10 == 4) {
if ((n % 1000) / 100 == 1)
n = n / 1000;
else {
cout << "NO";
return 0;
}
} else if ((n % 100) / 10 == 1)
n = n / 100;
else {
cout << "NO";
return 0;
}
} else if (n % 10 == 1)
n = n / 10;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return (a < b) ? a : b; }
int main() {
long long int n;
int len = 0;
cin >> n;
while (n != 0) {
if (n % 10 == 4) {
if ((n % 100) / 10 == 4) {
if ((n % 1000) / 100 == 1)
n = n / 1000;
else {
cout << "NO";
return 0;
}
} else if ((n % 100) / 10 == 1)
n = n / 100;
else {
cout << "NO";
return 0;
}
} else if (n % 10 == 1)
n = n / 10;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
cin >> n;
while (n > 0) {
if (n % 1000 == 144) {
n = n / 1000;
} else if (n % 100 == 14) {
n = n / 100;
} else if (n % 10 == 1) {
n = n / 10;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
cin >> n;
while (n > 0) {
if (n % 1000 == 144) {
n = n / 1000;
} else if (n % 100 == 14) {
n = n / 100;
} else if (n % 10 == 1) {
n = n / 10;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool isit(string s, int idx) {
if (idx == s.length()) return true;
if (s[idx] != '1')
return false;
else {
bool b = isit(s, idx + 1);
if (b)
return true;
else if (idx < int(s.length()) - 1) {
if (s[idx + 1] == '4') {
bool v = isit(s, idx + 2);
if (v)
return true;
else if (idx < int(s.length()) - 2) {
if (s[idx + 2] != '4')
return false;
else {
bool z = isit(s, idx + 3);
return z;
}
}
} else
return false;
}
}
}
void solve() {
string s;
cin >> s;
bool b = isit(s, 0);
if (b)
cout << "YES";
else
cout << "NO";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) {
solve();
cout << endl;
}
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isit(string s, int idx) {
if (idx == s.length()) return true;
if (s[idx] != '1')
return false;
else {
bool b = isit(s, idx + 1);
if (b)
return true;
else if (idx < int(s.length()) - 1) {
if (s[idx + 1] == '4') {
bool v = isit(s, idx + 2);
if (v)
return true;
else if (idx < int(s.length()) - 2) {
if (s[idx + 2] != '4')
return false;
else {
bool z = isit(s, idx + 3);
return z;
}
}
} else
return false;
}
}
}
void solve() {
string s;
cin >> s;
bool b = isit(s, 0);
if (b)
cout << "YES";
else
cout << "NO";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
while (t--) {
solve();
cout << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool MN(const string &s, int i) {
if (s[i] != '1') return false;
if (i + 1 >= s.size()) return true;
if (s[i + 1] == '4') {
if (s[i + 2] == '4') return MN(s, i + 3);
return MN(s, i + 2);
}
return MN(s, i + 1);
}
int main() {
string s;
cin >> s;
s += "1";
if (MN(s, 0))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool MN(const string &s, int i) {
if (s[i] != '1') return false;
if (i + 1 >= s.size()) return true;
if (s[i + 1] == '4') {
if (s[i + 2] == '4') return MN(s, i + 3);
return MN(s, i + 2);
}
return MN(s, i + 1);
}
int main() {
string s;
cin >> s;
s += "1";
if (MN(s, 0))
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool ismagical(string number) {
for (long long int i = 0; i < number.length(); i++)
if (number[i] != '1' && number[i] != '4') return false;
if (number[0] != '1') return false;
if (number.find("444") != number.npos) return false;
return true;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string n;
cin >> n;
if (ismagical(n))
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool ismagical(string number) {
for (long long int i = 0; i < number.length(); i++)
if (number[i] != '1' && number[i] != '4') return false;
if (number[0] != '1') return false;
if (number.find("444") != number.npos) return false;
return true;
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string n;
cin >> n;
if (ismagical(n))
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool magic(string n) {
for (int i = 0; i < (int)n.size(); i++)
if (n[i] != '1' && n[i] != '4') return false;
if (n[0] == '4') return false;
if (n.find("444") != n.npos) return false;
return true;
}
int main() {
string n;
cin >> n;
if (magic(n)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool magic(string n) {
for (int i = 0; i < (int)n.size(); i++)
if (n[i] != '1' && n[i] != '4') return false;
if (n[0] == '4') return false;
if (n.find("444") != n.npos) return false;
return true;
}
int main() {
string n;
cin >> n;
if (magic(n)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long int n;
int main() {
cin >> n;
while (n > 0) {
if (n % 10 == 4) {
n = n / 10;
if (n % 10 == 1 && n > 0) {
n = n / 10;
} else if (n % 10 == 4 && n > 0) {
n = n / 10;
if (n % 10 == 1 && n > 0) {
n = n / 10;
} else {
cout << "NO";
return 0;
}
} else {
cout << "NO";
return 0;
}
} else if (n % 10 == 1) {
n = n / 10;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long int n;
int main() {
cin >> n;
while (n > 0) {
if (n % 10 == 4) {
n = n / 10;
if (n % 10 == 1 && n > 0) {
n = n / 10;
} else if (n % 10 == 4 && n > 0) {
n = n / 10;
if (n % 10 == 1 && n > 0) {
n = n / 10;
} else {
cout << "NO";
return 0;
}
} else {
cout << "NO";
return 0;
}
} else if (n % 10 == 1) {
n = n / 10;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long inf = 100000000;
template <class T>
T bigmod(T b, T p, T m) {
if (p == 1) return b;
T res = bigmod(b, p / 2, m);
res = (res * res) % m;
if (p % 2 == 1) res = (res * b) % m;
return res;
}
template <class T>
T gcd(T x, T y) {
if (y == 0) return x;
return gcd(y, x % y);
}
template <typename T>
T POW(T b, T p) {
if (p == 1) return b;
if (p % 2 == 0) {
T s = POW(b, p / 2);
return s * s;
}
return b * POW(b, p - 1);
}
long long a[3000900];
int main() {
string n, s = "", a = "1", b = "41", c = "441";
map<string, bool> mp;
mp[a] = mp[b] = mp[c] = 1;
cin >> n;
for (long long i = n.size() - 1; i >= 0; i--) {
s += n[i];
if (mp[s] == 1) {
s.clear();
}
}
if (s.size() > 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
### Prompt
Generate a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long inf = 100000000;
template <class T>
T bigmod(T b, T p, T m) {
if (p == 1) return b;
T res = bigmod(b, p / 2, m);
res = (res * res) % m;
if (p % 2 == 1) res = (res * b) % m;
return res;
}
template <class T>
T gcd(T x, T y) {
if (y == 0) return x;
return gcd(y, x % y);
}
template <typename T>
T POW(T b, T p) {
if (p == 1) return b;
if (p % 2 == 0) {
T s = POW(b, p / 2);
return s * s;
}
return b * POW(b, p - 1);
}
long long a[3000900];
int main() {
string n, s = "", a = "1", b = "41", c = "441";
map<string, bool> mp;
mp[a] = mp[b] = mp[c] = 1;
cin >> n;
for (long long i = n.size() - 1; i >= 0; i--) {
s += n[i];
if (mp[s] == 1) {
s.clear();
}
}
if (s.size() > 0)
cout << "NO";
else
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
vector<string> v;
void gen(string s) {
if (s.size() > 9) return;
v.push_back(s);
gen(s + "1");
gen(s + "14");
gen(s + "144");
}
int main() {
gen("");
sort(v.begin(), v.end());
string s;
cin >> s;
if (binary_search(v.begin(), v.end(), s))
puts("YES");
else
puts("NO");
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int oo = 1e9;
vector<string> v;
void gen(string s) {
if (s.size() > 9) return;
v.push_back(s);
gen(s + "1");
gen(s + "14");
gen(s + "144");
}
int main() {
gen("");
sort(v.begin(), v.end());
string s;
cin >> s;
if (binary_search(v.begin(), v.end(), s))
puts("YES");
else
puts("NO");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int i, n, ans = 0, tmp = 0, j, t;
string s;
cin >> s;
int k = s.length();
if (s[0] != '1') {
cout << "NO" << endl;
return 0;
}
for (i = 0; i < k; i++) {
if (s[i] != '1' and s[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
int prev = 1;
for (i = 0; i < k; i++) {
if (s[i] == '4') {
if (prev == 1) {
prev = 4;
tmp = 1;
} else {
tmp++;
}
} else if (s[i] == '1') {
if (prev == 4) {
ans = max(ans, tmp);
tmp = 0;
}
}
}
ans = max(ans, tmp);
if (ans > 2) {
cout << "NO" << endl;
return 0;
} else {
cout << "YES" << endl;
return 0;
}
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int i, n, ans = 0, tmp = 0, j, t;
string s;
cin >> s;
int k = s.length();
if (s[0] != '1') {
cout << "NO" << endl;
return 0;
}
for (i = 0; i < k; i++) {
if (s[i] != '1' and s[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
int prev = 1;
for (i = 0; i < k; i++) {
if (s[i] == '4') {
if (prev == 1) {
prev = 4;
tmp = 1;
} else {
tmp++;
}
} else if (s[i] == '1') {
if (prev == 4) {
ans = max(ans, tmp);
tmp = 0;
}
}
}
ans = max(ans, tmp);
if (ans > 2) {
cout << "NO" << endl;
return 0;
} else {
cout << "YES" << endl;
return 0;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = "YES";
for (int i = 0; i < s.size();) {
if (s[i] == '1' && s[i + 1] != '4')
i += 1;
else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] != '4')
i += 2;
else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4')
i += 3;
else {
ans = "NO";
break;
}
}
cout << ans << endl;
return 0;
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = "YES";
for (int i = 0; i < s.size();) {
if (s[i] == '1' && s[i + 1] != '4')
i += 1;
else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] != '4')
i += 2;
else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4')
i += 3;
else {
ans = "NO";
break;
}
}
cout << ans << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
int test = 1;
string aux = "";
for (int i = 0; (i < n.size()) && (test); i++) {
aux = n[i];
if (aux == "1") {
if (i + 1 < n.size()) {
aux = aux + n[i + 1];
if (aux == "14") {
if (i + 2 < n.size()) {
aux = aux + n[i + 2];
if (aux == "144")
i = i + 2;
else
i = i + 1;
} else
i = i + 1;
}
}
} else {
test = 0;
cout << "NO";
}
}
if (test) cout << "YES";
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
int test = 1;
string aux = "";
for (int i = 0; (i < n.size()) && (test); i++) {
aux = n[i];
if (aux == "1") {
if (i + 1 < n.size()) {
aux = aux + n[i + 1];
if (aux == "14") {
if (i + 2 < n.size()) {
aux = aux + n[i + 2];
if (aux == "144")
i = i + 2;
else
i = i + 1;
} else
i = i + 1;
}
}
} else {
test = 0;
cout << "NO";
}
}
if (test) cout << "YES";
}
```
|
#include <bits/stdc++.h>
using namespace std;
string n;
int main() {
cin >> n;
while (n.size()) {
if (n.back() == '1')
n.resize(n.size() - 1);
else if (n.size() >= 2 && n.back() == '4' && n[n.size() - 2] == '1')
n.resize(n.size() - 2);
else if (n.size() >= 3 && n.back() == '4' && n[n.size() - 2] == '4' &&
n[n.size() - 3] == '1')
n.resize(n.size() - 2);
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string n;
int main() {
cin >> n;
while (n.size()) {
if (n.back() == '1')
n.resize(n.size() - 1);
else if (n.size() >= 2 && n.back() == '4' && n[n.size() - 2] == '1')
n.resize(n.size() - 2);
else if (n.size() >= 3 && n.back() == '4' && n[n.size() - 2] == '4' &&
n[n.size() - 3] == '1')
n.resize(n.size() - 2);
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
for (int i = 0; i < n.size(); i++) {
if (n[i] != '1' && n[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
if (n[0] == '4' || n.find("444") != n.npos) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
for (int i = 0; i < n.size(); i++) {
if (n[i] != '1' && n[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
if (n[0] == '4' || n.find("444") != n.npos) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool is(const string& s) {
if (s.find("444") != string::npos) {
return false;
}
for (int i = 0; i < s.size(); ++i) {
if (s[i] != '1' && s[i] != '4') return false;
}
if (s[0] == '4') return false;
}
int main() {
string s;
cin >> s;
if (is(s))
cout << "YES";
else
cout << "NO";
}
|
### Prompt
Please create a solution in CPP to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool is(const string& s) {
if (s.find("444") != string::npos) {
return false;
}
for (int i = 0; i < s.size(); ++i) {
if (s[i] != '1' && s[i] != '4') return false;
}
if (s[0] == '4') return false;
}
int main() {
string s;
cin >> s;
if (is(s))
cout << "YES";
else
cout << "NO";
}
```
|
#include <bits/stdc++.h>
int main(int argc, char** argv) {
std::string s, answer = "YES";
std::cin >> s;
for (int i = 0; i < s.length();) {
if (s.substr(i, 3) == "144") {
i += 3;
} else if (s.substr(i, 2) == "14") {
i += 2;
} else if (s[i] == '1') {
i += 1;
} else {
answer = "NO";
break;
}
if (i == s.length()) {
break;
}
}
std::cout << answer << std::endl;
return 0;
}
|
### Prompt
Develop a solution in Cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
int main(int argc, char** argv) {
std::string s, answer = "YES";
std::cin >> s;
for (int i = 0; i < s.length();) {
if (s.substr(i, 3) == "144") {
i += 3;
} else if (s.substr(i, 2) == "14") {
i += 2;
} else if (s[i] == '1') {
i += 1;
} else {
answer = "NO";
break;
}
if (i == s.length()) {
break;
}
}
std::cout << answer << std::endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
for (i = 0; i < s.size(); i++) {
if (s[0] != '1') {
c = 1;
break;
} else if (s[i] == '0' || s[i] == '2' || s[i] == '3' || s[i] == '5' ||
s[i] == '6' || s[i] == '7' || s[i] == '8' || s[i] == '9') {
c = 1;
break;
} else if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') {
c = 1;
}
}
if (c) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
for (i = 0; i < s.size(); i++) {
if (s[0] != '1') {
c = 1;
break;
} else if (s[i] == '0' || s[i] == '2' || s[i] == '3' || s[i] == '5' ||
s[i] == '6' || s[i] == '7' || s[i] == '8' || s[i] == '9') {
c = 1;
break;
} else if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') {
c = 1;
}
}
if (c) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
string str;
cin >> str;
n = str.length();
for (i = 0; i < n; i++) {
if (str[i] == '1') {
if (str[i + 1] == '4' && i < n - 1) {
if (str[i + 2] == '4' && i < n - 2)
i += 2;
else
i++;
}
} else
break;
}
if (i == n)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n;
string str;
cin >> str;
n = str.length();
for (i = 0; i < n; i++) {
if (str[i] == '1') {
if (str[i + 1] == '4' && i < n - 1) {
if (str[i + 2] == '4' && i < n - 2)
i += 2;
else
i++;
}
} else
break;
}
if (i == n)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string ulaz, jed = "1", dva = "14", tri = "144";
bool je[10];
int main() {
cin >> ulaz;
int l = ulaz.size();
for (int i = 0; i < l; i++) je[i] = false;
for (int i = 0; i < l; i++) {
if (je[i] == true) continue;
if (i + 2 < l) {
string nov;
nov = ulaz[i];
nov += ulaz[i + 1];
nov += ulaz[i + 2];
if (nov == tri) {
je[i] = true;
je[i + 1] = true;
je[i + 2] = true;
i += 2;
continue;
}
}
if (i + 1 < l) {
string nov;
nov = ulaz[i];
nov += ulaz[i + 1];
if (nov == dva) {
je[i] = true;
je[i + 1] = true;
i += 1;
continue;
}
}
if (ulaz[i] == jed[0]) {
je[i] = true;
continue;
}
}
for (int i = 0; i < l; i++)
if (je[i] == false) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string ulaz, jed = "1", dva = "14", tri = "144";
bool je[10];
int main() {
cin >> ulaz;
int l = ulaz.size();
for (int i = 0; i < l; i++) je[i] = false;
for (int i = 0; i < l; i++) {
if (je[i] == true) continue;
if (i + 2 < l) {
string nov;
nov = ulaz[i];
nov += ulaz[i + 1];
nov += ulaz[i + 2];
if (nov == tri) {
je[i] = true;
je[i + 1] = true;
je[i + 2] = true;
i += 2;
continue;
}
}
if (i + 1 < l) {
string nov;
nov = ulaz[i];
nov += ulaz[i + 1];
if (nov == dva) {
je[i] = true;
je[i + 1] = true;
i += 1;
continue;
}
}
if (ulaz[i] == jed[0]) {
je[i] = true;
continue;
}
}
for (int i = 0; i < l; i++)
if (je[i] == false) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool f = true;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
} else if (s[i] == '1' && s[i + 1] == '4') {
i += 1;
} else if (s[i] == '1') {
} else {
f = false;
}
}
if (f) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool f = true;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
} else if (s[i] == '1' && s[i + 1] == '4') {
i += 1;
} else if (s[i] == '1') {
} else {
f = false;
}
}
if (f) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, flag = 0, i;
cin >> n;
while (n > 0) {
if (n % 10 == 1) {
n = n / 10;
} else if (n % 100 == 14) {
n = n / 100;
} else if (n % 1000 == 144) {
n = n / 1000;
} else {
flag++;
break;
}
}
if (flag == 0)
cout << "YES";
else
cout << "NO";
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, flag = 0, i;
cin >> n;
while (n > 0) {
if (n % 10 == 1) {
n = n / 10;
} else if (n % 100 == 14) {
n = n / 100;
} else if (n % 1000 == 144) {
n = n / 1000;
} else {
flag++;
break;
}
}
if (flag == 0)
cout << "YES";
else
cout << "NO";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[12];
int i, j, k, p, l;
scanf("%s", &arr);
l = strlen(arr);
p = 0;
for (i = 0; i < l;) {
if (arr[i] - '0' == 1) {
if (arr[i + 1] - '0' == 4) {
if (arr[i + 2] - '0' == 4) {
i = i + 3;
} else {
i = i + 2;
}
} else {
i = i + 1;
}
} else {
p = 1;
break;
}
}
if (p == 1) {
printf("NO\n");
} else {
printf("YES\n");
}
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char arr[12];
int i, j, k, p, l;
scanf("%s", &arr);
l = strlen(arr);
p = 0;
for (i = 0; i < l;) {
if (arr[i] - '0' == 1) {
if (arr[i + 1] - '0' == 4) {
if (arr[i + 2] - '0' == 4) {
i = i + 3;
} else {
i = i + 2;
}
} else {
i = i + 1;
}
} else {
p = 1;
break;
}
}
if (p == 1) {
printf("NO\n");
} else {
printf("YES\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
bool flg = 0;
for (long long i = 0; i < s.size(); i++) {
cerr << "i"
<< " is " << i << '\n';
if (s[i] == '1') {
if (i + 1 < s.size() and s[i + 1] == '4') {
if (i + 2 < s.size() and s[i + 2] == '4')
i = i + 2;
else
i++;
}
} else {
flg = 1;
break;
}
}
if (flg)
cout << "NO" << '\n';
else
cout << "YES" << '\n';
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
bool flg = 0;
for (long long i = 0; i < s.size(); i++) {
cerr << "i"
<< " is " << i << '\n';
if (s[i] == '1') {
if (i + 1 < s.size() and s[i + 1] == '4') {
if (i + 2 < s.size() and s[i + 2] == '4')
i = i + 2;
else
i++;
}
} else {
flg = 1;
break;
}
}
if (flg)
cout << "NO" << '\n';
else
cout << "YES" << '\n';
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch;
int st = 0;
while (cin >> ch) {
switch (ch) {
case '1':
st = 1;
break;
case '4':
if (st == 3 || st == 0) {
cout << "NO" << endl;
return 0;
} else
++st;
break;
default:
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
char ch;
int st = 0;
while (cin >> ch) {
switch (ch) {
case '1':
st = 1;
break;
case '4':
if (st == 3 || st == 0) {
cout << "NO" << endl;
return 0;
} else
++st;
break;
default:
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool is_magic(const std::string &x) {
int a = 2;
for (size_t i = 0; i < x.size(); ++i)
if (x[i] == '1') {
a = 0;
} else if (x[i] == '4') {
if (++a > 2) {
return false;
}
} else {
return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
if (is_magic(s)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool is_magic(const std::string &x) {
int a = 2;
for (size_t i = 0; i < x.size(); ++i)
if (x[i] == '1') {
a = 0;
} else if (x[i] == '4') {
if (++a > 2) {
return false;
}
} else {
return false;
}
return true;
}
int main() {
ios_base::sync_with_stdio(false);
string s;
cin >> s;
if (is_magic(s)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void kick() {
string s = "";
char c;
int cn = 0;
c = getchar();
while (c != ' ' && c != '\n') {
s += c;
if (c == '1') cn++;
c = getchar();
}
if (cn == s.length()) {
cout << "YES" << endl;
return;
}
bool fl = true;
int tm = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] != '4' && s[i] != '1') {
cout << "NO" << endl;
fl = false;
return;
}
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
continue;
}
if (s[i] == '1' && s[i + 1] == '4') {
i++;
continue;
}
if (s[i] == '1') continue;
if (s[i] == '4') {
fl = false;
cout << "NO" << endl;
break;
}
}
if (fl) {
cout << "YES" << endl;
}
}
int main() { kick(); }
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void kick() {
string s = "";
char c;
int cn = 0;
c = getchar();
while (c != ' ' && c != '\n') {
s += c;
if (c == '1') cn++;
c = getchar();
}
if (cn == s.length()) {
cout << "YES" << endl;
return;
}
bool fl = true;
int tm = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] != '4' && s[i] != '1') {
cout << "NO" << endl;
fl = false;
return;
}
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
continue;
}
if (s[i] == '1' && s[i + 1] == '4') {
i++;
continue;
}
if (s[i] == '1') continue;
if (s[i] == '4') {
fl = false;
cout << "NO" << endl;
break;
}
}
if (fl) {
cout << "YES" << endl;
}
}
int main() { kick(); }
```
|
#include <bits/stdc++.h>
using namespace std;
void Solve();
int main() {
Solve();
return 0;
}
void Solve() {
string str;
cin >> str;
bool bol = true;
for (int i = 0; i < str.length(); i++) {
if (str[i] != '1' && str[i] != '4') {
bol = false;
break;
} else if (str[0] != '1') {
bol = false;
break;
} else if (str.find("444") != -1) {
bol = false;
break;
}
}
if (bol)
cout << "YES\n";
else
cout << "NO\n";
}
|
### Prompt
Generate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void Solve();
int main() {
Solve();
return 0;
}
void Solve() {
string str;
cin >> str;
bool bol = true;
for (int i = 0; i < str.length(); i++) {
if (str[i] != '1' && str[i] != '4') {
bol = false;
break;
} else if (str[0] != '1') {
bol = false;
break;
} else if (str.find("444") != -1) {
bol = false;
break;
}
}
if (bol)
cout << "YES\n";
else
cout << "NO\n";
}
```
|
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int flag = 1, num = 0;
cin >> s;
if (s[0] != '1') flag = 0;
for (int i = 0; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
flag = 0;
break;
} else if (s[i] == '4') {
num++;
if (num > 2) {
flag = 0;
break;
}
} else
num = 0;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int flag = 1, num = 0;
cin >> s;
if (s[0] != '1') flag = 0;
for (int i = 0; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
flag = 0;
break;
} else if (s[i] == '4') {
num++;
if (num > 2) {
flag = 0;
break;
}
} else
num = 0;
}
if (flag)
printf("YES\n");
else
printf("NO\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string ch;
cin >> ch;
while (ch[0] == '1') {
if (ch.find("144") == 0)
ch.erase(0, 3);
else if (ch.find("14") == 0) {
ch.erase(0, 2);
} else if (ch.find("1") == 0) {
ch.erase(0, 1);
}
}
if (ch.size() == 0)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Generate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string ch;
cin >> ch;
while (ch[0] == '1') {
if (ch.find("144") == 0)
ch.erase(0, 3);
else if (ch.find("14") == 0) {
ch.erase(0, 2);
} else if (ch.find("1") == 0) {
ch.erase(0, 1);
}
}
if (ch.size() == 0)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int kt = 1;
if (s[0] == '4')
kt = 0;
else
for (long i = 0; i < s.length(); i++) {
if (s[i] != '1' && s[i] != '4') {
kt = 0;
break;
} else if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') {
kt = 0;
break;
}
}
if (kt == 1)
cout << "YES";
else
cout << "NO";
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int kt = 1;
if (s[0] == '4')
kt = 0;
else
for (long i = 0; i < s.length(); i++) {
if (s[i] != '1' && s[i] != '4') {
kt = 0;
break;
} else if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') {
kt = 0;
break;
}
}
if (kt == 1)
cout << "YES";
else
cout << "NO";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string in;
cin >> in;
bool ok = 1;
for (int i = 0; i < in.size(); i++) {
if (in[i] != '1') {
ok = 0;
break;
}
int j = i + 1;
int c = 0;
while (j < in.size() && in[j] == '4') {
j++;
c++;
}
if (c > 2) {
ok = 0;
break;
}
i = j - 1;
}
cout << (ok ? "YES" : "NO") << endl;
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string in;
cin >> in;
bool ok = 1;
for (int i = 0; i < in.size(); i++) {
if (in[i] != '1') {
ok = 0;
break;
}
int j = i + 1;
int c = 0;
while (j < in.size() && in[j] == '4') {
j++;
c++;
}
if (c > 2) {
ok = 0;
break;
}
i = j - 1;
}
cout << (ok ? "YES" : "NO") << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long t, n, m;
int main() {
scanf("%d", &n);
int f = 0;
int s = 0;
while (n) {
int x = n % 10;
if (x == 4)
s++;
else if (x == 1) {
if (s > 2) {
f = 1;
break;
}
s = 0;
} else
f = 1;
n /= 10;
}
if (s) {
f = 1;
}
if (f == 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long t, n, m;
int main() {
scanf("%d", &n);
int f = 0;
int s = 0;
while (n) {
int x = n % 10;
if (x == 4)
s++;
else if (x == 1) {
if (s > 2) {
f = 1;
break;
}
s = 0;
} else
f = 1;
n /= 10;
}
if (s) {
f = 1;
}
if (f == 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
int f = 1, i;
while (n > 0) {
x = n % 10;
if (x == 1) {
n = n / 10;
} else if (x == 4) {
n = n / 10;
if (n % 10 == 1) {
n = n / 10;
} else if (n % 10 == 4) {
if (n % 100 != 14) {
f = 0;
break;
}
n = n / 100;
} else {
f = 0;
break;
}
} else {
f = 0;
break;
}
}
if (f == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n;
int f = 1, i;
while (n > 0) {
x = n % 10;
if (x == 1) {
n = n / 10;
} else if (x == 4) {
n = n / 10;
if (n % 10 == 1) {
n = n / 10;
} else if (n % 10 == 4) {
if (n % 100 != 14) {
f = 0;
break;
}
n = n / 100;
} else {
f = 0;
break;
}
} else {
f = 0;
break;
}
}
if (f == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int n, m, k, p = 1;
scanf("%d", &n);
m = n;
while (m != 0) {
if (m % 10 == 1) {
m = m / 10;
continue;
}
if (m % 100 == 14) {
m = m / 100;
continue;
}
if (m % 1000 == 144) {
m = m / 1000;
continue;
}
p = 0;
break;
}
if (p == 1)
printf("YES");
else
printf("NO");
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int n, m, k, p = 1;
scanf("%d", &n);
m = n;
while (m != 0) {
if (m % 10 == 1) {
m = m / 10;
continue;
}
if (m % 100 == 14) {
m = m / 100;
continue;
}
if (m % 1000 == 144) {
m = m / 1000;
continue;
}
p = 0;
break;
}
if (p == 1)
printf("YES");
else
printf("NO");
return 0;
}
```
|
#include <bits/stdc++.h>
char a[300];
int main() {
int len, i;
while (scanf("%s", a) != EOF) {
len = strlen(a);
for (i = 0; i < len; i++) {
if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4') {
i += 2;
continue;
}
if (a[i] == '1' && a[i + 1] == '4') {
i += 1;
continue;
}
if (a[i] == '1') {
continue;
}
break;
}
if (i >= len)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
### Prompt
Construct a cpp code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
char a[300];
int main() {
int len, i;
while (scanf("%s", a) != EOF) {
len = strlen(a);
for (i = 0; i < len; i++) {
if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4') {
i += 2;
continue;
}
if (a[i] == '1' && a[i + 1] == '4') {
i += 1;
continue;
}
if (a[i] == '1') {
continue;
}
break;
}
if (i >= len)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool magical(string s) {
for (int i = 0; i < s.size(); i++)
if (s[i] != '1' && s[i] != '4') return false;
if (s[0] == '4') return false;
if (s.find("444") != string::npos) return false;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
cout << (magical(s) ? "YES\n" : "NO\n");
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool magical(string s) {
for (int i = 0; i < s.size(); i++)
if (s[i] != '1' && s[i] != '4') return false;
if (s[0] == '4') return false;
if (s.find("444") != string::npos) return false;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
cout << (magical(s) ? "YES\n" : "NO\n");
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
while (n != 0) {
if (n % 10 == 1) {
n /= 10;
} else if (n % 100 == 14) {
n /= 100;
} else if (n % 1000 == 144) {
n /= 1000;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
### Prompt
Generate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
while (n != 0) {
if (n % 10 == 1) {
n /= 10;
} else if (n % 100 == 14) {
n /= 100;
} else if (n % 1000 == 144) {
n /= 1000;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
while (true) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
break;
}
}
if (n > 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
while (true) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
break;
}
}
if (n > 0)
cout << "NO";
else
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
if (s[0] != '1') {
cout << "NO";
return 0;
}
int i = 0;
while (i < s.size()) {
if (s[i] != '1' && s[i] != '4') {
cout << "NO";
return 0;
} else if (s[i] == '4') {
int c = 0;
while (s[i] == '4') {
c++;
if (c > 2) {
cout << "NO";
return 0;
}
i++;
}
} else
i++;
}
cout << "YES";
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
if (s[0] != '1') {
cout << "NO";
return 0;
}
int i = 0;
while (i < s.size()) {
if (s[i] != '1' && s[i] != '4') {
cout << "NO";
return 0;
} else if (s[i] == '4') {
int c = 0;
while (s[i] == '4') {
c++;
if (c > 2) {
cout << "NO";
return 0;
}
i++;
}
} else
i++;
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
getline(cin, s);
int n = s.length();
bool ok = true;
int num4s = 0;
for (int i = n - 1; i >= 0; i--) {
int k = s[i] - '0';
if (k == 1) {
if (num4s <= 2) {
num4s = 0;
}
} else if (k == 4) {
if (num4s >= 2 || i == 0) {
ok = false;
break;
}
num4s++;
} else {
ok = false;
break;
}
}
if (ok)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
getline(cin, s);
int n = s.length();
bool ok = true;
int num4s = 0;
for (int i = n - 1; i >= 0; i--) {
int k = s[i] - '0';
if (k == 1) {
if (num4s <= 2) {
num4s = 0;
}
} else if (k == 4) {
if (num4s >= 2 || i == 0) {
ok = false;
break;
}
num4s++;
} else {
ok = false;
break;
}
}
if (ok)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int x = 0;
while (s[x] == '1' && x <= s.size()) {
if (s.substr(x, 3) == "144")
x += 3;
else if (s.substr(x, 2) == "14")
x += 2;
else
x++;
}
if (x == s.size())
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
In cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int x = 0;
while (s[x] == '1' && x <= s.size()) {
if (s.substr(x, 3) == "144")
x += 3;
else if (s.substr(x, 2) == "14")
x += 2;
else
x++;
}
if (x == s.size())
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool flag = true;
long long x;
long long n = s.length();
for (long long i = 0; i < n;) {
if (s[i] == '1') {
i++;
if (s[i] == '4') {
i++;
if (s[i] == '4') {
i++;
}
}
} else {
flag = false;
break;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
### Prompt
Please provide a Cpp coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool flag = true;
long long x;
long long n = s.length();
for (long long i = 0; i < n;) {
if (s[i] == '1') {
i++;
if (s[i] == '4') {
i++;
if (s[i] == '4') {
i++;
}
}
} else {
flag = false;
break;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int MAXI = 0x7fffffff;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char dz[] = "SENW";
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
void debugarr(int* arr, int n) {
cout << "[";
for (int i = 0; i < n; i++) cout << arr[i] << " ";
cout << "]" << endl;
}
int a[1000010];
char str[1000010];
int main() {
int n, i, j, k, l, m, t, s = 0;
cin >> str;
m = strlen(str);
for (i = 0; i < m; i++) {
if (str[i] == '1') {
if (str[i + 1] == '4' && i + 1 < m) {
if (str[i + 2] == '4' && i + 2 < m) {
i = i + 2;
} else
i += 1;
}
} else {
printf("NO\n");
return (0);
}
}
printf("YES\n");
return (0);
}
|
### Prompt
Your task is to create a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int MAXI = 0x7fffffff;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const char dz[] = "SENW";
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
void debugarr(int* arr, int n) {
cout << "[";
for (int i = 0; i < n; i++) cout << arr[i] << " ";
cout << "]" << endl;
}
int a[1000010];
char str[1000010];
int main() {
int n, i, j, k, l, m, t, s = 0;
cin >> str;
m = strlen(str);
for (i = 0; i < m; i++) {
if (str[i] == '1') {
if (str[i + 1] == '4' && i + 1 < m) {
if (str[i + 2] == '4' && i + 2 < m) {
i = i + 2;
} else
i += 1;
}
} else {
printf("NO\n");
return (0);
}
}
printf("YES\n");
return (0);
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n > 0) {
if (n % 1000 == 144) {
n /= 1000;
} else if (n % 100 == 14) {
n /= 100;
} else if (n % 10 == 1) {
n /= 10;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Your challenge is to write a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n > 0) {
if (n % 1000 == 144) {
n /= 1000;
} else if (n % 100 == 14) {
n /= 100;
} else if (n % 10 == 1) {
n /= 10;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
char s[20];
scanf("%s", s);
int i, j, f = 0, c = 0;
if (s[0] != '1') {
f = 1;
} else {
for (i = 1; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
f = 1;
break;
} else if (s[i] == '4') {
for (j = i; s[j]; j++) {
if (s[j] == '4')
c++;
else if (s[j] == '1' || c > 2)
break;
}
if (c > 2) {
f = 1;
break;
}
c = 0;
}
}
}
if (f == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
char s[20];
scanf("%s", s);
int i, j, f = 0, c = 0;
if (s[0] != '1') {
f = 1;
} else {
for (i = 1; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
f = 1;
break;
} else if (s[i] == '4') {
for (j = i; s[j]; j++) {
if (s[j] == '4')
c++;
else if (s[j] == '1' || c > 2)
break;
}
if (c > 2) {
f = 1;
break;
}
c = 0;
}
}
}
if (f == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool isMagic(int n) {
while (n > 0) {
while (n % 1000 == 144) {
n /= 1000;
}
while (n % 100 == 14) {
n /= 100;
}
while (n % 10 == 1) {
n /= 10;
}
if (n == 0) {
return true;
}
if (n % 100 != 14 and n % 1000 != 144) {
return false;
}
}
return true;
}
int main() {
int n;
cin >> n;
if (isMagic(n)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool isMagic(int n) {
while (n > 0) {
while (n % 1000 == 144) {
n /= 1000;
}
while (n % 100 == 14) {
n /= 100;
}
while (n % 10 == 1) {
n /= 10;
}
if (n == 0) {
return true;
}
if (n % 100 != 14 and n % 1000 != 144) {
return false;
}
}
return true;
}
int main() {
int n;
cin >> n;
if (isMagic(n)) {
cout << "YES\n";
} else {
cout << "NO\n";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int len;
string str, n1, n2, n3;
cin >> str;
len = str.size();
str += "11111";
bool chk = true;
for (int i = 0; i < len; i++) {
n1 = str[i];
n1 += str[i + 1];
n1 += str[i + 2];
n2 = str[i];
n2 += str[i + 1];
n3 = str[i];
if ("144" == n1) {
i = i + 2;
} else if ("14" == n2) {
i = i + 1;
} else if ("1" == n3) {
i = i;
} else {
chk = false;
break;
}
}
if (chk)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int len;
string str, n1, n2, n3;
cin >> str;
len = str.size();
str += "11111";
bool chk = true;
for (int i = 0; i < len; i++) {
n1 = str[i];
n1 += str[i + 1];
n1 += str[i + 2];
n2 = str[i];
n2 += str[i + 1];
n3 = str[i];
if ("144" == n1) {
i = i + 2;
} else if ("14" == n2) {
i = i + 1;
} else if ("1" == n3) {
i = i;
} else {
chk = false;
break;
}
}
if (chk)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string input;
regex rex1("^((1)*(14)*(144)*)*$");
void inputData() {
cin >> input;
if (regex_match(input, rex1)) {
cout << "YES";
} else {
cout << "NO";
}
}
int main(int argc, char** argv) { inputData(); }
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string input;
regex rex1("^((1)*(14)*(144)*)*$");
void inputData() {
cin >> input;
if (regex_match(input, rex1)) {
cout << "YES";
} else {
cout << "NO";
}
}
int main(int argc, char** argv) { inputData(); }
```
|
#include <bits/stdc++.h>
template <typename T>
inline T gcd(T a, T b) {
T c;
while (b) {
c = b;
b = a % b;
a = c;
}
return a;
}
template <typename T>
T lcm(T a, T b) {
return b * (a / gcd(a, b));
}
template <typename T>
inline T pow2(T base, T n) {
T ansp = 1;
while (n) {
if (n & 1) ansp *= base;
n >>= 1;
base *= base;
}
return ansp;
}
using namespace std;
bool sortbyf(const pair<pair<long long, long long>, long long> &a,
const pair<pair<long long, long long>, long long> &b) {
return a.first.first < b.first.first;
}
bool sortbys(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return a.first < b.first;
}
long long mat[11][101][101];
int main() {
string s;
cin >> s;
if (s[0] == '1') {
for (long long i = 0; i < s.size(); i++) {
if (s[i] != '1' && s[i] != '4') {
printf("NO\n");
return 0;
}
}
int f = s.find("444");
if (f > -1) {
printf("NO\n");
return 0;
}
} else {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
template <typename T>
inline T gcd(T a, T b) {
T c;
while (b) {
c = b;
b = a % b;
a = c;
}
return a;
}
template <typename T>
T lcm(T a, T b) {
return b * (a / gcd(a, b));
}
template <typename T>
inline T pow2(T base, T n) {
T ansp = 1;
while (n) {
if (n & 1) ansp *= base;
n >>= 1;
base *= base;
}
return ansp;
}
using namespace std;
bool sortbyf(const pair<pair<long long, long long>, long long> &a,
const pair<pair<long long, long long>, long long> &b) {
return a.first.first < b.first.first;
}
bool sortbys(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return a.first < b.first;
}
long long mat[11][101][101];
int main() {
string s;
cin >> s;
if (s[0] == '1') {
for (long long i = 0; i < s.size(); i++) {
if (s[i] != '1' && s[i] != '4') {
printf("NO\n");
return 0;
}
}
int f = s.find("444");
if (f > -1) {
printf("NO\n");
return 0;
}
} else {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string palavra;
cin >> palavra;
int flag = 1;
for (int i = 0; i < palavra.size(); ++i) {
if (palavra[i] == '1') {
if (palavra[i + 1] == '4' && palavra[i + 2] == '4') {
i += 2;
continue;
} else if (palavra[i + 1] == '4') {
i += 1;
continue;
} else {
continue;
}
} else {
flag = 0;
break;
}
}
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
### Prompt
Your task is to create a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string palavra;
cin >> palavra;
int flag = 1;
for (int i = 0; i < palavra.size(); ++i) {
if (palavra[i] == '1') {
if (palavra[i + 1] == '4' && palavra[i + 2] == '4') {
i += 2;
continue;
} else if (palavra[i + 1] == '4') {
i += 1;
continue;
} else {
continue;
}
} else {
flag = 0;
break;
}
}
if (flag)
printf("YES\n");
else
printf("NO\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int inf = 1e9 + 5;
const long long int MOD = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
return !a ? b : gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
return a / gcd(a, b) * b;
}
int main() {
ios_base::sync_with_stdio(0);
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s.substr(i, 3) == "144") {
i += 2;
} else if (s.substr(i, 2) == "14") {
i += 1;
} else if (s.substr(i, 1) == "1") {
continue;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const long long int inf = 1e9 + 5;
const long long int MOD = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
return !a ? b : gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
return a / gcd(a, b) * b;
}
int main() {
ios_base::sync_with_stdio(0);
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s.substr(i, 3) == "144") {
i += 2;
} else if (s.substr(i, 2) == "14") {
i += 1;
} else if (s.substr(i, 1) == "1") {
continue;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
bool is_magical(string number) {
for (int i = 0; i < (int)number.size(); i++)
if (number[i] != '1' && number[i] != '4') return false;
if (number[0] == '4') return false;
if (number.find("444") != number.npos) return false;
return true;
}
int main() {
string number;
cin >> number;
if (is_magical(number))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
bool is_magical(string number) {
for (int i = 0; i < (int)number.size(); i++)
if (number[i] != '1' && number[i] != '4') return false;
if (number[0] == '4') return false;
if (number.find("444") != number.npos) return false;
return true;
}
int main() {
string number;
cin >> number;
if (is_magical(number))
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool ok = true;
for (int i = 0; i < s.size(); i++) {
if (i + 1 < s.size() && i + 2 < s.size() && s[i] == '1' &&
s[i + 1] == '4' && s[i + 2] == '4')
i += 2;
else if (i + 1 < s.size() && s[i] == '1' && s[i + 1] == '4')
i += 1;
else if (s[i] != '1')
ok = false;
}
ok == true ? cout << "YES" : cout << "NO";
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
bool ok = true;
for (int i = 0; i < s.size(); i++) {
if (i + 1 < s.size() && i + 2 < s.size() && s[i] == '1' &&
s[i + 1] == '4' && s[i + 2] == '4')
i += 2;
else if (i + 1 < s.size() && s[i] == '1' && s[i + 1] == '4')
i += 1;
else if (s[i] != '1')
ok = false;
}
ok == true ? cout << "YES" : cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
int main() {
int a, b, c;
char s[100];
gets(s);
a = 0, b = 0, c = 0;
while (s[a] != '\0') {
if (s[a] == '1')
b = 1;
else if (b == 0) {
c = 1;
break;
} else if (b <= 2 && s[a] == '4')
b++;
else if (s[a] != 1)
c = 1;
else
b = 1;
a++;
}
if (c == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
int main() {
int a, b, c;
char s[100];
gets(s);
a = 0, b = 0, c = 0;
while (s[a] != '\0') {
if (s[a] == '1')
b = 1;
else if (b == 0) {
c = 1;
break;
} else if (b <= 2 && s[a] == '4')
b++;
else if (s[a] != 1)
c = 1;
else
b = 1;
a++;
}
if (c == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int one = 0, four = 0;
string s;
cin >> s;
if (s[0] != '1') {
printf("NO\n");
return 0;
}
for (int i = 0; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
printf("NO\n");
return 0;
}
}
for (int i = 1; s[i]; i++) {
if (s[i] == '1') continue;
if (s[i] == '4' && s[i - 1] == '1')
continue;
else if (s[i] == '4' && s[i - 1] == '4' && s[i - 2] == '1')
continue;
else {
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int one = 0, four = 0;
string s;
cin >> s;
if (s[0] != '1') {
printf("NO\n");
return 0;
}
for (int i = 0; s[i]; i++) {
if (s[i] != '1' && s[i] != '4') {
printf("NO\n");
return 0;
}
}
for (int i = 1; s[i]; i++) {
if (s[i] == '1') continue;
if (s[i] == '4' && s[i - 1] == '1')
continue;
else if (s[i] == '4' && s[i - 1] == '4' && s[i - 2] == '1')
continue;
else {
printf("NO\n");
return 0;
}
}
printf("YES\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool prime(T n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n & 1 ^ 1 || n % 3 == 0) return false;
for (T i = 5; i * i <= n; i += 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int i = 0;
while (i < s.size()) {
if (s.size() - i >= 3 && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4')
i += 3;
else if (s.size() - i >= 2 && s[i] == '1' && s[i + 1] == '4')
i += 2;
else if (s[i] == '1')
i++;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool prime(T n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n & 1 ^ 1 || n % 3 == 0) return false;
for (T i = 5; i * i <= n; i += 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string s;
cin >> s;
int i = 0;
while (i < s.size()) {
if (s.size() - i >= 3 && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4')
i += 3;
else if (s.size() - i >= 2 && s[i] == '1' && s[i + 1] == '4')
i += 2;
else if (s[i] == '1')
i++;
else {
cout << "NO";
return 0;
}
}
cout << "YES";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int f = 0;
if (str[0] != '1') {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i < str.length(); ++i) {
if (str[i] == '4') {
++f;
if (f > 2) {
cout << "NO" << endl;
return 0;
}
} else if (str[i] == '1') {
f = 0;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Please formulate a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int f = 0;
if (str[0] != '1') {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i < str.length(); ++i) {
if (str[i] == '4') {
++f;
if (f > 2) {
cout << "NO" << endl;
return 0;
}
} else if (str[i] == '1') {
f = 0;
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, len, flag = 0;
char a[9];
gets(a);
len = strlen(a);
for (i = 0; i < len; i++) {
if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4')
i = i + 2;
else if (a[i] == '1' && a[i + 1] == '4')
i = i + 1;
else if (a[i] == '1')
i = i;
else {
flag = 1;
break;
}
}
if (flag == 1)
printf("NO\n");
else
printf("YES\n");
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, len, flag = 0;
char a[9];
gets(a);
len = strlen(a);
for (i = 0; i < len; i++) {
if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4')
i = i + 2;
else if (a[i] == '1' && a[i + 1] == '4')
i = i + 1;
else if (a[i] == '1')
i = i;
else {
flag = 1;
break;
}
}
if (flag == 1)
printf("NO\n");
else
printf("YES\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
bool flag = 0;
while (n && flag == 0) {
if (n % 10 == 1)
n /= 10;
else if (n % 10 == 4) {
int tmp = n / 10;
if (tmp % 10 == 1)
n /= 100;
else if (tmp % 10 == 4) {
int tmp1 = tmp / 10;
if (tmp1 % 10 == 1)
n /= 1000;
else
flag = 1;
} else
flag = 1;
} else
flag = 1;
}
if (flag == 0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
bool flag = 0;
while (n && flag == 0) {
if (n % 10 == 1)
n /= 10;
else if (n % 10 == 4) {
int tmp = n / 10;
if (tmp % 10 == 1)
n /= 100;
else if (tmp % 10 == 4) {
int tmp1 = tmp / 10;
if (tmp1 % 10 == 1)
n /= 1000;
else
flag = 1;
} else
flag = 1;
} else
flag = 1;
}
if (flag == 0)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string g;
cin >> g;
int n = g.size();
for (int i = 0; i < n; i++) {
if (g[i] != '1' and g[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
if (g[0] == '4') {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i < n; i++) {
if (g[i] == '4') {
if (g[i - 1] != '1') {
cout << "NO" << endl;
return 0;
} else
i++;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string g;
cin >> g;
int n = g.size();
for (int i = 0; i < n; i++) {
if (g[i] != '1' and g[i] != '4') {
cout << "NO" << endl;
return 0;
}
}
if (g[0] == '4') {
cout << "NO" << endl;
return 0;
}
for (int i = 1; i < n; i++) {
if (g[i] == '4') {
if (g[i - 1] != '1') {
cout << "NO" << endl;
return 0;
} else
i++;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, tam, flag = 0;
char magic[20];
cin >> magic;
tam = strlen(magic);
if (magic[0] != '1') flag = 1;
for (i = 0; i < tam; i++) {
if (magic[i] == '4' && magic[i + 1] == '4' && magic[i + 2] == '4') flag = 1;
if (magic[i] != '4' && magic[i] != '1') flag = 1;
if (magic[i] == '4' && magic[i - 1] != '1' && magic[i - 1] != '4') flag = 1;
}
if (flag != 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
### Prompt
Your task is to create a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, tam, flag = 0;
char magic[20];
cin >> magic;
tam = strlen(magic);
if (magic[0] != '1') flag = 1;
for (i = 0; i < tam; i++) {
if (magic[i] == '4' && magic[i + 1] == '4' && magic[i + 2] == '4') flag = 1;
if (magic[i] != '4' && magic[i] != '1') flag = 1;
if (magic[i] == '4' && magic[i - 1] != '1' && magic[i - 1] != '4') flag = 1;
}
if (flag != 0)
cout << "NO";
else
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, c, ans = 0;
string s;
cin >> s;
bool sol = 1;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
continue;
}
if (s[i] == '1' || (s[i] == '4' && s[i - 1] == '1'))
continue;
else
sol = 0;
}
if (sol)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, c, ans = 0;
string s;
cin >> s;
bool sol = 1;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 2;
continue;
}
if (s[i] == '1' || (s[i] == '4' && s[i - 1] == '1'))
continue;
else
sol = 0;
}
if (sol)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string n;
cin >> n;
int i = 0;
while (i < n.size()) {
if (n[i] == '1') {
i++;
continue;
} else if (n[i] == '4') {
if (i > 0 && n[i - 1] == '1') {
i++;
continue;
}
if (i > 1 && n[i - 1] == '4' && n[i - 2] == '1') {
i++;
continue;
}
break;
} else {
break;
}
}
cout << (i == n.size() ? "YES\n" : "NO\n");
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string n;
cin >> n;
int i = 0;
while (i < n.size()) {
if (n[i] == '1') {
i++;
continue;
} else if (n[i] == '4') {
if (i > 0 && n[i - 1] == '1') {
i++;
continue;
}
if (i > 1 && n[i - 1] == '4' && n[i - 2] == '1') {
i++;
continue;
}
break;
} else {
break;
}
}
cout << (i == n.size() ? "YES\n" : "NO\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, flag = 1;
scanf("%d", &n);
while (n) {
if (n % 10 == 4) {
n /= 10;
if (n % 10 == 4) {
n /= 10;
if (n % 10 != 1) flag = 0;
} else if (n % 10 == 1)
n /= 10;
else
flag = 0;
} else if (n % 10 == 1)
n /= 10;
else
flag = 0;
if (flag == 0) {
printf("NO\n");
break;
}
}
if (n == 0 && flag == 1) printf("YES\n");
return 0;
}
|
### Prompt
In Cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, flag = 1;
scanf("%d", &n);
while (n) {
if (n % 10 == 4) {
n /= 10;
if (n % 10 == 4) {
n /= 10;
if (n % 10 != 1) flag = 0;
} else if (n % 10 == 1)
n /= 10;
else
flag = 0;
} else if (n % 10 == 1)
n /= 10;
else
flag = 0;
if (flag == 0) {
printf("NO\n");
break;
}
}
if (n == 0 && flag == 1) printf("YES\n");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
char sav[200];
scanf("%s", sav);
int flag = 0;
int len = strlen(sav);
for (int i = 0; i < len; i++) {
if (sav[i] == '1')
continue;
else if (sav[i] == '4') {
if (i - 1 >= 0 && sav[i - 1] == '1')
continue;
else if (i - 1 >= 0 && sav[i - 1] == '4') {
if (i - 2 >= 0 && sav[i - 2] == '1')
continue;
else
flag = 1;
} else
flag = 1;
} else
flag = 1;
}
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
char sav[200];
scanf("%s", sav);
int flag = 0;
int len = strlen(sav);
for (int i = 0; i < len; i++) {
if (sav[i] == '1')
continue;
else if (sav[i] == '4') {
if (i - 1 >= 0 && sav[i - 1] == '1')
continue;
else if (i - 1 >= 0 && sav[i - 1] == '4') {
if (i - 2 >= 0 && sav[i - 2] == '1')
continue;
else
flag = 1;
} else
flag = 1;
} else
flag = 1;
}
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
char c[20];
cin >> c;
int p = 0, n = strlen(c);
bool es = true;
while (p < n) {
if (c[p] == '1' && c[p + 1] == '4' && c[p + 2] == '4') {
p += 3;
} else if (c[p] == '1' && c[p + 1] == '4') {
p += 2;
} else if (c[p] == '1') {
p++;
} else {
es = false;
break;
}
}
cout << (es ? "YES" : "NO") << endl;
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
char c[20];
cin >> c;
int p = 0, n = strlen(c);
bool es = true;
while (p < n) {
if (c[p] == '1' && c[p + 1] == '4' && c[p + 2] == '4') {
p += 3;
} else if (c[p] == '1' && c[p + 1] == '4') {
p += 2;
} else if (c[p] == '1') {
p++;
} else {
es = false;
break;
}
}
cout << (es ? "YES" : "NO") << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int n, i, k = 0;
cin >> str;
for (i = 0; i < str.size(); ++i) {
if (str[0] != '1') {
break;
}
if (str[i] != '1' && str[i] != '4') {
break;
}
if (str[i] == '1') {
k = 1;
}
if (str[i] == '4') {
k++;
}
if (k > 3) {
break;
}
}
if (i == str.size()) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
|
### Prompt
Create a solution in CPP for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int n, i, k = 0;
cin >> str;
for (i = 0; i < str.size(); ++i) {
if (str[0] != '1') {
break;
}
if (str[i] != '1' && str[i] != '4') {
break;
}
if (str[i] == '1') {
k = 1;
}
if (str[i] == '4') {
k++;
}
if (k > 3) {
break;
}
}
if (i == str.size()) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int f = 1;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
if (i + 1 < n) {
if (s[i + 1] == '4') {
if (i + 2 < n) {
if (s[i + 2] == '4')
i += 2;
else if (s[i + 2] == '1')
i += 1;
else {
f = 0;
break;
}
} else
i += 1;
} else if (s[i + 1] == '1')
continue;
else {
f = 0;
break;
}
}
} else {
f = 0;
break;
}
}
if (f == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int f = 1;
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
if (i + 1 < n) {
if (s[i + 1] == '4') {
if (i + 2 < n) {
if (s[i + 2] == '4')
i += 2;
else if (s[i + 2] == '1')
i += 1;
else {
f = 0;
break;
}
} else
i += 1;
} else if (s[i + 1] == '1')
continue;
else {
f = 0;
break;
}
}
} else {
f = 0;
break;
}
}
if (f == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%f\n", pt); }
inline void print(char pt[]) { printf("%s\n", pt); }
inline void scan(int &pt) { scanf("%d", &pt); }
inline void scan(long long &pt) { scanf("%I64d", &pt); }
inline void scan(double &pt) { scanf("%f", &pt); }
inline void scan(char pt[]) { scanf("%s", pt); }
struct pii {
int a;
int b;
friend int operator<(pii a, pii b) {
if (a.a != b.a) return a.a < b.a;
return a.b < b.b;
}
} p[500];
int n;
char stra[10000];
char strs[3][50] = {"144", "14", "1"};
int main() {
scan(stra);
int lena = strlen(stra);
for (int i = 0; i < lena;) {
if (stra[i] == '1') {
if (i == lena - 1) break;
if (stra[i + 1] == '4') {
if (i + 1 == lena - 1) break;
if (stra[i + 2] == '4') {
if (i + 2 == lena - 1) break;
i += 3;
continue;
}
i += 2;
continue;
}
i++;
continue;
} else {
print("NO");
return 0;
}
}
print("YES");
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
inline void print(int pt) { printf("%d\n", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%f\n", pt); }
inline void print(char pt[]) { printf("%s\n", pt); }
inline void scan(int &pt) { scanf("%d", &pt); }
inline void scan(long long &pt) { scanf("%I64d", &pt); }
inline void scan(double &pt) { scanf("%f", &pt); }
inline void scan(char pt[]) { scanf("%s", pt); }
struct pii {
int a;
int b;
friend int operator<(pii a, pii b) {
if (a.a != b.a) return a.a < b.a;
return a.b < b.b;
}
} p[500];
int n;
char stra[10000];
char strs[3][50] = {"144", "14", "1"};
int main() {
scan(stra);
int lena = strlen(stra);
for (int i = 0; i < lena;) {
if (stra[i] == '1') {
if (i == lena - 1) break;
if (stra[i + 1] == '4') {
if (i + 1 == lena - 1) break;
if (stra[i + 2] == '4') {
if (i + 2 == lena - 1) break;
i += 3;
continue;
}
i += 2;
continue;
}
i++;
continue;
} else {
print("NO");
return 0;
}
}
print("YES");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int flag = 1;
cin >> str;
int len = str.size();
str[len] = '1';
str[len + 1] = '1';
for (int i = 0; i < str.size();) {
string temp = "";
if (str[i] == '1') {
temp = str[i + 1];
if (temp == "4") {
temp += str[i + 2];
if (temp == "44") {
i += 3;
} else {
i += 2;
}
} else {
i++;
}
} else {
flag = 0;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int flag = 1;
cin >> str;
int len = str.size();
str[len] = '1';
str[len + 1] = '1';
for (int i = 0; i < str.size();) {
string temp = "";
if (str[i] == '1') {
temp = str[i + 1];
if (temp == "4") {
temp += str[i + 2];
if (temp == "44") {
i += 3;
} else {
i += 2;
}
} else {
i++;
}
} else {
flag = 0;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
char g[20];
int main() {
scanf("%s", g);
int len = strlen(g);
int flag = 0;
for (int i = 0; i < len;) {
if (g[i] == '1' && g[i + 1] == '4' && g[i + 2] == '4') {
i += 3;
continue;
}
if (g[i] == '1' && g[i + 1] == '4') {
i += 2;
continue;
}
if (g[i] == '1') {
i++;
continue;
}
flag = 1;
break;
}
if (flag == 0)
printf("YES");
else
printf("NO");
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
char g[20];
int main() {
scanf("%s", g);
int len = strlen(g);
int flag = 0;
for (int i = 0; i < len;) {
if (g[i] == '1' && g[i + 1] == '4' && g[i + 2] == '4') {
i += 3;
continue;
}
if (g[i] == '1' && g[i + 1] == '4') {
i += 2;
continue;
}
if (g[i] == '1') {
i++;
continue;
}
flag = 1;
break;
}
if (flag == 0)
printf("YES");
else
printf("NO");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
int i = 0;
while (i < n.size()) {
if (n[i] == '1') {
if (i + 1 < n.size() and n[i + 1] == '4') {
if (i + 2 < n.size() and n[i + 2] == '4') {
i += 3;
continue;
} else {
i += 2;
continue;
}
} else {
i += 1;
continue;
}
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
int i = 0;
while (i < n.size()) {
if (n[i] == '1') {
if (i + 1 < n.size() and n[i + 1] == '4') {
if (i + 2 < n.size() and n[i + 2] == '4') {
i += 3;
continue;
} else {
i += 2;
continue;
}
} else {
i += 1;
continue;
}
} else {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
int m = 0;
while (n > 0) {
m++;
if ((n - 144) % 1000 == 0) {
n -= 144;
n /= 1000;
} else if ((n - 14) % 100 == 0) {
n -= 14;
n /= 100;
} else if ((n - 1) % 10 == 0) {
n -= 1;
n /= 10;
} else {
break;
}
}
if (n == 0)
cout << "YES";
else
cout << "NO";
}
|
### Prompt
In Cpp, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
int m = 0;
while (n > 0) {
m++;
if ((n - 144) % 1000 == 0) {
n -= 144;
n /= 1000;
} else if ((n - 14) % 100 == 0) {
n -= 14;
n /= 100;
} else if ((n - 1) % 10 == 0) {
n -= 1;
n /= 10;
} else {
break;
}
}
if (n == 0)
cout << "YES";
else
cout << "NO";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
for (i = 0; s[i] != '\0';) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i = i + 3;
} else if (s[i] == '1' && s[i + 1] == '4') {
i = i + 2;
} else if (s[i] == '1') {
i = i + 1;
} else {
c = 1;
break;
}
}
if (c == 0)
cout << "YES";
else
cout << "NO";
}
|
### Prompt
Please create a solution in cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
for (i = 0; s[i] != '\0';) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i = i + 3;
} else if (s[i] == '1' && s[i + 1] == '4') {
i = i + 2;
} else if (s[i] == '1') {
i = i + 1;
} else {
c = 1;
break;
}
}
if (c == 0)
cout << "YES";
else
cout << "NO";
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
int main() {
int n, a[10];
while (cin >> n) {
memset(a, 0, sizeof(a));
int i = 0;
while (n) {
a[i] = n % 10;
n /= 10;
i++;
}
i -= 1;
int flag = 0;
reverse(a, a + i + 1);
for (int j = 0; j <= i; j++) {
if ((a[j] != 4 && a[j] != 1) || a[0] == 4 ||
(a[j] == 4 && a[j + 1] == 4 && a[j + 2] == 4)) {
flag = 1;
break;
}
}
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
int main() {
int n, a[10];
while (cin >> n) {
memset(a, 0, sizeof(a));
int i = 0;
while (n) {
a[i] = n % 10;
n /= 10;
i++;
}
i -= 1;
int flag = 0;
reverse(a, a + i + 1);
for (int j = 0; j <= i; j++) {
if ((a[j] != 4 && a[j] != 1) || a[0] == 4 ||
(a[j] == 4 && a[j + 1] == 4 && a[j + 2] == 4)) {
flag = 1;
break;
}
}
if (flag)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
int test = 0;
cin >> num;
bool mg = true;
while (num != 0) {
int dic = num % 10;
num = num / 10;
if (dic == 1) {
test = 0;
} else if (dic == 4 && test < 2) {
test += 1;
} else {
mg = false;
}
}
if (test != 0) {
mg = false;
}
if (mg)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
In CPP, your task is to solve the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int num;
int test = 0;
cin >> num;
bool mg = true;
while (num != 0) {
int dic = num % 10;
num = num / 10;
if (dic == 1) {
test = 0;
} else if (dic == 4 && test < 2) {
test += 1;
} else {
mg = false;
}
}
if (test != 0) {
mg = false;
}
if (mg)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string ip;
int f = 0, i = 0, j;
cin >> ip;
while (i != ip.size()) {
if (ip[i] == '1') {
i++;
if (ip[i] == '4' && i < ip.size()) {
i++;
if (ip[i] == '4' && i < ip.size()) i++;
}
f = 1;
} else {
f = 0;
break;
}
}
if (f == 0)
cout << "NO";
else
cout << "YES";
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string ip;
int f = 0, i = 0, j;
cin >> ip;
while (i != ip.size()) {
if (ip[i] == '1') {
i++;
if (ip[i] == '4' && i < ip.size()) {
i++;
if (ip[i] == '4' && i < ip.size()) i++;
}
f = 1;
} else {
f = 0;
break;
}
}
if (f == 0)
cout << "NO";
else
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
bool flag = true;
while (n > 0) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
cout << "NO"
<< "\n";
flag = false;
break;
}
}
if (flag)
cout << "YES"
<< "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
### Prompt
Your challenge is to write a Cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
bool flag = true;
while (n > 0) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
cout << "NO"
<< "\n";
flag = false;
break;
}
}
if (flag)
cout << "YES"
<< "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string s;
bool fun(int i) {
if (i >= s.size()) return 1;
if (s[i] == '1') {
if (s[i + 1] == '4') {
if (s[i + 2] == '4')
return fun(i + 3);
else
return fun(i + 2);
} else
return fun(i + 1);
} else
return 0;
}
int main() {
int i = 0;
cin >> s;
if (fun(i))
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Please create a solution in Cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string s;
bool fun(int i) {
if (i >= s.size()) return 1;
if (s[i] == '1') {
if (s[i + 1] == '4') {
if (s[i + 2] == '4')
return fun(i + 3);
else
return fun(i + 2);
} else
return fun(i + 1);
} else
return 0;
}
int main() {
int i = 0;
cin >> s;
if (fun(i))
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i = 0;
int flag1 = 0, flag2 = 0, flag3 = 0;
while (i < s.length()) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
flag1 = 1;
i += 3;
} else if (s[i] == '1' && s[i + 1] == '4') {
flag2 = 1;
i += 2;
} else if (s[i] == '1') {
flag3 = 1;
i++;
}
if (flag1 == 0 && flag2 == 0 && flag3 == 0) {
cout << "NO";
return 0;
}
flag1 = 0;
flag2 = 0;
flag3 = 0;
}
cout << "YES";
return 0;
}
|
### Prompt
Please formulate a CPP solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i = 0;
int flag1 = 0, flag2 = 0, flag3 = 0;
while (i < s.length()) {
if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
flag1 = 1;
i += 3;
} else if (s[i] == '1' && s[i + 1] == '4') {
flag2 = 1;
i += 2;
} else if (s[i] == '1') {
flag3 = 1;
i++;
}
if (flag1 == 0 && flag2 == 0 && flag3 == 0) {
cout << "NO";
return 0;
}
flag1 = 0;
flag2 = 0;
flag3 = 0;
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
int i, j, flag = 0, ar[20];
cin >> n;
for (i = 0; i < n.size(); ++i) {
ar[i] = n[i] - '0';
}
for (i = 0; i < n.size(); ++i) {
if (ar[i] != 1 && ar[i] != 4) flag = 1;
if (ar[i] == 1)
;
if (ar[i] == 4) {
if (i == 0) flag = 1;
if (i + 1 < n.size() && ar[i + 1] == 4) {
if (i + 2 < n.size() && ar[i + 2] == 4) flag = 1;
}
}
}
if (flag == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
int i, j, flag = 0, ar[20];
cin >> n;
for (i = 0; i < n.size(); ++i) {
ar[i] = n[i] - '0';
}
for (i = 0; i < n.size(); ++i) {
if (ar[i] != 1 && ar[i] != 4) flag = 1;
if (ar[i] == 1)
;
if (ar[i] == 4) {
if (i == 0) flag = 1;
if (i + 1 < n.size() && ar[i + 1] == 4) {
if (i + 2 < n.size() && ar[i + 2] == 4) flag = 1;
}
}
}
if (flag == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b,
long long m = (long long)(1e9 + 7)) {
long long res = 1;
a %= m;
while (b > 0) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
long long mulmod(long long a, long long b, long long m = (long long)(1e9 + 7)) {
long long res = 0;
a %= m;
while (b > 0) {
if (b & 1) res = (res + a) % m;
a = (a * 2) % m;
b >>= 1;
}
return res;
}
void init() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
}
int32_t main() {
init();
long long t = 1;
while (t--) {
long long n;
cin >> n;
bool flag = true;
while (n > 0) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
flag = false;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
|
### Prompt
Develop a solution in CPP to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b,
long long m = (long long)(1e9 + 7)) {
long long res = 1;
a %= m;
while (b > 0) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
long long mulmod(long long a, long long b, long long m = (long long)(1e9 + 7)) {
long long res = 0;
a %= m;
while (b > 0) {
if (b & 1) res = (res + a) % m;
a = (a * 2) % m;
b >>= 1;
}
return res;
}
void init() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
}
int32_t main() {
init();
long long t = 1;
while (t--) {
long long n;
cin >> n;
bool flag = true;
while (n > 0) {
if (n % 1000 == 144)
n /= 1000;
else if (n % 100 == 14)
n /= 100;
else if (n % 10 == 1)
n /= 10;
else {
flag = false;
break;
}
}
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
if (s[i + 1] == '4') {
if (s[i + 2] == '4') {
i = i + 2;
continue;
} else
i++;
continue;
} else
continue;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
|
### Prompt
Please provide a cpp coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
if (s[i + 1] == '4') {
if (s[i + 2] == '4') {
i = i + 2;
continue;
} else
i++;
continue;
} else
continue;
} else {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int cnt;
int main() {
string s;
cin >> s;
if (s[0] == '4') {
cout << "NO";
return 0;
} else {
for (int i = 0; i < s.size(); i++) {
if (s[i] != '1' && s[i] != '4') {
cout << "NO";
return 0;
} else {
if (s[i] == '4') {
cnt++;
if (cnt > 2) {
cout << "NO";
return 0;
}
} else {
cnt = 0;
}
}
}
}
cout << "YES";
}
|
### Prompt
Construct a Cpp code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int cnt;
int main() {
string s;
cin >> s;
if (s[0] == '4') {
cout << "NO";
return 0;
} else {
for (int i = 0; i < s.size(); i++) {
if (s[i] != '1' && s[i] != '4') {
cout << "NO";
return 0;
} else {
if (s[i] == '4') {
cnt++;
if (cnt > 2) {
cout << "NO";
return 0;
}
} else {
cnt = 0;
}
}
}
}
cout << "YES";
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
int t = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1' || s[i] == '4') {
t = 0;
} else {
t = 1;
cout << "NO";
break;
}
}
if (t == 0) {
int h = 0;
int j = 0;
for (int i = 0; i <= s.length(); i++) {
if (count == 4) {
cout << "NO";
h = 1;
break;
} else if (s[j] == '1') {
count = 1;
} else if (s[j] == '4' && count != 0) {
count++;
} else if (s[j] = '4' && count == 0) {
cout << "NO";
h = 1;
break;
}
j++;
}
if (h == 0) cout << "YES";
}
return 0;
}
|
### Prompt
Construct a CPP code solution to the problem outlined:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
int t = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1' || s[i] == '4') {
t = 0;
} else {
t = 1;
cout << "NO";
break;
}
}
if (t == 0) {
int h = 0;
int j = 0;
for (int i = 0; i <= s.length(); i++) {
if (count == 4) {
cout << "NO";
h = 1;
break;
} else if (s[j] == '1') {
count = 1;
} else if (s[j] == '4' && count != 0) {
count++;
} else if (s[j] = '4' && count == 0) {
cout << "NO";
h = 1;
break;
}
j++;
}
if (h == 0) cout << "YES";
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
bool possible = true;
for (int i = 0; i < str.length(); i++) {
if (str.substr(i, 3) == "144")
i += 2;
else if (str.substr(i, 2) == "14")
i++;
else if (str.substr(i, 1) == "1")
continue;
else {
possible = false;
break;
}
}
cout << (possible ? "YES" : "NO");
return 0;
}
|
### Prompt
Create a solution in Cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
getline(cin, str);
bool possible = true;
for (int i = 0; i < str.length(); i++) {
if (str.substr(i, 3) == "144")
i += 2;
else if (str.substr(i, 2) == "14")
i++;
else if (str.substr(i, 1) == "1")
continue;
else {
possible = false;
break;
}
}
cout << (possible ? "YES" : "NO");
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1.0L);
const long double EPS = static_cast<long double>(1e-9);
inline long long Pow(long long a, long long k) {
long long s = 1;
for (; k; k >>= 1) {
k& 1 ? s = 1LL * s * a % MOD : 0;
a = 1LL * a * a % MOD;
}
return s;
}
const long long N = 1e6 + 7;
void input() {}
void preprocess() {}
void debug() {
if (true) {
}
}
bool ok[12];
void solve() {
preprocess();
string s;
cin >> s;
string a[3] = {"144", "14", "1"};
for (long long i = (0); i < (3); i++) {
size_t pos = 0;
string t = a[i];
long long n = t.length();
while ((pos = s.find(t, pos)) != string::npos) {
if (!ok[pos]) {
for (long long i = (pos); i < (pos + n); i++) {
ok[i] = true;
}
}
pos += n;
}
}
long long m = s.length();
for (long long i = (0); i < (m); i++) {
if (!ok[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
void output() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
{
input();
solve();
output();
}
return 0;
}
|
### Prompt
Create a solution in cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const long long INF32 = 1e9;
const long long MOD = 1e9 + 7;
const long double PI = acos(-1.0L);
const long double EPS = static_cast<long double>(1e-9);
inline long long Pow(long long a, long long k) {
long long s = 1;
for (; k; k >>= 1) {
k& 1 ? s = 1LL * s * a % MOD : 0;
a = 1LL * a * a % MOD;
}
return s;
}
const long long N = 1e6 + 7;
void input() {}
void preprocess() {}
void debug() {
if (true) {
}
}
bool ok[12];
void solve() {
preprocess();
string s;
cin >> s;
string a[3] = {"144", "14", "1"};
for (long long i = (0); i < (3); i++) {
size_t pos = 0;
string t = a[i];
long long n = t.length();
while ((pos = s.find(t, pos)) != string::npos) {
if (!ok[pos]) {
for (long long i = (pos); i < (pos + n); i++) {
ok[i] = true;
}
}
pos += n;
}
}
long long m = s.length();
for (long long i = (0); i < (m); i++) {
if (!ok[i]) {
cout << "NO" << endl;
return;
}
}
cout << "YES" << endl;
}
void output() {}
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
{
input();
solve();
output();
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string ismagic(const string &s) {
if (s.length() == 0) {
return "YES";
}
long long i = 0;
while (i < s.length()) {
if (s.substr(i, 3) == "144") {
i += 3;
} else if (s.substr(i, 2) == "14") {
i += 2;
} else if (s.substr(i, 1) == "1") {
i += 1;
} else
return "NO";
}
return "YES";
}
int main(int argc, const char *argv[]) {
string s;
cin >> s;
cout << ismagic(s);
return 0;
}
|
### Prompt
Please provide a CPP coded solution to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string ismagic(const string &s) {
if (s.length() == 0) {
return "YES";
}
long long i = 0;
while (i < s.length()) {
if (s.substr(i, 3) == "144") {
i += 3;
} else if (s.substr(i, 2) == "14") {
i += 2;
} else if (s.substr(i, 1) == "1") {
i += 1;
} else
return "NO";
}
return "YES";
}
int main(int argc, const char *argv[]) {
string s;
cin >> s;
cout << ismagic(s);
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int a, n;
cin >> n;
a = n;
while (true) {
if (n % 1000 == 144) {
n = n / 1000;
continue;
} else if (n % 100 == 14) {
n = n / 100;
continue;
} else if (n % 10 == 1) {
n = n / 10;
continue;
}
if (n == 0) {
cout << "YES" << endl;
return 0;
}
break;
}
cout << "NO" << endl;
return 0;
}
|
### Prompt
Develop a solution in cpp to the problem described below:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long long int a, n;
cin >> n;
a = n;
while (true) {
if (n % 1000 == 144) {
n = n / 1000;
continue;
} else if (n % 100 == 14) {
n = n / 100;
continue;
} else if (n % 10 == 1) {
n = n / 10;
continue;
}
if (n == 0) {
cout << "YES" << endl;
return 0;
}
break;
}
cout << "NO" << endl;
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int NINF = INT_MIN;
string s;
void Solve() {
cin >> s;
for (int i = 0; i <= s.length() - 1; i++) {
if (i + 2 < s.length() && s[i] == '1' && s[i + 1] == '4' &&
s[i + 2] == '4') {
i += 2;
continue;
} else if (i + 1 < s.length() && s[i] == '1' && s[i + 1] == '4') {
i += 1;
continue;
} else if (i < s.length() && s[i] == '1')
continue;
else {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
Solve();
return 0;
}
|
### Prompt
Please create a solution in cpp to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = INT_MAX;
const int NINF = INT_MIN;
string s;
void Solve() {
cin >> s;
for (int i = 0; i <= s.length() - 1; i++) {
if (i + 2 < s.length() && s[i] == '1' && s[i + 1] == '4' &&
s[i + 2] == '4') {
i += 2;
continue;
} else if (i + 1 < s.length() && s[i] == '1' && s[i + 1] == '4') {
i += 1;
continue;
} else if (i < s.length() && s[i] == '1')
continue;
else {
cout << "NO\n";
return;
}
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
Solve();
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool isMagic = true;
int i = 0;
for (i = 0; i < s.size(); i++) {
if (s[0] == '4') {
isMagic = false;
break;
} else if (s[i] == '1')
continue;
else if (s[i] == '4') {
int consec_four = 1;
while (i + 1 < s.size() && s[i + 1] == '4') {
consec_four++;
i++;
}
if (consec_four > 2) {
isMagic = false;
break;
}
} else {
isMagic = false;
break;
}
}
if (isMagic)
cout << "YES";
else
cout << "NO";
return 0;
}
|
### Prompt
Your challenge is to write a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool isMagic = true;
int i = 0;
for (i = 0; i < s.size(); i++) {
if (s[0] == '4') {
isMagic = false;
break;
} else if (s[i] == '1')
continue;
else if (s[i] == '4') {
int consec_four = 1;
while (i + 1 < s.size() && s[i + 1] == '4') {
consec_four++;
i++;
}
if (consec_four > 2) {
isMagic = false;
break;
}
} else {
isMagic = false;
break;
}
}
if (isMagic)
cout << "YES";
else
cout << "NO";
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
int one, four;
one = four = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1') {
++one;
} else if (s[i] == '4') {
++four;
} else {
return "NO";
}
}
if (one < 1) {
return "NO";
}
if (s[0] == '4') {
return "NO";
}
if (s.find("444") != s.npos) {
return "NO";
}
return "YES";
}
int main(void) {
string n;
while (cin >> n) {
cout << solve(n) << endl;
}
return 0;
}
|
### Prompt
Please formulate a cpp solution to the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
string solve(string s) {
int one, four;
one = four = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '1') {
++one;
} else if (s[i] == '4') {
++four;
} else {
return "NO";
}
}
if (one < 1) {
return "NO";
}
if (s[0] == '4') {
return "NO";
}
if (s.find("444") != s.npos) {
return "NO";
}
return "YES";
}
int main(void) {
string n;
while (cin >> n) {
cout << solve(n) << endl;
}
return 0;
}
```
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[10], k = 0, t = 1000000000;
scanf("%d", &n);
if (n == 1000000000)
printf("NO");
else {
for (; t >= 10; t /= 10) {
if (k != 0) {
a[k] = ((n % t) - (n % (t / 10))) / (t / 10);
k++;
} else {
if (((n % t) - (n % (t / 10))) / (t / 10) != 0) {
a[k] = ((n % t) - (n % (t / 10))) / (t / 10);
k++;
}
}
}
bool c = (a[0] == 1);
for (int i = 0; i < k; i++)
if (a[i] != 1 && a[i] != 4) c = false;
for (int i = 0; i < k - 2; i++)
if (a[i] == 4 && a[i + 1] == 4 && a[i + 2] == 4) c = false;
if (c)
printf("YES");
else
printf("NO");
}
}
|
### Prompt
Create a solution in cpp for the following problem:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not.
Input
The first line of input contains an integer n, (1 ≤ n ≤ 109). This number doesn't contain leading zeros.
Output
Print "YES" if n is a magic number or print "NO" if it's not.
Examples
Input
114114
Output
YES
Input
1111
Output
YES
Input
441231
Output
NO
### Response
```cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[10], k = 0, t = 1000000000;
scanf("%d", &n);
if (n == 1000000000)
printf("NO");
else {
for (; t >= 10; t /= 10) {
if (k != 0) {
a[k] = ((n % t) - (n % (t / 10))) / (t / 10);
k++;
} else {
if (((n % t) - (n % (t / 10))) / (t / 10) != 0) {
a[k] = ((n % t) - (n % (t / 10))) / (t / 10);
k++;
}
}
}
bool c = (a[0] == 1);
for (int i = 0; i < k; i++)
if (a[i] != 1 && a[i] != 4) c = false;
for (int i = 0; i < k - 2; i++)
if (a[i] == 4 && a[i + 1] == 4 && a[i + 2] == 4) c = false;
if (c)
printf("YES");
else
printf("NO");
}
}
```
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.