Problem:
プログラム停止判定
皆さんは、苦労して作ったプログラムを実行してみたら、無限ループになってしまった経験はありませんか？ プログラムの実行が停止するかどうかを、実行しなくても事前に判定できると便利ですよね。
残念ながら、皆さんがふだん使っているプログラミング言語では、あらゆるプログラムに対してそのような判定をすることは不可能です。しかし、それよりもはるかに計算能力の低いプログラミング言語なら、その言語で書いたプログラムが停止するかどうかを判定するプログラムを書ける場合があります。
TinyPowerというプログラミング言語を考えます。この言語のプログラムは行の並びです。プログラムの各行には、先頭に行番号を書き、その後ろに文を一つ書きます。この言語で書ける文の種類は以下の通りです。
文の種類
動作
ADD var
1
var
2
var
3
変数 var
2
の値と var
3
の値を加算した結果を変数 var
1
に代入する
ADD var
1
var
2
con
変数 var
2
の値と定数 con を加算した結果を変数 var
1
に代入する
SUB var
1
var
2
var
3
変数 var
2
の値から var
3
の値を減算した結果を変数 var
1
に代入する
SUB var
1
var
2
con
変数 var
2
の値から定数 con を減算した結果を変数 var
1
に代入する
SET var
1
var
2
変数 var
2
の値を変数 var
1
に代入する
SET var
1
con
定数 con を変数 var
1
に代入する
IF var
1
dest
変数 var
1
の値が０でないときだけ、行番号 dest にジャンプする
HALT
プログラムを停止させる
行番号は正の整数で、プログラム中に同じ行番号が２つ以上現れることはありません。変数は英小文字一文字で表し、定数と変数の値は整数です。変数の宣言は不要で、変数の初期値は０です。
プログラムの実行は先頭の文から始まり、並んでいる順に文が実行されます。ただし、上の表に書かれたように、IF文の変数の値が０でないときは、変数の後ろに書かれた行番号で指定される行にジャンプし、その行に書かれた文から実行を続けます。プログラムは以下のときに停止します。
HALT文を実行したとき。
負の整数または１６以上の整数を変数に代入しようとしたとき（変数の値は更新されない）。
プログラムに現れない行番号にジャンプしようとしたとき。
プログラムの最後の文を実行した後、そこからどの行にもジャンプしないとき。
TinyPowerのプログラムが与えられたとき、それが停まるかどうかを判定するプログラムを作成せよ。
Input
入力は以下の形式で与えられる。
N
stmt
1
stmt
2
:
stmt
N
１行目にプログラムの行数
N
(1 ≤
N
≤ 50) が与えられる。続く
N
行に、TinyPowerプログラムの文
stmt
i
が与えられる。
stmt
i
は、以下のいずれかの形式で与えられる。
line
ADD
var
1
var
2
var
3
または
line
ADD
var
1
var
2
con
または
line
SUB
var
1
var
2
var
3
または
line
SUB
var
1
var
2
con
または
line
SET
var
1
var
2
または
line
SET
var
1
con
または
line
IF
var
1
dest
または
line
HALT
line
,
dest
(1 ≤
line
,
dest
≤ 1000) は行番号、
var
j
(英小文字１文字)は変数、
con
(0 ≤
con
≤ 15) は定数を表す。
stmt
i
中の区切りは空白１文字とする。なお、プログラム中に変数は必ず１つ以上現れ、異なる変数名は５つまでしか現れないものとする。
Output
プログラムが停止するときは、プログラムに現れる変数の結果を、変数名の辞書順に改行区切りで出力し、停止しないときは「inf」を出力する。変数の結果は、変数名と変数の値を「=」で区切って出力する。
Sample Input 1
6
10 SET c 1
20 SET i 5
100 ADD s s i
110 SUB i i c
120 IF i 100
200 HALT
Sample Output 1
c=1
i=0
s=15
入力例１は、１から５までの整数の和を計算し、その結果を変数sに格納したあと、HALT文の実行で停止する。
Sample Input 2
3
10 SET c 1
120 IF c 10
20 HALT
Sample Output 2
inf
入力例２は、行番号10でcに1を代入し、次の行番号120のIF文で行番号10に戻ることを繰り返すので、停止しない。
Sample Input 3
3
111 SET c 1
12 SUB c c 2
777 SET a 4
Sample Output 3
a=0
c=1
入力例３は、行番号111でcに1を代入し、次の行番号12でcに-1を代入しようとするので、停止する。このときcの値は-1に更新されない。行番号777は実行されないので、aの値は初期値0のままである。

Submitted solutions:

