akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



string S;

string solve() {
    map<char,int> ma;
    for (int i = 0; i < S.size(); ++i) {
        if (ma.count(S[i])) ma[S[i]] = 1;
        else ma[S[i]] = 1;
    }
    if (ma['N'] != ma['S']) return "No";
    if (ma['W'] != ma['E']) return "No";
    return "Yes";
}

int main() {
    while (cin >> S) {
        cout << solve() << endl;
    }
}











Measured memory_bytes: 256
import math

n=int(input())

def get_sieve_of_eratosthenes(n):
    if n==1:
        return []
    prime = []
    limit = math.sqrt(n)
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

e=get_sieve_of_eratosthenes(n)
l=len(e)

co=1
for i in range(l):
    k=e[i]
    co_sub=1
    l_sub=int(math.log(n,k))
    for j in range(1,l_sub+1):
        co_sub+=n//(k**j)
    co*=co_sub
    co%=(10**9+7)
    #print(co_sub)
print(co)


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

int child(int x, bool isleft) { return 2 * x + 1 + isleft; }
int parent(int x) { return (x - 1) / 2; }

template<class T, class F, T Init>
class SegmentTree{
private:
    int n;
    std::vector<T> node;
    F f;
public:
    SegmentTree(const std::vector<T>& v, F func) : f(func) {
        int vsize = v.size();
        n = 1;
        while (n < vsize) n <<= 1;
        node = std::vector<T>(2 * n - 1, Init);
        for (int i = 0; i < vsize; ++i) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; --i) node[i] = f(node[child(i, 0)], node[child(i, 1)]);
    }
    void update(int x, T val){
        x += n - 1;
        node[x]=val;
        while(x>0){
            x = parent(x);
            node[x] = f(node[child(x, 0)], node[child(x, 1)]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if (r <= 0) r = n;
        if (r <= a || b <= l) return Init;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, child(k, 0), l, (l + r) / 2);
        T vr = query(a, b, child(k, 1), (l + r) / 2, r);
        return f(vl, vr);
    }
};

using namespace std;

signed main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<int> v(n, 1);
    auto aton = [](char c) {
        int i = 1;
        while (c > 'a') i <<= 1, --c;
        return i;
    };
    for (int i = 0; i < n; ++i) v[i] = aton(s[i]);

    auto f = [](int a, int b) { return a | b; };
    SegmentTree<int, decltype(f), 0> st(v, f);

    while(q--){
        int qt;
        cin >> qt;
        if(qt==1){
            int i;
            char c;
            cin >> i >> c;
            --i;
            st.update(i, aton(c));
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            cout << bitset<26>(st.query(l, r)).count() << endl;
        }
    }
}

Measured memory_bytes: 6916
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    int N;
    cin >> N;
    int res = N;
    int n = 0;
    int ls = N % 10;
    while(res >= 10) {
        res/=10;
        n++;
    }
    n++;
    ll ans = 0;

    REP(i, 1, N+1) {
        int j = i;
        int l = j % 10;
        while(j >= 10) {
            j/=10;
        }
        if (l == 0) {
            continue;
        } else if (l == j) {
            ans++;
        }
        int k = l*10 + j;
        if (k > N) {
            continue;
        }
        ans++;
        REP(r, 1,n-2){
            ans += pow(10, r);
        }

        if (n > 2) {
                k = l*pow(10, n-1) + j;
            if (N >= k && res == l ) {
                ans += (N - k)/10 + 1;
            } else if (N >= k ){
                ans += pow(10, n-2);
            }
        }

    }
    cout << ans << endl;
}



Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
ans=0
while sum(h)>0:
    i=0
    while i < n:
        if h[i]>0:
            ans+=1    
            while i<n and h[i]>0:
                h[i]-=1
                i+=1
        i+=1
print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  ll k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];

  vector<int> s;
  vector<int> ord(n + 1, -1);
  int c = 1, l = 0;

  {
    int v = 1;
    while (ord[v] == -1) {
      ord[v] = s.size();
      s.push_back(v);
      v = a[v - 1];
    }
    c = s.size() - ord[v];
    l = ord[v];
  }
  if (k < l)
    cout << s[k] << endl;
  else {
    k -= l;
    k %= c;
    cout << s[l + k] << endl;
  }
}


