Problem:
Problem A:
Era Name
As many of you know, we have two major calendar systems used in Japan today. One of them
is Gregorian calendar which is widely used across the world. It is also known as “Western
calendar” in Japan.
The other calendar system is era-based calendar, or so-called “Japanese calendar.” This system
comes from ancient Chinese systems. Recently in Japan it has been a common way to associate
dates with the Emperors. In the era-based system, we represent a year with an era name given
at the time a new Emperor assumes the throne. If the era name is “A”, the first regnal year
will be “A 1”, the second year will be “A 2”, and so forth.
Since we have two different calendar systems, it is often needed to convert the date in one
calendar system to the other. In this problem, you are asked to write a program that converts
western year to era-based year, given a database that contains association between several
western years and era-based years.
For the simplicity, you can assume the following:
A new era always begins on January 1st of the corresponding Gregorian year.
The first year of an era is described as 1.
There is no year in which more than one era switch takes place.
Please note that, however, the database you will see may be incomplete. In other words, some
era that existed in the history may be missing from your data. So you will also have to detect
the cases where you cannot determine exactly which era the given year belongs to.
Input
The input contains multiple test cases. Each test case has the following format:
N Q
EraName
1
EraBasedYear
1
WesternYear
1
.
.
.
EraName
N
EraBasedYear
N
WesternYear
N
Query
1
.
.
.
Query
Q
The first line of the input contains two positive integers
N
and
Q
(1 ≤
N
≤ 1000, 1 ≤
Q
≤ 1000).
N
is the number of database entries, and Q is the number of queries.
Each of the following N lines has three components: era name, era-based year number and the
corresponding western year (1 ≤
EraBasedYear
i
≤
WesternYear
i
≤ 10
9
). Each of era names
consist of at most 16 Roman alphabet characters. Then the last
Q
lines of the input specifies
queries (1 ≤
Query
i
≤ 10
9
), each of which is a western year to compute era-based representation.
The end of input is indicated by a line containing two zeros. This line is not part of any dataset
and hence should not be processed.
You can assume that all the western year in the input is positive integers, and that there is no
two entries that share the same era name.
Output
For each query, output in a line the era name and the era-based year number corresponding to
the western year given, separated with a single whitespace. In case you cannot determine the
era, output “
Unknown
” without quotes.
Sample Input
4 3
meiji 10 1877
taisho 6 1917
showa 62 1987
heisei 22 2010
1868
1917
1988
1 1
universalcentury 123 2168
2010
0 0
Output for the Sample Input
meiji 1
taisho 6
Unknown
Unknown

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;
const ll INF = 1e18;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    while(1) {
        ll n, q;
        cin >> n >> q;
        if(n == 0) break;
        vector<tuple<string, ll, ll>> era(n);
        for(auto& [name, e, w] : era) {
            cin >> name >> e >> w;
        }

        for(int i = 0; i < q; i++) {
            ll a;
            cin >> a;
            string s = "";
            ll ans;
            for(auto [name, e, w] : era) {
                if(w - e + 1 <= a && a <= w) {
                    s = name;
                    ans = a - (w - e);
                }
            }
            if(s.size())
                cout << s << ' ' << ans << endl;
            else
                cout << "Unknown" << endl;
        }
    }

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3584
final_rank: 16

code_snippet: #include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<string>
using namespace std;

typedef int ll;
const int inf = 1000000;
#define N 300005
int n, m;
struct node{
    char s[20]; int x, y;
}a[1005];
void input(){
    for(int i = 1; i <= n; i++){
        scanf("%s %d %d", a[i].s, &a[i].x, &a[i].y);
      //  printf("--%s %d %d\n", a[i].s, a[i].x, a[i].y);
    }
}
int main(){
	while(scanf("%d %d", &n, &m), n+m){
        input();
        while(m--){
            bool ok = false;
            int year ; scanf("%d", &year);
         //   printf("year : %d\n", year);
            for(int i = 1; i <= n; i++)
            {
                if(a[i].y - a[i].x + 1 <= year && year <= a[i].y)
                {
                    printf("%s %d\n", a[i].s, a[i].x - (a[i].y - year));
                    ok = true; break;
                }
            }
            if(ok==false)puts("Unknown");
        }
	}
	return 0;
}
/*


*/
accuracy: 1
time_ms: 10
memory_kb: 3584
final_rank: 10

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  while(1){
    int n,Q;cin >> n >> Q;
    if(!n)break;
    vector<pair<int,string>> cor;
    map<string,int> mp;
    rep(i,0,n){
      string s;int a,b;cin >> s >> a >> b;
      cor.emplace_back(b-a+1,s);
      chmax(mp[s],a);
    }
    sort(ALL(cor));cor.erase(unique(ALL(cor)),cor.end());
    while(Q--){
      int x;cin >> x;
      pair<int,string> g = make_pair(x+1,"Z");
      int k = LB(cor,g)-1;
      if(k >= 0 && x <= cor[k].first+mp[cor[k].second]-1){
        cout << cor[k].second << " " << x-cor[k].first+1 << "\n";
      }else cout << "Unknown\n";
    }
  }
  

  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3840
