akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
from collections import deque

mod = 10 ** 9 + 7
N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

##### Settings
unit = 1
merge = lambda a, b: a * b % mod
adj_bu = lambda a, i: a * inv(SIZE[i]) % mod
adj_td = lambda a, i, p: a * inv(N-SIZE[i]) % mod
adj_fin = lambda a, i: a * fa[N-1] % mod
#####

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod

inv = lambda i: fainv[i] * fa[i-1] % mod

SIZE = [1] * N
for i in reversed(R[1:]):
    SIZE[P[i]] += SIZE[i]

ME = [unit] * N
XX = [0] * N
TD = [unit] * N
for i in reversed(R[1:]):
    XX[i] = adj_bu(ME[i], i)
    p = P[i]
    ME[p] = merge(ME[p], XX[i])
XX[R[0]] = adj_fin(ME[R[0]], R[0])

for i in R:
    ac = TD[i]
    for j in X[i]:
        TD[j] = ac
        ac = merge(ac, XX[j])
    ac = unit
    for j in reversed(X[i]):
        TD[j] = adj_td(merge(TD[j], ac), j, i)
        ac = merge(ac, XX[j])
        XX[j] = adj_fin(merge(ME[j], TD[j]), j)

print(*XX, sep = "\n")

Measured memory_bytes: 109972
#include<bits/stdc++.h>
using namespace std;
 
typedef    long long          ll;
typedef    vector<long long>    vi; 
typedef    vector<vi>         vvi; 
typedef    pair<long,long>      ii; 
#define    sz(a)              long((a).size()) 
#define    pb                 push_back 
#define    mp                   make_pair
#define    all(c)             (c).begin(),(c).end() 
#define    tr(c,i)            for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define    present(c,x)       ((c).find(x) != (c).end()) 
#define    cpresent(c,x)      (find(all(c),x) != (c).end())  
#define    input(v,n)           for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define    output(v,n)          for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}\n";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
 
ll mod = 1e9 + 7;


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

  ll n,i,j;
  cin>>n;
  string s;
  cin>>s;

  vector< vi  > dp(n+3,vi(n+3,0));

  dp[0][1]=1;

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

    for(j=1;j<=i+2;j++)
    {
      if(s[i]=='>')
      {
        dp[i+1][j]=(dp[i][i+1]-dp[i][j-1])%mod;
      }
      else 
      {
        dp[i+1][j]=(dp[i][j-1]-dp[i][0])%mod;
      }
    }

    for(j=1;j<=i+2;j++)
      {dp[i+1][j]+=dp[i+1][j-1];dp[i+1][j]%=mod;}
  }

  //debug(dp);

  cout<<(dp[n-1][n]+mod)%mod;




  return 0;
}