code_snippet: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	int N;
	string tmpNNN;
	getline(cin ,tmpNNN);
	sscanf(tmpNNN.c_str(), "%d", &N);
	vector<string>code;
	map<int, int>rev;
	map<char, int>var;
	for (int i = 0; i < N; ++i)
	{
		string s;
		getline(cin, s);
		int lin;
		sscanf(s.c_str(),"%d",&lin);
		rev[lin] = i;
		while (s.front() < 'A' || 'Z' < s.front())
		{
			s.erase(s.begin(), s.begin() + 1);
		}
		code.push_back(s);
	}
	char v1[10], v2[10], v3[10];
	for (int i = 0; i < N; ++i)
	{
		const string& s = code[i];
		if (s[0] == 'A')
		{
			//ADD
			sscanf(s.c_str(), "ADD %s %s %s", v1, v2, v3);
			var[v1[0]] = 0;
			var[v2[0]] = 0;
			if ('a' <= v3[0] && v3[0] <= 'z')
				var[v3[0]] = 0;
		}
		else if (s[0] == 'S' && s[1] == 'U')
		{
			//SUB
			sscanf(s.c_str(), "SUB %s %s %s", v1, v2, v3);
			var[v1[0]] = 0;
			var[v2[0]] = 0;
			if ('a' <= v3[0] && v3[0] <= 'z')
				var[v3[0]] = 0;
		}
		else if (s[0] == 'I')
		{
			//IF
			sscanf(s.c_str(), "IF %s %s", v1, v2);
			var[v1[0]] = 0;
		}
		else if (s[0] == 'H')
		{
			//HALT
		}
		else
		{
			//SET
			sscanf(s.c_str(), "SET %s %s", v1, v2);
			var[v1[0]] = 0;
			if ('a' <= v2[0] && v2[0] <= 'z')
				var[v2[0]] = 0;
		}
	}
	bool mugen = true;
	int i = 0;
	for (int looptime = 0; looptime < 33333333; ++looptime)
	{
		if (i >= code.size())
		{
			//end of program
			mugen = false; break;
		}
		const string& s = code[i];
		if (s[0] == 'A')
		{
			//ADD
			sscanf(s.c_str(), "ADD %s %s %s", v1, v2, v3);
			int cons;
			if ('a' <= v3[0] && v3[0] <= 'z')
			{
				cons = var[v3[0]];
			}
			else
			{
				cons = stoi(v3);
			}
			int tmp = var[v2[0]] + cons;
			if (tmp < 0 || tmp >= 16)
			{
				//overflow
				mugen = false; break;
			}
			var[v1[0]] = tmp;
		}
		else if (s[0] == 'S' && s[1] == 'U')
		{
			//SUB
			sscanf(s.c_str(), "SUB %s %s %s", v1, v2, v3);
			int cons;
			if ('a' <= v3[0] && v3[0] <= 'z')
			{
				cons = var[v3[0]];
			}
			else
			{
				cons = stoi(v3);
			}
			int tmp = var[v2[0]] - cons;
			if (tmp < 0 || tmp >= 16)
			{
				//overflow
				mugen = false; break;
			}
			var[v1[0]] = tmp;
		}
		else if (s[0] == 'I')
		{
			//IF
			sscanf(s.c_str(), "IF %s %s", v1, v2);
			int lin = stoi(v2);
			if (var[v1[0]])
			{
				//jump
				if (!rev.count(lin))
				{
					//cannot jump to unknown line
					mugen = false; break;
				}
				else
				{
					i = rev[lin];
					continue;
				}
			}
		}
		else if (s[0] == 'H')
		{
			//HALT
			//progam halted
			mugen = false; break;
		}
		else
		{
			//SET
			sscanf(s.c_str(), "SET %s %s", v1, v2);
			int cons;
			if ('a' <= v2[0] && v2[0] <= 'z')
			{
				cons = var[v2[0]];
			}
			else
			{
				cons = stoi(v2);
			}
			var[v1[0]] = cons;
		}
		++i;
	}
	if (mugen)
	{
		cout << "inf\n";
		return 0;
	}
	for (auto p : var)
	{
		cout << p.first << '=' << p.second << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 2760
memory_kb: 3512
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    int l[n];
    string s[n];
    int v[n][3] = {};
    char c[n][3] = {};
    string t;
    vector<int> pos(1000, -1);
    int var[26] = {};
    bool var_exist[26] = {};
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        cin >> s[i];
        if (s[i] == "ADD" || s[i] == "SUB") {
            cin >> c[i][0] >> c[i][1] >> t;
            var_exist[c[i][0] - 'a'] = true;
            var_exist[c[i][1] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][2] = stoi(t);
            } else {
                c[i][2] = t[0];
                var_exist[c[i][2] - 'a'] = true;
            }
        } else if (s[i] == "SET") {
            cin >> c[i][0] >> t;
            var_exist[c[i][0] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][1] = stoi(t);
            } else {
                c[i][1] = t[0];
                var_exist[c[i][1] - 'a'] = true;
            }
        } else if (s[i] == "IF") {
            cin >> c[i][0] >> v[i][1];
            var_exist[c[i][0] - 'a'] = true;
        }
        pos[l[i]] = i;
    }
    int now = 0;
    int cnt = 0;
    while (1) {
        cnt++;
        if (cnt > 52428800) {
            cout << "inf\n";
            return(0);
        }
        if (s[now] == "ADD") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] + var[c[now][2] - 'a'] && var[c[now][1] - 'a'] + var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] + v[now][2] && var[c[now][1] - 'a'] + v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SUB") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] - var[c[now][2] - 'a'] && var[c[now][1] - 'a'] - var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] - v[now][2] && var[c[now][1] - 'a'] - v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SET") {
            if (c[now][1] != 0) {
                var[c[now][0] - 'a'] = var[c[now][1] - 'a'];
            } else {
                var[c[now][0] - 'a'] = v[now][1];
            }
        } else if (s[now] == "HALT") {
            break;
        }
        if (s[now] == "IF") {
            if (var[c[now][0] - 'a'] != 0) {
                if (pos[v[now][1]] != -1) {
                    now = pos[v[now][1]];
                } else {
                    break;
                }
            } else {
                if (now + 1 < n) {
                    now++;
                } else {
                    break;
                }
            }
        } else {
            if (now + 1 < n) {
                now++;
            } else {
                break;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        if (var_exist[i]) {
            cout << (char)('a' + i) << "=" << var[i] << "\n";
        }
    }
    return(0);
}
accuracy: 1
time_ms: 1210
memory_kb: 3444
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    clock_t start = clock();
    int n;
    cin >> n;
    int l[n];
    string s[n];
    int v[n][3] = {};
    char c[n][3] = {};
    string t;
    vector<int> pos(1000, -1);
    int var[26] = {};
    bool var_exist[26] = {};
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        cin >> s[i];
        if (s[i] == "ADD" || s[i] == "SUB") {
            cin >> c[i][0] >> c[i][1] >> t;
            var_exist[c[i][0] - 'a'] = true;
            var_exist[c[i][1] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][2] = stoi(t);
            } else {
                c[i][2] = t[0];
                var_exist[c[i][2] - 'a'] = true;
            }
        } else if (s[i] == "SET") {
            cin >> c[i][0] >> t;
            var_exist[c[i][0] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][1] = stoi(t);
            } else {
                c[i][1] = t[0];
                var_exist[c[i][1] - 'a'] = true;
            }
        } else if (s[i] == "IF") {
            cin >> c[i][0] >> v[i][1];
            var_exist[c[i][0] - 'a'] = true;
        }
        pos[l[i]] = i;
    }
    int now = 0;
    while (1) {
        clock_t end = clock();
        const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (time >= 4990) {
            cout << "inf\n";
            return(0);
        }
        if (s[now] == "ADD") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] + var[c[now][2] - 'a'] && var[c[now][1] - 'a'] + var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] + v[now][2] && var[c[now][1] - 'a'] + v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SUB") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] - var[c[now][2] - 'a'] && var[c[now][1] - 'a'] - var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] - v[now][2] && var[c[now][1] - 'a'] - v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SET") {
            if (c[now][1] != 0) {
                var[c[now][0] - 'a'] = var[c[now][1] - 'a'];
            } else {
                var[c[now][0] - 'a'] = v[now][1];
            }
        } else if (s[now] == "HALT") {
            break;
        }
        if (s[now] == "IF") {
            if (var[c[now][0] - 'a'] != 0) {
                if (pos[v[now][1]] != -1) {
                    now = pos[v[now][1]];
                } else {
                    break;
                }
            } else {
                if (now + 1 < n) {
                    now++;
                } else {
                    break;
                }
            }
        } else {
            if (now + 1 < n) {
                now++;
            } else {
                break;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        if (var_exist[i]) {
            cout << (char)('a' + i) << "=" << var[i] << "\n";
        }
    }
    return(0);
}
accuracy: 0.8333333333333334
time_ms: 4980
memory_kb: 3444
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    clock_t start = clock();
    int n;
    cin >> n;
    int l[n];
    string s[n];
    int v[n][3] = {};
    char c[n][3] = {};
    string t;
    map<int, int> pos;
    int var[26] = {};
    bool var_exist[26] = {};
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        cin >> s[i];
        if (s[i] == "ADD" || s[i] == "SUB") {
            cin >> c[i][0] >> c[i][1] >> t;
            var_exist[c[i][0] - 'a'] = true;
            var_exist[c[i][1] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][2] = stoi(t);
            } else {
                c[i][2] = t[0];
                var_exist[c[i][2] - 'a'] = true;
            }
        } else if (s[i] == "SET") {
            cin >> c[i][0] >> t;
            var_exist[c[i][0] - 'a'] = true;
            if (!('a' <= t[0] && t[0] <= 'z')) {
                v[i][1] = stoi(t);
            } else {
                c[i][1] = t[0];
                var_exist[c[i][1] - 'a'] = true;
            }
        } else if (s[i] == "IF") {
            cin >> c[i][0] >> v[i][1];
            var_exist[c[i][0] - 'a'] = true;
        }
        pos[l[i]] = i;
    }
    int now = 0;
    while (1) {
        clock_t end = clock();
        const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
        if (time >= 4500) {
            cout << "inf\n";
            return(0);
        }
        if (s[now] == "ADD") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] + var[c[now][2] - 'a'] && var[c[now][1] - 'a'] + var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] + v[now][2] && var[c[now][1] - 'a'] + v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] + v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SUB") {
            if (c[now][2] != 0) {
                if (0 <= var[c[now][1] - 'a'] - var[c[now][2] - 'a'] && var[c[now][1] - 'a'] - var[c[now][2] - 'a'] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - var[c[now][2] - 'a'];
                } else {
                    break;
                }
            } else {
                if (0 <= var[c[now][1] - 'a'] - v[now][2] && var[c[now][1] - 'a'] - v[now][2] < 16) {
                    var[c[now][0] - 'a'] = var[c[now][1] - 'a'] - v[now][2];
                } else {
                    break;
                }
            }
        } else if (s[now] == "SET") {
            if (c[now][1] != 0) {
                var[c[now][0] - 'a'] = var[c[now][1] - 'a'];
            } else {
                var[c[now][0] - 'a'] = v[now][1];
            }
        } else if (s[now] == "HALT") {
            break;
        }
        if (s[now] == "IF") {
            if (var[c[now][0] - 'a'] != 0) {
                if (pos.count(v[now][1])) {
                    now = pos[v[now][1]];
                } else {
                    break;
                }
            } else {
                if (now + 1 < n) {
                    now++;
                } else {
                    break;
                }
            }
        } else {
            if (now + 1 < n) {
                now++;
            } else {
                break;
            }
        }
    }
    for (int i = 0; i < 26; i++) {
        if (var_exist[i]) {
            cout << (char)('a' + i) << "=" << var[i] << "\n";
        }
    }
    return(0);
}
accuracy: 0.8333333333333334
time_ms: 4490
memory_kb: 3448
final_rank: 13

code_snippet: #include"bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<vpllint> vvpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)
#define mod9 998244353
#define Inf 2147483647
#define llInf 9223372036854775807
#define all(x) x.begin(),x.end()
#define isin(i,n) (0<=i&&i<n)