final_rank: 15

code_snippet: /*
 * Package: StandardCodeLibrary.Core
 * */
//引进常用的头文件并使用std名字空间
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <climits>
using namespace std;

//用于减少代码量的宏
#define lp for(;;)
#define repf(i,a,b) for (int i=(a);i<(b);++i)
#define rrepf(i,a,b) for (int i=(a)-1;i>=(b);--i)
#define rep(i,n) repf(i,0,n)
#define rrep(i,n) rrepf(i,n,0)
#define ft(i,a,b) for (int i=(a);i<=(b);++i)
#define fdt(i,a,b) for (int i=(a);i>=(b);--i)
#define for_nonempty_subsets(subset,set) for (int subset=set;subset;subset=(subset-1)&(set))
#define for_in_charset(i,charset) for (cstr i=(charset);*i;i++)
#define whl while
#define rtn return
#define fl(x,y) memset((x),char(y),sizeof(x))
#define clr(x) fl(x,char(0))
#define cpy(x,y) memcpy(x,y,sizeof(x))
#define sf scanf
#define pf printf
#define vec vector
#define pr pair
#define que queue
#define prq priority_queue
#define itr iterator
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define ins insert
#define ers erase
#define lb lower_bound
#define ub upper_bound
#define rnk order_of_key
#define sel find_by_order
#define sz(x) (int((x).size()))
#define all(x) (x).begin(),(x).end()
#define srt(x) sort(all(x))
#define uniq(x) srt(x),(x).erase(unique(all(x)),(x).end())
#define rev(x) reverse(all(x))
#define shf(x) random_shuffle(all(x))
#define nxtp(x) next_permutation(all(x))

//常用数据类型
#define lli int
typedef double db;
typedef const char* cstr;
typedef string str;
typedef vec<int> vi;
typedef vec<vi> vvi;
typedef vec<bool> vb;
typedef vec<vb> vvb;
typedef vec<str> vs;
typedef pr<int,int> pii;
typedef pr<lli,lli> pll;
typedef pr<db,db> pdd;
typedef map<int,int> mii;
typedef map<str,int> msi;
typedef map<char,int> mci;
typedef set<int> si;
typedef set<str> ss;
typedef que<int> qi;
typedef vec<pii> vpii;
typedef vec<pdd> vpdd;

//常用常量:int的最大值;lli的最大值;db的误差相关常数;欧拉常数;圆周率;移动向量;取模使用的除数
int oo=(~0u)>>1;
lli ooll=(~0ull)>>1;
db inf=1e+10;
db eps=1e-10;
db gam=0.5772156649015328606;
db pi=acos(-1.0);
int dx[]={1,0,-1,0,1,-1,-1,1,0};
int dy[]={0,1,0,-1,1,1,-1,-1,0};
int MOD=1000000007;