Measured memory_bytes: 72832
while True:
    H, W = map(int, input().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if (i + j) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")
        print()
    print()

Measured memory_bytes: 9020
n,tl=map(int,input().split())
c=[]
t=[]
cl=[1001]
for i in range (n):
    c1,t1=[int(i) for i in input().split()]
    c.append(c1)
    t.append(t1)

for i in range(n):
    if  int(t[i])<=tl:
        cl.append(c[i])
if min(cl)==1001:
    print('TLE')
else:
    print(min(cl))

Measured memory_bytes: 3064
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.*;

public class Main {

  private static void solve(int[][] points, int d) {
    int cnt = 0;
    for (int[] p : points) {
      if (dist(p[0], p[1]) <= d) {
        cnt++;
      }
    }
    System.out.println(cnt);
  }

  private static double dist(int x, int y) {
    BigDecimal i = BigDecimal.valueOf(x);
    BigDecimal j = BigDecimal.valueOf(y);
    return i.multiply(i).add(j.multiply(j)).sqrt(MathContext.DECIMAL64).doubleValue();
  }

  public static void main(String[] args) {
    int n = scanner.nextInt();
    int d = scanner.nextInt();
    int[][] points = new int[n][2];
    for (int j = 0; j < n; j++) {
      points[j][0] = scanner.nextInt();
      points[j][1] = scanner.nextInt();
    }
    solve(points, d);
  }

  private static final Scanner scanner = new Scanner(System.in);
}


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

int main() {
  // int A,B,C;

  // cin >> A >> B >> C;
  // if (A == B  && B == C && C == A) {
  //   cout << "No" << endl;
  // } 
  // else if (A != B && B != C && A != C)
  // {
  //   cout << "No" << endl;
  // }
  // else {
  //   cout << "Yes" << endl;
  // }
  // int N;
  // cin >> N;
  // vector<int> A(N);
  // for (int i = 0; i < N; i++) {
  //   cin >> A.at(i);
  // }
  // string ans = "APPROVED";
  // for (int i = 0; i < N; i++)
  // {
  //   if (A.at(i) % 2 != 0) {
  //     continue;
  //   }
  //   if (A.at(i) % 3 == 0 || A.at(i) % 5 == 0) {
  //     continue;
  //   } else {
  //     ans = "DENIED";
  //     break;
  //   }
  // }
  // cout << ans << endl;
  int N;
  cin >> N;
  vector<string> S(N);
  map<string, int> count;
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  for (int i = 0; i < N; i++)
  {
    if (count.count(S.at(i)) == 0) {
      count[S.at(i)] = 1;
    } else {
      count[S.at(i)] += 1;
    }
  }
  int max_num = 0;
  int pre_max = 0;
  vector<string> ans;
  for (auto it = count.begin(); it != count.end(); ++it) {
    max_num = max(max_num, it->second);
    if (pre_max < it->second) {
      ans = {};
    }
    if (it->second == max_num) {
      ans.push_back(it->first);
    }
    pre_max = max(max_num, it->second);
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans.at(i) << endl;
  }
}

Measured memory_bytes: 28916
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  priority_queue<ll> pq;

  while (true) {
    string s; cin >> s;
    if (s == "end") break;
    if (s == "extract") {
      outl(pq.top());
      pq.pop();
    } else {
      ll k; cin >> k;
      pq.push(k);
    }
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



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

ll N, ans;

int main() {
    cin >> N;
    // findAllDivisors
    vector<ll> divisors;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i) continue;
        divisors.push_back(i);
        if (i * i != N) divisors.push_back(N / i);
    }

    // solve
    rep(i, divisors.size()) {
        ll now = divisors[i] - 1;
        if (now == 0) continue;
        if (N / now == N % now) ans += now;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, m; cin >> n >> m;
	vector<vector<int>> d(n, vector<int>(m));

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> d[i][j];
		}
	}

	set<int> s;
	for (int i = 0; i < 10000; i++) {
		s.insert(i*i);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			int val = 0;
			for (int k = 0; k < m; k++) {
				int diff = abs(d[i][k] - d[j][k]);
				val += diff * diff;
			}

			if (s.count(val))ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;

    ll Xabs = abs(X);
    if (Xabs / D >= K) {
        cout << Xabs - D * K << endl;
        return 0;
    }
    ll Xrest = Xabs % D;
    ll Krest = K - (Xabs / D);
    if (Krest %2 == 0) {
        cout << Xrest << endl;
    } else {
        cout << abs(Xrest - D) << endl;
    }
}

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

using namespace std;

#define ll 			long long
#define db			double
#define up(i,j,n)		for (int i = j; i <= n; i++)
#define down(i,j,n)	for (int i = j; i >= n; i--)
#define cadd(a,b)		a = add (a, b)
#define cpop(a,b)		a = pop (a, b)
#define cmul(a,b)		a = mul (a, b)
#define pr			pair<int, int>
#define fi			first
#define se			second
#define SZ(x)		(int)x.size()
#define bin(i)		(1 << (i))
#define Auto(i,node)	for (int i = LINK[node]; i; i = e[i].next)

template<typename T> inline bool cmax(T & x, T y){return y > x ? x = y, true : false;}
template<typename T> inline bool cmin(T & x, T y){return y < x ? x = y, true : false;}
template<typename T> inline T dmax(T x, T y){return x > y ? x : y;}
template<typename T> inline T dmin(T x, T y){return x < y ? x : y;}

const int MAXN = 2e5 + 5;

int N, a[MAXN];