Measured memory_bytes: 5460
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextDouble();
        double b = scanner.nextDouble();
        double x = scanner.nextDouble();
        double y = scanner.nextDouble();
        double c = x - a;
        double z = y - b;
        double d = (c * c) + (z * z);
        double p = Math.sqrt(d);
        System.out.printf("%.4f\n", p);

    }
}



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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n, t, a;
	cin >> n >> t >> a;
	vector<int>h(n);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}

	int ind;
	double sa = INF;

	for(int i = 0; i < n; ++i){
		if(abs(a - (t - (double)h[i] * 0.006)) < sa){
			ind = i;
			sa = abs(a -  (t - (double)h[i] * 0.006));
		}
	}
	
	cout << ind + 1 << "\n";
	
	return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def getQ(n:Int,b:ArrayBuffer[Int]):String = {
    if(n/4==0) {
      b += n%4
      b.toArray.reverse.mkString
    }
    else {
      b += n%4
      getQ(n/4,b)
    }
  }

  def main(args:Array[String]) = {
    var n = -1
    var s1 = "0"
    while({n=readInt;n} != -1) {
      println(getQ(n,new ArrayBuffer[Int]()))
    }
  }

}

Measured memory_bytes: 45060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
ll a[200006];
ll n;
int main(){
    ll a,b,x; cin>>a>>b>>x;
    if(a%x==0){
        cout<<b/x-a/x+1;
    }
    else cout<<b/x-a/x;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (long long)(1e17)
using namespace std;

unsigned long long popcount(unsigned long long x) {
  x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) + (x & 0x5555555555555555UL);
  x = ((x & 0xccccccccccccccccUL) >> 2) + (x & 0x3333333333333333UL);
  x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) + (x & 0x0f0f0f0f0f0f0f0fUL);
  x = ((x & 0xff00ff00ff00ff00UL) >> 8) + (x & 0x00ff00ff00ff00ffUL);
  x = ((x & 0xffff0000ffff0000UL) >> 16) + (x & 0x0000ffff0000ffffUL);
  x = ((x & 0xffffffff00000000UL) >> 32) + (x & 0x00000000ffffffffUL);
  return x;
}

struct dat {
  long long c[2], p;
};

int n;
vector<dat> v;
vector<long long> res;
vector<vector<long long>> memo[2], dp[2];

void solve();
long long calc(int b, int num, bool xy);

int main() {
  cin >> n;
  v.resize(n);
  for (auto &p : v) cin >> p.c[0] >> p.c[1] >> p.p;
  solve();
  for (auto p : res) cout << p << endl;
  return 0;
}

void solve() {
  res.assign(n + 1, inf);
  for (int t = 0; t < 2; ++t) {
    memo[t].assign(n, vector<long long>(1 << n, inf));
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < (1 << n); ++j) {
        memo[t][i][j] = abs(v[i].c[t]);
        for (int k = 0; k < n; ++k)
          if (j >> k & 1)
            memo[t][i][j] = min(memo[t][i][j], abs(v[i].c[t] - v[k].c[t]));
      }
  }
  for (int t = 0; t < 2; ++t)
    dp[t].assign(n + 1, vector<long long>(1 << n, -1));

  for (int i = 0; i <= n; ++i)
    for (int xline = 0; xline <= i; ++xline) {
      for (int b = 0; b < (1 << n); ++b)
        res[i] = min(res[i],
                     calc(b, xline, 0) + calc((1 << n) - 1 - b, i - xline, 1));
    }
}

long long calc(int b, int num, bool xy) {
  if (dp[xy][num][b] != -1) return dp[xy][num][b];
  long long res = inf;
  if (popcount(b) <= num) return 0;
  for (int s = b; s >= 0; --s &= b) {
    if (popcount(s) == num) {
      long long now = 0;
      for (int i = 0; i < n; ++i)
        if (b >> i & 1) now += memo[xy][i][s] * v[i].p;
      res = min(now, res);
    }
    if (s == 0) break;
  }
  return dp[xy][num][b] = res;
}

Measured memory_bytes: 19412
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <cstdio>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
int n,ans=50;
int main(void){
    cin>>n;
    for(int i=1;i<n;i++){
        int a=i,b=n-i,c=0;
        while(a>0){
            c+=a%10;
            a/=10;
        }
        while(b>0){
            c+=b%10;
            b/=10;
        }
        ans=min(ans,c);
    }
    cout<<ans<<endl;
}

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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << " = " << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define SP << " " <<

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

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;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    string s;
    cin>>s;
    int n=s.size();
    string t=s;
    reverse(all(t));
    string sx="";
    rep(i,n) if(s[i]!='x') sx+=s[i];
    string sy=sx;
    reverse(all(sy));
    int ng=0;
    rep(i,sx.size()) if(sx[i]!=sy[i]) ng++;
    if(ng!=0){
        cout<<-1<<endl;
        return 0;
    }    
    int k=sx.size()/2+sx.size()%2;
    int cnt=0;
    vec a(k+10);
    vec b(k+10);
    rep(i,k){
        while(sx[i]!=s[cnt]){
            a[i]++;
            cnt++;
        }
        cnt++;
        // cout<<sx[i]<<endl;
        // cout<<a[i]<<endl;
    }
    reverse(all(s));
    cnt=0;
    rep(i,k){
        while(sx[i]!=s[cnt]){
            b[i]++;
            cnt++;
        }
        cnt++;
        // cout<<sx[i]<<endl;
        // cout<<b[i]<<endl;
    }
    int ans=0;
    rep(i,k){
        ans+=abs(a[i]-b[i]);
    }
    cout<<ans<<endl;
}

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

