akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool flag = false;
  
  if(s.at(0) == s.at(1)) flag = true;
  if(s.at(1) == s.at(2)) flag = true;
  if(s.at(2) == s.at(3)) flag = true;
  
  if(flag){
    cout << "Bad" << endl;
  }else{
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){
	long long n,k;	cin>>n>>k;
	vector< pair<int,int> > a_b(n);
	for(int i=0;i<n;i++){
		int a,b;	cin>>a>>b;
		a_b[i]={a,b};
	}
	sort(a_b.begin(), a_b.end());

	long long now=0;
	for(int i=0;i<n;i++){
		now+=a_b[i].second;
		if(now>=k){
			cout<<a_b[i].first<<endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn dfs(g: &[Vec<(usize, usize)>], col: &mut [usize], d: usize,
       v: usize, par: usize) {
    let n = g.len();
    let mut used = HashSet::new();
    for &(w, idx) in &g[v] {
        if w == par {
            used.insert(col[idx % n]);
            break;
        }
    }
    let mut c = 1;
    for &(w, idx) in &g[v] {
        if w == par { continue; }
        while used.contains(&c) { c += 1; }
        col[idx % n] = c;
        c += 1;
        dfs(g, col, d, w, v);
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        ab: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for (i, &(a, b)) in ab.iter().enumerate() {
        g[a].push((b, i));
        g[b].push((a, n + i));
    }
    let mut d = 0;
    for i in 0..n { d = max(d, g[i].len()); }
    puts!("{}\n", d);
    let mut col = vec![0; n - 1];
    dfs(&g, &mut col, d, 0, n);
    for i in 0..n - 1 {
        puts!("{}\n", col[i]);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 59644
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::size_t K;
  std::string S;
  std::cin >> K >> S;
  std::cout << (S.size() <= K ? S : S.substr(0, K) + "...") << std::endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int o;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return a.o > b.o;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int o = 0, c = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        o++;
      } else {
        if (o) {
          o--;
        } else {
          c++;
        }
      }
    }
    if (o >= c) {
      a.push_back({o, -c});
    } else {
      b.push_back({o, -c});
    }
    sumtop += o - c;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o + it.mn;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o + it.mn;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 11180
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    set<int> req;
    for (int i = 50; i >= 0; --i) {
        vvi dist(51, vi(51, 1 << 28));
        for (int j = 0; j < 51; ++j) {
            dist[j][j] = 0;
        }
        for (auto &r : req) {
            for (int j = 0; j <= 50; ++j) {
                dist[j][j % r] = 1;
            }
        }
        for (int j = i; j >= 1; --j) {
            for (int k = 0; k < 51; ++k) {
                dist[k][k % j] = 1;
            }
        }
        // dist is adjacency matrix, no edge = INF
        for (int i = 0; i < 51; ++i) {
            for (int j = 0; j < 51; ++j) {
                for (int k = 0; k < 51; ++k) {
                    chmin(dist[j][k], dist[j][i] + dist[i][k]);
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < n; ++j) {
            if (dist[a[j]][b[j]] == 1 << 28)
                ok = false;
        }
        if (!ok) {
            if (i == 50) {
                cout << -1 << "\n";
                return 0;
            }
            req.insert(i + 1);
        }
    }
    ll ret = 0;
    for (auto &r : req) {
        ret += 1LL << r;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        double ans = 0;
        for(int i = 1; i <= n; i++){
            long tmp = (long)n;
            if(i >= k){
                ans += 1d/(double)tmp;
                continue;
            }
            int now = i;
            while(now < k){
                now *= 2;
                tmp *= 2;
            }
            ans += 1d/(double)tmp;
        }
        System.out.println(String.format("%.12f", ans));
    }
}


Measured memory_bytes: 21332
//daca nr de A pe poz impare + nr de B poz pare>n/2 nu se poate, altfel se poate
// la fel B,A
#include<iostream>
#define MOD 998244353

using namespace std;

int Fact[10000005],Inv[10000005],P2[10000005];

int put(int a, int b)
{
    int rez=1;
    for(int i=0; (1<<i)<=b; i++)
    {
        if((1<<i)&b)
            rez=(1LL*rez*a)%MOD;
        a=(1LL*a*a)%MOD;
    }
    return rez;
}

int comb(int n, int k)
{
    return (1LL*((1LL*Fact[n]*Inv[k])%MOD)*Inv[n-k])%MOD;
}

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

    int n;
    cin>>n;
    int rez=put(3,n);

    Fact[0]=1;
    for(int i=1; i<=n; i++)
        Fact[i]=(1LL*Fact[i-1]*i)%MOD;

    Inv[n]=put(Fact[n],MOD-2);
    for(int i=n-1; i>=0; i--)
        Inv[i]=(1LL*Inv[i+1]*(i+1))%MOD;

    P2[0]=1;
    for(int i=1; i<=n/2; i++)
        P2[i]=(2LL*P2[i-1])%MOD;

    for(int i=n/2+1; i<=n; i++)
    {
        int act=0;
        act=(act+(2LL*comb(n,i)*P2[n-i]%MOD))%MOD;
        rez=(rez-act+MOD)%MOD;
    }

    cout<<rez<<"\n";
    return 0;
}


Measured memory_bytes: 99072
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,s,n) for(ll i=(s);i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;

vin par(10010);
vin deep(10010);
void init(int n);
int root(int x);
void unite(int x,int y);
bool same(int x,int y);
vector<tuple<int,int,int>> edge(100010);
int v,e;

int kruskal(){
    sort(all(edge));
    init(v);
    int res=0;
    for(auto hen:edge){
        if(!same(get<1>(hen),get<2>(hen))){
            unite(get<1>(hen),get<2>(hen));
            res+=get<0>(hen);
        }
    }
    return res;
}

int main(){
    cin>>v>>e;
    rep(i,e){
        int s,t,w;cin>>s>>t>>w;
        edge[i]=make_tuple(w,s,t);
    }
    cout<<kruskal()<<endl;
}

void init(int n){
    rep(i,n){
        par[i]=i;
        deep[i]=0;
    }
}
int root(int x){
    if(par[x]==x)return x;
    else return par[x]=root(par[x]);
}
void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(deep[x]<deep[y])par[x]=y;
    else{
        par[y]=x;
        if(deep[x]==deep[y])deep[x]++;
    }
}
bool same(int x,int y){
    return root(x)==root(y);
}


Measured memory_bytes: 3976
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int numItems = in.nextInt();

		int[] currencies = new int[numItems];
		for (int i = 0; i < numItems; i++) {
			currencies[i] = in.nextInt();
		}

		System.out.println(maxProfitDP(numItems, currencies));
	}

	public static int maxProfit(int n, int[] R) {
		int max_profit = Integer.MIN_VALUE;
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (R[j] - R[i] > max_profit)
					max_profit = R[j] - R[i];
			}
		}
		return max_profit;
	}

	public static int maxProfitDP(int n, int[] R) {
		int[] profits = new int[n];
		profits[0] = Integer.MIN_VALUE;
		int minVal = R[0];

		for (int i = 1; i < n; i++) {
			profits[i] = Math.max(profits[i - 1], R[i] - minVal);
			minVal = Math.min(minVal, R[i]);
		}

		return profits[n - 1];
	}
}