bool history[(int)1e9];
int varcnt = 0;
map<int, int>line;
map<string, int>str;
map<int, int>ch;

int main() {
	str["SET"] = 0;
	str["ADD"] = 1;
	str["SUB"] = 2;
	str["IF"] = 3;
	str["HALT"] = 4;
	int n;
	cin >> n;
	vvint order(n, vint(4));
	rep(i, n) {
		{
			int l;
			cin >> l;
			line[l] = i + 1;
		} {
			string s;
			cin >> s;
			order[i][0] = str[s];
			if (order[i][0] == 4)continue;
		} {
			char c;
			cin >> c;
			if (ch[c] == 0) ch[c] = ++varcnt;
			order[i][1] = ch[c] - 1;
		} {
			if (order[i][0] == 3) {
				cin >> order[i][2];
				continue;
			}
			else {
				string s;
				cin >> s;
				if ('a' <= s[0] && s[0] <= 'z') {
					if (ch[s[0]] == 0)ch[s[0]] = ++varcnt;
					order[i][2] = -ch[s[0]];
				}
				else {
					int cnt = 0;
					rep(i, s.size())(cnt += s[i] - '0') *= 10;
					order[i][2] = cnt / 10;
				}
				if (order[i][0] == 0)continue;
			}
		} {
			string s;
			cin >> s;
			if ('a' <= s[0] && s[0] <= 'z') {
				if (ch[s[0]] == 0)ch[s[0]] = ++varcnt;
				order[i][3] = -ch[s[0]];
			}
			else {
				int cnt = 0;
				rep(i, s.size())(cnt += s[i] - '0') *= 10;
				order[i][3] = cnt / 10;
			}
		}
	}
	rep(i, n) if (order[i][0] == 3)order[i][2] = line[order[i][2]] - 1;

	int value = 0;
	rep(i, varcnt) {
		value *= 17; value += 16;
	}
	int nowline = 0;
	bool isWorking = true;
	while (isWorking && 0 <= nowline && nowline < n) {
		if (history[nowline + value * n]) {
			cout << "inf" << endl;
			return 0;
		}
		history[nowline + value * n] = true;
		int var[5] = {};
		rep(i, 5) {
			var[i] = value % 17;
			value /= 17;
		}
		switch (order[nowline][0]) {
		case 0: {
			int x = 0;
			if (order[nowline][2] < 0) {
				x = (var[-order[nowline][2] - 1] %= 16);
			}
			else x = order[nowline][2];
			var[order[nowline][1]] = x;
			break;
		}
		case 1: {
			order[nowline][1] %= 16;
			int x = 0, y = 0;
			if (order[nowline][2] < 0) {
				x = (var[-order[nowline][2] - 1] %= 16);
			}
			else x = order[nowline][2];
			if (order[nowline][3] < 0) {
				y = (var[-order[nowline][3] - 1] %= 16);
			}
			else y = order[nowline][3];
			int tmp = x + y;
			if (tmp > 15 || tmp < 0) {
				isWorking = false;
				break;
			}
			else {
				var[order[nowline][1]] = tmp;
				break;
			}
		}
		case 2: {
			order[nowline][1] %= 16;
			int x = 0, y = 0;
			if (order[nowline][2] < 0) {
				x = (var[-order[nowline][2] - 1] %= 16);
			}
			else x = order[nowline][2];
			if (order[nowline][3] < 0) {
				y = (var[-order[nowline][3] - 1] %= 16);
			}
			else y = order[nowline][3];
			int tmp = x - y;
			if (tmp > 15 || tmp < 0) {
				isWorking = false;
				break;
			}
			else {
				var[order[nowline][1]] = tmp;
				break;
			}
		}
		case 3: {
			if (var[order[nowline][1]]) {
				nowline = order[nowline][2];
				nowline--;
			}
			break;
		}
		case 4: {
			isWorking = false;
			break;
		}
		}
		value = 0;
		drep(i, varcnt) {
			value *= 17;
			value += var[i];
		}
		nowline++;
	}

	int var[5] = {};
	rep(i, varcnt) {
		var[i] = value % 17;
		value /= 17;
	}
	vector<pair<char, int>>ans;
	for (auto [c, i] : ch) {
		ans.push_back({ c,var[i - 1] });
	}
	sort(all(ans));
	rep(i, varcnt) {
		cout << ans[i].first << "=" << ans[i].second % 16 << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 70536
final_rank: 8

code_snippet: /* -*- coding: utf-8 -*-
 *
 * 0330.cc: プログラム停止判定
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<set>
#include<algorithm>
#include<utility>
 
using namespace std;

/* constant */

const int MAX_N = 50;
const int MAX_M = 5;
const int MAX_LN = 1000;
const int CONB = 1 << 4;

enum { ADD, SUB, SET, IF, HALT };

/* typedef */

typedef set<int> si;
typedef pair<int,int> pii;

struct Prog {
  int op, v0, v1, v2;
  Prog() {}
  Prog(int _op, int _v0, int _v1, int _v2):
    op(_op), v0(_v0), v1(_v1), v2(_v2) {}
};

/* global variables */

int ltbl[MAX_LN + 1], vtbl[26];
char vnms[MAX_M];
Prog pgs[MAX_N];
si stset[MAX_N];
pii vcs[MAX_M];

/* subroutines */

int s2op(char s[]) {
  if (! strcmp(s, "ADD")) return ADD;
  if (! strcmp(s, "SUB")) return SUB;
  if (! strcmp(s, "SET")) return SET;
  if (! strcmp(s, "IF")) return IF;
  if (! strcmp(s, "HALT")) return HALT;
  return -1;
}

int alloc_var(char c, int &m) {
  int ci = c - 'a';
  if (vtbl[ci] < 0) {
    vnms[m] = c;
    vtbl[ci] = m++;
  }
  return vtbl[ci];
}

int alloc_var_con(char s[], int &m) {
  if (s[0] >= 'a' && s[0] <= 'z') return alloc_var(s[0], m);
  return atoi(s) | CONB;
}

inline int getvar(int st, int i) { return (st >> (i * 4)) & 0xf; }

inline int setvar(int st, int i, int v) {
  st &= ~(0xf << (i * 4));
  st |= (v << (i * 4));
  return st;
}

/* main */

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);

  fill(ltbl, ltbl + MAX_LN + 1, -1);
  fill(vtbl, vtbl + 26, -1);

  int n;
  scanf("%d", &n);

  int m = 0;
  for (int i = 0; i < n; i++) {
    int ln;
    scanf("%d", &ln);
    ltbl[ln] = i;

    char s0[8], s1[8], s2[8], s3[8];
    scanf("%s", s0);
    int op = s2op(s0);

    if (op == ADD || op == SUB) {
      scanf("%s%s%s", s1, s2, s3);
      int v0 = alloc_var(s1[0], m);
      int v1 = alloc_var(s2[0], m);
      int v2 = alloc_var_con(s3, m);
      pgs[i] = Prog(op, v0, v1, v2);
    }
    else if (op == SET) {
      scanf("%s%s", s1, s2);
      int v0 = alloc_var(s1[0], m);
      int v1 = alloc_var_con(s2, m);
      pgs[i] = Prog(op, v0, v1, -1);
    }
    else if (! strcmp(s0, "IF")) {
      int dst;
      scanf("%s%d", s1, &dst);
      int v0 = alloc_var(s1[0], m);
      pgs[i] = Prog(op, v0, dst, -1);
    }
    else
      pgs[i] = Prog(op, -1, -1, -1);
  }
  //printf("m=%d\n", m);

  int st = 0;
  for (int pc = 0; pc < n;) {
    Prog &pg = pgs[pc];

    if (pg.op == ADD) {
      int v1 = getvar(st, pg.v1);
      int v2 = (pg.v2 < CONB) ? getvar(st, pg.v2) : (pg.v2 ^ CONB);
      int v0 = v1 + v2;
      if (v0 < 0 || v0 >= CONB) break;
      st = setvar(st, pg.v0, v0);
      pc++;
    }
    else if (pg.op == SUB) {
      int v1 = getvar(st, pg.v1);
      int v2 = (pg.v2 < CONB) ? getvar(st, pg.v2) : (pg.v2 ^ CONB);
      int v0 = v1 - v2;
      if (v0 < 0 || v0 >= CONB) break;
      st = setvar(st, pg.v0, v0);
      pc++;
    }
    else if (pg.op == SET) {
      int v1 = (pg.v1 < CONB) ? getvar(st, pg.v1) : (pg.v1 ^ CONB);
      st = setvar(st, pg.v0, v1);
      pc++;
    }
    else if (pg.op == IF) {
      si::iterator sit = stset[pc].find(st);
      if (sit != stset[pc].end()) { puts("inf"); return 0; }
      stset[pc].insert(st);

      if (getvar(st, pg.v0) != 0) {
	pc = ltbl[pg.v1];
	if (pc < 0) break;
      }
      else
	pc++;
    }
    else
      break;
  }

  for (int i = 0; i < m; i++)
    vcs[i] = pii(vnms[i], getvar(st, i));
  sort(vcs, vcs + m);

  for (int i = 0; i < m; i++)
    printf("%c=%d\n", vcs[i].first, vcs[i].second);
  return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 41096
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> line(N);
  vector<string> T(N);
  vector<char> var1(N), var2(N), var3(N);
  vector<int> con(N);
  vector<int> t(N);
  vector<int> dest(N);
  for (int i = 0; i < N; i++){
    cin >> line[i] >> T[i];
    if (T[i] == "ADD" || T[i] == "SUB"){
      cin >> var1[i] >> var2[i];
      string S;
      cin >> S;
      if (isalpha(S[0]) != 0){
        var3[i] = S[0];
        t[i] = 0;
      } else {
        con[i] = stoi(S);
        t[i] = 1;
      }
    }
    if (T[i] == "SET"){
      cin >> var1[i];
      string S;
      cin >> S;
      if (isalpha(S[0]) != 0){
        var2[i] = S[0];
        t[i] = 0;
      } else {
        con[i] = stoi(S);
        t[i] = 1;
      }
    }
    if (T[i] == "IF"){
      cin >> var1[i] >> dest[i];
    }
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[line[i]] = i;
  }
  for (int i = 0; i < N; i++){
    line[i] = i;
  }
  for (int i = 0; i < N; i++){
    if (T[i] == "IF"){
      if (mp.count(dest[i]) == 0){
        dest[i] = N;
      } else {
        dest[i] = mp[dest[i]];
      }
    }
  }
  vector<char> var;
  for (int i = 0; i < N; i++){
    if (T[i] == "ADD" || T[i] == "SUB"){
      var.push_back(var1[i]);
      var.push_back(var2[i]);
      if (t[i] == 0){
        var.push_back(var3[i]);
      }
    }
    if (T[i] == "SET"){
      var.push_back(var1[i]);
      if (t[i] == 0){
        var.push_back(var2[i]);
      }
    }
    if (T[i] == "IF"){
      var.push_back(var1[i]);
    }
  }
  sort(var.begin(), var.end());
  var.erase(unique(var.begin(), var.end()), var.end());
  vector<int> id1(N), id2(N), id3(N);
  for (int i = 0; i < N; i++){
    if (T[i] == "ADD" || T[i] == "SUB"){
      id1[i] = lower_bound(var.begin(), var.end(), var1[i]) - var.begin();
      id2[i] = lower_bound(var.begin(), var.end(), var2[i]) - var.begin();
      if (t[i] == 0){
        id3[i] = lower_bound(var.begin(), var.end(), var3[i]) - var.begin();
      }
    }
    if (T[i] == "SET"){
      id1[i] = lower_bound(var.begin(), var.end(), var1[i]) - var.begin();
      if (t[i] == 0){
        id2[i] = lower_bound(var.begin(), var.end(), var2[i]) - var.begin();
      }
    }
    if (T[i] == "IF"){
      id1[i] = lower_bound(var.begin(), var.end(), var1[i]) - var.begin();
    }
  }
  int M = var.size();
  int mx = N;
  for (int i = 0; i < M; i++){
    mx *= 16;
  }
  int p = 0;
  vector<int> x(M, 0);
  int cnt = 0;
  while (true){
    if (p == N){
      break;
    }
    if (cnt > mx){
      break;
    }
    if (T[p] == "ADD"){
      int nxt;
      if (t[p] == 0){
        nxt = x[id2[p]] + x[id3[p]];
      } else {
        nxt = x[id2[p]] + con[p];
      }
      if (nxt >= 16){
        break;
      }
      x[id1[p]] = nxt;
      p++;
    } else if (T[p] == "SUB"){
      int nxt;
      if (t[p] == 0){
        nxt = x[id2[p]] - x[id3[p]];
      } else {
        nxt = x[id2[p]] - con[p];
      }
      if (nxt < 0){
        break;
      }
      x[id1[p]] = nxt;
      p++;
    } else if (T[p] == "SET"){
      if (t[p] == 0){
        x[id1[p]] = x[id2[p]];
      } else {
        x[id1[p]] = con[p];
      }
      p++;
    } else if (T[p] == "IF"){
      if (x[id1[p]] == 0){
        p++;
      } else {
        p = dest[p];
      }
    } else {
      break;
    }
    cnt++;
  }
  if (cnt > mx){
    cout << "inf" << endl;
  } else {
    for (int i = 0; i < M; i++){
      cout << var[i] << '=' << x[i] << endl;
    }
  }
}
accuracy: 1
time_ms: 950
memory_kb: 3460
final_rank: 1