//常用函数:最大最小值更新;数学相关函数;输入和输出;树状数组;并查集;可合并堆;
template<typename type>inline bool cmax(type& a,const type& b){rtn a<b?a=b,true:false;}
template<typename type>inline bool cmin(type& a,const type& b){rtn b<a?a=b,true:false;}
template<typename type>inline type sqr(const type& x){rtn x*x;}
template<typename type>inline type mod(const type& x){rtn x%MOD;}
inline int sgn(const db& x){rtn (x>+eps)-(x<-eps);}
inline int dbcmp(const db& a,const db& b){rtn sgn(a-b);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& x){rtn mp(-x.x,-x.y);}
template<typename type>inline pr<type,type> operator+(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x+b.x,a.y+b.y);}
template<typename type>inline pr<type,type> operator-(const pr<type,type>& a,const pr<type,type>& b){rtn mp(a.x-b.x,a.y-b.y);}
template<typename type>inline pr<type,type> operator*(const pr<type,type>& a,const type& b){rtn mp(a.x*b,a.y*b);}
template<typename type>inline pr<type,type> operator/(const pr<type,type>& a,const type& b){rtn mp(a.x/b,a.y/b);}
template<typename type>inline pr<type,type>& operator-=(pr<type,type>& a,const pr<type,type>& b){rtn a=a-b;}
template<typename type>inline pr<type,type>& operator+=(pr<type,type>& a,const pr<type,type>& b){rtn a=a+b;}
template<typename type>inline pr<type,type>& operator*=(pr<type,type>& a,const type& b){rtn a=a*b;}
template<typename type>inline pr<type,type>& operator/=(pr<type,type>& a,const type& b){rtn a=a/b;}
template<typename type>inline type cross(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.y-a.y*b.x;}
template<typename type>inline type dot(const pr<type,type>& a,const pr<type,type>& b){rtn a.x*b.x+a.y*b.y;}
template<typename type>inline type gcd(type a,type b){if(b)whl((a%=b)&&(b%=a));rtn a+b;}
template<typename type>inline type lcm(type a,type b){rtn a*b/gcd(a,b);}
template<typename istream,typename first_type,typename second_type>inline istream& operator>>(istream& cin,pr<first_type,second_type>& x){rtn cin>>x.x>>x.y;}
template<typename ostream,typename first_type,typename second_type>inline ostream& operator<<(ostream& cout,const pr<first_type,second_type>& x){rtn cout<<x.x<<" "<<x.y;}
template<typename istream,typename type>inline istream& operator>>(istream& cin,vec<type>& x){rep(i,sz(x))cin>>x[i];rtn cin;}
template<typename ostream,typename type>inline ostream& operator<<(ostream& cout,const vec<type>& x){rep(i,sz(x))cout<<x[i]<<(i+1==sz(x)?"":" ");rtn cout;}
inline ostream& pdb(int prcs,db x){rtn cout<<setprecision(prcs)<<fixed<<(sgn(x)?(x):0);}
template<typename type>inline void bit_inc(vec<type>& st,int x,type inc){whl(x<sz(st))st[x]+=inc,x|=x+1;}
template<typename type>inline type bit_sum(const vec<type>& st,int x){type s=0;whl(x>=0)s+=st[x],x=(x&(x+1))-1;rtn s;}
template<typename type>inline type bit_kth(const vec<type>& st,int k){int x=0,y=0,z=0;whl((1<<(++y))<=sz(st));fdt(i,y-1,0){if((x+=1<<i)>sz(st)||z+st[x-1]>k)x-=1<<i;else z+=st[x-1];}rtn x;}
inline void make_set(vi& st){rep(i,sz(st))st[i]=i;}
inline int find_set(vi& st,int x){int y=x,z;whl(y!=st[y])y=st[y];whl(x!=st[x])z=st[x],st[x]=y,x=z;rtn y;}
inline bool union_set(vi& st,int a,int b){a=find_set(st,a),b=find_set(st,b);rtn a!=b?st[a]=b,true:false;}
template<typename type>inline void merge(type& a,type& b){if(sz(a)<sz(b))swap(a,b);whl(sz(b))a.ins(*b.begin()),b.ers(b.begin());}

int main()
{
	int n,q;
	whl(cin>>n>>q,n||q)
	{
		msi beg,end;
		rep(i,n)
		{
			str a;
			int b,c;
			cin>>a>>b>>c;
			beg[a]=c-b+1;
			cmax(end[a],c);
		}
		vec<pr<pii,str> > rec;
		for(msi::itr it=beg.begin();it!=beg.end();it++) rec.pb(mp(mp(it->y,end[it->x]),it->x));
		rep(i,q)
		{
			int qry;
			cin>>qry;
			bool fnd=false;
			rep(i,sz(rec)) if (rec[i].x.x<=qry&&qry<=rec[i].x.y)
			{
				cout<<rec[i].y<<" "<<qry-rec[i].x.x+1<<endl;
				fnd=true;
			}
			if (!fnd) cout<<"Unknown"<<endl;
		}
	}
}
accuracy: 1
time_ms: 70
memory_kb: 3616
final_rank: 17