int main(){
#ifdef cydiater
	freopen("input.in", "r", stdin);
#endif
	scanf("%d", &N);
	up (i, 1, N) scanf("%d", &a[i]);
	ll ans = 0; int cur = 0;
	down (i, N, 1) {
		if (a[i] == cur) {
			cur--;
			cmax(cur, 0);
		}else if (a[i] < cur) return 0 * puts("-1");
		else {
			if (i - a[i] >= 1) {
				ans += a[i];
				cur = a[i] - 1;
				cmax(cur, 0);
			}else return 0 * puts("-1");
		}
	}
	printf("%lld\n", ans);
	return 0;
}



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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int n, ac = 0, wa= 0, tle =0, re=0;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		if (s == "AC") {
			++ac;
		} else if (s == "WA") {
			++wa;
		} else if (s == "TLE") {
			++tle;
		} else {
			++re;
		}
	}
	cout << "AC x " << ac << nl;
	cout << "WA x " << wa << nl;
	cout << "TLE x " << tle << nl;
	cout << "RE x " << re << nl;

}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}


//ここまでライブラリ
//ここから本文


int main() {
	int n, t;
	cin >> n >> t;
	int c, a;
	int mini = 100000000;
	for (int i = 0; i < n; i++) {
		cin >> c >> a;
		if (a <= t) {
			if (mini > c) mini = c;
		}
	}
	if (mini == 100000000) {
		cout << "TLE" << endl;
	}
	else {
		cout << mini << endl;
	}
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
m=[]
p=[]
s=0
c=0
for i in range(n):
    s+=abs(a[i])
    if a[i]<0:
        c+=1
        c%=2
        m.append(a[i])
    else:p.append(a[i])
if c==0:print(s)
else:
    m.sort()
    if len(p)==0:
        print(s+2*m[-1])
        exit()
    p.sort()
    if abs(m[-1])>abs(p[0]):print(s+m[-1]-p[0]-m[-1]-p[0])
    else:print(s+m[-1]*2)

Measured memory_bytes: 14464
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let A1: usize = sc.get();
    let A2: usize = sc.get();
    let A3: usize = sc.get();
    if A1 + A2 + A3 >= 22 {
        println!("bust");
    } else {
        println!("win");
    }
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int f(int n){
  return (n*n+4)/8;
}

int main(){
  string s; cin >> s;
  int bt = 0;
  for(auto e:s){
    bt ^= (1<<(e-'a'));
  }
  cout << (bt == 0 ? "Yes" : "No") << endl;
}



Measured memory_bytes: 3608
n = int(input())

A =[int(x) for x in input().split()]
B =[int(x) for x in input().split()]
C =[int(x) for x in input().split()]

ans = 0
ans = sum(B)

for i in range(n-1):
    
    if((A[i]+1)==A[i+1]):
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); ++i)
const int INF = 1 << 30;
using namespace std;

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

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

  int n; cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int dp[100010] = {};
  rep(i, n) dp[i] = INF;
  dp[0] = 0;

  rep(i, n) {
    chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
    chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
  }
  cout << dp[n-1] << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

vector<int> Spath, Tpath;

struct circle {
  int x, y, r;
  vector<int> e;
};

vector<circle> S, T;

bool asc(const circle& a, const circle& b) {
  return a.r < b.r;
}

double dist(int x0, int y0, int x1, int y1) {
  return sqrt((x0-x1)*(x0-x1)+(y0-y1)*(y0-y1));
}

bool include(circle a, circle b) {//a???b??????????????????
  if(dist(a.x, a.y, b.x, b.y)+b.r < a.r)
    return true;
  else
    return false;
}

bool intersect(circle a, circle b) {
  if(dist(a.x, a.y, b.x, b.y) <= a.r + b.r)
    return true;
  else
    return false;
}

void S_search(int x) {
  if(Spath[x] < 0) {
    if(S[x].e.size() > 0) {
      int m = -1;
      for(int i = 0; i < S[x].e.size(); i++) {
	if(Spath[S[x].e[i]] > 0) {//already search
	  if(m < Spath[S[x].e[i]]) m = Spath[S[x].e[i]];
	}
	else {//not yet search
	  S_search(S[x].e[i]);
	  if(m < Spath[S[x].e[i]]) m = Spath[S[x].e[i]];
	}
      }
      Spath[x] = m+1;
    }
    else
      Spath[x] = 1;
  }
}