code_snippet: #include<iostream>
#include<set>
#include<map>
using namespace std;
struct state{
	int a[5];
	int to_i()const{
		return a[0]<<16|a[1]<<12|a[2]<<8|a[3]<<4|a[4];
	}
};
int N;
int line[1001];
string op[50];
bool S[50][1<<20];
map<string,int>mp;
int var[50][3];
int rd()
{
	string s;
	cin>>s;
	if(isdigit(s[0]))
	{
		if(s.size()==1)return s[0]-'0';
		else return(s[0]-'0')*10+s[1]-'0';
	}
	if(mp.find(s)==mp.end())
	{
		int t=mp.size();
		mp[s]=~t;
	}
	return mp[s];
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int num;cin>>num;
		line[num]=i+1;
		cin>>op[i];
		if(op[i]=="ADD"||op[i]=="SUB")
		{
			var[i][0]=rd();
			var[i][1]=rd();
			var[i][2]=rd();
		}
		else if(op[i]=="SET")
		{
			var[i][0]=rd();
			var[i][1]=rd();
		}
		else if(op[i]=="IF")
		{
			var[i][0]=rd();
			cin>>var[i][1];
		}
	}
	state now;
	for(int i=0;i<5;i++)now.a[i]=0;
	int num=0;
	while(num>=0&&num<N)
	{
		int T=now.to_i();
		if(S[num][T])
		{
			cout<<"inf"<<endl;
			return 0;
		}
		S[num][T]=true;
		int ai=var[num][0];
		int bi=var[num][1];
		int ci=var[num][2];
		if(op[num]=="ADD")
		{
			int T=now.a[~bi]+(ci>=0?ci:now.a[~ci]);
			if(T<0||T>=16)break;
			now.a[~ai]=T;
		}
		else if(op[num]=="SUB")
		{
			int T=now.a[~bi]-(ci>=0?ci:now.a[~ci]);
			if(T<0||T>=16)break;
			now.a[~ai]=T;
		}
		else if(op[num]=="SET")
		{
			now.a[~ai]=bi>=0?bi:now.a[~bi];
		}
		else if(op[num]=="HALT")break;
		if(op[num]=="IF"&&now.a[~ai]>0)
		{
			num=line[bi]-1;
		}
		else num++;
	}
	for(pair<string,int>p:mp)
	{
		cout<<p.first<<"="<<now.a[~p.second]<<endl;
	}
}
accuracy: 1
time_ms: 820
memory_kb: 47328
final_rank: 6

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<string> split(string &s){
    vector<string> res;
    string tmp;
    for (auto &&i : s) {
        if(i == ' '){
            if(!tmp.empty()) {
                res.emplace_back(tmp);
                tmp.clear();
            }
        }else tmp += i;
    }
    if(!tmp.empty()) res.emplace_back(tmp);
    return res;
}
bitset<1 << 20> dp[50];
int main() {
    int n;
    cin >> n;
    vector<vector<string>> v(n);
    map<string, int> m;
    array<char, 256> vars;
    fill(vars.begin(),vars.end(), -1);
    int cnt = 0;
    cin.ignore();
    for (int i = 0; i < n; ++i) {
        string s;
        getline(cin, s);
        v[i] = split(s);
        m[v[i][0]] = i;
        v[i].erase(v[i].begin());
        for (int j = 1; j < v[i].size(); ++j) {
            if(islower(v[i][j][0]) && !~vars[v[i][j][0]]){
                vars[v[i][j][0]] = cnt++;
            }
        }
    }
    int cur = 0, val = 0;
    while(true){
        if(cur == n) break;
        if(dp[cur][val]) {
            puts("inf");
            return 0;
        }
        /*for (auto &&i : v[cur]) {
            cout << i << " ";
        }
        puts("");*/
        dp[cur].set(val);
        if(v[cur][0] == "HALT"){
            break;
        }else if(v[cur][0] == "ADD"){
            int val1 = (val >> (vars[v[cur][2][0]]*4))&15, val2 = (~vars[v[cur][3][0]] ? (val >> (vars[v[cur][3][0]]*4))&15 : stoi(v[cur][3]));
            if(val1 + val2 > 15) break;
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + ((val1+val2) << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "SUB"){
            int val1 = (val >> (vars[v[cur][2][0]]*4))&15, val2 = (~vars[v[cur][3][0]] ? (val >> (vars[v[cur][3][0]]*4))&15 : stoi(v[cur][3]));
            if(val1 - val2 < 0) break;
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + ((val1-val2) << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "SET"){
            int vall = (~vars[v[cur][2][0]] ? (val >> (vars[v[cur][2][0]]*4))&15 : stoi(v[cur][2]));
            val = (val & (-1 - (15 << vars[v[cur][1][0]]*4))) + (vall << vars[v[cur][1][0]]*4);
        }else if(v[cur][0] == "IF"){
            int val1 = (val >> (vars[v[cur][1][0]]*4))&15;
            if(val1) {
                if(!m.count(v[cur][2])) break;
                cur = m[v[cur][2]];
                continue;
            }
        }
        cur++;
    }
    for (int i = 0; i < 256; ++i) {
        if(~vars[i]){
            printf("%c=%d\n", i, (val >> (vars[i]*4))&15);
        }
    }
    return 0;
}
accuracy: 1
time_ms: 1080
memory_kb: 7868
final_rank: 3

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <bitset>

#define MAX_VALUE (1000 * 16 * 16 * 16 * 16 * 16)


enum cmd_t {
	CMD_ADD,
	CMD_SUB,
	CMD_SET,
	CMD_IF,
	CMD_HALT
};


struct command {
	cmd_t type;
	int var1;
	int var2;
	int var3;
	int opt;
};


struct vm_stat {
	int pc;
	int env[5];

	vm_stat(void) {
		pc = 0;
		env[0] = 0;
		env[1] = 0;
		env[2] = 0;
		env[3] = 0;
		env[4] = 0;
	}

	size_t encode(void) {
		int code = pc;
		code = code * 16 + env[0];
		code = code * 16 + env[1];
		code = code * 16 + env[2];
		code = code * 16 + env[3];
		code = code * 16 + env[4];
		return code;
	}
};


static std::bitset<MAX_VALUE> stats;
static command plist[50];
static int n;
static int lines[1001];

int main(int argc, char* argv[]) {
	int atom['z' - 'a' + 1];
	int atom_n = 0;
	for (int i = 'a'; i <= 'z'; ++i) {
		atom[i - 'a'] = -1;
	}	
	for (int i = 0; i <= 1000; ++i) {
		lines[i] = -1;
	}

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		char s[16];
		int d;

		scanf("%d", &d);
		lines[d] = i;
		scanf(" %s", s);
		if (strcmp(s, "ADD") == 0) {
			plist[i].type = CMD_ADD;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SUB") == 0) {
			plist[i].type = CMD_SUB;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SET") == 0) {
			plist[i].type = CMD_SET;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var2 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var2 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "IF") == 0) {
			plist[i].type = CMD_IF;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %d", &d);
			plist[i].opt = d;
		}
		else {
			plist[i].type = CMD_HALT;
		}
	}

	vm_stat stat;
	bool halted = true;
	stats.set(stat.encode());
	for (;;) {
		const command c = plist[stat.pc++];

		if (c.type == CMD_ADD) {
			const int rvalue = stat.env[c.var2] + (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SUB) {
			const int rvalue = stat.env[c.var2] - (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SET) {
			if (c.var2 < 0) {
				stat.env[c.var1] = c.opt;
			}
			else {
				stat.env[c.var1] = stat.env[c.var2];
			}
		}
		else if (c.type == CMD_IF) {
			if (stat.env[c.var1]) {
				if (lines[c.opt] == -1) {
					break;
				}
				else {
					stat.pc = lines[c.opt];
				}
			}
		}
		else {
			break;
		}

		if (stats.test(stat.encode())) {
			halted = false;
			break;
		}
		if (stat.pc >= n) {
			break;
		}
		stats.set(stat.encode());
	}

	if (halted) {
		for (int i = 'a'; i <= 'z'; ++i) {
			if (atom[i - 'a'] >= 0) {
				printf("%c=%d\n", i, stat.env[atom[i - 'a']]);
			}
		}
	}
	else {
		puts("inf");
	}

	return EXIT_SUCCESS;
}
accuracy: 1
time_ms: 210
memory_kb: 130760
final_rank: 11

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <bitset>

#define MAX_VALUE (1000 * 16 * 16 * 16 * 16 * 16)


enum cmd_t {
	CMD_ADD,
	CMD_SUB,
	CMD_SET,
	CMD_IF,
	CMD_HALT
};


struct command {
	cmd_t type;
	int var1;
	int var2;
	int var3;
	int opt;
};


struct vm_stat {
	int pc;
	int env[5];

	vm_stat(void) {
		pc = 0;
		env[0] = 0;
		env[1] = 0;
		env[2] = 0;
		env[3] = 0;
		env[4] = 0;
	}

	size_t encode(void) {
		int code = pc;
		code = code * 16 + env[0];
		code = code * 16 + env[1];
		code = code * 16 + env[2];
		code = code * 16 + env[3];
		code = code * 16 + env[4];
		return code;
	}
};


static std::bitset<MAX_VALUE> stats;
static command plist[50];
static int n;
static int lines[1001];

int main(int argc, char* argv[]) {
	int atom['z' - 'a' + 1];
	int atom_n = 0;
	for (int i = 'a'; i <= 'z'; ++i) {
		atom[i - 'a'] = -1;
	}	

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		char s[16];
		int d;

		scanf("%d", &d);
		lines[d] = i;
		scanf(" %s", s);
		if (strcmp(s, "ADD") == 0) {
			plist[i].type = CMD_ADD;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SUB") == 0) {
			plist[i].type = CMD_SUB;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SET") == 0) {
			plist[i].type = CMD_SET;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var2 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var2 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "IF") == 0) {
			plist[i].type = CMD_IF;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %d", &d);
			plist[i].opt = d;
		}
		else {
			plist[i].type = CMD_HALT;
		}
	}

	vm_stat stat;
	bool halted = true;
	stats.set(stat.encode());
	for (;;) {
		const command c = plist[stat.pc++];

		if (c.type == CMD_ADD) {
			const int rvalue = stat.env[c.var2] + (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SUB) {
			const int rvalue = stat.env[c.var2] - (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SET) {
			if (c.var2 < 0) {
				stat.env[c.var1] = c.opt;
			}
			else {
				stat.env[c.var1] = stat.env[c.var2];
			}
		}
		else if (c.type == CMD_IF) {
			if (stat.env[c.var1]) {
				stat.pc = lines[c.opt];
			}
		}
		else {
			break;
		}

		if (stats.test(stat.encode())) {
			halted = false;
			break;
		}
		if (stat.pc >= n) {
			break;
		}
		stats.set(stat.encode());
	}

	if (halted) {
		for (int i = 'a'; i <= 'z'; ++i) {
			if (atom[i - 'a'] >= 0) {
				printf("%c=%d\n", i, stat.env[atom[i - 'a']]);
			}
		}
	}
	else {
		puts("inf");
	}

	return EXIT_SUCCESS;
}
accuracy: 0.6666666666666666
time_ms: 30
memory_kb: 130696
final_rank: 17

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <bitset>

#define MAX_VALUE (1000 * 16 * 16 * 16 * 16 * 16)


enum cmd_t {
	CMD_ADD,
	CMD_SUB,
	CMD_SET,
	CMD_IF,
	CMD_HALT
};


struct command {
	cmd_t type;
	int var1;
	int var2;
	int var3;
	int opt;
};


struct vm_stat {
	int pc;
	int env[5];

	vm_stat(void) {
		pc = 0;
		env[0] = 0;
		env[1] = 0;
		env[2] = 0;
		env[3] = 0;
		env[4] = 0;
	}

	size_t encode(void) {
		int code = pc;
		code = code * 16 + env[0];
		code = code * 16 + env[1];
		code = code * 16 + env[2];
		code = code * 16 + env[3];
		code = code * 16 + env[4];
		return code;
	}
};


static std::bitset<MAX_VALUE> stats;
static command plist[50];
static int n;
static int lines[1001];

int main(int argc, char* argv[]) {
	int atom['z' - 'a' + 1];
	int atom_n = 0;
	for (int i = 'a'; i <= 'z'; ++i) {
		atom[i - 'a'] = -1;
	}	

	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		char s[16];
		int d;

		scanf("%d", &d);
		lines[d] = i;
		scanf(" %s", s);
		if (strcmp(s, "ADD") == 0) {
			plist[i].type = CMD_ADD;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SUB") == 0) {
			plist[i].type = CMD_SUB;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var2 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var3 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var3 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "SET") == 0) {
			plist[i].type = CMD_SET;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %s", s);
			if (isdigit(*s)) {
				plist[i].var2 = -1;
				plist[i].opt = atoi(s);
			}
			else {
				if (atom[*s - 'a'] == -1) {
					atom[*s - 'a'] = atom_n++;
				}
				plist[i].var2 = atom[*s - 'a'];
			}
		}
		else if (strcmp(s, "IF") == 0) {
			plist[i].type = CMD_IF;
			scanf(" %s", s);
			if (atom[*s - 'a'] == -1) {
				atom[*s - 'a'] = atom_n++;
			}
			plist[i].var1 = atom[*s - 'a'];
			scanf(" %d", &d);
			plist[i].opt = d;
		}
		else {
			plist[i].type = CMD_HALT;
		}
	}

	vm_stat stat;
	bool halted = true;
	stats.set(stat.encode());
	for (;;) {
		const command c = plist[stat.pc++];

		if (c.type == CMD_ADD) {
			const int rvalue = stat.env[c.var2] + (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SUB) {
			const int rvalue = stat.env[c.var2] - (c.var3 < 0 ? c.opt : stat.env[c.var3]);
			if (rvalue < 0 || 16 <= rvalue) {
				break;
			}
			stat.env[c.var1] = rvalue;
		}
		else if (c.type == CMD_SET) {
			if (c.var2 < 0) {
				stat.env[c.var1] = c.opt;
			}
			else {
				stat.env[c.var1] = stat.env[c.var2];
			}
		}
		else if (c.type == CMD_IF) {
			if (stat.env[c.var1]) {
				stat.pc = lines[c.opt];
			}
		}
		else {
			break;
		}

		if (stats.test(stat.encode())) {
			halted = false;
			break;
		}
		stats.set(stat.encode());
	}

	if (halted) {
		for (int i = 'a'; i <= 'z'; ++i) {
			if (atom[i - 'a'] >= 0) {
				printf("%c=%d\n", i, stat.env[atom[i - 'a']]);
			}
		}
	}
	else {
		puts("inf");
	}

	return EXIT_SUCCESS;
}
accuracy: 0.3333333333333333
time_ms: 30
memory_kb: 130620
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int main() {
    ll N;
    cin >> N;
    using s = string;
    vector<tuple<s, s, s, s>> P(N);
    map<ll, ll> L;
    map<s, ll> V;
    vector
 S;
    rep(i, N) {
        ll A;
        s B, C, D, E;
        cin >> A >> B;
        if (B == "ADD" || B == "SUB") {
            cin >> C >> D >> E;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
            if (!('0' <= E[0] && E[0] <= '9')) {
                S.push_back(E);
            }
        } else if (B == "SET" || B == "IF") {
            cin >> C >> D;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
        }
        P[i] = make_tuple(B, C, D, E);
        L[A] = i + 1;
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll line = 0;
    rep(loop, 40000000) {
        s B, C, D, E;
        tie(B, C, D, E) = P[line];
        if (B == "ADD") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] + stoi(E) > 15) {
                    break;
                }
                V[C] = V[D] + stoi(E);
            } else {
                if (V[D] + V[E] > 15) {
                    break;
                }
                V[C] = V[D] + V[E];
            }
        } else if (B == "SUB") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] - stoi(E) < 0) {
                    break;
                }
                V[C] = V[D] - stoi(E);
            } else {
                if (V[D] - V[E] < 0) {
                    break;
                }
                V[C] = V[D] - V[E];
            }
        } else if (B == "SET") {
            if ('0' <= D[0] && D[0] <= '9') {
                V[C] = stoi(D);
            } else {
                V[C] = V[D];
            }
        } else if (B == "IF") {
            if (V[C]) {
                line = L[stoi(D)] - 1;
                if (line == -1) break;
                if (loop + 1 == 40000000) {
                    return puts("inf") & 0;
                }
                continue;
            }
        } else if (B == "HALT") {
            break;
        }
        if (++line == N) break;
        if (loop + 1 == 40000000) {
            return puts("inf") & 0;
        }
    }
    for (auto i : S) cout << i << '=' << V[i] << endl;
}
accuracy: 1
time_ms: 4180
memory_kb: 3220
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int main() {
    ll N;
    cin >> N;
    using s = string;
    vector<tuple<s, s, s, s>> P(N);
    map<ll, ll> L;
    map<s, ll> V;
    vector
 S;
    rep(i, N) {
        ll A;
        s B, C, D, E;
        cin >> A >> B;
        if (B == "ADD" || B == "SUB") {
            cin >> C >> D >> E;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
            if (!('0' <= E[0] && E[0] <= '9')) {
                S.push_back(E);
            }
        } else if (B == "SET" || B == "IF") {
            cin >> C >> D;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
        }
        P[i] = make_tuple(B, C, D, E);
        L[A] = i + 1;
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll line = 0;
    rep(loop, 1000000) {
        s B, C, D, E;
        tie(B, C, D, E) = P[line];
        if (B == "ADD") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] + stoi(E) > 15) {
                    break;
                }
                V[C] = V[D] + stoi(E);
            } else {
                if (V[D] + V[E] > 15) {
                    break;
                }
                V[C] = V[D] + V[E];
            }
        } else if (B == "SUB") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] - stoi(E) < 0) {
                    break;
                }
                V[C] = V[D] - stoi(E);
            } else {
                if (V[D] - V[E] < 0) {
                    break;
                }
                V[C] = V[D] - V[E];
            }
        } else if (B == "SET") {
            if ('0' <= D[0] && D[0] <= '9') {
                V[C] = stoi(D);
            } else {
                V[C] = V[D];
            }
        } else if (B == "IF") {
            if (V[C]) {
                line = L[stoi(D)] - 1;
                if (line == -1) break;
                if (loop + 1 == 1000000) {
                    return puts("inf") & 0;
                }
                continue;
            }
        } else if (B == "HALT") {
            break;
        }
        if (++line == N) break;
        if (loop + 1 == 1000000) {
            return puts("inf") & 0;
        }
    }
    for (auto i : S) cout << i << '=' << V[i] << endl;
}
accuracy: 0.8333333333333334
time_ms: 90
memory_kb: 3232
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int main() {
    ll N;
    cin >> N;
    using s = string;
    vector<tuple<s, s, s, s>> P(N);
    map<ll, ll> L;
    map<s, ll> V;
    vector
 S;
    rep(i, N) {
        ll A;
        s B, C, D, E;
        cin >> A >> B;
        if (B == "ADD" || B == "SUB") {
            cin >> C >> D >> E;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
            if (!('0' <= E[0] && E[0] <= '9')) {
                S.push_back(E);
            }
        } else if (B == "SET" || B == "IF") {
            cin >> C >> D;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
        }
        P[i] = make_tuple(B, C, D, E);
        L[A] = i + 1;
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll line = 0;
    rep(loop, 1000000) {
        s B, C, D, E;
        tie(B, C, D, E) = P[line];
        if (B == "ADD") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] + stoi(E) > 15) {
                    break;
                }
                V[C] = V[D] + stoi(E);
            } else {
                if (V[D] + V[E] > 15) {
                    break;
                }
                V[C] = V[D] + V[E];
            }
        } else if (B == "SUB") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] - stoi(E) < 0) {
                    break;
                }
                V[C] = V[D] - stoi(E);
            } else {
                if (V[D] - V[E] < 0) {
                    break;
                }
                V[C] = V[D] - V[E];
            }
        } else if (B == "SET") {
            if ('0' <= D[0] && D[0] <= '9') {
                V[C] = stoi(D);
            } else {
                V[C] = V[D];
            }
        } else if (B == "IF") {
            if (V[C]) {
                line = L[stoi(D)] - 1;
                if (loop + 1 == 1000000) {
                    return puts("inf") & 0;
                }
                continue;
            }
        } else if (B == "HALT") {
            break;
        }
        if (++line == N) break;
        if (loop + 1 == 1000000) {
            return puts("inf") & 0;
        }
    }
    for (auto i : S) cout << i << '=' << V[i] << endl;
}
accuracy: 0.6666666666666666
time_ms: 90
memory_kb: 3212
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int main() {
    ll N;
    cin >> N;
    using s = string;
    vector<tuple<s, s, s, s>> P(N);
    map<ll, ll> L;
    map<s, ll> V;
    vector
 S;
    rep(i, N) {
        ll A;
        s B, C, D, E;
        cin >> A >> B;
        if (B == "ADD" || B == "SUB") {
            cin >> C >> D >> E;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
            if (!('0' <= E[0] && E[0] <= '9')) {
                S.push_back(E);
            }
        } else if (B == "SET" || B == "IF") {
            cin >> C >> D;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
        }
        P[i] = make_tuple(B, C, D, E);
        L[A] = i + 1;
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll line = 0;
    rep(loop, 1000000) {
        s B, C, D, E;
        tie(B, C, D, E) = P[line];
        if (B == "ADD") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] + stoi(E) > 0) {
                    break;
                }
                V[C] = V[D] + stoi(E);
            } else {
                if (V[D] + V[E] > 15) {
                    break;
                }
                V[C] = V[D] + V[E];
            }
        } else if (B == "SUB") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] - stoi(E) < 0) {
                    break;
                }
                V[C] = V[D] - stoi(E);
            } else {
                if (V[D] - V[E] < 0) {
                    break;
                }
                V[C] = V[D] - V[E];
            }
        } else if (B == "SET") {
            if ('0' <= D[0] && D[0] <= '9') {
                V[C] = stoi(D);
            } else {
                V[C] = V[D];
            }
        } else if (B == "IF") {
            if (V[C]) {
                line = L[stoi(D)] - 1;
                if (loop + 1 == 1000000) {
                    return puts("inf") & 0;
                }
                continue;
            }
        } else if (B == "HALT") {
            break;
        }
        if (++line == N) break;
        if (loop + 1 == 1000000) {
            return puts("inf") & 0;
        }
    }
    for (auto i : S) cout << i << '=' << V[i] << endl;
}
accuracy: 0.3333333333333333
time_ms: 90
memory_kb: 3236
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int main() {
    ll N;
    cin >> N;
    using s = string;
    vector<tuple<s, s, s, s>> P(N);
    map<ll, ll> L;
    map<s, ll> V;
    vector
 S;
    rep(i, N) {
        ll A;
        s B, C, D, E;
        cin >> A >> B;
        if (B == "ADD" || B == "SUB") {
            cin >> C >> D >> E;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
            if (!('0' <= E[0] && E[0] <= '9')) {
                S.push_back(E);
            }
        } else if (B == "SET" || B == "IF") {
            cin >> C >> D;
            if (!('0' <= C[0] && C[0] <= '9')) {
                S.push_back(C);
            }
            if (!('0' <= D[0] && D[0] <= '9')) {
                S.push_back(D);
            }
        }
        P[i] = make_tuple(B, C, D, E);
        L[A] = i + 1;
    }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    ll line = 0;
    rep(loop, 1000000) {
        s B, C, D, E;
        tie(B, C, D, E) = P[line];
        if (B == "ADD") {
            if ('0' <= E[0] && E[0] <= '9') {
                V[C] = V[D] + stoi(E);
            } else {
                V[C] = V[D] + V[E];
            }
        } else if (B == "SUB") {
            if ('0' <= E[0] && E[0] <= '9') {
                if (V[D] - stoi(E) < 0) {
                    break;
                }
                V[C] = V[D] - stoi(E);
            } else {
                if (V[D] - V[E] < 0) {
                    break;
                }
                V[C] = V[D] - V[E];
            }
        } else if (B == "SET") {
            if ('0' <= D[0] && D[0] <= '9') {
                V[C] = stoi(D);
            } else {
                V[C] = V[D];
            }
        } else if (B == "IF") {
            if (V[C]) {
                line = L[stoi(D)] - 1;
                if (loop + 1 == 1000000) {
                    return puts("inf") & 0;
                }
                continue;
            }
        } else if (B == "HALT") {
            break;
        }
        if (++line == N) break;
        if (loop + 1 == 1000000) {
            return puts("inf") & 0;
        }
    }
    for (auto i : S) cout << i << '=' << V[i] << endl;
}
accuracy: 0.5833333333333334
time_ms: 90
memory_kb: 3164
final_rank: 18