Measured memory_bytes: 100364
/*its_Rashid*/
#include <bits/stdc++.h>
using namespace std ;

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main ()
{
    fastio
    st s ;
    lli cnt = 0 ;
    cin >> s ;

    for (lli i = 0 ; i  < s . size() ; i ++)
    {
        if (s[i] == '+')
            cnt ++ ;
        else
            cnt -- ;
    }
    cout << cnt ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <stdio.h>
struct circle{
    long double x;
    long double y;
    long double r;
};
long double abs(long double a){
    if(a<0)return -a;
    return a;
}
long double range(circle a,circle b){
    return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int main(){
    int n;
    circle a[2];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++)scanf("%Lf%Lf%Lf",&a[j].x,&a[j].y,&a[j].r);
        if((a[0].r+a[1].r)*(a[0].r+a[1].r)<range(a[0],a[1])){
            printf("0\n");
        }
        else if(range(a[0],a[1])>=abs(a[0].r-a[1].r)*abs(a[0].r-a[1].r)&&range(a[0],a[1])<=(a[0].r+a[1].r)*(a[0].r+a[1].r)){
            printf("1\n");
        }
        else{
            if(a[0].r>a[1].r)printf("2\n");
            else printf("-2\n");
        }
    }
}

Measured memory_bytes: 2600
/*
Created on Thu Aug 27 21:32:39 2020

@author: roastedcoder

*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
const int mod = 1e9+7;
const int INF = INT_MAX;
#define endl "\n"
#define append push_back
#define roastedcoder ios_base::sync_with_stdio(false); cin.tie(NULL);
//__________________________________________________________________

set <int> graph[200001];
int vis[200001];

int dfs(int node) {
	vis[node] = 1;
	int cnt = 1;
	for(auto child : graph[node]) {
		if(vis[child] == 0) {
			cnt += dfs(child);
		}
	}
	return cnt;
}

int main() {
	roastedcoder
	int n, e, a, b;
	cin>>n>>e;
	for(int i = 0; i<e; i++) {
		cin>>a>>b;
		graph[a].insert(b);
		graph[b].insert(a);
	}
	int res = 0;
	for(int i = 1; i<=n; i++) {
		if(vis[i] == 0) {
			int cnt = dfs(i);
			res = max(cnt, res);
		}
	}
	cout<<res<<endl;
}

//__________________________________________________________________
/*
Sample Input:
8 5
1 2
2 3
2 4
3 5
6 7

Sample Output:
3

*/