int main() {
	int N, T, A;
	cin >> N >> T >> A;
	int h[1010];
	int i;
	for(i=0; i<N; ++i) cin >> h[i];
	for(i=0; i<N; ++i)
	{
		h[i] = 1000*T - 6*h[i];
		h[i] = abs(1000*A - h[i]);
	}
	int j=0;
	for(i=1; i<N; ++i) if(h[j]>h[i]) j=i;
	cout << j+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
bool isSitigosan(int n){
    bool seven=false,five=false,three=false;
    while(n>0){
        if(n%10==7)seven=true;
        else if(n%10==5)five=true;
        else if(n%10==3)three=true;
        else return false;
        n/=10;
    }
    return (seven&&five&&three);
}
int nextnum(int n){
    if(n<3)return 3;
    else if(n>=777777777)return 1e9;
    else if(n%10==7)return nextnum(n/10)*10+3;
    else return n+2;
}
int main(){
    int n,cnt=0;
    scanf("%d",&n);
    for(int i=3;i<=n;i=nextnum(i)){
        if(isSitigosan(i)){
            cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; 
    cin >> n;
    int sum = 0, maxl = 0;
    for(int i=0; i<n; i++){
        int l;
        cin >> l;
        sum += l;
        maxl = max(maxl,l);
    }
    if(maxl < sum - maxl){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
from operator import itemgetter

n, k = map(int, input().split())
td = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = sorted(td, key=itemgetter(1), reverse=True)

ans = [0]
s = set()
t = []
for i in range(k):
    ans[0] += a[i][1]
    if a[i][0] not in s:
        s.add(a[i][0])
    else:
        t.append(a[i][1])

p = len(s)
q = len(t) - 1

if q < 0:
    print(ans[0] + k * k)
    exit()

v = []
for i in range(k, n):
    if a[i][0] not in s:
        s.add(a[i][0])
        v.append(a[i][1])

ans[0] += p * p
d = 0

for x in v:
    ans.append(ans[d] + x - t[q] + (p + 1) * (p + 1) - p * p)
    p += 1
    d += 1
    q -= 1
    if q < 0:
        break

print(max(ans))

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

int main(){
	int n;
	cin >> n;
	vector<int> x;
	x.resize(n);  //入力されたNを配列の数に設定
	for(int i=0;i < n;i++){
		cin >> x[i];
	}
	sort(x.begin(),x.end());	//最大値、最小値を求めるためのソート
	int xmin = x[0],xmax = x[n-1], ans = 10000000;
	for(int  i = xmin;i <= xmax;i++){	//ここが最小値から最大値のループ
		int cost=0;
		for(int a = 0;a < n;a++) cost += pow(x[a] - i,2);	//総和の計算
		ans = min(ans, cost);	//小さい値を答えにする比較
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
"""
https://atcoder.jp/contests/abc167/tasks/abc167_d
"""
import numpy as np
from numba import jit


@jit(nopython=True, parallel=False)
def calc(N: int, K: int, A: np.ndarray) -> int:
    current_pos = 0
    first_sight = np.zeros((N,), dtype=np.int64) - 1
    consumed = 0
    first_sight[0] = 0
    while consumed < K:
        next_pos = A[current_pos] - 1
        consumed += 1
        current_pos = next_pos

        if first_sight[next_pos] == -1:
            first_sight[next_pos] = consumed
        else:
            loop_size = consumed - first_sight[current_pos]
            if loop_size <= K - consumed:
                remain = (K - consumed) % loop_size
                consumed = K - remain
    return current_pos + 1


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")], dtype=np.int64)


def main() -> None:
    N, K = load_input_as_int_array()
    A = load_input_as_int_array()
    result = calc(N, K, A)
    print(result)
    # print("Yes" if result else "No")


main()


Measured memory_bytes: 115664
#include<iostream>
#include<cmath>
#define lli long long int
// #define MODINT 1000000007
using namespace std;

// Problem https://atcoder.jp/contests/abc055/tasks/abc055_b
lli solver(int TRAINING){
    lli result;
    result = 1;
    const lli MODINT = pow(10,9)+7;
    for(int j=1;j< (TRAINING+1);j++){
        result = (result * j) % MODINT;
    }
    return result;
}

int main(void){
    lli answer;
    answer = 0;
    int N;
    cin >> N;
    answer = solver(N);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
S = input()
l = len(S)
if l % 2 == 0:
    ans = l // 2
    after_half = l//2
    before_half = after_half - 1
    s = S[l//2]
    for i in range(l//2):
        if S[before_half] == S[after_half] and S[before_half] == s:
            ans += 1
            before_half -= 1
            after_half += 1
        else:
            break
if l % 2 == 1:
    ans = l // 2 
    after_half = l//2
    before_half = after_half
    s = S[l//2]
    for i in range(l//2 + 1):
        if S[before_half] == S[after_half] and S[before_half] == s:
            ans += 1
            before_half -= 1
            after_half += 1
        else:
            break

print(ans)


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

int main(){

int n,m,b[1000],a[1000][1000],SUM[1000];

for(int i=1;i<1000;i++){
SUM[i]=0;
}

cin>>n>>m;

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

cin>>a[i][j];

}
}

for(int i=1;i<=m;i++){
cin>>b[i];
}

for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
SUM[i] += a[i][j]*b[j];
}
cout<<SUM[i]<<endl;
}

return 0;
}

Measured memory_bytes: 1564
import copy

MOD = 10 ** 9 + 7

def pow_k(x, n, mod):
  if n == 0:
    return 1

  K = 1
  while n > 1:
    if n % 2 != 0:
      K = (x * K) % mod
        
    x = (x * x) % mod

    n //= 2

  return (x * K) % mod

n,k = map(int,input().split())

array = [0] * (k+1)
for i in range(1, k+1):
  tmp = k // i
  array[i] = pow_k(tmp, n, MOD)
  
ans = 0
for i in reversed(range(1,k+1)):
  for j in range(i*2,k+1,i):
    array[i] -= array[j]
    
  ans += array[i] * i 
  ans %= MOD
  
print(ans)
  

Measured memory_bytes: 11520
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mii map<int,int>
#define msi map<string,int>
#define mci map<char,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define repd(i,l,r) for (int i=r;i>=l;i--)
#define ins insert
#define inf 10000000000000000ll
#define vpi vector< pair<int,int> >
#define vpl vector< pair<ll,ll> >
#define eps 1e-7
#define endl "\n"
/*ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b%a,a);}
ll modexp(ll x,ll y,ll p)
{ll res=1;x%=p;while(y){if(y&1){res=(res*x)%p;}y=y>>1;x=(x*x)%p;}return res;}
int x[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int y[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; */
const int maxn = 2e5 + 10;
int a[maxn];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n; cin >> n;
	int m1 = 0, m2 = 0;
	rep(i, 1, n)
	{
		cin >> a[i];
		int x = a[i];
		if (m1 < x)
		{
			m2 = m1;
			m1 = x;
		}
		else
			if (m2 < x)
			{
				m2 = x;
			}
	}
	rep(i, 1, n)
	{
		if (a[i] == m1)
		{
			cout << m2 << "\n";
		}
		else
		{
			cout << m1 << "\n";
		}
	}


	return 0;

	/*check for long long or int*/
}


Measured memory_bytes: 2432
import java.util.*;
import java.io.*;

public class Main {
    static StringBuilder sb;

    public static void solve(int n, int x, int t) {
        if (n % x == 0) sb.append(n / x * t);
        else sb.append((n / x + 1) * t);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        sb = new StringBuilder();

        int n = sc.nextInt();
        int x = sc.nextInt();
        int t = sc.nextInt();

        solve(n, x, t);

        pw.print(sb);
        pw.flush();
        sc.close();
    }
}

Measured memory_bytes: 35968
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <functional>
using namespace std;

long long N, A[200009], B[200009], cnt; map<long long, long long>M;

int main() {
	cin >> N; M[0] = 1; long long ret = 0;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; ret += A[i]; cnt += M[ret]; M[ret]++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 14336
<?php
fscanf(STDIN, '%s', $str);
fscanf(STDIN, '%s', $tar);
$strLen = strlen($str);
$tarLen = strlen($tar);
$ans = $tarLen;
for ($i=0; $i <= $strLen - $tarLen; $i++) { 
    $tmp = 0;
    for ($j=0; $j < $tarLen; $j++) { 
        if ($tar[$j] != $str[$i + $j]) {
            $tmp++;
        }
    }
    $ans = min($ans, $tmp);
}
echo $ans;

Measured memory_bytes: 16192
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll n;
    cin>>n;
    printf("%.6lf\n",(n%2==0?0.5:((double)(n+1)/2)/n));
    return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n;
    cin >> n;
    vector<int> a(n),x(n);
    rep(i,1,n){
        cin >> a[i];
        --a[i];
        ++x[a[i]];
    }

    priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>> que;
    rep(i,0,n) que.push(make_tuple(x[i],0,i));
    
    vector<int> c(n),m(n);
    int r=n;
    while(r>1){
        int k,p,i;
        tie(k,p,i)=que.top();
        que.pop();
        if(x[i]<k) continue;
        --x[i];
        --x[a[i]];
        ++c[i];
        ++c[a[i]];
        --r;
        m[a[i]]=max(m[i],m[a[i]])+1;
        que.push(make_tuple(x[a[i]],m[a[i]],a[i]));
    }
 
    cout << m[0] << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

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; }
template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

string s;
mint dp[100000][13];
int dp2[100000][10];
int main(void){
    cin >> s;
    int n = s.length();

    rep(i,13) dp[n-1][i] = 0;
    if(s[n-1] == '?') rep(i,10) dp[n-1][i] = 1;
    else {
        int c = s[n-1] - '0';
        dp[n-1][c] = 1;
    }

    rep(i,10) dp2[n-1][i] = i;
    for(int i=n-2;i>=0;i--){
        rep(j,10) dp2[i][j] = (dp2[i+1][j]*10)%13;
        if(s[i] == '?'){
            for(int k=0;k<10;k++) for(int j=0;j<13;j++) dp[i][(j+dp2[i][k])%13] += dp[i+1][j];
        }else{
            int c = s[i] - '0';
            for(int j=0;j<13;j++) dp[i][(j+dp2[i][c])%13] = dp[i+1][j];
        }
    }

    cout << dp[0][5] << endl;
    return 0;
}



Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    ll ans = pow(3,n);
    cin >> a[0];
    ll odd = (a[0]%2==0? 2 : 1);
    REPP(i,n-1) {
        cin >> a[i];
        odd *= (a[i]%2==0 ? 2 : 1);
    }
    ans -= odd;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        int N = scanner.nextInt();

        ArrayList<Integer> smaller = new ArrayList<>();
        ArrayList<Integer> bigger = new ArrayList<>();

        for (int i = 0; i < N; i++) {
            int temp = scanner.nextInt();
            if (temp < X) {
                smaller.add(temp);
            } else {
                bigger.add(temp);
            }
        }

        scanner.close();

        Collections.sort(smaller);
        Collections.reverse(smaller);
        Collections.sort(bigger);

        int small = -1;
        int big = -1;
        for (int i = 0; i < smaller.size(); i++) {
            if (X - 1 - i != smaller.get(i)) {
                small = X - 1 - i;
                break;
            }
        }

        for (int i = 0; i < bigger.size(); i++) {
            if (X + i != bigger.get(i)) {
                big = X + i;
                break;
            }
        }

        if (bigger.size() > 0 && smaller.size() > 0) {
            if (small == -1) {
                small = smaller.get(smaller.size() - 1) - 1;
            }
            if (big == -1) {
                big = bigger.get(bigger.size() - 1) + 1;
            }

            if (X - small < big - X) {
                System.out.println(small);
            } else if (X - small > big - X) {
                System.out.println(big);
            } else {
                System.out.println(small);
            }
        } else if (bigger.size() == 0) {
            System.out.println(X);
        } else if (smaller.size() == 0) {
            if (bigger.contains(X)) {
                System.out.println(X - 1);
            } else {
                System.out.println(X);
            }
        }

    }
}


Measured memory_bytes: 36036
using System;
using System.Linq;

class Program {
  static void Main() {
    var a = new int[4];
    for (int i = 0; i < 4; i++) {
      a[i] = int.Parse(Console.ReadLine());
    }
    var b = int.Parse(Console.ReadLine());
    var c = int.Parse(Console.ReadLine());
    Console.WriteLine(a.Sum() - a.Min() + Math.Max(b, c));
  }
}


Measured memory_bytes: 20236
#include <stdio.h>
int F[44];

void fib(int n) {
  int i;
  F[0] = 1;
  F[1] = 1;
  for (i = 2; i <= n; i++) {
    F[i] = F[i-2] + F[i-1];
  }
}

int main(int argc, char const *argv[]) {
  int n;
  scanf("%d\n", &n);
  fib(n);
  printf("%d\n", F[n]);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int S;
  S = 0;
  for (int i = 0; i<N; i++ ) {
    int a,b;
    cin >> a >> b;
    S += b-a+1;
  }
  cout << S <<endl;
}
    

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

s = S()
s = deque(s)
n = I()
flg = 0
for _ in range(n):
    L = LS()
    if L[0] == '1':
        flg ^= 1
    else:
        if flg ^ (L[1] == '1'):
            s.appendleft(L[2])
        else:
            s.append(L[2])


if flg:
    s.reverse()
ans = ''.join(s)
print(ans)


Measured memory_bytes: 72924
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int x; cin >>x;
  cout <<(x<1200 ? "ABC":"ARC") <<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
#define sz(v)           ((int)(v).size())
#define rep(i,a,b)      for(int i=a;i<=b;i++)
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
// C++ program for the above approach 

// Function to find the gcd of a & b 
// by Euclid's method 

// x and y store solution of 
// equation ax + by = g 
void oblivious()
{
    int n;
    cin>>n;
    int a[n][2];
    int f=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1];
    }
    for(int i=0;i<n;i++)
    {
        if(i+2<n)
        {
            if(a[i][0]==a[i][1]&&a[i+1][0]==a[i+1][1]&&a[i+2][0]==a[i+2][1])
            {
                cout<<"Yes"<<endl;
                return;
            }
        }
    }
    cout<<"No"<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    //int z=t;
    while(t--)
    {
        //cout<<"Case #"<<(z-t)<<": ";
        oblivious();
    }
    return 0;
}
//Editorial
/*

    */

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
const int MOD = 1e9+7;

vector<pii> path[maxN];
int dis[maxN];
int deep[maxN];
int pre[maxN][20];
void dfs(int x)
{
	for(auto p:path[x])
	{
		int y = p.first;
		int z = p.second;
		if(y == pre[x][0])
			continue;
		deep[y] = deep[x] + 1;
		dis[y] = (dis[x] + z)%2;
		pre[y][0] = x;
		dfs(y);
	}
}
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v,z;
		scanf("%d%d%d",&u,&v,&z);
		z = z%2;
		path[u].push_back(pii(v,z));
		path[v].push_back(pii(u,z));
	}
	dis[1] = 0;
	dfs(1);
	for(int i=1;i<=n;i++)
	{
		printf("%d\n",dis[i]);
	}
	return 0;
}

Measured memory_bytes: 21376
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream &operator << (ostream& out,const pair<S,T>& o){
    out << "(" << o.first << "," << o.second << ")"; return out;
}
/*
 Atcoder 100~200点代
 アな問題が多いので,まとめる
*/
// https://abc042.contest.atcoder.jp/tasks/abc042_a
//void solve(){ ll A,B,C; cin >> A >> B >> C; if(A == 5 && B == 5 && C == 7){ cout << "YES" << endl; return;} if(A == 5 && B == 7 && C == 5){ cout << "YES" << endl; return;} if(A == 7 && B == 5 && C == 5){ cout << "YES" << endl; return;} cout << "NO" << endl; return ; }
// https://abc043.contest.atcoder.jp/tasks/abc043_a
//void solve(){ ll N; cin >> N; cout << N*(N+1)/2 << endl; }
// https://abc044.contest.atcoder.jp/tasks/abc044_a
//void solve(){ll N,K,X,Y;cin>>N>>K>>X>>Y; cout<<X*min(N,K)+Y*max(0LL,N-K)<<endl;}
// https://abc045.contest.atcoder.jp/tasks/abc045_a
//void solve(){ll a,b,h;cin>>a>>b>>h;cout<<(a+b)*h/2<<endl;}
// https://abc046.contest.atcoder.jp/tasks/abc046_a
//void solve(){ ll a,b,c; cin >> a >> b >> c; set<ll> s; s.insert(a); s.insert(b); s.insert(c); cout << s.size() << endl; }
// https://abc047.contest.atcoder.jp/tasks/abc047_a
//void solve(){ll a,b,c;cin>>a>>b>>c;if(a==b+c||b==a+c||c==a+b)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
// https://abc048.contest.atcoder.jp/tasks/abc048_a
//void solve(){string s1,s2,s3;cin>>s1>>s2>>s3;cout<<"A"<<s2[0]<<"C"<<endl;}
// https://abc049.contest.atcoder.jp/tasks/abc049_a
//void solve(){char c;cin>>c;string s="aiueo";if(s.find(c)!=string::npos)cout<<"vowel"<<endl;else cout<<"consonant"<<endl;}
// https://abc050.contest.atcoder.jp/tasks/abc050_a
//void solve(){ll A,B;char op;cin>>A>>op>>B;if(op=='+')cout<<A+B<<endl;else cout<<A-B<<endl;}
// https://abc051.contest.atcoder.jp/tasks/abc051_a
//void solve(){string s;cin>> s;cout<<s.substr(0,5)<<" "<<s.substr(6,7)<<" "<<s.substr(14)<<endl;}
// https://abc052.contest.atcoder.jp/tasks/abc052_a
//void solve(){ll A,B,C,D;cin>>A>>B>>C>>D;cout<<max(A*B,C*D)<<endl;}
// https://abc053.contest.atcoder.jp/tasks/abc053_a
//void solve(){ll x;cin>>x;cout<<(x<1200?"ABC":"ARC")<<endl;}
// https://abc054.contest.atcoder.jp/tasks/abc054_a
//void solve(){ll A,B;cin>>A>>B;if(A==1)A=14;if(B==1)B=14;cout<<(A>B?"Alice":(A==B?"Draw":"Bob"))<<endl;}
// https://abc055.contest.atcoder.jp/tasks/abc055_a
//void solve(){ll N;cin>>N;cout<<800*N-200*(N/15)<<endl;}
// https://abc056.contest.atcoder.jp/tasks/abc056_a
//void solve(){char a,b;cin>>a>>b;if(a=='H')cout<<b<<endl;else if(b=='H')cout<<'D'<<endl;else cout<<'H'<<endl;}
// https://abc057.contest.atcoder.jp/tasks/abc057_a
void solve(){ll A,B;cin>>A>>B;cout<<(A+B)%24<<endl;}

// Main function
int main(void) {cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

struct UnionFind {
  vector<int> parent;
  UnionFind (int n) : parent(n, -1) {}
  int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (parent[y] < parent[x]) swap(x, y);
    if (parent[x] == parent[y]) --parent[x];
    parent[y] = x;
    return true;
  }
};

struct Edge{
  int src, dest;
  int idx;
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

bool dfs(const Graph& g, const vector<bool>& vb,
    vector<bool>& vis, vector<bool>& cut, int i, int p = -1, int ei = -1) {
  vis[i] = true;
  bool parity = false;
  for (auto&& e : g[i]) {
    if (e.dest == p) continue;
    bool child = dfs(g, vb, vis, cut, e.dest, i, e.idx);
    parity = parity != child; // XOR
  }
  bool flip = vb[i] != vb[i+1];
  if (flip != parity) {
    if (ei != -1) {
      cut[ei] = true;
      return true;
    } else {
      throw std::runtime_error("invalid");
    }
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> vp;
  for(auto&& _:irange(0,n)) {
    int a,b;
    cin>>a>>b;
    vp.emplace_back(a,b);
  }
  boost::sort(vp);
  Graph g(n+1);
  UnionFind uf(n+1);
  for(auto&& i:irange(0,m)) {
    int l,r;
    cin>>l>>r;
    int il = boost::lower_bound(vp,make_pair(l,0)) - begin(vp);
    int ir = boost::lower_bound(vp,make_pair(r+1,0)) - begin(vp);
    if (uf.merge(il, ir)) {
      g[il].push_back({il, ir, i});
      g[ir].push_back({ir, il, i});
    }
  }
  vector<bool> vb(n+2, false);
  for(auto&& i:irange(0,n)) {
    vb[i+1] = vp[i].second;
  }
  vector<bool> vis(n+1, false);
  vector<bool> cut(m, false);
  for(auto&& i:irange(0,n+1)) {
    if (vis[i]) continue;
    try {
      dfs(g, vb, vis, cut, i);
    } catch(...) {
      cout << -1 << endl;
      return 0;
    }
  }
  int k = boost::count(cut, true);
  cout<<k<<endl;
  int cnt = 0;
  for(auto&& i:irange(0,m)) {
    if (cut[i]) {
      if (cnt) cout<<" ";
      cout<<i+1;
      ++cnt;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 8308
#include<stdio.h>

int main(void){
	int a,b,z=0;
	char op=0;
	for(;;){	
	scanf("%d %c %d",&a,&op,&b);
		if(op=='+') z=a+b;
		else if(op=='-') z=a-b;
		else if(op=='*') z=a*b;
		else if(op=='/') z=a/b;
		else if(op=='?') break;
		printf("%d\n",z);
	}
return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>

void output(int[],int);
void insertionSort(int[],int);

int main(){
  int N,i;
  int A[100];

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

  output(A,N);
  insertionSort(A,N);

  return 0;
}

void output(int A[],int N){
  int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[],int N){
  int i,j,v;
  for(i=1;i<N;i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    output(A,N);
  }
}



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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  int l_max[n];
  int r_max[n];
  l_max[0] = a[0];
  for (int i=1; i<n; i++) {
    l_max[i] = max(l_max[i-1], a[i]);
  }
  r_max[n-1] = a[n-1];
  for (int i=n-2; i>=0; i--) {
    r_max[i] = max(r_max[i+1], a[i]);
  }
  for (int i=0; i<n; i++) {
    if (i ==0) {
      cout<<r_max[1]<<endl;
    } else if (i == n-1) {
      cout<<l_max[n-2]<<endl;
    } else {
      cout<<max(l_max[i-1], r_max[i+1])<<endl;
    }
  }
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <numeric>
#define ll long long 
#define wolfe ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define elif else if
using namespace std;
int main () {
    wolfe;
    int n;
    cin >> n;
    int sum = 0;
    while(n>=500) {
        n -= 500;
        sum += 1000;
    }
    while(n>=5) {
        n -=5;
        sum += 5;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var ans = 0;
            for (int i = 1; i <= N; i++)
            {
                if (N - i > i) ans++;
                else if (N - i <= i) break;
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  //input
  int N; cin>>N;
  vector<int>H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
  }
  //compute
  int ans=0;
  for(int i=0;i<N;i++){
    bool is_candidate=true;
    for(int j=0;j<i;++j){
      if(H[j]>H[i]){
        is_candidate=false;
        break;
      }
    }
    if(is_candidate){
      ++ans;
    }
  }
  //output
  cout<<ans<<endl;  
}
  


Measured memory_bytes: 256
$<.each{|line|
  n = line.to_i
  ret = 0
  (0..9).each{|a|
    (0..9).each{|b|
      (0..9).each{|c|
        (0..9).each{|d|
          ret+=1 if n == a + b + c + d
        }
      }
    }
  }
  puts ret  
}

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

int dp[100005];
vector<int> X[100005];

int solve(int i)
{
    if(dp[i]!=-1)
        return dp[i];

    int ans = 0;
    vector<int> Y;

    for(int j=0; j<X[i].size(); j++)
        Y.push_back(solve(X[i][j]));

    sort(Y.begin(), Y.end());

    for(int j=0; j<Y.size(); j++)
    {
        if(j==0)
            ans = Y[j]+1;
        else
            ans = max(ans+1, Y[j]+1);
    }

    Y.clear();
    return dp[i] = ans;
}

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

    for(int i=2; i<=N; i++)
    {
        int x;
        cin >> x;

        X[x].push_back(i);
    }

    int ans = 0;
    memset(dp, -1, sizeof(dp));

    printf("%d\n", solve(1));

    return 0;
}


Measured memory_bytes: 15488
def fib(n):
    if n <= 1:
        return n
    result = [1, 0, 0, 1]
    matrix = [1, 1, 1, 0]
    while n > 0:
        if n % 2:
            result = mul(matrix, result)
        matrix = mul(matrix, matrix)
        n //= 2
    return result[2]

def mul(a, b):
    return [a[0]*b[0] + a[1]*b[2],
            a[0]*b[1] + a[1]*b[3],
            a[2]*b[0] + a[3]*b[2],
            a[2]*b[1] + a[3]*b[3]]

N, M = map(int, input().split())
A = []
for i in range(M):
  A.append(int(input()))

flag = False
for i in range(M-1):
  if (A[i]+1 == A[i+1]):
    flag = True

if flag:
  print(0)
elif M != 0:
  parts = []  
  for i in range(M):
    if i == 0:
      a_list = [x for x in range(0, A[i])]
      parts.append(a_list)
    else:
      a_list = [x for x in range(A[i-1]+1, A[i])]
      parts.append(a_list)
  a_list = [x for x in range(A[M-1]+1, N+1)]
  parts.append(a_list)
  ans = 1
  for part in parts:
    part_ans = fib(len(part))
    ans *= part_ans
  print(ans % 1000000007)
else:
  ans = fib(N+1)
  print(ans % 1000000007)

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

#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

const int N = 200005;

int n;

integer main(){
    ios_base::sync_with_stdio(false);

    int a, b;
    int c = 0;
    cin >> a >> b;
    for (int i = 0; i < b; i++){
        int x;
        cin >> x;
        c += x;
    }
    cout << (c >= a ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256