akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val S = next()
    val deque = java.util.LinkedList<Char>(S.toList())
    val Q = nextInt()
    var reverse = false
    repeat(Q) {
        val query = listOfString()
        when (query[0]) {
            "1" -> {
                reverse = !reverse
            }
            "2" -> {
                when (query[1]) {
                    "1" -> {
                        if (reverse)
                            deque.addLast(query[2][0])
                        else
                            deque.addFirst(query[2][0])
                    }
                    "2" -> {
                        if (reverse)
                            deque.addFirst(query[2][0])
                        else
                            deque.addLast(query[2][0])
                    }
                }
            }
        }
    }
    val ans = deque.joinToString(separator = "")
    println(if (reverse) ans.reversed() else ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta


Measured memory_bytes: 83484
#include<iostream>
using namespace std;
int t, n, i, ii, ok, jj;
long long v[205], d[70][2], x;
char s[205];
int main(){
    cin>> t;
    for(; t; t--){
        cin>> n;
        for(i = 1; i <= n; i++){
            cin>> v[i];
        }
        for(ii = 0; ii < 60; ii++){
            d[ii][0] = d[ii][1] = 0;
        }
        cin>> s + 1;
        for(i = n; i >= 1; i--){
            if(s[i] == '0'){
                x = v[i];
                for(ii = 59; ii >= 0; ii--){
                    if( ( (x >> ii) & 1) == 1){
                        if(d[ii][0] != 0){
                            x ^= d[ii][0];
                        }
                        else{
                            d[ii][0] = x;
                            break;
                        }
                    }
                }
            }
            else{
                x = v[i];
                for(jj = 59; jj >= 0; jj--){
                    if(( (x >> jj) & 1) == 1){
                        x ^= d[jj][0];
                    }
                }
                if(x != 0){
                    cout<<"1\n";
                    break;
                }
            }
        }
        if(i == 0){
            cout<<"0\n";
        }
    }
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    char c[n];
    for(int i=0;i<n;++i){
        cin >> c[i];
    }

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, 0));
    dp[0][0] = 1;
    for(int i=0;i<n;++i) {
        for(int j=0;j<=i;++j) {
            if(!dp[i][j]) continue;
            if(c[i] == 'U') {
                dp[i+1][j] += (dp[i][j] * j) % MOD;
                dp[i+1][j] %= MOD;
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            } else if(c[i] == 'D') {
                if(j) {
                    dp[i+1][j-1] += (dp[i][j] * j * j) % MOD;
                    dp[i+1][j-1] %= MOD;
                }
                dp[i+1][j] += (dp[i][j] * j) % MOD;
                dp[i+1][j] %= MOD;
            } else {
                dp[i+1][j] = dp[i][j];
            }
                
        }
    }

    cout << dp[n][0] << endl;
}


Measured memory_bytes: 3280
def main():
    n = int(input())
    P = list(map(int, input().split()))

    count = 0
    p1 = P[0]
    p2 = P[1]
    for i in range(2, n):
        p3 = P[i]
        if p1 < p2 < p3 or p1 > p2 > p3:
            count += 1
        p1 = p2
        p2 = p3

    print(count)


main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S, W;
    cin >> S >> W;
    if (W >= S) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  string ans="";
  for(ll i=0;i<n;i++) {
    if(s[i]!='B') ans=ans+s[i];
    else if(ans.size()) ans=ans.substr(0,ans.size()-1);
  }
  cout << ans << endl;
}

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

using namespace std;

bool vis[1000005];

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

    int cur = 0;
    int cnt = 0;

    while (true) {
        cnt++;
        cur = cur * 10 + 7;
        cur %= k;

        if (vis[cur]) return 0 * printf("-1\n");
        vis[cur] = 1;

        if (cur == 0) return 0 * printf("%d\n", cnt);
    }
}