Measured memory_bytes: 41852
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
	int D,T,S;
	cin>>D>>T>>S;
	int T1;
	T1=D/S;
	if (D%S!=0){
		T1++;
	}
	if (T1<=T){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
int n;
ll a[101];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n){
		cin>>a[i];
	}
	ll ans=1000;
	rep(i,n-1){
		if(a[i]>=a[i+1])
		continue;
		ll s=ans/a[i];
		ans%=a[i];
		ans+=s*a[i+1];
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
int h,w;
string c[101];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void dfs(int x,int y,char s){
  c[x][y]='.';
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    if(0<=nx&&nx<h&&0<=ny&&ny<w){
      if(c[nx][ny]==s){
        dfs(nx,ny,s);
        }
      }
    }
  }
int main(){
  for(int i=0;i<=20;i++){
    cin>>h>>w;
    if(h==0&&w==0)
      break;
    for(int i=0;i<h;i++)
      cin>>c[i];
    int ans=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(c[i][j]!='.'){
          ans++;
          dfs(i,j,c[i][j]);
          }
        }
      }
    cout<<ans<<endl;
    }
  return 0;
  }

  


Measured memory_bytes: 4012
#include <cstdio>
#include <iostream>

using namespace std;

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

	int A[n];
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		A[i] = v;
	}

	int L[n];
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (L[length - 1] < A[i]) {
			L[length++] = A[i];
		} else {
// L[j] (j ??? 0 ?????? lengh-1) ????????§ A[i] ??\?????¨??????????????? j ????????? = A[i]
			int left = 0;
			int right = length;
			int mid = (left + right) / 2;

			while (left < right) {
				if (L[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
				mid = (left + right) / 2;
			}
			L[mid] = A[i];
		}
	}

	cout << length << endl;

	return 0;
}