code_snippet: #include <iostream>
#include <iomanip>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <tuple>
#include <ranges>
namespace ranges = std::ranges;
namespace views = std::views;
// #include "Src/Number/IntegerDivision.hpp"
// #include "Src/Utility/BinarySearch.hpp"
// #include "Src/Sequence/CompressedSequence.hpp"
// #include "Src/Sequence/RunLengthEncoding.hpp"
// #include "Src/Algebra/Group/AdditiveGroup.hpp"
// #include "Src/DataStructure/FenwickTree/FenwickTree.hpp"
// #include "Src/DataStructure/SegmentTree/SegmentTree.hpp"
// using namespace zawa;
// #include "atcoder/modint"
// using mint = atcoder::modint998244353;
int N, Q, A[1000], B[1000];
std::string S[1000];
bool solve() {
    std::cin >> N >> Q;
    if (N == 0 and Q == 0) return false;
    for (int i = 0 ; i < N ; i++) {
        std::cin >> S[i] >> A[i] >> B[i];
    }
    while (Q--) {
        int c;
        std::cin >> c;
        int ans = -1;
        for (int i = 0 ; i < N ; i++) {
            if (B[i] - A[i] + 1 <= c and c <= B[i]) {
                ans = i;
                break;
            }
        }
        if (ans == -1) {
            std::cout << "Unknown\n";
        }
        else {
            const int y = A[ans] - (B[ans] - c);
            std::cout << S[ans] << ' ' << y << '\n';
        }
    }
    return true;
}
int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
    while (solve()) ;
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 14

code_snippet: #include <vector>
#include <iostream>
using namespace std;

