stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include<stdio.h>

#include<string.h>

#include<time.h>

#include<math.h>

#include<stdlib.h>

#include<iostream>

#include<iomanip>

#include<utility>

#include<algorithm>

#include<stack>

#include<queue>

#include<map>

#include<set>

#define ll long long

#define fi first

#define sec second

#define pb push_back

#define mp make_pair

#define rep(a,b,c) for(int a=1;a<=b;a+=c)

#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)



const double PI=acos(-1);

const double EPS=1e-12;

const int MOD=1e9+7;

const int INF=1<<30;





using namespace std;



double dat[3005][1505][2];

double p[3005];

int in;



double prob(int pos,int cnt,int phase){

	if(2*cnt>in)return dat[pos][cnt][phase]=0.0;

	if(pos==in)return dat[pos][cnt][phase]=1.0;

	if(dat[pos][cnt][phase]>-EPS)return dat[pos][cnt][phase];

	double temp=p[pos+1]*prob(pos+1,cnt,0)+(1.0-p[pos+1])*prob(pos+1,cnt+1,1);

	return dat[pos][cnt][phase]=temp;

}



int main(){

	//ios::sync_with_stdio(false);cin.tie(NULL);	cout.tie(NULL);

	cin>>in;

	double res;

	repp(j,0,1500,1){

		repp(k,0,1,1){

			dat[0][j][k]=-1e5;

		}

	}

	rep(i,in,1){

		cin>>p[i];

		repp(j,0,1500,1){

			repp(k,0,1,1){

				dat[i][j][k]=-1e5;

			}

		}

	}

	cout<<fixed<<setprecision(10)<<prob(0,0,0)<<endl;

	return 0;

}




// Faster C++ solution for the same problem (measured speedup: 1.1054346751758528x):


#include<bits/stdc++.h>

using namespace std;

int main()

{

    int n;

    cin>>n;

    double arra[n+5];

    for(int i=0; i<n; i++)

    {

        cin>>arra[i];

    }

    double dp[n+5][n+5];

    for(int i=0; i<=n; i++)

    {

        for(int j=0; j<=n; j++)

        {

            dp[i][j]=0.0;

        }

    }

    dp[0][0]=1.0;

    for(int i=1; i<=n; i++)

    {

        for(int j=0; j<=i; j++)

        {

            if(j==0)

            {

                dp[i][j]=dp[i-1][j]*(1-arra[i-1]);



            }

            else

            {

                dp[i][j]=dp[i-1][j]*(1.0-arra[i-1])+dp[i-1][j-1]*arra[i-1];





            }

        }

    }

    double tota=0.0;

    for(int i=(n/2)+1; i<=n; i++)

    {

        // printf("%.10lf\n",dp[n][i]);

        tota+=dp[n][i];



    }



    printf("%.10lf\n",tota);





}
// Slower C++ solution:
#include <iostream>

#include <sstream>

#include <vector>

#include <cmath>

#include <cstdio>

#include <queue>

#include <set>

#include <map>

#include <cstdlib>

#include <cstring>

#include <algorithm>

#define maxn 100005

using namespace std;

typedef long long ff;

int fo[2*maxn+5];

long long kx[2*maxn+5],ty[2*maxn+5];



int fin(int x)

{

       if(fo[x]==x)

       return x;

       else

       return fo[x]=fin(fo[x]);



}

int main()

{

    int n;

    scanf("%d",&n);

    for(int i=1;i<2*maxn;i++)

    {fo[i]=i;

    ty[i]=0;

    kx[i]=0;

    }

    long long ans=0;

    int x,y;

    for(int i=0;i<n;i++)

    {

       scanf("%d %d",&x,&y);

       fo[fin(x)]=fin(y+maxn);

     //  printf("%d\n",fo[fin(x)]);

      // fo[find(y+maxn)]=y;

    }

     for(int i=1;i<maxn;i++)

     kx[fin(i)]++;

     for(int i=maxn;i<maxn*2;i++)

     ty[fin(i)]++;



     for(int i=1;i<=2*maxn;i++)

     {

     ans+=kx[i]*ty[i];

    // if(kx[i]*ty[i]!=0)

     //printf("%d %d\n",i,kx[i]*ty[i]);

     }

     printf("%lld",ans-n);



}