void T_search(int x) {
  if(Tpath[x] < 0) {
    if(T[x].e.size() > 0) {
      int m = -1;
      for(int i = 0; i < T[x].e.size(); i++) {
	if(Tpath[T[x].e[i]] > 0) {//already search
	  if(m < Tpath[T[x].e[i]]) m = Tpath[T[x].e[i]];
	}
	else {//not yet search
	  T_search(S[x].e[i]);
	  if(m < Tpath[T[x].e[i]]) m = Tpath[T[x].e[i]];
	}
      }
      Tpath[x] = m+1; 
    }
    else {
      Tpath[x] = 1;
    }
  }
}
    

int main() {
  while(true) {
    int n, xt, yt, xs, ys, x, y, r;
    cin >> n;
    if(n == 0) break;
    cin >> xs >> ys >> xt >> yt;
    for(int i = 0; i < n; i++) {
      cin >> x >> y >> r;
      double ds, dt;
      ds = dist(x, y, xs, ys);
      dt = dist(x, y, xt, yt);
      if((ds > r) && (dt < r)) {//??´???????????????
	circle tmp;
	tmp.x = x; tmp.y = y; tmp.r = r;
	T.push_back(tmp);
      }
      else if((ds < r) && (dt > r)) {//?????????????????????
	circle tmp;
	tmp.x = x; tmp.y = y; tmp.r = r;
	S.push_back(tmp);
      }
    }
    if(S.size() > 0) sort(S.begin(), S.end(), asc);
    if(T.size() > 0) sort(T.begin(), T.end(), asc);	       
    for(int i = 0; i < S.size(); i++) {
      for(int j = 0; j < S.size(); j++) {
	if(include(S[i], S[j])) S[i].e.push_back(j);
      }
      Spath.push_back(-1);
    }
    for(int i = 0; i < T.size(); i++) {
      for(int j = 0; j < T.size(); j++) {
	if(include(T[i], T[j])) T[i].e.push_back(j);
      }
      Tpath.push_back(-1);
    }
    for(int i = 0; i < S.size(); i++) {
      S_search(i);
    }
    for(int i = 0; i < T.size(); i++) {
      T_search(i);
    }
    int maxS = 0, maxT = 0, maxST = 0;
    if(S.size() > 0) maxS = *max_element(Spath.begin(), Spath.end());
    if(T.size() > 0) maxT = *max_element(Tpath.begin(), Tpath.end());
    for(int i = 0; i < S.size(); i++) {
      for(int j = 0; j < T.size(); j++) {
	if(!intersect(S[i], T[j])){
	  if(maxST < Spath[i]+Tpath[j]) maxST = Spath[i]+Tpath[j];
	}
      }
    }
    cout << max({maxS, maxT, maxST}) << endl;
    S.clear();
    T.clear();
    Spath.clear();
    Tpath.clear();
  }
  return 0;
}
	  

Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    string s; cin >> s;
    int n = s.size();
    bool ans = true;
    rep(i,(n-1)/2){
        char a = s[i];
        char b = s[(n-1)/2-i-1];
        char c = s[(n-1)/2+i+1];
        char d = s[n-1-i];
        if(!(a == b && b == c && c == d)){
            ans = false;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

inline ll min(ll a, ll b) {
	return a < b ? a : b;
}

const int Max = 1e5 + 12;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, A[Max], B[Max]; 
	ll ans = 0;
	cin >> N;
	for (ll i = 1; i <= N + 1; ++i) {
		cin >> A[i];
	}
	for (ll i = 1; i <= N; ++i) {
		cin >> B[i];
	}
	int i = N;
	while (i >= 1) {
		int V = min(A[i + 1], B[i]); A[i + 1] -= V; B[i] -= V; ans += V;

		V = min(A[i], B[i]); A[i] -= V; B[i] -= V; ans += V;
		--i;
	}
	cout << ans;
	//system("pause");
	return 0;
}


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

int main() {
     string str; cin>>str; int len=str.length();
     int arr[4]={};
     for (int i = 0; i < 4; ++i)
     {
    // cout<<arr[i]<<" " ;
     }
     //cout<<"\n";K
     for (int i = 0; i < len; ++i)
     {
         if(str[i]=='N'){arr[0]=1;}
         else if (str[i]=='S'){arr[2]=1;}
         else if (str[i]=='E'){arr[1]=1;}
         else if(str[i]=='W'){arr[3]=1;}
     }
     for (int i = 0; i < 4; ++i)
     {
     //cout<<arr[i]<<" " ;
     }
  if(arr[0]==arr[2] && arr[1]==arr[3]){cout<<"Yes";}
  else {cout<<"No";}

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define MAX_N 100005
int par[MAX_N]; //親
int ran[MAX_N]; //木の深さ

//n要素で初期化
void init(int n) {
    rep(i,n) {
		par[i] = i; ran[i] = 0;
	}
}

//木の根を求める
int root(int x){ return par[x]==x ? x : par[x]=root(par[x]); }

//x,yの属する集合の併合
void unite(int x, int y) {
	x = root(x); y = root(y);
	if(x == y) return ;

	if(ran[x] < ran[y]) par[x] = y;
	else {
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}

//x,yが同じ集合に属するか
bool same(int x, int y) { return root(x) == root(y); }

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

    int N, M; cin >> N >> M;
    vei p(N); rep(i,N) { cin >> p[i]; p[i]--; par[i] = i; }
    rep(i,M) {
        int x, y; cin >> x >> y; x--; y--;
        unite(x, y);
    }
    int cnt = 0;
    rep(i,N) if( same(i, p[i]) ) cnt++;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 1408
N = int(input())
X = input()

cnt = X.count("1")
res0 = 0
res1 = 0
for i in range(N):
    if X[i] == "1":
        res0 = (res0 + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)

        if cnt - 1 > 0:
            res1 = (res1 + pow(2, N - i - 1, cnt - 1)) % (cnt - 1)

for i in range(N):
    ans = 0
    if X[i] == "0":
        div = cnt + 1
        tmp = (res0 + pow(2, N - i - 1, div)) % div
        ans += 1
    else:
        if cnt - 1 > 0:
            div = cnt - 1
            tmp = (res1 + div - pow(2, N - i - 1, div)) % div
            ans += 1
        else:
            tmp = 0

    while tmp > 0:
        ans += 1
        div = bin(tmp).count("1")
        tmp %= div
        
    print(ans)


Measured memory_bytes: 79768
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int ans[N+1]={};
    for(int i=1;i<=100;i++) for(int j=1;j<=100;j++) for(int k=1;k<=100;k++){
        int res=i*i+j*j+k*k+i*j+j*k+k*i;
        if(res<=N) ans[res]++;
    }
    for(int i=1;i<=N;i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P =pair<int,int>;

int main(){
    ll n;
    cin >> n;
    vector <ll> s(n+1,n+1);
    ll c;
    rep(i,n){
        cin >> c;
        s[c]=i;
    }

    int k=1,kmax=0;
    rep(i,n){
        if(s[i]<s[i+1]){
            ++k;
        }
        else{
            kmax=max(k,kmax);
            k=1;
        }
    }

    kmax=max(k,kmax);

    cout << n-kmax << endl;
    

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int a,b;
    string s;
    cin>>a>>b>>s;
    for (int i=0;i<s.size();i++) {
        if (i==a&&s[i]!='-'||i!=a&&!isdigit(s[i])) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC158D
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            int Q = int.Parse(Console.ReadLine());
            string[] Query = new string[Q];
            for(int i = 0; i < Q; i++)
            {
                Query[i] = Console.ReadLine();
            }
            List<string> LeftReverse = new List<string>();
            List<string> Center = new List<string>();
            List<string> Right = new List<string>();
            for (int i = 0; i < S.Length; i++)
            {
                Center.Add(S[i].ToString());
            }
            bool hanten = false;
            for(int i = 0; i < Q; i++)
            {
                if (Query[i][0].ToString() == "1")
                {
                    if (hanten == true)
                    {
                        hanten = false;
                    }
                    else
                    {
                        hanten = true;
                    }
                }
                else if (Query[i][0].ToString() == "2")
                {
                    if (Query[i][2].ToString() == "1")
                    {
                        if (hanten == true)
                        {
                            Right.Add(Query[i][4].ToString());
                        }
                        else
                        {
                            LeftReverse.Add(Query[i][4].ToString());
                        }
                        
                    }
                    else if (Query[i][2].ToString() == "2")
                    {
                        if (hanten == false)
                        {
                            Right.Add(Query[i][4].ToString());
                        }
                        else
                        {
                            LeftReverse.Add(Query[i][4].ToString());
                        }
                    }
                }
            }
            List<string> ans = new List<string>();
            for(int i = LeftReverse.Count-1; i >= 0; i--)
            {
                ans.Add(LeftReverse[i]);
            }
            for (int i = 0; i < Center.Count; i++)
            {
                ans.Add(Center[i]);
            }
            for (int i = 0; i < Right.Count; i++)
            {
                ans.Add(Right[i]);
            }
            if (hanten == true)
            {
                ans.Reverse();
            }
            Console.WriteLine(string.Join("", ans));
        }
    }
}


Measured memory_bytes: 64608
n = gets.to_i
a = []
idx = 1
n.times do
  x,y = gets.split
  y = y.to_i
  a.push( [ x, y, idx ] )
  idx += 1
end

a.sort!{ |a, b| ( a[0] <=> b[0] ).nonzero? || (b[1] <=> a[1] ) }
a.each do |x|
  puts x[2]
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main ()  
{  
    int n;  
    cin>>n;
    if(n>=2&&n<=100000)
	{
		int a=0,b=0,m,t;  
    	for(int i=0;i<n;i++)  
    	{  
        	cin>>t;
			if(t<1&&t>1000000000)
			goto loop;  
        	if(t%2==0)  
        	a++;  
        	if(t%4==0)  
        	b++;  
    	}  
    	m=a-b;  
    	if(n<=2*b+m&&m!=0)  
    	cout<<"Yes";  
    	else if(n<=2*b+1&&m==0)  
    	cout<<"Yes";  
    	else  
    	loop: cout<<"No";  
	}
    cout<<endl;
    return 0;
}  

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	for(int i=0;i<a.length();i++)
	{
		cout<<a[i];
		if(i<b.length())cout<<b[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int si;
  si = s.size();
  sort(s.begin(),s.end());
  int c[30];
  for(int i=0;i<30;i++)c[i] = 0;
  for(int i = 0; i < si; i++){
    c[s[i] - 'a']++;
  }
  for(int i = 0;i < 26;i++){
    if(c[i] == 0){
      cout << (char)(i + 'a') << endl;
  	  return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 512
n = int(input())
l = [int(input()) for i in range(n)]
def f():
  ans = sum(l)
  if ans % 10 == 0:
    for i in sorted(l):
      if not (ans - i) % 10 == 0:
        return ans-i
    return 0
  else:
    return ans

print(f())

Measured memory_bytes: 2940
#include <iostream>
#include <fstream>

using namespace std;



int main(){
    int n,a,b,c,d;
    cin>>n;
    a=n%10;
    b=n/10%10;
    c=n/100%10;
    d=n/1000%10;
    if(a==b|| b==c|| c==d)
    {
        cout<<"Bad";
    }
    else{
        cout<<"Good";
    }
    return 0;
}
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  vbool judge(n,true);
  vint a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  rep(i,n){
    if(judge[a[i]] && a[a[i]] == i){
      ans++;
      judge[i] = false;
      judge[a[i]] = false;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdint>
#include <iostream>

using namespace std;

int64_t DigitSum(int64_t num)
{
    int64_t sum = 0;
    while (num > 0) {
        sum += num % 10;
        num /= 10;
    }
    return sum;
}

double Rate(int64_t num)
{
    return 1.0 * num / DigitSum(num);
}

int64_t Digits(int64_t num)
{
    int64_t digits = 0;
    while (num > 0) {
        digits += 1;
        num /= 10;
    }
    return digits;
}

int64_t Next(int64_t num)
{
    if (num < 9) {
        return num + 1;
    }

    num += 1;

    int64_t best_next = num;
    double best_rate = Rate(num);

    int64_t digits = Digits(num);
    int64_t power = 1;
    for (int64_t i = 0; i < digits; i += 1) {
        num -= num / power % 10;
        num += 9 * power;
        power *= 10;

        auto rate = Rate(num);
        if (rate < best_rate) {
            best_next = num;
            best_rate = rate;
        }
    }
    return best_next;
}

int main()
{
    int64_t nums;
    cin >> nums;

    int64_t curr = 1;
    for (int64_t i = 0; i < nums; i += 1) {
        cout << curr << "\n";
        curr = Next(curr);
    }

    return 0;
}


Measured memory_bytes: 256
package main
import "fmt"
func main(){
    var h, n int
    fmt.Scan(&h,&n)
    var sum int
    for i := 0; i < n; i++{
        var a int
        fmt.Scan(&a)
        sum += a
    }
    if sum >= h{
        fmt.Println("Yes")
    }else{
        fmt.Println("No")
    }
}


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

int main() {
  int N ,A ,B ,C ,D;
  cin >> N;
  A = N / 1000;
  B = N % 1000 / 100;
  C = N % 100 / 10;
  D = N % 10;
  
  if((A == B && B== C)  || (B == C && C == D)){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a, b, k=0, p=0, i, j;
    cin>>a;
    string s;
    vector<string>v;
    for(i=0; i<a; i++){
        cin>>s;
        sort(s.begin(), s.end());
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    for(i=1; i<v.size(); i++){
        if(v[i]==v[i-1]){
            k++;
            p=p+k;
        }
        else{
            k=0;
        }
    }
    cout<<p<<endl;
    return 0;
}




Measured memory_bytes: 5748
#include<stdio.h>
#define INFINITY (1<<30)
#define N 500000
int n,cnt = 0;
void merge(int *A, int left, int mid, int right){
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  int L[n1+1], R[n2+1];
  for(i = 0; i < n1; i++) L[i] = A[left + i];
  for(i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
      cnt++;
    }else{
      A[k] = R[j];
      j++;
      cnt++;
    }
  }
}
void mergeSort(int *A, int left, int right){
  int mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
int main(){
  int i;
  int a[N];
  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&a[i]);
  mergeSort(a,0,n);
  for(i = 0; i < n; i++){
    if(i != n - 1) printf("%d ",a[i]);
    else printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}




Measured memory_bytes: 5632
#include<stdio.h>
int X=1000000;
int WHITE=0;
int GRAY=1;
int BLACK=2;
int n,i;
int G[100][100];
int Path(){
  int i;
  int u,v,min;
  int d[100],color[100];
  
  for(i=0;i<n;i++){
    d[i]=X;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    min=X;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&color[i]!=BLACK){
	u=i;
	min=d[i];
      }
    }
    if(u==-1) break;
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK&&G[u][v]!=X){
	if((d[u]+G[u][v])<d[v]){
	  color[v]=GRAY;
	  d[v]=d[u]+G[u][v];
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(d[i]!=-1&&d[i]!=X)
      printf("%d %d\n",i,d[i]);
  }
  return 0;
}
int main(){
  int c,k,u,v;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=X;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      G[u][v]=c;
    }
  }
  Path();
  return 0;
}





Measured memory_bytes: 2088
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
using namespace std;
int main(int argc,char** argv){

  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3,x4,y3,y4;

  int xd,yd;
  xd = x2 - x1;
  yd = y2 - y1;

  x3 = x2 - yd;
  y3 = y2 + xd;
  x4 = x1 - yd;
  y4 = y1 + xd;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
  return 0;
}


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


int main() {
	int n;
	cin >> n;

	int64_t sum =0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			for (int l=1; l<=n; l++) {
				int g = gcd(j, l);
				sum += gcd(i, g);
			}
		}
	}

	cout << sum << endl;

}


Measured memory_bytes: 3624
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr uint64_t INF = 1e18;

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

  int32_t N;
  cin >> N;
  int cnt = 0;
  bool yes = false;
  for (int i = 0; i < N; i++) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      cnt++;
      if (cnt ==3) {
       yes = true;
      }
    } else {
      cnt = 0;
    }
  }
  if (yes == true) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    
    ll A,B;
    cin >> A >> B;
    if(A == B){
        out(A);
        return 0;
    }
    
    ll ans = A;
    A++;
    
    while (A%4!=0 && A < B) {
        ans ^= A;
        A++;
    }
    //out(A);
    
    if(A<=B){
        
        ll C = (B/4)*4;
        if(C <= A){
            for (ll i = A; i <= B; i++) {
                ans ^= i;
            }
        }else{
            for (ll i = C; i <= B; i++) {
                ans ^= i;
            }
        }
        
        
        
    }
    
    out(ans);



    return 0;
}


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

int main(){

string s;
  cin >> s;
  int a,b;
  int N = s.size();
  for(int i=0;i<N;i++){
  if(s[i]=='A'){
    a=i;
    break;
  }
  }
  for(int i=N-1;i>=0;i--){
  if(s[i]=='Z') {
    b=i;
    break;
  }
  }
  cout << b-a+1 << endl;
}
  

Measured memory_bytes: 3732
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System;

public class P
{
    public int eq { get; set; }
    public int wp { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        var d = new Dictionary<int, P>();
        for (int i = 0; i < n; i++)
        {
            var w = (int)(decimal.Parse(Console.ReadLine().Trim()) * 1000);
            a[i] = w;
            if (d.ContainsKey(w)) d[w].eq++;
            else d[w] = new P { eq = 1 };
        }
        getAns(a, d, n);
    }
    static void getAns(int[] a, Dictionary<int, P> d, int n)
    {
        var less = 0;
        foreach (var x in d.OrderBy(y => y.Key))
        {
            d[x.Key].wp = d[x.Key].eq + less * 3 - 1;
            less += d[x.Key].eq;
        }
        var sb = new StringBuilder();
        foreach (var x in a)
            sb.Append(d[x].wp.ToString() + "\n");
        Console.Write(sb);
    }
}



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

int main()
{
	int N;
	cin >> N;
	vector<long long> A( N + 1 );
	for( int i = 0; i < N + 1; i++ ) {
		cin >> A[i];
	}
	vector<long long> B( N );
	for( int i = 0; i < N; i++ ) {
		cin >> B[i];
	}

	long long ans = 0;
	for( int i = 0; i < N; i++ ) {
		long long d = B[i] - A[i];
		long long a;
		if( d > 0 ) {
			d = min( d, A[i + 1] );
			A[i + 1] -= d;
			a = A[i] + d;
		}
		else {
			a = B[i];
		}
		ans += a;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>          
using namespace std;
typedef long long ll;

int main() {
    int X, N;
    cin >> X >> N;

    if (N==0) {
        cout << X << endl;
        exit(0);
    }

    vector<int> p(N);
    for (int i=0; i<N; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i=0; i<=100; i++) {
        int judge1=0, judge2=0;

        for (int j=0; j<N; j++) {
            if (X-i==p[j]) {
                judge1 = 1;
                break;
            }
        }
        if (judge1==0) {
            ans = X-i;
            break;
        }

        for (int j=0; j<N; j++) {
            if (X+i==p[j]) {
                judge2 = 1;
                break;
            }
        }
        if (judge2==0) {
            ans = X+i;
            break;
        }

    }

    cout << ans << endl;
    // cout << X << endl;
}

Measured memory_bytes: 3604
n = int(input())
h = list(map(int,input().split()))
a = [0 for _ in range(n)]
a[1] = abs(h[1]-h[0])
for i in range(2,n):
  a[i] = min(a[i-1]+abs(h[i]-h[i-1]),a[i-2]+abs(h[i]-h[i-2]))
print(a[n-1])
  
  

Measured memory_bytes: 13928
[N,M] = [int(s) for s in input().rstrip().split(' ')]
L = [-1 for i in  range(N)]
k = 0
if M >= 1:
  for m in range(M):
    [s_m,c_m] = [int(s) for s in input().rstrip().split(' ')]
    if L[s_m - 1] == -1:
      L[s_m - 1] = c_m
    else: #すでに値が割り振られてる
      if L[s_m - 1] != c_m:
        k = "-1"
        break
  if k == "-1":
    print("-1")
  elif N != 1 and L[0] == 0:
    print("-1")
  else:
    for i in range(N):
      if L[i] == -1:
        if i == 0:
          L[i] = 1
        else:
          L[i] = 0
    print("".join([str(s) for s in L]))
else:
  if N == 1:
    print("0")
  elif N == 2:
    print("10")
  else:
    print("100")

Measured memory_bytes: 3064