Measured memory_bytes: 4000
#include<bits/stdc++.h>
using namespace std;
int main(){
  int d,l,a,b;
  int count = 0;

  cin >> d >> l;

  a = d/l;
  count = a;
  if(count != 0 || d<l){
    b = d%l;
    b = b/1;
    count += b;
  }
    cout << count << endl;

  return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>

int main(void){
    int i,n,m;
    for(i=1;;i++){
        scanf("%d %d",&n,&m);
        if (n!=0 || m!=0){
            if(n<m)
                printf("%d %d\n",n,m);
            else
                printf("%d %d\n",m,n);
        }else
            break;
    }
    return 0;
}

Measured memory_bytes: 600
/*{{{*/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/

ll MOD = 1e9+7;
int main() {
  ll n;
  cin >> n;
  vl a((n+1)/2,0);
  REP(i,n){
    ll ai;
    cin >> ai;
    if(ai%2==n%2){
      cout << 0 << endl;
      return 0;
    }
    a[ai/2]++;
  }
  if(n%2==1) a[0]++;
  REP(i,a.size()){
    if (a[i]!=2){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  REP(i,n/2){
    ans *= 2;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define llu unsigned long long
#define ld long double
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector < int >
#define vll vector < ll >
#define pb push_back
#define pf push_front
#define iter :: iterator
#define pii pair < int , int >
#define pll pair < ll, ll >
#define mp make_pair
#define ff first
#define ss second
#define msi multiset < int >
#define msll multiset < ll >
#define pqi priority_queue < int >
#define pqll priority_queue < ll >
#define all(x) x.begin(),x.end()
#define foreach(it,v) for( __typeof((v).begin())it = (v).begin() ; it != (v).end() ; it++ )
#define present(v,x) (v).find(x) != (v).end()
#define cpresent(v,x) (find(all(v),x) != (v).end())
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()
#define endl '\n'
#define shout()  {cout << "I'm Here...!!!" << endl;}
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }

inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

int main()
{
	ios_base::sync_with_stdio(false);
 	cin.tie(NULL);
	
	int n;
	cin >> n;
	int a[n+1][3];
	for(int i=1; i<=n; i++)
		for(int j=0; j<3; j++)
			cin >> a[i][j];
	int dp[n+1][3] = {0};
	for(int i=1; i<=n; i++)
		for(int j=0; j<3; j++)
			dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + a[i][j];
	cout << *max_element(dp[n], dp[n]+3) << endl;
	
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
using namespace std;

int main()
{
  int card1, card2;

  cin >> card1 >> card2;

  if(card1 < card2)
  {
    if (card1 == 1 && card2 != 1)
    {
      cout << "Alice" << endl;
    }
    else
    cout << "Bob"<< endl;
  }
  else if(card1 == card2)
  {
    cout << "Draw" << endl;
  }
  else if (card1 != 1 && card2 ==1)
  {
    cout << "Bob" << endl;
  }
  else
  cout << "Alice" << endl;
}


Measured memory_bytes: 3592
#include<stdio.h>
 
template<typename T>
T gcd(T x,T y){return y?gcd(y,x%y):x;}
 
int main()
{
	int T; scanf("%d",&T);
	unsigned long int A,B,C,D;
	for(;0<T;T--)
	{
		scanf("%ld%ld%ld%ld",&A,&B,&C,&D);
		if(A<B||D<B||C<A%B||C<B-gcd(B,D)) puts("No");
		else puts("Yes");
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define MOD 1000000007
#define mod 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2*1e9


int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<int,pair<int,int> > >v(n);
    pair<int,pair<int,int> >p=make_pair(0,make_pair(0,0));
    for(int i=n-1;i>-1;i--)
    {
        if(s[i]=='R')
            p.first+=1;
        else if(s[i]=='G')
            p.second.first+=1;
        else
            p.second.second+=1;
        v[i]=p;
    }
    lli ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(s[i]=='R')
            {
                if(s[j]=='G')
                {
                    ans+=v[j].second.second;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='B')
                        ans-=1;
                }
                else if(s[j]=='B')
                {
                    ans+=v[j].second.first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='G')
                        ans-=1;
                }
            }
            else if(s[i]=='G')
            {
                if(s[j]=='R')
                {
                    ans+=v[j].second.second;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='B')
                        ans-=1;
                }
                else if(s[j]=='B')
                {
                    ans+=v[j].first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='R')
                        ans-=1;
                }
            }
            else if(s[i]=='B')
            {
                if(s[j]=='R')
                {
                    ans+=v[j].second.first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='G')
                        ans-=1;
                }
                else if(s[j]=='G')
                {
                    ans+=v[j].first;
                    int diff=j-i;
                    int ind=j+diff;
                    if(ind<n and s[ind]=='R')
                        ans-=1;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  k <- readLn
  print $ solve k

solve n
  | even n = -1
  | n `mod` 5  == 0 = -1
  | otherwise = go 7
    where
      go p
        | q == 0 = 1
        | otherwise = 1 + go (10 * q + 7)
          where
            q = p `mod` n


-- Input

getInt :: IO Int
getInt = readLn
second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine
 
getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


Measured memory_bytes: 13096
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long x,y,r,res,l,h,m;
    cin>>x>>y;
    r = y/x;
    l=0,h=62;
    while(l<=h)
    {
    	m=(l+h)/2;
    	if((long long)pow(2,m)<=r)
    	{
    		l=m+1;
    		res=m;
    	}
    	else
    		h=m-1;
    }
    cout<<res+1<<endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int n;
# define rep (i,n) for(int i =0; i < n ; i++)
int N, M;
int P[100000], Y[100000];
vector < int > yd[100001];
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0;i < M;i++) {
		scanf("%d%d",&P[i],&Y[i]);yd[P[i]].push_back(Y[i]);
	}
	for (int i = 0;i < N;i++) {
		sort(yd[i + 1].begin(), yd[i + 1].end());
	}
	for (int i = 0;i < M;i++) {
		printf("%012lld\n", ll(P[i]) * 1000000 + int(lower_bound(yd[P[i]].
			begin(), yd[P[i]].end(), Y[i]) - yd[P[i]].begin()) + 1);
	}
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;

int main(){
	int n, k;
	cin >> n >> k;
	vector<string> stuff(n+1);
	for(int i = 0; i <= n; i++) cin >> stuff[i];
	vector<vector<int> > s(1, vector<int>(1 << (n+1)));
	for(int i = 0; i <= n; i++){
		for(int a = 0; a < (1 << i); a++){
			s[0][a + (1 << i)] = stuff[i][a] - '0';
		}
	}
	vector<vector<int> > ans(n+1);
	for(int b = 0; b <= n; b++){
		vector<int> cnt(1 << b, 0);
		for(int i = 0; i < (1 << b); i++){
			for(int x : s[i]){
				cnt[i] += x;
			}
		}
		ans[b] = cnt;
		if(b == n) break;

		vector<vector<int> > news(1 << (b+1), vector<int>(1 << (n-b), 0));
		for(int len = 1; len <= n-b; len++){
			for(int q = 0; q < 2; q++){
				int st = (1 << (len - 1)) - (1 - q);
				for(int a = st; a < (1 << (n+1-b)); a += (1 << len)){
					for(int i = 0; i < (1 << b); i++){
						news[i + (q << b)][a >> len] += s[i][a];
					}
				}
			}
		}
		for(int i = 0; i < (1 << (b+1)); i++){
			news[i][0] = 0;
		}
		s = news;
	}
	for(int b = n; b >= 0; b--){
		for(int i = 0; i < (1 << b); i++){
			if(ans[b][i] >= k){
				for(int x = b-1; x >= 0; x--){
					cout << ((i >> x) & 1);
				}
				cout << '\n';
				return 0;
			}
		}
	}
}

Measured memory_bytes: 151932
#include <iostream>
#include <queue>
using namespace std;

int h, w, g[1005][1005], ans[1005][1005], vis[1005][1005], ch, cw, dh, dw;
string s;

int main() {
    cin >> h >> w;
    cin >> ch >> cw >> dh >> dw;
    for (int i = 1; i <= h; i++){
        cin >> s;
        for (int j = 1; j <= w; j++){
            if (s[j-1] == '.') g[i][j] = 1;
        }
    }
    priority_queue <pair<int,pair<int,int> >,vector<pair<int,pair<int,int> > >,greater<pair<int,pair<int,int> > > > pq;
    pq.push({0, {ch, cw}});
    while (!pq.empty()){
        int d = pq.top().first, x = pq.top().second.first, y = pq.top().second.second;
        pq.pop();
        if (vis[x][y]) continue;
        ans[x][y] = d;
        vis[x][y] = 1;
        for (int i = max(1, x-2); i <= min(h, x+2); i++){
            for (int j = max(1, y-2); j <= min(w, y+2); j++){
                if (!g[i][j] || vis[i][j]) continue;
                if (abs(i-x)+abs(j-y) == 1){
                    ans[i][j] = ans[x][y];
                    pq.push({ans[i][j], {i, j}});
                }
                else{
                    ans[i][j] = ans[x][y]+1;
                    pq.push({ans[i][j], {i, j}});
                }
            }
        }
    }
    if (!vis[dh][dw]) cout << -1 << "\n";
    else cout << ans[dh][dw] << "\n";
}


Measured memory_bytes: 15688
#include<iostream>
#include<string>
using namespace std;
string s;
bool iscat(int l, int r) {
	if (l > r) return true;
	if (s[l] != 'm' || s[r] != 'w') return false;
	int rec = 0;
	for (int i = l + 1; i < r; i++) {
		if (rec == 0 && s[i] == 'e') return iscat(l + 1, i - 1) && iscat(i + 1, r - 1);
		else if (s[i] == 'm') rec++;
		else if (s[i] == 'w') rec--;
		if (rec < 0) return false;
	}
}
int main() {
	cin >> s;
	cout << (iscat(0, s.size() - 1) ? "Cat" : "Rabbit") << endl;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	cout<<(1+(b-a-1))*(b-a-1)/2-a<<'\n';
	return 0;
}


Measured memory_bytes: 256
#76a
R = int(input()) #now rating
G = int(input()) #target rating

#現在のレーティングを aとする。
#次のコンテストで, パフォーマンス bを取ったとする。
#そのとき, レーティングは aと b の平均まで変化する。 
#after rating = (a+b)/2
#→G = (R+b)/2
# →2*G = R+b
#  →b = 2*G -R
print(2*G-R)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

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; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int calc(int& a, int& b, int& c)
{
  return a * 10 + b + c;
}

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (a - b >= 0) {
    cout << "delicious" << endl;
  } else if (b - a > x) {
    cout << "dangerous" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
#include <algorithm>
#include <vector>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  int H,W;
  cin>>H>>W;
  char s[1000][1000];
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cin>>s[i][j];
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      int cnt=0;
      if(s[i][j]=='.'){
        if(s[i][j+1]=='#'){cnt++;}
        if(s[i][j-1]=='#'){cnt++;}
        if(s[i+1][j]=='#'){cnt++;}
        if(s[i-1][j]=='#'){cnt++;}
        if(s[i+1][j+1]=='#'){cnt++;}
        if(s[i-1][j-1]=='#'){cnt++;}
        if(s[i-1][j+1]=='#'){cnt++;}
        if(s[i+1][j-1]=='#'){cnt++;}
        s[i][j]=(char)(cnt+'0');
      }
    }
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      cout<<s[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

string s;
ll ans = 0;
void sum(ll i, ll sum_num, ll num){
  //cout << i << " " << sum_num << endl;
  
  if (i == s.size()) {
    ans += sum_num + num;
  } else {  
    sum(i+1,sum_num, num*10 + s[i]-'0');
    sum(i+1,sum_num+num, s[i]-'0');
  }
}

int main() {

  cin >> s;
  sum(1,0,s[0]-'0');
  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;

void call(int n){

    int x;
    
    for(int i=1; i<=n; i++){
        x = i ;
        if(x%3==0){
            cout<< " " << i;
             continue;
        }
        
        while(1){
            if(x%10==3){
            cout << " " << i;
            break;
            }
            x /=  10;
             if(x==0)break;
        }
    }
}

int main(){
    int f;
   cin >> f;
  call(f);
  
   cout << endl;
} 


Measured memory_bytes: 3104
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
#include <map>
#include <ctime>
#include <cstdlib>
#include <random>
#include <unistd.h>
using namespace std;

#define int long long

signed main(){
	char a;
	cin >> a;
	if(a <= 'Z')cout << "A" << endl;
	else cout << "a" << endl;
	return 0;
}

Measured memory_bytes: 3584
#include        <bits/stdc++.h>
using   namespace       std;

bool    F2(string &s, int a, int b, char c) {
        a--;
        b--;
        for (int i=a; i<b; i++)
                if (c==s.at(i))
                        if (c==s.at(i+1))
                                return true;
        return false;
};

bool    F3(string &s, int a, int b, char c) {
        a--;
        b--;
        for (int i=a; i<b-1; i++)
                if (c==s.at(i))
                        if (c==s.at(i+1))
                                if (c==s.at(i+2))
                                        return true;
        return false;
};

int     main() {
        int N, A, B, C, D;
        string S;
        cin >>N >>A >>B >>C >>D >>S;
        if (F2(S, A, C, '#')) {
                cout <<"No" <<endl;
                return 0;
        }
        if (F2(S, B, D, '#')) {
                cout <<"No" <<endl;
                return 0;
        }
        if (C>D)
                if (!F3(S, B-1, D+1, '.')) {
                        cout <<"No" <<endl;
                        return 0;
                }
        cout <<"Yes" <<endl;
        return 0;
}

Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  a=[]
  b=[]
  for x in l:
    if len(a)>0:
      if x==a[-1]:
        a.pop()
        b.append(x)
      else:
        a.pop()
        a.append(x)
    else:
      a.append(x)

  b.sort()

  if len(b)<2:
    return 0

  return b[-1]*b[-2]

print(main())


Measured memory_bytes: 17160
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)
     swap(a,b);
     if(a>c)
     swap(a,c);
     if(b>c)
     swap(b,c);
     cout<<a<<" "<<b<<" "<<c << endl;

    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

// left or right
int board[1010][110][2];
void solve(int r, int c, int prev) {
    if(r == 1001) {
        cout << c << endl;
        return;
    }
    if(board[r][c][1] && prev != 0) {
        solve(r, c+1, 1);
    }
    else if(board[r][c][0] && prev != 1) {
        solve(r, c-1, 0);
    }
    else solve(r+1, c, -1);
}
signed main() {
    int n, m, a;
    while(cin >> n >> m >> a, n || m || a) {
        memset(board, 0, sizeof(board));
        rep(i,0,m) {
            int h, p, q; cin >> h >> p >> q;
            board[1001-h][p][1] = 1;
            board[1001-h][q][0] = 1;
        }
        solve(0, a, -1);
    }
    return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    vector<string> S(N);
    for (int i = 0; i < N; i++)
    {
        cin >> S[i];
    }

    ll ans = 0;

    int a = 0;
    for (int b = 0; b < N; b++)
    {
        bool can = true;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                int newX = (i + a) % N;
                int newY = (j + b) % N;

                int newA = (newY - a);
                int newB = (newX - b);

                if(newA < 0){
                    newA+=N;
                }
                if(newB < 0){
                    newB+=N;
                }
                if (S[i][j] != S[newA][newB])
                {
                    can = false;
                }
            }
        }

        if (can)
        {
            ans++;
        }
    }

    cout << ans * N << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    int ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ans = max(ans, abs(A[i] - A[j]));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main(){
    int x;
    cin >> x;
    long long ans1 = 1;
    long long ans2 = 2;
    for(int i = 0; i < x; i++){
        ans1 *= 2;
        ans1 += 2;
        ans2 *= 2;
        ans2 += 2;
    }
    cout << max(ans1,ans2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef int64_t ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

bool solve(const string s, vector<char>& ans) {
  int n = s.size();  
  for (int i = 1; i < n - 1; i++) {
    if ((ans[i] == 'S' && s[i] == 'o') || (ans[i] == 'W' && s[i] == 'x')) {
      ans[i+1] = ans[i-1];
    }
    if ((ans[i] == 'S' && s[i] == 'x') || (ans[i] == 'W' && s[i] == 'o')) {
      if (ans[i-1] == 'W') ans[i+1] = 'S';
      if (ans[i-1] == 'S') ans[i+1] = 'W';
    }
  }

  if ((ans[n-1] == 'S' && s[n-1] == 'o') || (ans[n-1] == 'W' && s[n-1] == 'x')) {
    if (ans[n-2] != ans[0]) return false;
  }

  if (ans[0] == 'S' && s[0] == 'o' || (ans[0] == 'W' && s[0] == 'x')) {
    if (ans[n-1] != ans[1]) return false;
  }

  if ((ans[n-1] == 'S' && s[n-1] == 'x') || (ans[n-1] == 'W' && s[n-1] == 'o')) {
    if (ans[n-2] == ans[0]) return false;
  }

  if ((ans[0] == 'S' && s[0] == 'x') || (ans[0] == 'W' && s[0] == 'o')) {
    if (ans[n-1] == ans[1]) return false;
  }

  return true;
}

void print_vec(const vector<char> ans) {
  for (auto c : ans) {
    printf("%c", c);
  }
  printf("\n");
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<char> ans(n);
  ans[0] = 'S';
  ans[1] = 'S';
  if (solve(s, ans)) {
    print_vec(ans);
    return 0;
  }

  ans[0] = 'S';
  ans[1] = 'W';
  if (solve(s, ans)) {
    print_vec(ans);
    return 0;
  }

  ans[0] = 'W';
  ans[1] = 'S';
  if (solve(s, ans)) {
    print_vec(ans);
    return 0;
  }

  ans[0] = 'W';
  ans[1] = 'W';
  if (solve(s, ans)) {
    print_vec(ans);
    return 0;
  }
    
  puts("-1");
  
  return 0;
}


Measured memory_bytes: 720