Measured memory_bytes: 4704
N, M = map(int, input().split())
R = [tuple(map(int, input().split())) for _ in range(M)]
R.sort(key=lambda x: x[0], reverse=True)
count = 0
broke = 10**6
for a, b in R:
    if b <= broke:
        count += 1
        broke = a

print(count)

Measured memory_bytes: 18232
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  P = list(map(int, input().split()))
  for d in range(100):
    if X - d not in P:
      print(X - d)
      break
    if X + d not in P:
      print(X + d)
      break

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

using ll = long long;
static const int MOD = 1e9 + 7;

vector<ll> x;

void div_add(int n) {
  int num = n;
  for(int i = 2; i <= n; i++){
    while(num % i == 0){
      x.at(i)++;
      num /= i;
    }
  }
  return;
}

ll div_count(int n) {
  ll ans = 1;
  for(int i = 2; i <= n; i++){
    ans = (ans * (x.at(i) + 1)) % MOD;
  }
  return ans % MOD;
}

int main() {
  int n;
  cin >> n;
  
  x.resize(n + 1);
  
  for(int i = 1; i <= n; i++){
    div_add(i);
  }
  
  cout << div_count(n) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

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

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    vector<int> a(n), l(n + 1), r(n + 1);
    for (int i = 0; i < n; ++i) scanf("%d", &a.at(i));
    for (int i = 1; i <= n; ++i) l.at(i) = gcd(l.at(i - 1), a.at(i - 1));
    for (int i = n - 1; i >= 0; --i) r.at(i) = gcd(r.at(i + 1), a.at(i));
    for (int i = 0; i < n; ++i) ans = max(ans, gcd(l.at(i), r.at(i + 1)));
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string S,T; cin >> S >> T;
    int N = S.size();
    int M = T.size();

    auto match=[](char x, char y) {
        return x==y or x=='?';
    };
    reverse(all(S));
    reverse(all(T));
    rep(i,N-M+1) {
        bool ok = 1;
        rep(j,M) {
            if (!match(S[i+j],T[j])) ok = 0;
        }
        if (ok) {
            rep(j,M) S[i+j] = T[j];
            for (int j = N-1; j >= 0; j--) {
                cout << (S[j]=='?' ? 'a' : S[j]);
            }
            cout << ln;
            return 0;
        }
    }

    cout << "UNRESTORABLE" << ln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

double r;
int main() {
    cin >> r;
    double ans = 2.0*r*acos(-1);
    printf("%.14f\n", ans);
}

Measured memory_bytes: 3788
#include<iostream>
#include<string>
using namespace std;
int main(){
  int p[60];
  p[0]=11;p[1]=31;p[2]=41;p[3]=61;p[4]=71;
  p[5]=101;p[6]=131;p[7]=151;p[8]=181;p[9]=211;p[10]=311;
  p[11]=331;p[12]=401;p[13]=491;p[14]=521;p[15]=541;
  p[16]=601;p[17]=661;p[18]=691;p[19]=701;p[20]=751;
  p[21]=761;p[22]=811;p[23]=821;p[24]=881;p[25]=911;
  p[26]=971;p[27]=991;p[28]=1021;p[29]=1031;p[30]=1051;
  p[31]=1061;p[32]=1091;p[33]=1151;p[34]=1201;p[35]=1231;
  p[36]=1301;p[37]=1321;p[38]=1361;p[39]=1381;p[40]=1451;
  p[41]=1471;p[42]=1481;p[43]=1511;p[44]=1531;p[45]=1571;
  p[46]=1601;p[47]=1621;p[48]=1721;p[49]=1741;p[50]=1831;
  p[51]=1871;p[52]=1901;p[53]=1931;p[54]=1951;p[55]=2011;
  p[56]=2111;p[57]=2131;p[58]=2141;p[59]=2161;p[60]=2221;
   int N,i;
   cin >> N;
   for(i=0;i<N-1;i++){
     cout <<p[i]<<" ";
   }
   cout <<p[N-1];
}

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

int main() {
   vector<int> a(3);
   cin >> a.at(0) >> a.at(1) >> a.at(2);
   if(a.at(0)==a.at(1) && a.at(2) != a.at(1)) cout << "Yes";
   else if(a.at(2)==a.at(1) && a.at(0) != a.at(1)) cout << "Yes";
   else if(a.at(2)==a.at(0) && a.at(2) != a.at(1)) cout << "Yes";
   else cout << "No";
}

Measured memory_bytes: 256
def mlen(n,m):
	global M,s,c
	return abs(s[n][0] - c[m][0]) + abs(s[n][1] - c[m][1])

N,M = [int(i) for i in input().split()]
s=[] #position of student
c=[] #position of checkpoint
for i in range(N):
	x,y=[int(i) for i in input().split()]
	s.append([x,y])
for i in range(M):
	x,y=[int(i) for i in input().split()]
	c.append([x,y])
for i in range(N):
	pos = 0
	min = mlen(i,0)
	for j in range(1,M):
		if mlen(i,j) < min:
			pos = j
			min = mlen(i,j)
	print(pos+1)

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

using namespace std;

void Main() {
    int A, B;
    string op;
    cin >> A >> op >> B;
    if (op == "+") {
        cout << A + B << endl;
    }
    else {
        cout << A - B << endl;
    }
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;int N,a,b,i,V[1<<20],f[1<<20];pair<int,int>R[1<<20];main(){for(cin>>N;i<N;cin>>a>>b,R[i]={a,a+b},i++);for(sort(R,R+N),b=V[N]=1;a=i--;b=V[i]=(b+V[f[i]=a])%998244353)for(;a<N&R[a].first<R[i].second;a=f[a]);cout<<*V;}

Measured memory_bytes: 5888
#include "bits/stdc++.h"
using namespace std;

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

    vector<string> vecs(N);
    for (int i = 0; i < N; i++) {
        cin >> vecs.at(i);
    }

    int M;
    cin >> M;

    vector<string> vect(M);
    for (int i = 0; i < M; i++) {
        cin >> vect.at(i);
    }

    vector<int> sum(N);
    for (int i = 0; i < N; i++) {
        int sum0 = 0;
        for (int j = 0; j < N; j++) {
            if (vecs.at(i) == vecs.at(j)) {
                sum0++;
            }
        }
        for (int j = 0; j < M; j++) {
            if (vecs.at(i) == vect.at(j)) {
                sum0--;
            }
        }
        sum.at(i) = sum0;
    }

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

    if (sum.at(N - 1) > 0) {
        cout << sum.at(N - 1) << endl;
    }
    else {
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
import copy
class SegmentTree:
    __slots__ = ['sz','func','I','seg']
    def __init__(self, N, func, I):
        self.sz = N
        self.func = copy.deepcopy(func)
        self.I = I
        self.seg = [I for i in range(self.sz * 2)]
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = self.func(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k //= 2
            self.seg[k] = self.func(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        L = self.I
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                L = self.func(L, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = self.func(self.seg[b], R)
            a //= 2
            b //= 2
        return self.func(L, R)

def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    from fractions import gcd
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 82340
#include <stdio.h>
#include <string.h>

char S[32], T[32];
int A, B;
char U[32];

int main(void) {
	if (scanf("%31s%31s", S, T) != 2) return 1;
	if (scanf("%d%d", &A, &B) != 2) return 1;
	if (scanf("%31s", U) != 1) return 1;
	printf("%d %d\n", A - (strcmp(S, U) == 0), B - (strcmp(T, U) == 0));
	return 0;
}


Measured memory_bytes: 128
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
print(n * (n-1) // 2)

Measured memory_bytes: 3064
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;

int x,y,muki,ren;
vi xlist,ylist;
bool dp[2][32001];
string s;

int main(){
    cin >> s;
    I(x); I(y);
    int idx = 0;
    while ( idx < s.size() && s[idx] == 'F' ){
        x--; idx++;
    }

    FOR(i,idx+1,(int)s.size()){
        if (s[i] == 'F') {
            ren++;
        } else {
            if(ren){
                if(muki){
                    xlist.pb(ren);
                } else {
                    ylist.pb(ren);
                }
                ren = 0;
            }
            muki ^= 1;
        }
    }

    if(ren){
        if(muki){
            xlist.pb(ren);
        } else {
            ylist.pb(ren);
        }
        ren = 0;
    }

    muki = 1;
    dp[0][16000] = 1;
    for (auto i: xlist){
        memset(dp[muki],0,sizeof(dp[muki]));
        REP(j,32001){
            dp[muki][j] = (0 <= j-i) && dp[muki^1][j-i] || (j+i <= 32000) && dp[muki^1][j+i];
        }
        muki ^= 1;
    }

    if (!dp[muki^1][x+16000]) {
        cout << "No" << endl;
        return 0;
    }

    memset(dp,0,sizeof(dp));

    muki = 1;
    dp[0][16000] = 1;
    for (auto i: ylist){
        memset(dp[muki],0,sizeof(dp[muki]));
        REP(j,32001){
            dp[muki][j] = (0 <= j-i) && dp[muki^1][j-i] || (j+i <= 32000) && dp[muki^1][j+i];
        }
        muki ^= 1;
    }

    if (!dp[muki^1][y+16000]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <utility>
#include <cstdlib>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;
const lli inf = 1e18;
typedef pair<lli, lli> pll;


int main(){
    int n,k;
    cin >> n >> k;
    int full = (n-1)*(n-2)/2;
    if(k > full){
        cout << -1 << endl;
        return 0;
    }

    int m = full -k +(n-1);
    cout << m << endl;
    for(int i=1; i<n; i++){
        cout << 1 << " " << i+1 << endl;
    }

    int rem = full -k;
    for(int i=1; i<n and rem>0; i++){
        for(int j=i+1; j<n and rem>0; j++){
            cout << i+1 << " " << j+1 << endl;
            rem--;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int n;
vector<int> values;
vvector<int> edges;
vector<int> anses;

vector<int> lines;

void setup(){
  n = in();
  values.resize(n);
  edges.resize(n);
  foreach(i,values)i=in();
  foreach(i,values)assert(1<=i and i<=1e9);
  anses.resize(n);
  lines.resize(n+4,INF);
  rep(i,n-1){
    int a = in()-1;
    int b = in()-1;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
}

void func(int place,int last){
  int p = lower_bound(all(lines),values[place])-lines.begin();
  int v = values[place];
  swap(lines[p],v);
  anses[place] = lower_bound(all(lines),INF)-lines.begin();
  foreach(i,edges[place]){
    if(i==last)continue;
    func(i,place);
  }
  swap(lines[p],v);
}

int main(){
  setup();
  func(0,-1);
  foreach(i,anses)cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 27960
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
int main()
{
    ll n,a,b,c,d;
    scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
    {
        n--;
        for(ll i=0;i<=n;i++)
        {
            if((c*(n-i)-d*i)<=(b-a)&&(b-a)<=d*(n-i)-c*i)
            {
                puts("YES");
                return 0;
            }
        }
        puts("NO");
    }
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
int main() {
//	ios::sync_with_stdio(false);
//	cin.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int> > a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(a.begin(), a.end());           // 从小到大排序 
	sort(b.begin(), b.end());
	for (int i = 0; i < n; i++) {
		if (a[i].first > b[i].first) {
			cout << "No\n";
			return 0;
		}
	}
//	printf("%d\n",a[0]);
	for (int i = 1; i < n; i++) {
		if (a[i] <= b[i - 1]) {
			cout << "Yes\n";
			return 0;
		}
	}
	vector<int> to(n);
	for (int i = 0; i < n; i++) {
		to[a[i].second] = b[i].second;
//		printf("a = %d b = %d\n",a[i].second,b[i].second);
	}
	int cur = 0;
	int cnt = 0;
	do {
		cur = to[cur];
		cnt++;
	} while (cur != 0);
//	printf("%d\n",cnt);
	cout << (cnt == (n) ? "No\n" : "Yes\n");
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

const int maxN = (int)5e5 + 10;



void solve() {
  int n, x;
  cin >> n;
  int cnt[maxN] = {0};
  for (int i = 0 ; i < n - 1; i++) {
    cin >> x;
    cnt[x]++;
  }
  for (int i = 1 ; i <= n ; i++) cout << cnt[i] << endl;
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 5616
/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const int p=1e9+7;
const int N=2e5+10;
char s[N];
int main(){
    in>>s+1;
    int n=strlen(s+1);
    if(n==6){
        if(s[3]==s[4]&&s[5]==s[6])
        {puts("Yes");return 0;}
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
import math
A, B, H, M = map(int,input().split())
nagai = (60*H+M)/2
mijikai = 6*M
Nx= A*math.sin(math.radians(nagai))
Ny = A*math.cos(math.radians(nagai))
Sx= B*math.sin(math.radians(mijikai))
Sy= B*math.cos(math.radians(mijikai))

ans = ((Nx-Sx)**2+(Ny-Sy)**2)**0.5
print(ans)


Measured memory_bytes: 62580
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;
vector<string> field;

int main(void)
{
    int H, W;
    cin >> H >> W;
    cin.ignore();
    for (int i = 0; i < H; ++i)
    {
        string s;
        getline(cin, s);
        field.push_back(s);
    }

    bool ok = true;
    for (int i = 0; i < H; ++i)
    {
        for (int j = 0; j < W; ++j)
        {
            if (field[i][j] == '#')
            {
                if (i == 0 && j == 0)
                {
                    if (field[i + 1][j] != '#' && field[i][j + 1] != '#')
                        ok = false;
                }
                else if (i == 0 && j == W - 1)
                {
                    if (field[i + 1][j] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
                else if (i == H - 1 && j == 0)
                {
                    if (field[i - 1][j] != '#' && field[i][j + 1] != '#')
                        ok = false;
                }
                else if (i == H - 1 && j == W - 1)
                {
                    if (field[i - 1][j] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
                else if (i == 0)
                {
                    if (field[i + 1][j] != '#' && field[i][j + 1] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
                else if (i == H - 1)
                {
                    if (field[i - 1][j] != '#' && field[i][j + 1] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
                else if (j == 0)
                {
                    if (field[i + 1][j] != '#' && field[i - 1][j] != '#' && field[i][j + 1] != '#')
                        ok = false;
                }
                else if (j == W - 1)
                {
                    if (field[i + 1][j] != '#' && field[i - 1][j] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
                else
                {
                    if (field[i + 1][j] != '#' && field[i][j + 1] != '#' && field[i - 1][j] != '#' && field[i][j - 1] != '#')
                        ok = false;
                }
            }
            if (!ok)
                break;
        }
    }
    if (ok)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int ans=0;

void check(int n,int num){
    
    
        //357がひとつ以上あればカウント
        bool san=0;
        bool go=0;
        bool nana=0;
        string str = to_string(num);
        for(int i = 0; i < (int)str.size(); ++i){
            if(str[i]=='3'){san =true;}
            if(str[i]=='5'){go  =true;}
            if(str[i]=='7'){nana=true;}
        }
        if(san&&go&&nana){ans++;}

        if(10*(double)num+3<=n){check(n,10*num+3);}
        if(10*(double)num+5<=n){check(n,10*num+5);}
        if(10*(double)num+7<=n){check(n,10*num+7);}

    

}

int main()
{

//整数値の入力
int n;
cin >> n;
int i;


check(n,3);
check(n,5);
check(n,7);



//回答
cout <<ans<< endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll dat[100];
U_MAP mp;
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    dat[0]=1;
    rrep(i,1,ohara){
        dat[i]=dat[i-1]*2;
        if(dat[i]>=2*1e9){
            tmp=i;
            break;
        }
    }
    cin>>n;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    rrrep(i,tmp,0){
        rep(j,n){
            if(dat[i]-a[j]<=0)continue;
            if(dat[i]-a[j]==a[j]){
                if(mp[dat[i]-a[j]]>=2){
                    ans++;
                    mp[dat[i]-a[j]]--;
                    mp[a[j]]--;
                }
            }
            else{
            if(mp[dat[i]-a[j]]>=1&&mp[a[j]]>=1){
                ans++;
                mp[dat[i]-a[j]]--;
                mp[a[j]]--;
            }
            }
        }
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 38032
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<cmath>
typedef long long int ll;
using namespace std;
int main()
{
	int n,m;
	cin >> n >> m;
	
	int x = 1900*m + 100*(n-m);
	int ans = pow(2,m);
	ans *= x;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<set>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string s;
    set<string> myset;
    for(int i=0; i<n; ++i)
    {
        cin>>s;
        cin.ignore();
        myset.insert(s);
    }
    cout<<myset.size()<<endl;
    return 0;
}


Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       READ               freopen("in.txt", "r", stdin);
#define       WRITE              freopen("out.txt", "w", stdout);
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       gcd(a, b)          __gcd(a, b)
#define       MX                 300005
#define       MOD               1000000007
#define       inf               (int)(1e18)
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
inline ll mod(ll a, ll m){ if(a<0) return ((a%m)+m)%m; else if(a<m) return a; else return (a%m); }
/*bool cmp(ll x,ll y)
{
   return x>y;
}*/
bool cmp(pair<int,int>a, pair<int,int>b)
{
   if(a.first==b.first)
      return a.second<b.second;
   else
      return a.first<b.first;
}
int main(void)
{
   optimize
   ll t,n,m,k,x,y,a[200001];
   vector<ll> v,v1,v2;
   vector< pair<ll,ll> > p,p1,p2;
   set<ll> st;
   map<ll,ll> mp;
   priority_queue<ll> pq;
   priority_queue< ll,vector<ll>,greater<ll> > lpq;
   priority_queue< pair<ll,ll> > phpq;
   priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair<ll,ll> > > plpq;
   string s;
   cin>>s;
   if(s[s.size()-1]=='s')
      cout<<s<<"es";
   else
      cout<<s<<"s";
   return 0;
}


Measured memory_bytes: 3620
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    ulong N, M;
    int[] p;
    bool input() {
        scanf("%lld %lld\n", &N, &M);
        if (N == 0 && M == 0) return false;
        p = new int[M];
        foreach (i; 0 .. M) {
            scanf("%d", &p[i]);
        }
        scanf("\n");
        p.sort;
        return true;
    }

    void solve() {
        writefln("%.8f", (p[0] == 1 ? 0.0 : N / 2.0));
    }

    while (input) solve;
}

Measured memory_bytes: 1136
import sys
from itertools import accumulate
N, M, Q = map(int, sys.stdin.readline().split())
 
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
  L, R = map(int, sys.stdin.readline().split())
  LR[L-1][R-L] += 1
 
for i in range(N-2,-1,-1):
  for j, acc in enumerate(accumulate(LR[i])):
    LR[i][j] = acc + (0 if j==0 else LR[i+1][j-1])
 
for i in range(Q):
  p, q = map(int, sys.stdin.readline().split())
  sys.stdout.write(str(LR[p-1][q-p])+"\n")

Measured memory_bytes: 8668
N,A,B,C,D=map(int,input().split())

S=input()
jump=False
n=0
R=0

for i in range(A-1,D):
    if S[i]=="#":
        R+=1
        n=0
        if R>=2:
            print("No")
            exit()
    else:
        n+=1
        R=0

b=0
S=S+"G"
for j in range(B-2,D+1):
    if S[j]==".":
        b+=1
        if b>=3:
            print("Yes")
            exit()
    else:
        b=0

if C<D:
    print("Yes")
else:
    print("No")
    


Measured memory_bytes: 9352
#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 2e9
#define ll long long
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) v.begin(), v.end()

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b,c; cin >> a >> b >>c;
     cout << c/a*b<< endl;
}



Measured memory_bytes: 256
unittest
{
	assert( [ "3", "abc", "cde" ].parse.expand.solve == 5 );
	assert( [ "1", "a", "z" ].parse.expand.solve == 2 );
	assert( [ "4", "expr", "expr" ].parse.expand.solve == 4 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	return tuple( s, t );
}

auto solve( dchar[] s, dchar[] t )
{
	for( auto i = 0L; i < s.length; i++ )
	{
		if( s[ i .. $ ] == t[ 0 .. $ - i ] ) return s.length + i;
	}
	return s.length + t.length;
}


Measured memory_bytes: 256
def gcd(a,b):
    a,b = min(a,b),max(a,b)
    if a == 0:
        return b
    else:
        return gcd(a,b%a)

n = int(input())
for i in range(n):
    t = int(input())
    if i == 0:
        t1 = t
    else:
        t2 = t
        gcdt = gcd(t1,t2)
        lcn = t1*t2//gcdt
        t1 = lcn
print(t1)

Measured memory_bytes: 38308
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mp make_pair
#define M 1000000007
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
const int N=2e5+5, mod=998244353;
int main(){
	int n;
	cin>>n;
	ll ans=(n/500)*1000LL;
	n-=(n/500)*500LL;
	ans+=(n/5)*5LL;
	cout<<ans<<endl;
}

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

int main()
{
    int n;
    cin >> n;
    int total = 0;
    int max1 = 0;
    for (int i = 0; i < n; i++)
    {
        int p;
        cin >> p;
        total += p;
        max1 = max(max1, p);
    }
    total -= max1 / 2;
    cout << total << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int,int> > vp;

int main()
{
  int n,m;
  cin >> n >> m;
  vi students(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> students[i];
    }
  for(int k=1;k<=m;k++)
    {
      for(int i=0;i<n-1;i++)
	{
	  if((students[i]%k)>(students[i+1]%k))
	    {
	      swap(students[i],students[i+1]);
	    }
	}
    }
  for(int i=0;i<n;i++)
    {
      cout << students[i] << endl;
    }
  return 0;
}
      



Measured memory_bytes: 3092
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
const li inf = 1 << 60;

void _main(int tc) {
  li n, W;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n) { cin >> w[i] >> v[i]; }
  vector<vector<li>> mem(n, vector<li>(W + 1, -1));
  function<li(int, int)> knapsack = [&](int i, int k) -> li {
    if (i == n) return 0;
    if (mem[i][k] != -1) return mem[i][k];
    if (k + w[i] <= W) mem[i][k] = v[i] + knapsack(i + 1, k + w[i]);
    mem[i][k] = max(mem[i][k], knapsack(i + 1, k));
    return mem[i][k];
  };
  cout << knapsack(0, 0) << endl;
  // rrep(i, n) {
  //   rrep(k, W) {
  //     if (i == n - 1) {
  //       if (k + w[i] <= W) mem[i][k] = v[i];
  //       else mem[i][k] = 0;
  //       continue;
  //     }
  //     if (k + w[i] <= W) mem[i][k] = v[i] + mem[i + 1][k + w[i]];
  //     mem[i][k] = max(mem[i][k], mem[i + 1][k]);
  //   }
  // }
  // cout << mem[0][0] << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 79488
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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;
}
using namespace std;

vector<vector<int>>g;
vector<int>cost,par;


void solve(){
	int n,m;
	cin>>n>>m;
	cost.resize(n,0);
	par.resize(n);
	g.resize(n);
	map<int,int>r;
	int root;
	rep(i,n+m-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		r[b]++;
		g[a].pb(b);
	}
	for(int i=0;i<n;++i){
		if(!r[i])root=i;
	}
	par[root]=root;
	stack<int>q;
	q.push(root);
	while(!q.empty()){//子孫の計算が終わっていない状態で探索を開始するとやり直しになり、TLEになる。
		int v=q.top();
		q.pop();
		for(int x:g[v]){
			r[x]--;
			if(chmax(cost[x],cost[v]+1))par[x]=v+1;
			if(!r[x])q.push(x);
		}
	}
	for(int i=0;i<n;++i){
		if(i==root)cout<<0<<"\n";
		else cout<<par[i]<<"\n";
	}
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 11904
from operator import itemgetter

n, m = map(int, input().split())
ab = sorted([tuple(map(int, input().split())) for i in range(m)], key = itemgetter(1))
bridge = 0
ans = 0

for a, b in ab:
    if bridge <= a:
        bridge = b
        ans += 1
        
print(ans)

Measured memory_bytes: 18972
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    int n;
    cin>>n;
    vl a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vl pref(n);
    pref[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--) {
        pref[i]=(pref[i+1]+a[i])%mod;
    }
    ll ans=0;
    for(int i=0;i<n-1;i++) {
        ans += (pref[i+1]*a[i])%mod;
        ans%=mod; 
    }

    cout<<ans;

}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 6360
#include<stdio.h>
int main(){
  int n,i;
  long long int count=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    if(i%3!=0 && i%5!=0)
      count+=i;
  }
  printf("%lld\n",count);
  return 0;
}


Measured memory_bytes: 1732
#include <stdio.h>
#include <vector>
#include <string.h>

#pragma warning(disable:4996)
int main(void) {
	int N, M;
	scanf("%d %d", &N, &M);
	int Lmax = 1;
	int Rmin = N;
	for (int i = 0; i < M; ++i) {
		int L, R;
		scanf("%d %d", &L, &R);
		if (L > Lmax) {
			Lmax = L;
		}
		if (R < Rmin) {
			Rmin = R;
		}
	}
	int num = Rmin - Lmax + 1;
	if (Lmax > Rmin) num = 0;
	printf("%d", num);
	return 0;
}

Measured memory_bytes: 128
using System;

 class Program
 {
     static void Main(string[] args)
     {
         /*
         double data1, data2, data3,data4,data5,temp;
         double[] result = new double[3];
         String nyuryoku;
         nyuryoku = Console.ReadLine();
         string[] data = nyuryoku.Split(' ');
         data1 = Double.Parse(data[0]); 
         data2 = Double.Parse(data[1]);
         data3 = Double.Parse(data[2]);
         data4 = Double.Parse(data[3]);
         data5 = Double.Parse(data[4]);
         */
         string nyuryoku;
         double result,count = 0;
         while (true)
         {
             nyuryoku = Console.ReadLine();
             result = Double.Parse(nyuryoku);
             if (result == 0)
                 return;
             count++;
             Console.WriteLine("Case {0}: {1}", count, result);
         }
      }
 }


Measured memory_bytes: 18008
#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>
#include <climits>
#include <sstream>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define vi vector<ll>
#define pii pair<int, int>
#define fi(n) for(ll i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define RFOR(i, k, n) for(int i = (k); i >= (n); i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define umin(a, b) a = min(a, b)
#define umax(a, b) a = max((ll)a, (ll)b)

//const long long LINF = LLONG_MAX;
//const long long LINF = 1e14;
const int INF = 1e9 + 1;
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	cout << (a - b) * ((k % 2) ? -1 : 1) << endl;
 	return 0; 
}

Measured memory_bytes: 256