// Faster C++ solution for the same problem (measured speedup: 1.4626603528921314x):
#include <cstdio>

#include <cctype>

#define int long long



const int MAXN = 100000;



int n, ans;

int f[200005], a1[200005], a2[200005];



int read() {

    int ret, f = 1;

    char ch;

    while(!isdigit(ch = getchar())) (ch == '-') && (f = -1);

    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');

    return ret * f;

}



void print(int x) {

    if(x < 0) putchar('-'), x = -x;

    if(x > 9) print(x / 10);

    putchar(x % 10 + '0');

}



void init(int x) {

    for(int i = 1; i <= x; ++i) f[i] = i;

}



int find(int x) {

    return f[x] == x ? x : f[x] = find(f[x]);

}



void merge(int x, int y) {

    f[find(x)] = find(y + MAXN);

}



signed main() {

    n = read();

    init(MAXN << 1);

    for(int i = 1; i <= n; ++i)

        merge(read(), read());

    for(int i = 1; i <= MAXN; ++i) ++a1[find(i)];

    for(int i = MAXN + 1; i <= MAXN << 1; ++i) ++a2[find(i)];

    for(int i = 1; i <= MAXN << 1; ++i)

        ans += a1[i] * a2[i];

    return print(ans - n), 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

 

int main(){

  int l, r, t = 0;

  scanf("%d", &l);

  for(r = 0; (1<<r) <= l; r++); r--;

  for(int i = l; i; i -= i&-i, t++); t--;

  printf("%d %d\n", r+1, 2*r+t);

  for(int i = 0; i < r; i++){

    printf("%d %d %d\n", i+1, i+2, 1<<i);

    printf("%d %d %d\n", i+1, i+2, 0);

    if(l&(1<<i)) printf("%d %d %d\n", i+1, r+1, l-=l&-l);

  }

}

// Faster C++ solution for the same problem (measured speedup: 5.153967638822922x):
#include<cstdio>



int main(){

  int l, r = 0, t = 0;

  scanf("%d", &l);

  for(; (1<<r) <= l; r++) if(l&(1<<r)) t++;

  printf("%d %d\n", r, 2*r+t-3);

  for(int i = 1; i < r; i++){

    printf("%d %d %d\n%d %d %d\n", i, i+1, 1<<(i-1), i, i+1, 0);

    if(l&(1<<(i-1))) printf("%d %d %d\n", i, r, l-=l&-l);

  }

}
// Slower C++ solution:
#include <stdio.h>

#include <tuple>

#include <queue>



int main(void){

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

    int n = 0; while((1 << (n+1)) <= L) n++;

    std::queue<std::tuple<int, int, int>> Q;

    for(int x = 0; x + 1 <= n; ++x) Q.emplace(x, x+1, 0), Q.emplace(x, x+1, 1 << x);

    int N = (1 << n) - 1; int U = L - N - 1;

    int l = L;

    for(int d = n; d >= 0; --d) if((U >> d) & 1){ // 101

        Q.emplace(d, n, l - (1 << d) ); l -= (1 << d);

    }



    printf("%d %lu\n", n+1, Q.size());

    while(not Q.empty()){

        int x, y, c; std::tie(x, y, c) = Q.front(); Q.pop();

        printf("%d %d %d\n", x + 1, y + 1, c);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.4730931980832995x):
#include <stdio.h>

int main(void){

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

    int n = 0; while((1 << (n+1)) <= L) n++;

    int N = (1 << n) - 1; int U = L - N - 1;

    int l = L;

    int m = 2 * n + __builtin_popcount(U);

    printf("%d %d\n", n+1, m);

    for(int x = 0; x + 1 <= n; ++x) printf("%d %d 0\n%d %d %d\n", x+1, x+2, x+1, x+2, (1 << x));

    for(int d = n; d >= 0; --d) if((U >> d) & 1){

        l -= (1 << d);

        printf("%d %d %d\n", d+1, n+1, l);

    }

    return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <tuple>

#include <queue>



int main(void){

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

    int n = 0; while((1 << (n+1)) <= L) n++;

    std::queue<std::tuple<int, int, int>> Q;

    for(int x = 0; x + 1 <= n; ++x) Q.emplace(x, x+1, 0), Q.emplace(x, x+1, 1 << x);

    int N = (1 << n) - 1; int U = L - N - 1;

    int l = L;

    for(int d = n; d >= 0; --d) if((U >> d) & 1){ // 101

        Q.emplace(d, n, l - (1 << d) ); l -= (1 << d);

    }



    printf("%d %lu\n", n+1, Q.size());

    while(not Q.empty()){

        int x, y, c; std::tie(x, y, c) = Q.front(); Q.pop();

        printf("%d %d %d\n", x + 1, y + 1, c);

    }

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 4.471792358584811x):
#include <stdio.h>

int main(void){

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

    int n = 0; while((1 << (n+1)) <= L) n++;

    int N = (1 << n) - 1; int U = L - N - 1;

    int l = L;

    int m = 2 * n + __builtin_popcount(U);

    printf("%d %d\n", n+1, m);

    for(int x = 0; x + 1 <= n; ++x) printf("%d %d 0\n%d %d %d\n", x+1, x+2, x+1, x+2, (1 << x));

    for(int d = n; d >= 0; --d) if((U >> d) & 1){

        l -= (1 << d);

        printf("%d %d %d\n", d+1, n+1, l);

    }

    return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

struct edge{

	int x,y,co;

}e[125];

int n,l,m,cnt;

void ins(int a,int b,int c)

{

	e[++cnt].x=a;e[cnt].y=b;e[cnt].co=c;

}

int main()

{

	scanf("%d",&l);

	n=floor(log2(l))+1;

	for(int i=1;i<n;i++)

	{

		ins(i,i+1,1<<(i-1));

		ins(i,i+1,0);

	}

	int now=0;int fu=1<<(n-1);

	while(l>1)

	{

		if(l&1)

		{

			ins(now+1,n,fu);

			fu|=1<<now;

		}

		l>>=1;

		now++;

	}

	printf("%d %d\n",n,cnt);

	for(int i=1;i<=cnt;i++) printf("%d %d %d\n",e[i].x,e[i].y,e[i].co);

}

// Faster C++ solution for the same problem (measured speedup: 5.021301911793075x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

struct E{int u,v,c;};

int l,p=1,mx,n,s1;

vector<E> ans;

int main(){

	scanf("%d",&l);l--;

	int i;

	for(i=1;mx+p<=l;++i){

		ans.push_back({i,i+1,p});

		ans.push_back({i,i+1,0});

		mx+=p,p*=2;

	}

	n=i--,p/=2,s1=mx-p;

	while(mx<l){

		if(mx+s1+1<=l)ans.push_back({i,n,mx+1}),mx+=s1+1;

		p/=2,s1-=p,i--;

	}

	printf("%d %d\n",n,ans.size());

	for(int i=0;i<ans.size();++i)printf("%d %d %d\n",ans[i].u,ans[i].v,ans[i].c);

} 

// Faster C++ solution for the same problem (measured speedup: 5.033163843637659x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>



#define maxn 100005



using namespace std;

typedef long long ll;



int main(){



  ios_base::sync_with_stdio(0);



  int L;

  cin >> L;

  L--;



  cout << 20 << ' ';



  vector < int > u, v, c;

  #define add(x, y, z) {u.push_back(x); v.push_back(y); c.push_back(z);}



  int i;



  for (i = 19; i > 0 && L > (1 << (19 - i)); --i){

    add(i, i + 1, 0);

    add(i, i + 1, (1 << (19 - i)));

    L -= (1 << (19 - i));

  }



  if (i) add(i, i + 1, 0);



  int val = (1 << (19 - i));



  for (int is = 0; is <= 20; ++is) {

    if ((L >> is)&1) {

      add(max(i, 1), 20 - is, val);

      val += (1 << is);

    }

  }



  while ((--i) > 0)

    add(i, i + 1, 0);



  cout << u.size() << '\n';



  for (int i = 0; i < u.size(); ++i)

    cout << u[i] << ' ' << v[i] << ' ' << c[i] << '\n';

  return 0;



}


// Faster C++ solution for the same problem (measured speedup: 5.198284638488476x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



int n, m, L;

vector<pair<int, int>> adj[25];



void addEdge(int u, int v, int w) {

  ++m;

  adj[u].emplace_back(v, w);

}



int main() {

  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

  cin >> L;

  int r = 0;

  while (1 << (r + 1) <= L) ++r;

  n = r + 1;

  for (int i = 1; i < n; ++i) {

    addEdge(i, i + 1, 0);

    addEdge(i, i + 1, 1 << (i - 1));

  }

  int done = (1 << r) - 1;

  while (done < L - 1) {

    int t = 1;

    while (done + (1 << t) < L) ++t;

    addEdge(t, n, done + 1);

    done += 1 << (t - 1);

  }

  cout << n << " " << m << "\n";

  for (int i = 1; i <= n; ++i)

    for (auto &p: adj[i])

      cout << i << " " << p.first << " " << p.second << "\n";

  return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.124585487157319x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)

#define pb          push_back

#define inf         2e9+5

#define mp          make_pair

#define ll          long long

#define pii         pair<int,int >

#define fileout     freopen("output.txt","w",stdout)

#define filein      freopen("input.txt","r",stdin)

#define mem(x,i)    memset(x,i,sizeof x)

#define PI          acos(-1.0)

#define ff          first

#define ss          second

#define all(x)      x.begin(),x.end()

#define Case(t)     for(int ks=1;ks<=t;ks++)

#define sf          scanf

#define pf          printf

/*------------------------------Graph Moves----------------------------*/

const int fx[]= {+1,-1,+0,+0};

const int fy[]= {+0,+0,+1,-1};

//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move

//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move

//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

/*---------------------------------------------------------------------*/

using namespace std;

//using namespace __gnu_pbds;

//

//template <typename T>  using orderedSet =

//    tree<T, null_type, less<T>,

//    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key

//



ll dp[2020][2020];

const int mod=1000000007;

void nCr()

{

    for(int i=0;i<=2008;i++)

    {

        for(int j=0;j<=i;j++)

        {

            if(j==0 || j==i) dp[i][j]=1;

            else dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%mod;

        }

    }

}



bool vis[1000006];

int main()

{

    int n,n2;

    cin>>n;n2=n;

    vector<pii>adj[30];

    int lg=log2(n);

    int edge=0;

    for(int i=2;i<=lg+1;i++)

    {

        adj[i-1].pb({i,0});

        adj[i-1].pb({i,(1<<(i-2))});

        edge+=2;

    }



    for(int i=0;i<lg;i++)

    {

        if(n &(1<<i))

        {

            adj[i+1].pb({lg+1,n2-(1<<i)});

            n2-=(1<<i);

            edge++;

        }

    }

    cout<<lg+1<<' '<<edge<<endl;

    for(int i=0;i<30;i++)

    {

        for(pii p:adj[i])

        {

            cout<<i<<' '<<p.ff<<' '<<p.ss<<endl;

        }

    }

}


// Faster C++ solution for the same problem (measured speedup: 5.100434965663199x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;

#define N 1000010

int i,n,y,L,cnt;

struct edge {

    int u, v, w;

}e[110];

inline void add(int u,int v,int w) {

    e[++cnt] = (edge) {u, v, w};

}

int main() {

    cin >> L;

    for (i = L; i; ++n, i >>= 1);

    for (i = 1; i < n; ++i)add(i, i + 1, 1 << i - 1), add(i, i + 1, 0);

    for (y = 1 << n - 1, i = 1; L != 1; ++i, L >>= 1)if (L & 1)add(i, n, y), y |= 1 << i - 1;

    printf("%d %d\n", n, cnt);

    for (i = 1; i <= cnt; ++i)printf("%d %d %d\n", e[i].u, e[i].v, e[i].w);

}


// Faster C++ solution for the same problem (measured speedup: 5.020914681112014x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



struct edge {

	int u, v, w;

	edge(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}

};



int main() {

	ios::sync_with_stdio(0);

	cin.tie(0); cout.tie(0);

	int l; cin >> l;

	int n = 32 - __builtin_clz(l);

	vector<edge> g;

	int u = 1;

	for (int i = 1; i < n; i++) {

		g.emplace_back(i, i + 1, u);

		g.emplace_back(i, i + 1, 0);

		u <<= 1;

	}

	for (int i = 0; i < n - 1; i++) {

		if (l >> i & 1) {

			g.emplace_back(i + 1, n, l >> (i + 1) << (i + 1));

		}

	}

	cout << n << ' ' << g.size() << endl;

	for (auto e : g) {

		cout << e.u << ' ' << e.v << ' ' << e.w << "\n";

	}

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.16929725376001x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



struct Data {

	int u, v, w;

	Data(int u = 0, int v = 0, int w = 0) : u(u), v(v), w(w) {}

};



int main() {

	

	ios::sync_with_stdio(0);

	cin.tie(0), cout.tie(0);

	

	int L; cin >> L;

	int n = 32 - __builtin_clz(L);

	vector<Data> edges;

	

	for (int i = 1; i < n; i++) {

		edges.emplace_back(i, i + 1, 1 << i - 1);

		edges.emplace_back(i, i + 1, 0);

	}

	int cur = 1 << n - 1;

	for (int i = n - 2; i >= 0; i--) if (L >> i & 1) {

		edges.emplace_back(i + 1, n, cur);

		cur |= 1 << i;

	}

	

	cout << n << " " << edges.size() << "\n";

	for (auto it : edges) cout << it.u << " " << it.v << " " << it.w << "\n";

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.170047777225485x):
#include <cstdio>



struct Edge {

	int u, v, w;

	Edge(int a = 0, int b = 0, int c = 0) {

		u = a, v = b, w = c;

	}

} edge[100];



int main() {

	int n, ct = 0;

	scanf("%d", &n);

--n;

	int cur = 20;

	while (n) {

		edge[ct++] = Edge(cur - 1, cur, (n + 2) / 2);

		edge[ct++] = Edge(cur - 1, cur, 1 - n % 2);

		if (n % 2 == 0)

			edge[ct++] = Edge(1, cur, 0);

		n = (n - 1) / 2;

		--cur;

	}

	for (int i = 1; i < cur; ++i)

		edge[ct++] = Edge(i, i + 1, 0);

	printf("20 %d\n", ct);

	for (int i = 0; i < ct; ++i)

		printf("%d %d %d\n", edge[i].u, edge[i].v, edge[i].w);

	return 0;

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <climits>

#include <cfloat>

#include <map>

#include <utility>

#include <set>

#include <iostream>

#include <memory>

#include <string>

#include <vector>

#include <algorithm>

#include <functional>

#include <sstream>

#include <complex>

#include <stack>

#include <cstring>

#include <queue>

#include <sys/time.h>

using namespace std;

static const double EPS = 1e-10;

typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)n;i++)

#define rev(i,n) for(int i=(int)n-1;i>=0;i--)

#define all(a) a.begin(),a.end()

#define mp(a,b) make_pair(a,b)

#define pb(a) push_back(a)

#define SS stringstream

#define bitcount(b) __builtin_popcount(b)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)



#define delete(a,n) a.erase(remove(all(a),n),a.end())

#define gcd(a,b) __gcd((a),(b))

#define lcm(a,b) ( (a)/__gcd((a),(b))*(b) )



template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }

template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}

bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 

ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}

string itos(int n){stringstream ss;ss << n;return ss.str();}



int a[50000],b[50000],o[50000];

int main(){

	int H,W,q;

	while(cin >> H >> W >> q && H){

		int ans = 0;

		rep(i,q) cin >> a[i] >> b[i] >> o[i];

		set<int> g[2];

		rev(i,q){

			if(a[i]==0){

				if(!g[0].count(b[i]) && o[i]) ans += W - g[1].size();

				g[0].insert(b[i]);

			}else{

				if(!g[1].count(b[i]) && o[i]) ans += H - g[0].size();

				g[1].insert(b[i]);

			}

		}

		cout << ans << endl;

	}

}

// Faster C++ solution for the same problem (measured speedup: 1.0951589973933773x):
#include <cstdio>

#include <tr1/unordered_set>

using namespace std;

int a[50000],b[50000],o[50000];

int main(){

	int H,W,q;

	while(scanf("%d%d%d",&H,&W,&q)&&H){

		int ans = 0;

		for(int i = 0 ; i < q ; i++)

			scanf("%d%d%d",&a[i],&b[i],&o[i]);

		tr1::unordered_set<int> g[2];

		for(int i = q-1 ; i >= 0 ; i--){

			if(a[i]==0){

				if(!g[0].count(b[i]) && o[i]) ans += W - g[1].size();

				g[0].insert(b[i]);

			}else{

				if(!g[1].count(b[i]) && o[i]) ans += H - g[0].size();

				g[1].insert(b[i]);

			}

		}

		printf("%d\n",ans);

	}

}