code_snippet: #include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int Q;
	cin >> Q;
	vector<int> ln(Q), c1(Q), c2(Q), c3(Q); vector<string> tp(Q), v1(Q), v2(Q), v3(Q);
	vector<string> varlist;
	function<bool(string)> is_number = [&](string str) {
		for (int i = 0; i < str.size(); ++i) {
			if (!('0' <= str[i] && str[i] <= '9')) {
				return false;
			}
		}
		return true;
	};
	function<int(string)> get_index = [&](string varname) {
		int ptr = find(varlist.begin(), varlist.end(), varname) - varlist.begin();
		return ptr;
	};
	for (int i = 0; i < Q; ++i) {
		cin >> ln[i] >> tp[i];
		if (tp[i] == "ADD" || tp[i] == "SUB") {
			cin >> v1[i] >> v2[i] >> v3[i];
			varlist.push_back(v1[i]);
			if (!is_number(v2[i])) varlist.push_back(v2[i]);
			if (!is_number(v3[i])) varlist.push_back(v3[i]);
		}
		if (tp[i] == "SET") {
			cin >> v1[i] >> v2[i];
			varlist.push_back(v1[i]);
			if (!is_number(v2[i])) varlist.push_back(v2[i]);
		}
		if (tp[i] == "IF") {
			cin >> v1[i] >> v2[i];
			varlist.push_back(v1[i]);
		}
		if (tp[i] == "HALT") {
			// input nothing
		}
	}
	sort(varlist.begin(), varlist.end());
	varlist.erase(unique(varlist.begin(), varlist.end()), varlist.end());
	int S = varlist.size();
	for (int i = 0; i < Q; ++i) {
		if (tp[i] == "ADD" || tp[i] == "SUB") {
			c1[i] = get_index(v1[i]) - S;
			c2[i] = (is_number(v2[i]) ? stoi(v2[i]) : get_index(v2[i]) - S);
			c3[i] = (is_number(v3[i]) ? stoi(v3[i]) : get_index(v3[i]) - S);
		}
		if (tp[i] == "SET") {
			c1[i] = get_index(v1[i]) - S;
			c2[i] = (is_number(v2[i]) ? stoi(v2[i]) : get_index(v2[i]) - S);
		}
		if (tp[i] == "IF") {
			c1[i] = get_index(v1[i]) - S;
			c2[i] = find(ln.begin(), ln.end(), stoi(v2[i])) - ln.begin(); // if not found, c2[i] will be Q
		}
		if (tp[i] == "HALT") {
			// do nothing
		}
	}
	vector<int> vars(S, 0);
	int cur = 0;
	bool halted = true;
	vector<vector<bool> > vis(Q, vector<bool>(1 << (S * 4), false));
	while (cur < Q) {
		int h = 0;
		for (int i = 0; i < S; ++i) {
			h = h * 16 + vars[i];
		}
		if (vis[cur][h]) {
			halted = false;
			break;
		}
		vis[cur][h] = true;
		vector<int> prevars = vars;
		if (tp[cur] == "ADD") {
			vars[c1[cur] + S] = (c2[cur] >= 0 ? c2[cur] : vars[c2[cur] + S]) + (c3[cur] >= 0 ? c3[cur] : vars[c3[cur] + S]);
		}
		if (tp[cur] == "SUB") {
			vars[c1[cur] + S] = (c2[cur] >= 0 ? c2[cur] : vars[c2[cur] + S]) - (c3[cur] >= 0 ? c3[cur] : vars[c3[cur] + S]);
		}
		if (tp[cur] == "SET") {
			vars[c1[cur] + S] = (c2[cur] >= 0 ? c2[cur] : vars[c2[cur] + S]);
		}
		if (tp[cur] == "IF") {
			if (vars[c1[cur] + S] != 0) {
				cur = c2[cur];
				continue;
			}
		}
		if (tp[cur] == "HALT") {
			break;
		}
		if (vars[c1[cur] + S] < 0 || 16 <= vars[c1[cur] + S]) {
			vars = prevars;
			break;
		}
		++cur;
	}
	if (!halted) {
		cout << "inf" << endl;
	}
	else {
		for (int i = 0; i < S; ++i) {
			cout << varlist[i] << "=" << vars[i] << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 1690
memory_kb: 9744
final_rank: 5

code_snippet: #include <iostream>
#include <chrono>
#include <string>
#include <map>
using namespace std;
using ll = long long;

struct Line {
	string op;
	string v1, v2, v3;
	
	Line () {};
	Line (string &op, string &v1, string &v2, string &v3):
	op(op), v1(v1), v2(v2), v3(v3) {};
};

int n;
map<string, int> var;
Line program[1005];
int i2n[1005];

int main() {
	for (int i = 0; i < 1005; i++) {
		i2n[i] = -1;
	}
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l;
		string op;
		string v1, v2, v3;
		
		cin >> l >> op;
		if (op == "ADD" || op == "SUB") {
			cin >> v1 >> v2 >> v3;
			
			if ('a' <= v1[0] && v1[0] <= 'z') {
				var[v1] = 0;
			}
			if ('a' <= v2[0] && v2[0] <= 'z') {
				var[v2] = 0;
			}
			if ('a' <= v3[0] && v3[0] <= 'z') {
				var[v3] = 0;
			}
		}
		
		if (op == "SET" || op == "IF") {
			cin >> v1 >> v2;
			if ('a' <= v1[0] && v1[0] <= 'z') {
				var[v1] = 0;
			}
			if ('a' <= v2[0] && v2[0] <= 'z') {
				var[v2] = 0;
			}
		}
		
		Line v(op, v1, v2, v3);
		program[i] = v;
		i2n[l] = i;
	}
	
	int pc = 0;
	auto start = chrono::system_clock::now();
	auto end = chrono::system_clock::now();
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	while (elapsed <= 4500.0) {
		if (pc < 0 || pc >= n ||
			program[pc].op.empty()) {
			for (auto &x:var) {
				cout << x.first << '=' << x.second << endl;
			}
			return 0;
		}
		
		Line p = program[pc]; pc++;
		bool over_flow = false;
		
		if (p.op == "ADD") {
			if ('a' <= p.v3[0] && p.v3[0] <= 'z') {
				if (var[p.v2] + var[p.v3] >= 16) over_flow = true;
				else var[p.v1] = var[p.v2] + var[p.v3];
			}
			else {
				if (var[p.v2] + stoi(p.v3) >= 16) over_flow = true;
				else var[p.v1] = var[p.v2] + stoi(p.v3);
			}
		}
		
		if (p.op == "SUB") {
			if ('a' <= p.v3[0] && p.v3[0] <= 'z') {
				if (var[p.v2] - var[p.v3] < 0) over_flow = true;
				else var[p.v1] = var[p.v2] - var[p.v3];
			}
			else {
				if (var[p.v2] - stoi(p.v3) < 0) over_flow = true;
				else var[p.v1] = var[p.v2] - stoi(p.v3);
			}
		}
		
		if (p.op == "SET") {
			if ('a' <= p.v2[0] && p.v2[0] <= 'z') {
				var[p.v1] = var[p.v2];
			}
			else {
				int v = stoi(p.v2);
				if (v >= 0 && v < 16) {
					var[p.v1] = v;
				}
				else {
					over_flow = true;
				}
			}
		}
		
		if (p.op == "IF") {
			if (var[p.v1]) {
				pc = i2n[stoi(p.v2)];
			}
		}
		
		if (p.op == "HALT" ||
			over_flow) {
			for (auto &x:var) {
				cout << x.first << '=' << x.second << endl;
			}
			return 0;
		}
		
		end = chrono::system_clock::now();
		elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	}
	
	cout << "inf" << endl;
	
	return 0;
}
accuracy: 1
time_ms: 4490
memory_kb: 3216
final_rank: 10

code_snippet: #include <iostream>
#include <chrono>
#include <string>
#include <map>
using namespace std;
using ll = long long;

struct Line {
	string op;
	string v1, v2, v3;
	
	Line () {};
	Line (string &op, string &v1, string &v2, string &v3):
	op(op), v1(v1), v2(v2), v3(v3) {};
};

int n;
map<string, int> var;
Line program[1005];
int i2n[1005];

int main() {
	for (int i = 0; i < 1005; i++) {
		i2n[i] = -1;
	}
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l;
		string op;
		string v1, v2, v3;
		
		cin >> l >> op;
		if (op == "ADD" || op == "SUB") {
			cin >> v1 >> v2 >> v3;
			
			if ('a' <= v1[0] && v1[0] <= 'z') {
				var[v1] = 0;
			}
			if ('a' <= v2[0] && v2[0] <= 'z') {
				var[v2] = 0;
			}
			if ('a' <= v3[0] && v3[0] <= 'z') {
				var[v3] = 0;
			}
		}
		
		if (op == "SET" || op == "IF") {
			cin >> v1 >> v2;
			if ('a' <= v1[0] && v1[0] <= 'z') {
				var[v1] = 0;
			}
			if ('a' <= v2[0] && v2[0] <= 'z') {
				var[v2] = 0;
			}
		}
		
		Line v(op, v1, v2, v3);
		program[i] = v;
		i2n[l] = i;
	}
	
	int pc = 0;
	auto start = chrono::system_clock::now();
	auto end = chrono::system_clock::now();
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	while (elapsed <= 4500.0) {
		if (program[pc].op.empty() ||
			pc >= n) {
			for (auto &x:var) {
				cout << x.first << '=' << x.second << endl;
			}
			return 0;
		}
		
		Line p = program[pc]; pc++;
		bool over_flow = false;
		
		if (p.op == "ADD") {
			if ('a' <= p.v3[0] && p.v3[0] <= 'z') {
				if (var[p.v2] + var[p.v3] >= 16) over_flow = true;
				else var[p.v1] = var[p.v2] + var[p.v3];
			}
			else {
				if (var[p.v2] + stoi(p.v3) >= 16) over_flow = true;
				else var[p.v1] = var[p.v2] + stoi(p.v3);
			}
		}
		
		if (p.op == "SUB") {
			if ('a' <= p.v3[0] && p.v3[0] <= 'z') {
				if (var[p.v2] - var[p.v3] < 0) over_flow = true;
				else var[p.v1] = var[p.v2] - var[p.v3];
			}
			else {
				if (var[p.v2] - stoi(p.v3) < 0) over_flow = true;
				else var[p.v1] = var[p.v2] - stoi(p.v3);
			}
		}
		
		if (p.op == "SET") {
			if ('a' <= p.v2[0] && p.v2[0] <= 'z') {
				var[p.v1] = var[p.v2];
			}
			else {
				int v = stoi(p.v2);
				if (v >= 0 && v < 16) {
					var[p.v1] = v;
				}
				else {
					over_flow = true;
				}
			}
		}
		
		if (p.op == "IF") {
			if (var[p.v1]) {
				pc = i2n[stoi(p.v2)];
			}
		}
		
		if (p.op == "HALT" ||
			over_flow) {
			for (auto &x:var) {
				cout << x.first << '=' << x.second << endl;
			}
			return 0;
		}
		
		end = chrono::system_clock::now();
		elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	}
	
	cout << "inf" << endl;
	
	return 0;
}
accuracy: 0.6666666666666666
time_ms: 4490
memory_kb: 3184
final_rank: 16