malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int read() {     int ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar();     return ans;   }   inline long long L_read() {     long long ans = 0;     char ch = getchar();     while (ch <  0  || ch >  9 ) ch = getchar();     while (ch >=  0  && ch <=  9 )       ans = (ans << 1) + (ans << 3) + (ch ^ 48), ch = getchar();     return ans;   }   int dx[5] = {0, -1, 1, 0, 0};   int dy[5] = {0, 0, 0, -1, 1};   struct cz {     long long Time;     bool Initial;   };   cz state[1050][1050];   bool mp[1050][1050];   long long p;   string s;   struct pos {     int x;     int y;   };   pos ww;   inline bool check(int x, int y, int n, int m) {     for (int i = 1; i <= 4; i++) {       int nowx = x + dx[i], nowy = y + dy[i];       if (nowx >= 1 && nowx <= n && nowy >= 1 && nowy <= m)         if (mp[nowx][nowy] == mp[x][y]) return true;     }     return false;   }   int n, m, k, x, y;   bool vis[1050][1050];   queue<pos> qwq;   inline void bfs() {     while (!qwq.empty()) {       int nowx = qwq.front().x;       int nowy = qwq.front().y;       qwq.pop();       for (int i = 1; i <= 4; i++) {         if (nowx + dx[i] >= 1 && nowx + dx[i] <= n && nowy + dy[i] >= 1 &&             nowy + dy[i] <= m) {           if (!vis[nowx + dx[i]][nowy + dy[i]]) {             vis[nowx + dx[i]][nowy + dy[i]] = 1;             state[nowx + dx[i]][nowy + dy[i]].Time = state[nowx][nowy].Time + 1;             ww.x = nowx + dx[i];             ww.y = nowy + dy[i];             qwq.push(ww);           }         }       }     }   }   int Odd(long long i) { return (i & 1) != 0; }   int main() {     bool ff = 0;     n = read(), m = read(), k = read();     for (int i = 1; i <= n; i++) {       cin >> s;       for (int j = 0; j < m; j++) {         if (s[j] ==  1 ) state[i][j + 1].Initial = 1, mp[i][j + 1] = 1;       }     }     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j)         if (check(i, j, n, m)) {           ww.x = i, ww.y = j;           vis[i][j] = 1;           qwq.push(ww);           ff = 1;         }     if (!ff) {       for (int i = 1; i <= k; i++) {         x = read(), y = read(), p = L_read();         cout << mp[x][y] <<   n ;       }       return 0;     }     bfs();     for (int i = 1; i <= k; i++) {       x = read(), y = read();       p = L_read();       if (p <= state[x][y].Time) {         cout << state[x][y].Initial <<   n ;         continue;       }       if (!Odd(p - state[x][y].Time))         cout << state[x][y].Initial <<   n ;       else {         if (state[x][y].Initial == 0)           cout << 1 <<   n ;         else           cout <<  0 n ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   inline char gc() {     static const long long L = 233333;     static char sxd[L], *sss = sxd, *ttt = sxd;     if (sss == ttt) {       ttt = (sss = sxd) + fread(sxd, 1, L, stdin);       if (sss == ttt) {         return EOF;       }     }     return *sss++;   }   inline char readalpha() {     char c = gc();     for (; !isalpha(c); c = gc())       ;     return c;   }   inline char readchar() {     char c = gc();     for (; c ==    ; c = gc())       ;     return c;   }   template <class T>   inline bool read(T& x) {     bool flg = false;     char c = gc();     x = 0;     for (; !isdigit(c); c = gc()) {       if (c ==  - ) {         flg = true;       } else if (c == EOF) {         return false;       }     }     for (; isdigit(c); c = gc()) {       x = (x << 1) + (x << 3) + (c ^ 48);     }     if (flg) {       x = -x;     }     return true;   }   template <class T>   inline void write(T x) {     if (x < 0) {       putchar( - );       x = -x;     }     if (x < 10) {       putchar(x | 48);       return;     }     write(x / 10);     putchar((x % 10) | 48);   }   const int maxn = 20;   const int maxl = 1000005;   int n;   int f[1 << maxn];   int g[1 << maxn];   char s[maxl];   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     for (int i = 1; i <= n; ++i) {       int now = i, nowzt = 0;       while (now) {         if (nowzt & (1 << (s[now] -  a ))) {           break;         }         nowzt |= (1 << (s[now] -  a ));         now--;         f[nowzt] = i - now;       }     }     int ans = 0;     for (int i = 0; i < 1 << 20; ++i) {       g[i] = f[i];     }     for (int i = 0; i < 1 << 20; ++i) {       for (int j = 0; j < 20; ++j) {         g[i | (1 << j)] = max(g[i], g[i | (1 << j)]);       }     }     for (int i = 0; i < 1 << 20; ++i) {       ans = max(ans, f[i] + g[((1 << 20) - 1) ^ i]);     }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m, sum = 0;     cin >> n >> m;     vector<int> v;     for (int i = 0; i < n; i++) {       int ff;       cin >> ff;       v.push_back(ff);     }     for (int i = 0; i < m; i++) {       int x;       cin >> x;       if (x == 1) {         int l, k;         cin >> l >> k;         v[l - 1] = k - sum;       }       if (x == 2) {         int y;         cin >> y;         { sum += y; }       }       if (x == 3) {         int ans;         cin >> ans;         cout << v[ans - 1] + sum << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> used;   int main() {     int n, k;     scanf( %d %d , &n, &k);     int a[n];     long long ans = 0;     int p = 0;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       used[a[i]]++;       if (used[a[i]] == k) {         ans += (long long)(n - i);         while (1) {           used[a[p]]--;           if (a[p++] == a[i]) break;           ans += (long long)(n - i);         }       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   const int maxn = 2e5 + 9, inf = 0x3f3f3f3f;   void Chkmax(int &x, int y) {     if (y > x) x = y;   }   int n, ans, mx, root;   int a[maxn], sum[maxn];   void Solve(int v) {     static int b[maxn], last[maxn << 1];     for (int i = 1; i <= n; ++i) {       if (a[i] == root) {         b[i] = 1;       } else if (a[i] == v) {         b[i] = -1;       } else         b[i] = 0;     }     int V(n);     for (int i = 0; i <= 2 * n; ++i) last[i] = inf;     last[V] = 0;     int nw(0);     for (int i = 1; i <= n; ++i) {       nw += b[i];       if (last[nw + V] <= i) {         Chkmax(ans, i - last[nw + V]);       } else         last[nw + V] = i;     }   }   int main() {     scanf( %d , &n);     mx = 0;     for (int i = 1; i <= n; ++i) {       scanf( %d , a + i);       sum[a[i]]++;       Chkmax(mx, a[i]);     }     root = 0;     for (int i = 1; i <= mx; ++i) {       if (sum[i] > sum[root]) {         root = i;       }     }     for (int i = 1; i <= mx; ++i)       if (i ^ root) {         Solve(i);       }     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) {       int n, x;       cin >> n >> x;       vector<pair<int, int> > v;       for (int i = 0; i < n; i++) {         int k, l;         cin >> k >> l;         v.push_back(make_pair(k, l));       }       int j = 0, ma = -1, b = 0;       for (int i = 0; i < n; i++) {         b = max(b, v[i].first);         if ((v[i].first - v[i].second) > ma) {           ma = max(v[i].first - v[i].second, ma);           j = v[i].first;         } else if ((v[i].first - v[i].second) == ma) {           if (v[i].first > j) {             j = v[i].first;           }         }       }       if (b >= x) {         cout <<  1  << endl;       } else if (ma > 0) {         if ((x - b) % ma == 0) {           cout << (x - b) / ma + 1 << endl;         } else {           cout << (x - b) / ma + 2 << endl;         }       } else {         cout <<  -1  << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 100;   int add[N << 6], num[N << 6], lazy[N << 6], ls[N << 6], rs[N << 6], total;   int init() {     num[total] = add[total] = lazy[total] = 0;     ls[total] = rs[total] = -1;     return total++;   }   void down(int l, int r, int o) {     if (ls[o] == -1) ls[o] = init();     if (rs[o] == -1) rs[o] = init();     int ll = ls[o], rr = rs[o];     add[ll] += add[o];     add[rr] += add[o] + num[o] * ((l + r) / 2 + 1 - l);     num[ll] += num[o];     num[rr] += num[o];     lazy[ll] += lazy[o];     lazy[rr] += lazy[o];     num[o] = add[o] = lazy[o] = 0;   }   int L, R, V, op;   void update(int l, int r, int o) {     if (L <= l && r <= R) {       if (op == 0) {         lazy[o] += V;       } else {         add[o] += l - L + 1;         num[o]++;       }       return;     }     down(l, r, o);     int ll = ls[o], rr = rs[o];     if (L <= (l + r) / 2) update(l, (l + r) / 2, ll);     if (R > (l + r) / 2) update((l + r) / 2 + 1, r, rr);   }   int query(int l, int r, int o, int x) {     if (l == r) {       return add[o] + lazy[o];     }     down(l, r, o);     int ll = ls[o], rr = rs[o];     if (x <= (l + r) / 2)       return query(l, (l + r) / 2, ll, x);     else       return query((l + r) / 2 + 1, r, rr, x);   }   struct Node {     int l, t, fg;     Node() {}     Node(int l, int t, int fg) : l(l), t(t), fg(fg) {}     bool operator<(const Node& th) const {       if (l != th.l) return l < th.l;       if (fg != th.fg) return fg > th.fg;       return t < th.t;     }   } node[N * 2];   int ll[N * 4], rr[N * 4], tt[N * 4];   multiset<int> st;   int main() {     int n, m;     while (scanf( %d%d , &n, &m) != EOF) {       int tot = 0;       for (int i = 0; i < m; i++) {         int l, r, t;         scanf( %d%d%d , &l, &r, &t);         r--;         node[tot++] = Node(l, t, 1);         node[tot++] = Node(r, t, -1);       }       sort(node, node + tot);       int cnt = 0, pre;       st.clear();       for (int i = 0; i < tot; i++) {         int l = node[i].l, t = node[i].t, fg = node[i].fg;         if (st.size() == 0) {           pre = l;           st.insert(t);           continue;         }         if (l > pre) {           ll[cnt] = pre;           rr[cnt] = l - 1;           tt[cnt] = *st.begin();           cnt++;           pre = l;         }         if (fg == -1) {           if (pre == l) {             ll[cnt] = pre;             rr[cnt] = l;             tt[cnt] = *st.begin();             cnt++;             pre = l + 1;           }           st.erase(st.lower_bound(t));         } else {           st.insert(t);         }       }       int ed = 1e9;       total = 0;       init();       for (int i = 0; i < cnt; i++) {         int l = ll[i], r = rr[i], t = tt[i];         op = 0;         V = r - l + 1;         L = max(0, t - l + 1), R = ed;         if (L <= R) update(0, ed, 0);         L = t - r, R = t - l;         op = 1;         if (R >= 0) update(0, ed, 0);       }       for (int i = 0; i < n; i++) {         int a;         scanf( %d , &a);         printf( %d n , query(0, ed, 0, a));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxm = 1000000 + 5;   const int maxn = 6400 + 5;   struct Edge {     int to, next;   } edges[maxm];   int indices[maxn];   int deg[maxn];   char ans[maxm];   int an;   int over;   inline int Trans_index(char* s) { return (s[0] -  0 ) * 80 + (s[1] -  0 ); }   void DFS(int x) {     while (indices[x] != -1) {       int y = edges[indices[x]].to;       indices[x] = edges[indices[x]].next;       DFS(y);     }     ans[an++] = x / 80 +  0 ;   }   int main() {     int n;     scanf( %d n , &n);     memset(indices, 0xff, sizeof(indices));     int start;     for (int i = 0; i < n; i++) {       char line[5];       gets(line);       int x = start = Trans_index(line);       edges[i].to = Trans_index(line + 1);       ;       edges[i].next = indices[x];       indices[x] = i;       deg[edges[i].to]++;       deg[x]--;     }     int cnt_err = 0;     over = -1;     for (int i = 0; i < maxn; i++) {       if (deg[i] == 0)         continue;       else if (deg[i] < 0)         start = i, cnt_err -= deg[i];       else         over = i, cnt_err += deg[i];     }     if (cnt_err != 0 && cnt_err != 2) {       puts( NO );       return 0;     }     DFS(start);     for (int i = 0; i < maxn; i++) {       if (indices[i] != -1) {         printf( NO );         return 0;       }     }     puts( YES );     reverse(ans, ans + an);     if (cnt_err == 0) over = start;     ans[an++] =  0  + over % 80;     ans[an++] =   0 ;     puts(ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000050;   int a[N];   int main() {     int n, k;     cin >> n >> k;     if (n == 1 && k == 10)       cout <<  -1  << endl;     else {       if (k == 10) {         cout <<  1 ;         for (int i = 1; i < n; i++) cout <<  0 ;         cout << endl;       } else {         for (int i = 0; i < n; i++) cout << k;         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long dad = 1e6;   int n, m, l = 1, r;   long long k;   long long d[dad], a[dad], b[dad], res, ans[dad], dem[dad];   struct yasu {     int id, l, r;   } p[dad], c[dad];   bool cmp(yasu u, yasu v) {     return (u.l / 300 < v.l / 300 || (u.l / 300 == v.l / 300 && u.r < v.r));   }   void update(int u, long long gt1, long long gt2, long long gt3) {     res += dem[c[u].l] * gt2;     res += dem[c[u].r] * gt3;     dem[c[u].id] += gt1;   }   int getint() {     int ww = 0;     char cc = getchar();     while (cc >  9  || cc <  0 ) cc = getchar();     while (cc >=  0  && cc <=  9 ) {       ww = ww * 10 + cc -  0 ;       cc = getchar();     }     return ww;   }   long long getll() {     long long ww = 0;     char cc = getchar();     while (cc >  9  || cc <  0 ) cc = getchar();     while (cc >=  0  && cc <=  9 ) {       ww = ww * 10 + cc -  0 ;       cc = getchar();     }     return ww;   }   void input() {     scanf( %d%lld , &n, &k);     for (int i = 1; i <= n; ++i) {       d[i] = getll();       d[i] = d[i] == 1 ? 1 : -1;     }     for (int i = 1; i <= n; ++i) {       scanf( %lld , &a[i]);       a[i] = a[i - 1] + a[i] * d[i];     }     for (int i = 0; i <= n; ++i) {       b[++*b] = a[i];       b[++*b] = a[i] + k;       b[++*b] = a[i] - k;     }     sort(b + 1, b + *b + 1);     *b = unique(b + 1, b + *b + 1) - b - 1;     scanf( %d , &m);     for (int i = 1; i <= m; ++i) {       scanf( %d%d , &p[i].l, &p[i].r);       --p[i].l;       p[i].id = i;     }     for (int i = 0; i <= n; ++i) {       c[i].id = lower_bound(b + 1, b + *b + 1, a[i]) - b;       c[i].l = lower_bound(b + 1, b + *b + 1, a[i] - k) - b;       c[i].r = lower_bound(b + 1, b + *b + 1, a[i] + k) - b;     }     sort(p + 1, p + m + 1, cmp);     for (int i = 1; i <= m; ++i) {       int l1 = p[i].l;       int r1 = p[i].r;       while (l < l1) {         --dem[c[l].id];         res -= dem[c[l].r];         ++l;       }       while (l > l1) {         --l;         res += dem[c[l].r];         ++dem[c[l].id];       }       while (r < r1) {         ++r;         res += dem[c[r].l];         ++dem[c[r].id];       }       while (r > r1) {         --dem[c[r].id];         res -= dem[c[r].l];         --r;       }       ans[p[i].id] = res;     }     for (int i = 1; i <= m; ++i) printf( %lld n , ans[i]);   }   void output() {}   int main() {     input();     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = unsigned long long;   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int k;     cin >> k;     int n = (1 << k);     vector<vector<ll> > a(n, vector<ll>(n, 0));     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) cin >> a[i][j];     int t;     cin >> t;     vector<pair<int, int> > shape(t);     for (int i = 0; i < t; i++) cin >> shape[i].first >> shape[i].second;     for (int r = 0; r < k; r++) {       vector<vector<ll> > b(n, vector<ll>(n, 0));       for (int c = 0; c < t; c++) {         for (int i = 0; i < (1 << k); i++) {           for (int j = 0; j < (1 << k); j++) {             b[(i + shape[c].first) & ((1 << k) - 1)]              [(j + shape[c].second) & ((1 << k) - 1)] ^= a[i][j];           }         }       }       a = b;       for (int c = 0; c < t; c++) {         shape[c].first = (shape[c].first * 2) % n;         shape[c].second = (shape[c].second * 2) % n;       }     }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (a[i][j]) ans++;     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int xinc[] = {0, 0, 1, -1};   const int yinc[] = {1, -1, 0, 0};   const long double PI = acos(-1.0);   int n, k;   void solve() {     cin >> n >> k;     int d = n - k;     if (k == 1) {       cout << 1;       for (int i = 0; i < n - 1; i++) cout << 0;       cout <<   n ;       return;     }     d /= 2;     string p =  1 ;     for (int i = 0; i < d; i++) p +=  0 ;     int z = p.size();     for (int i = 0; i < n; i++) cout << p[i % z];     cout <<   n ;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t;     t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct info {     double val;     string a;   };   vector<info> t;   int n, x, y, hcnt, sumh;   double aa;   long long res = 0;   bool cmp(const info &u, const info &v) { return u.val > v.val; }   int main() {     string a;     cin >> n;     for (int i = 0; i < n; i++) {       x = y = 0;       cin >> a;       for (int j = 0; a[j]; j++)         if (a[j] ==  s )           x++;         else if (a[j] ==  h )           y++;       sumh += y;       if (y == 0)         aa = 2e9;       else         aa = (double)x / y;       t.push_back({aa, a});     }     sort(t.begin(), t.end(), cmp);     int Size = t.size();     for (int i = 0; i < Size; i++) {       int sSize = t[i].a.size();       for (int j = 0; j < sSize; j++) {         if (t[i].a[j] ==  h )           sumh--;         else if (t[i].a[j] ==  s )           res += sumh;       }     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1005;   char s[N], t[N];   int dp[N][N][15][2];   int main() {     int n, m, lim;     scanf( %d %d %d %s %s , &n, &m, &lim, s, t);     for (int i = 0; i < N; i++) {       for (int j = 0; j < N; j++) {         for (int k = 0; k < 15; k++) {           dp[i][j][k][0] = dp[i][j][k][1] = -1e9;         }       }     }     dp[0][0][0][0] = 0;     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         for (int k = 0; k <= lim; k++) {           int zero = dp[i][j][k][0];           int one = dp[i][j][k][1];           if (s[i] == t[j]) {             dp[i + 1][j + 1][k + 1][1] =                 max(dp[i + 1][j + 1][k + 1][1], zero + 1);             dp[i + 1][j + 1][k + 1][1] = max(dp[i + 1][j + 1][k + 1][1], one + 1);             dp[i + 1][j + 1][k][1] = max(dp[i + 1][j + 1][k][1], one + 1);           }           for (int a = 0; a < 2; a++) {             dp[i + 1][j][k][0] = max(dp[i + 1][j][k][0], dp[i][j][k][a]);             dp[i][j + 1][k][0] = max(dp[i][j + 1][k][0], dp[i][j][k][a]);           }         }       }     }     int ans = 0;     for (int i = 0; i <= n; i++) {       for (int j = 0; j <= m; j++) {         ans = max(ans, dp[i][j][lim][0]);         ans = max(ans, dp[i][j][lim][1]);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100010], dp[100010][2];   char s[100010];   int main() {     int(n);     scanf( %d , &n);     for (int i = 0; i < (n); ++i) scanf( %d , &(a[i]));     scanf( %s , (s));     memset((dp), -1, sizeof((dp)));     dp[n][1] = 0;     for (int i = n - 1; i >= 0; i--) {       dp[i][1] = dp[i + 1][1] + a[i] * (s[i] ==  1 );       if (s[i] ==  1 ) dp[i][0] = dp[i + 1][1];       dp[i][0] = max(dp[i][0], dp[i + 1][0]);       if (dp[i + 1][0] != -1) dp[i][0] = max(dp[i][0], dp[i + 1][0] + a[i]);     }     printf( %d n , max(dp[0][0], dp[0][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 200100;   const long long oo = 2e18;   long long i, n, m, l, r, mid;   long long a[N], f[N][2];   inline long long read() {     long long x = 0, f = 0, c = getchar();     for (; c >  9  || c <  0 ; f = c ==  - , c = getchar())       ;     for (; c >=  0  && c <=  9 ; c = getchar()) x = (x << 1) + (x << 3) + c -  0 ;     return f ? -x : x;   }   bool check(long long x) {     long long i, k1, k2, start0 = 0, start1 = 0;     while (start0 <= x) {       if (!start0)         f[0][0] = -x;       else         f[0][0] = start0;       f[0][1] = start1;       for (i = 1; i <= n; i++) f[i][0] = oo, f[i][1] = 0;       for (i = 0; i < n; i++) {         if (f[i][0] > x) return 0;         if (f[i][0] > 0)           k1 = a[i + 1] - a[i] + f[i][0];         else {           k1 = a[i + 1] - a[i] - x;           if (k1 > 0) k1--;         }         if (k1 < 0)           f[i + 1][0] = -x;         else           f[i + 1][0] = min(f[i + 1][0], k1);         k2 = a[i + 1] - a[i] + f[i][1];         if (k2 > 0) k2--;         if (k2 < 0)           f[i + 1][0] = -x;         else           f[i + 1][0] = min(f[i + 1][0], k2);         if (k1 <= x) f[i + 1][1] = min(f[i + 1][1], a[i + 1] - a[i] - x);         f[i + 1][1] = min(f[i + 1][1], k2);       }       if (f[n][0] <= start0 && f[n][1] <= start1) return 1;       start0 = f[n][0];       start1 = f[n][1];     }     return 0;   }   signed main() {     m = read();     n = read();     for (i = 0; i < n; i++) a[i] = read();     a[n] = a[0] + m;     sort(a, a + n + 1);     l = 0;     r = m - n;     while (l < r) {       mid = (l + r - 1) >> 1;       if (check(mid))         r = mid;       else         l = mid + 1;     }     printf( %I64d n , l);   }
#include <bits/stdc++.h>   using namespace std;   const int MAX_N = 300000;   const int MAX_E2 = 1 << 20;   const long double PI = acosl(-1.0);   struct Elm {     long double x, y, th;     Elm() : x(0.0), y(0.0), th(0.0) {}     Elm(long double _x, long double _y, long double _th)         : x(_x), y(_y), th(_th) {}     Elm &extend(int l) {       x += l * cosl(th), y += l * sinl(th);       return *this;     }     Elm &rot(long double dth) {       long double c = cosl(dth), s = sinl(dth);       long double x0 = c * x - s * y;       long double y0 = s * x + c * y;       x = x0, y = y0;       th += dth;       return *this;     }     Elm operator+(const Elm &e) const {       long double c = cosl(th), s = sinl(th);       long double x0 = c * e.x - s * e.y;       long double y0 = s * e.x + c * e.y;       return Elm(x + x0, y + y0, th + e.th);     }   };   template <typename T, const int MAX_E2>   struct SegTree {     int e2;     T nodes[MAX_E2], defv;     SegTree() {}     void init(int n, T _defv) {       defv = _defv;       for (e2 = 1; e2 < n; e2 <<= 1)         ;       fill(nodes, nodes + MAX_E2, defv);     }     T &get(int i) { return nodes[e2 - 1 + i]; }     void seti(int i, T v) { get(i) = v; }     void setall() {       for (int j = e2 - 2; j >= 0; j--)         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];     }     void set(int i, T v) {       int j = e2 - 1 + i;       nodes[j] = v;       while (j > 0) {         j = (j - 1) / 2;         nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];       }     }   };   SegTree<Elm, MAX_E2> st;   int main() {     int n, m;     scanf( %d%d , &n, &m);     st.init(n, Elm(0.0, 0.0, 0.0));     for (int i = 0; i < n; i++) st.seti(i, Elm(1.0, 0.0, 0.0));     st.setall();     for (int i = 0; i < m; i++) {       int x, y, z;       scanf( %d%d%d , &x, &y, &z);       y--;       Elm e = st.get(y);       if (x == 1)         e.extend(z);       else         e.rot(-PI * z / 180);       st.set(y, e);       Elm r = st.nodes[0];       printf( %.10Lf %.10Lf n , r.x, r.y);     }     return 0;   }