int main() {
	while (true) {
		int N, Q;
		cin >> N >> Q;
		if (N == 0 && Q == 0) {
			break;
		}
		vector<string> S(N);
		vector<int> A(N), B(N);
		for (int i = 0; i < N; i++) {
			cin >> S[i] >> A[i] >> B[i];
		}
		for (int i = 0; i < Q; i++) {
			int x;
			cin >> x;
			pair<string, int> v = {"Unknown", -1};
			for (int j = 0; j < N; j++) {
				if (B[j] - A[j] + 1 <= x && x <= B[j]) {
					v = {S[j], x - (B[j] - A[j])};
				}
			}
			if (v.second != -1) {
				cout << v.first << ' ' << v.second << endl;
			} else {
				cout << v.first << endl;
			}
		}
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3492
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

#include <unistd.h>

namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf


uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio


using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */

int main() {
while(1) {
    int N, Q;
    cin >> N >> Q;
    if (N == 0 && Q == 0) return 0;
    vector<string> S(N);
    vector<int> A(N), B(N);
    rep(i,0,N) cin >> S[i] >> A[i] >> B[i];
    rep(i,0,Q) {
        int C;
        cin >> C;
        bool flag = false;
        rep(j,0,N) {
            if (B[j]-A[j] < C && C <= B[j]) {
                cout << S[j] << ' ' << C - (B[j]-A[j]) << endl;
                flag = true;
            }
        }
        if (!flag) cout << "Unknown" << endl;
    }
}
}
accuracy: 1
time_ms: 30
memory_kb: 3540
final_rank: 13

code_snippet: // (⁠◕⁠ᴗ⁠◕⁠✿⁠)

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define srep(i, s, n) for (ll i = s; i < (n); i++)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using vvv = vv<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
const ld pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const ll mod = 1000000007;
const ll mod = 998244353;
inline bool inside(ll y, ll x, ll H, ll W) {return 0 <= (y) and (y) < (H) and 0 <= (x) and (x) < (W); }

#define debug(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vc<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vv<T>& vv){ for(const auto& v : vv){ view(v); } }

vc<pair<string, int>> solve(int N, int Q){
    vc<tuple<string, int, int>> period(N);
    rep(i, N){
        string s; int a, b; cin >> s >> a >> b;
        period[i] = {s, b - a + 1, b};
    }
    vc<pair<string, int>> ans(Q, {"Unknown", 0});
    rep(i, Q){
        int t; cin >> t;
        for (auto [s, l, r] : period){
            if (l <= t && t <= r){
                ans[i] = {s, t - l + 1};
            }
        }
    }
    return ans;
}

int main(){
    vc<vc<pair<string, int>>> ans;
    while (true){
        int N, Q; cin >> N >> Q;
        if (N == 0) break;
        ans.push_back(solve(N, Q));
    }
    for (auto x : ans){
        for (auto [a, b] : x){
            if (a == "Unknown") cout << a << endl;
            else cout << a << " " << b << endl;
        }
    }
}
accuracy: 1
time_ms: 160
memory_kb: 4144
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m, y;
    while(cin >> n >> m, n){
        string s[1010];
        int a[1010], b[1010];
        for(int i=0;i<n;i++) cin >> s[i] >> a[i] >> b[i];
        for(int i=0;i<m;i++){
            bool ok = false;
            cin >> y;
            for(int j=0;!ok&&j<n;j++){
                if(b[j]-a[j]<y && y<=b[j]){
                    cout << s[j] << " " << y-b[j]+a[j] << endl;
                    ok = true;
                }
            }
            if(!ok) cout << "Unknown" << endl;
        }
    }
    return(0);
}
accuracy: 1
time_ms: 50
memory_kb: 3096
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

#define foa(s, v) for (auto &s : v)
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define rep(i, n) for (int i = 0; i < int(n); i++)

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

int n;
void solve()
{
    int q;
    cin >> q;
    vector<tuple<ll, ll, string>> eras(n);

    rep(i, n)
    {
        ll len, end;
        string c;
        cin >> c >> len >> end;
        ll start = end - len + 1;
        eras.emplace_back(start, end, c);
    }

    auto query = [&](ll val) -> string
    {
        for (auto [st, e, c] : eras)
        {
            if (st <= val && val <= e)
            {
                return c + " " + to_string(val - st + 1);
            }
        }
        return "Unknown";
    };

    rep(j, q)
    {
        ll s;
        cin >> s;
        cout << query(s) << endl;
    }

    return;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    while (cin >> n && n)
        solve();
}
accuracy: 1
time_ms: 190
memory_kb: 3644
final_rank: 19

code_snippet: #include <bits/stdc++.h>

#define MT make_tuple
#define MP make_pair
#define PB push_back
#define ALL(c) (c).begin(), (c).end()

using namespace std;

int main() {
	int n, q;
	while(cin >> n >> q && n) { 
		string name;
		int start, end, len;
		vector<tuple<int, int, string> > t;
		
		for(int i=0;i<n;i++) { 
			cin >> name >> len >> end;
			t.PB(MT(end-len+1, len, name));	
		}

		sort(ALL(t));
		int query, index;
		for(int i=0;i<q;i++) {
			cin >> query;
			index = n-1;
			for(int j=0;j<n;j++) {
				if(get<0>(t[j]) > query) {
					index = j-1;
					break;
				}
			}
			if(index == -1) {
				cout << "Unknown" << endl;
				continue;
			}
				
			start = get<0>(t[index]);
			len = get<1>(t[index]);
			name =  get<2>(t[index]);
			
			if(query-start < len) {
				cout << name << " " << query-start+1 << endl;
			} else {
				cout << "Unknown" << endl;
			}		
		}
	}
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3212
final_rank: 1

code_snippet: #include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int n, q;
map<long long, long long>my;
map<long long, string>mn;
int a[2000];

void solve(){
	for(int i = 0; i < n; i++){
		long long yi; string si;
		cin >> si >> yi >> a[i];
		my[a[i]] = yi;
		mn[a[i]] = si;
	}
	sort(a, a+n);
	while(q--){
		int y; cin >> y;
		int l = -1, r = n; // a[l] < y <= a[r]
		while(r - l > 1){
			int mid = (l + r)/2;
			if(y <= a[mid]) r = mid;
			else l = mid;
		}
		if(r == n)cout << "Unknown\n";
		else if(a[r] - my[a[r]] + 1 <= y && y <= a[r])cout << mn[a[r]] << ' ' << y - (a[r] - my[a[r]]) << "\n";
		else cout << "Unknown\n";
	}
}

int main(int argc, char **argv){
	while(cin >> n >> q){
		if(!q)break;
		my.clear();
		mn.clear();
		solve();
	}
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3476
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i,end) for(int i = 0; i <= (int)(end); i++)
#define reps(i,start,end) for(int i = start; i < (int)(end); i++)
#define repsn(i,start,end) for(int i = start; i <= (int)(end); i++)
#define ll long long
#define print(t) cout << t << endl 
#define all(a)  (a).begin(),(a).end()
// << std::fixed << std::setprecision(0)
const ll INF = 1LL << 60;
 
template<class T> void chmin(T& a, T b){
 if(a > b){
  a = b;
 }
}
 
template<class T> void chmax(T& a, T b){
 if(a < b){
  a = b;
 }
}
  
ll lpow(ll x,ll n){
  ll ans = 1;
  while(n >0){
    if(n & 1)ans *= x;
    x *= x;
    n >>= 1;
  }
  return ans;
}
// for AOJ or ICPC or etc..
template<class Tp>
bool zero (const Tp &x) {
    return x == 0;
}

template<class Tp, class... Args>
bool zero (const Tp &x, const Args& ...args) {
    return zero(x) and zero(args...);
}

int main(){
  while(true){
    ll n,q;cin >> n >> q;
    if(zero(n,q))break;
    vector<tuple<ll,ll,string>> era;
    rep(i,n){
      string s; ll a,b;cin >> s >> a >> b;
      era.push_back({b-a+ 1,b,s});
    }
    sort(all(era));
    // rep(i,n)cout << era[i].first << " " << era[i].second << endl;

    rep(i,q){
      ll m;cin >> m;
      ll ng = -1;
      ll ok = n-1; //配列サイズ
      while(abs(ok-ng) > 1){
        // cout << ok << " " << ng << endl;
        ll mid = (ok + ng)/2;
        auto [a,b,c] = era[mid];
        if(a <= m && m<= b){
          ok = mid;
          break;
        }
        if(b < m){
          ng = mid;
        }else{
          ok = mid;
        }
      }
      auto[a,b,c] = era[ok];
      if(ok == 0 && a > m){
        cout << "Unknown" << endl;
      }else{
        if(a <= m && m <= b){  
          cout << c << " "<< m - a+ 1 << endl;  
        }else{
          cout << "Unknown" << endl;
        }
      }
    }
  }
}
accuracy: 1
time_ms: 20
memory_kb: 3436
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(void){
    ll n,q;
    while(cin>>n>>q,n){
        ll a[1000],b[1000],t;
        string s[1000];
        for(ll i=0;i<n;i++){
            cin>>s[i]>>a[i]>>b[i];
        }
        while(q--){
            ll c=0;
            cin>>t;
            for(ll i=0;i<n;i++){
                if(b[i]>=t && b[i]-a[i]<t){
                    cout<<s[i]<<" "<<a[i]-b[i]+t<<endl;
                    c++;
                }
            }
            if(!c){
                cout<<"Unknown\n";
            }
        }
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3244
final_rank: 3

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

void solve(int N, int Q) {
    vector<tuple<string, int, int>> A(N);
    rep(i, N) {
        string s;
        int a, b;
        cin >> s >> a >> b;
        A[i] = {s, a, b};
    }

    while (Q--) {
        int year;
        cin >> year;

        bool flag = false;
        rep(i, N) {
            auto &[name, len, end] = A[i];
            if (end - len < year && year <= end) {
                cout << name << " " << len - end + year << "\n";
                flag = true;
                break;
            }
        }
        if (!flag)
            cout << "Unknown\n";
    }
}

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

    int N, Q;
    while (cin >> N >> Q) {
        if (N == 0 && Q == 0) break;
        solve(N, Q);
    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3404
final_rank: 6

code_snippet: #include <bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
using v2ll = vector<vll>;
using v3ll = vector<v2ll>;
using v4ll = vector<v3ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)



int main() {
    while(1){
        ll N,Q;
        cin>>N>>Q;
        if(N==0)return 0;
        vector<tuple<string,ll,ll>> E(N);
        rep(i,N){
            string S;
            ll A,B;
            cin>>S>>A>>B;
            E[i]={S,A,B};
        }
        rep(q,Q){
            ll P;
            cin>>P;
            bool C=true;
            rep(n,N){
                if(P>get<2>(E[n]))continue;
                if(P>get<2>(E[n])-get<1>(E[n])){
                    cout<<get<0>(E[n])<<" ";
                    cout<<P-(get<2>(E[n])-get<1>(E[n]))<<endl;
                    C=false;
                    break;
                }
            }
            if(C)cout<<"Unknown"<<endl;
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3256
final_rank: 4

code_snippet: #include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    while(1){
        INT(n,q);
        if(n==0&&q==0)return 0;
        vector<tuple<int,int,string>> a;
        string s;
        int l,r;
        rep(i,n){
            in(s,l,r);
            a.emplace_back(r-l+1,r,s);
        }
        sort(all(a));
        while(q--){
            INT(y);
            string ans;
            int ans2=-1;
            rep(i,n){
                tie(l,r,s)=a[i];
                if(l<=y&&y<=r){
                    ans=s;
                    ans2=y-l+1;
                }
            }
            if(ans2==-1)out("Unknown");
            else out(ans,ans2);
        }
    }
}
accuracy: 1
time_ms: 130
memory_kb: 3560
final_rank: 18

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    while(true) {
        int N,Q; cin >> N >> Q; if(N == 0) break;
        vector<string> S(N);
        vector<int> E(N), W(N);
        rep(i,N) cin >> S[i] >> E[i] >> W[i];

        rep(_,Q) {
            int q; cin >> q;
            string str = "Unknown";
            int ans = -1;
            rep(i,N) {
                if(W[i] - E[i] + 1 <= q && q <= W[i]) {
                    str = S[i];
                    ans = E[i] - W[i] + q;
                }
            }
            if(str == "Unknown") cout << str;
            else cout << str << " " << ans; cout << endl;
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3260
final_rank: 5

code_snippet: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using PL = pair<ll,ll>;
using PPL = pair<pair<ll,ll>,ll>;
#define INF 1000000000
#define INFLL 1000000000000000000
#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--)
#define mp make_pair
#define tp make_tuple
#define ALL(vec) vec.begin(), vec.end()
template <class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return true;}return false;}
template <class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return true;}return false;}
ll mod = 1000000007;
ll mod2 = 998244353;

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

    while (1) {
        ll n,m;cin>>n>>m;
        if (n==0 && m==0) {
            break;
        }
    vector<pair<string, pair<ll,ll>>> a(n);
    rep(i,0,n) {
        string a1;cin>>a1;
        ll a2,a3;cin>>a2>>a3;
        a[i] =mp(a1, mp(a3-a2+1, a3));
    }
    rep(i,0,m) {
        ll q;cin>>q;
        string ans_str = "";
        ll ans_num = 0;
        rep(j,0,n) {
            if (a[j].second.first <= q && q <= a[j].second.second) {
                ans_str = a[j].first;
                ans_num = q - a[j].second.first + 1;
                break;
            }
        }

        if (ans_num == 0) {
            cout << "Unknown" << endl;
        } else {
            cout << ans_str << " " << ans_num << endl;
        }
    }
    }
}
accuracy: 1
time_ms: 20
memory_kb: 3416
final_rank: 7

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

const int INF = 1e9;
const long long inf = 1LL<<60;
using ll = long long;

bool solve() {
  int n, q; cin >> n >> q;
  if (n == 0) return false;
  vector<int> y;
  map<int, string> m;
  map<int, int> d;
  for (int i=0; i<n; i++) {
    string s;
    int a, b;
    cin >> s >> a >> b;
    d[b] = a;
    m[b] = s;
    y.push_back(b);
  }
  sort(y.begin(), y.end());
  while (q--) {
    int p; cin >> p;
    if (p > y.back()) {
      cout << "Unknown" << endl;
      continue;
    }
    int cur = lower_bound(y.begin(), y.end(), p) - y.begin();
    if (y[cur] - (d[y[cur]]-1) <= p && p <= y[cur]) {
      cout << m[y[cur]] << " " << p - (y[cur] - (d[y[cur]]-1)) + 1 << endl;
    } else {
      cout << "Unknown" << endl;
    }
  }
  return true;
}

int main() {
  while (solve());
}
accuracy: 1
time_ms: 20
memory_kb: 3456
final_rank: 9