akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

using Weight = int;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(const int &s = 0, const int &d = 0, const Weight &w = 0) : src(s), dst(d), weight(w) {}
};

using Edges = std::vector<Edge>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

class Graph {
  std::vector<Edges> g;
  using iterator = std::vector<Edges>::iterator;
  using const_iterator = std::vector<Edges>::const_iterator;

public:
  Graph(const int &size = 0) : g(size) {}
  int size() const { return g.size(); }
  const Edges &operator[](const int &i) const { return g[i]; }
  void addArc(const int &src, const int &dst, const Weight &w = 1) { g[src].emplace_back(src, dst, w); }
  void addEdge(const int &node1, const int &node2, const Weight &w = 1) {
    addArc(node1, node2, w);
    addArc(node2, node1, w);
  }
  iterator begin() { return g.begin(); }
  const_iterator begin() const { return g.begin(); }
  iterator end() { return g.end(); }
  const_iterator end() const { return g.end(); }
};

std::vector<int> tsort(const Graph &g) {
  int n = g.size(), k = 0;
  std::vector<int> ord(n), in(n);
  for (auto &es : g)
    for (auto &e : es) in[e.dst]++;
  std::queue<int> q;
  rep(i, n) if (in[i] == 0) q.push(i);
  while (q.size()) {
    int v = q.front();
    q.pop();
    ord[k++] = v;
    for (auto &e : g[v])
      if (--in[e.dst] == 0) q.push(e.dst);
  }
  return *std::max_element(in.begin(), in.end()) == 0 ? ord : std::vector<int>();
}

main {
  int m;
  int n;
  cin >> m >> n;
  Graph g(m);
  while (n--) {
    int x, y;
    cin >> x >> y;
    g.addArc(--x, --y);
  }
  vi v = tsort(g);
  for (auto &x : v) cout << x + 1 << endl;
}

Measured memory_bytes: 3172
#include <stdio.h>
int main() {
	int n;
	scanf("%d", &n);
	if (n == 1) {
		printf("Hello World\n");
	} else {
		int a, b;
		scanf("%d%d", &a, &b);
		printf("%d\n", a + b);
	}
	return 0;
}

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

int DP[15][11] = { {}, { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 } }, total[15] = { 0, 9 };

void Initialize() {
	for (int i = 2; i < 15; ++i) {
		total[i] = total[i - 1];
		for (int j = 0; j < 10; ++j) {
			for (int k = j - 1; k <= j + 1 && k < 10; ++k)
				DP[i][j] += DP[i - 1][k];
			total[i] += (!!j) * DP[i][j];
		}
	}
}

void FindNthLunLunNumber(int number) {
	int sums = 0, length = -1, previous;
	for (int i = 1; i < 15; ++i) {
		for (int j = 1; j < 10; ++j) {
			if (sums + DP[i][j] >= number) {
				cout << j, previous = j, length = i - 1, number -= sums;
				break;
			}
			sums += DP[i][j];
		}
		if (length != -1)
			break;
	}
	for (; length; --length) {
		sums = 0;
		for (int i = previous - 1; i <= previous + 1 && i < 10; ++i) {
			if (sums + DP[length][i] >= number) {
				cout << i, previous = i, number -= sums;
				break;
			}
			sums += DP[length][i];
		}
	}
}

int main() { 
	cin.sync_with_stdio(false), cin.tie(nullptr);
	Initialize();
	int number;
	cin >> number, FindNthLunLunNumber(number);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n;cin >> n;
  vector<ll> hoge(n);
  rep_i(i, n){
    cin >> hoge[i];
  }

  if(n == 1){
    cout << hoge[0] << endl;
    return 0;
  }
  ll a;
  for (int i = 0; i < n; i++){
    if(i == 0){
      a = lcm(hoge[i], hoge[i+1]);
    }else{
      a = lcm(a, hoge[i]);
    }
  }
  cout << a << endl;
}

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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

const ll inf = 1LL << 60;

int n;
ll a[20];
unordered_map<ll, ll> dp[20][20];

ll getRes(int l, int r, ll nl, ll nr) {
  if (l + 1 == r) {
    return 0;
  }
  ll h = (nl << 30) + nr;
  if (dp[l][r].find(h) != dp[l][r].end())
    return dp[l][r][h];
  ll & res = dp[l][r][h];
  res = inf;
  for (int i = l + 1; i < r; i++)
    res = min(res, getRes(l, i, nl, nl + nr) + getRes(i, r, nl + nr, nr) + (nl + nr) * a[i]);
  return res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  cout << getRes(0, n - 1, 1, 1) + a[0] + a[n - 1] << "\n";
}


Measured memory_bytes: 11264
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	//入力
	int n;
	cin >> n;
	string s;
	cin >> s;
	//処理
	//初期設定
	//初めに全員西を向かせる
	int change_num(0);
	for (int i(0); i < n; i++) {
		if (s[i] == 'E')change_num++;
	}
	//西の人から順に東を向かせていく
	int min_num(change_num);
	for (int i(0); i < n; i++) {
		if (s[i] == 'W') change_num++;
		else change_num--;
		if (min_num > change_num)min_num = change_num;
	}
	cout << min_num << endl;
	return 0;
}

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

int main(){
    int q1, b, c1, c2, q2;
    while(1){
        cin >> q1;
        if(q1 == 0) break;
        cin >> b >> c1 >> c2 >> q2;

        int aizu = min(q2, b/c1);
        b -= aizu * c1;
        int normal = b/c2;
        b -= normal * c2;

        if(aizu + normal < q1 && c1 > c2){
            while(aizu + normal < q1 && aizu > 0){
                aizu--;
                b += c1;
                normal += b/c2;
                b %= c2;
            }
        }

        if(aizu > 0 && aizu + normal >= q1) cout << aizu << " " << normal << endl;
        else                    cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 2992
var readline = require('readline')
var reader = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var lines = [];
reader.on('line', function(line) {
  lines.push(line);
});

reader.on('close', function() {
  console.log(lines[0].slice(0,3) + '8' + lines[0].slice(4));
});

Measured memory_bytes: 7628
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int dp[110][110][15][15][4];
char board[110][110];

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

struct Elem {
    int x, y, a, b, dir;
};

int N, M, A;
int sx, sy, gx, gy;
int dfs(int x, int y, int a, int b, int dir) {
    int& val = dp[x][y][a][b][dir];

    if(~val) return val;
    if(x == gx && y == gy) return val = 0;

    int nx, ny, na, nb, nd;
    vector<int> dirs = {dir, 3-dir, dir^1};
    vector<int> use_a = {0, 1, 0};
    vector<int> use_b = {0, 0, 1};

    val = INF;
    for(int k=0; k<3; k++) {
        nd = dirs[k];
        nx = x + dx[ nd ];
        ny = y + dy[ nd ];
        na = a + use_a[k];
        nb = b + use_b[k];

        if(x == sx && y == sy && k != 0) continue;
        if(nx < 0 || nx >= N || ny < 0 || ny >= M) continue;
        if(board[nx][ny] == '#') continue;
        if(na > A || nb > A) continue;

        char orig = board[x][y];
        if(x != sx || y != sy) board[x][y] = '#';
        val = min(val, dfs(nx, ny, na, nb, nd) + (k != 0));
        board[x][y] = orig;
    }
    return val;
}

int main() {
    scanf("%d%d%d", &N, &M, &A);
    for(int i=0; i<N; i++) {
        for(int j=0; j<M; j++) {
            scanf(" %c", &board[i][j]);
            if(board[i][j] == 'S') sx = i, sy = j;
            if(board[i][j] == 'G') gx = i, gy = j;
        }
    }

    fill(dp[0][0][0][0], dp[110][0][0][0], -1);
    int ans = dfs(sx, sy, 0, 0, 0);
    if(ans == INF) printf("-1\n");
    else printf("%d\n", ans);
    return 0;
}


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

typedef long long       ll;
const int MOD=1000000007;
const int MAX=1e5+9;
ll cnt[MAX];

ll fastPow(ll a, ll b) {
    if (!b) {
        return 1;
    }

    ll sq=fastPow(a, (b>>1LL));
    sq*=sq;

    if (b&1LL) {
        sq%=MOD;
        sq*=a;
    }

    return sq%MOD;
}

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

    int n, k;
    cin >> n >> k;
    ll ans=0;
    for (int i=k; i>=1; --i) {
        int mul=k/i;
        if (!mul) {
            continue;
        }

        cnt[i]=fastPow(mul, n);
        for (int j=2; 1LL*j*i<=k; ++j) {
            cnt[i]-=cnt[j*i];
            if (cnt[i]<MOD) {
                cnt[i]+=MOD;
            }
        }

        ans+=(1LL*i*cnt[i])%MOD;
        ans%=MOD;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 4304
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    S=list(map(int,list(input())))
    ans=0
    nuri=False
    for i in range(len(S)-1):
        if nuri==False:
            if S[i+1] == S[i]:
                ans+=1
                nuri=True
            else:
                pass
        else:
            if S[i+1] == S[i]:
                nuri=False
            else:
                ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 49392
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int a,b;
  cin>>a>>b;
  if(a%3==0 || b%3==0 || (a+b)%3==0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;

  return 0;
}


Measured memory_bytes: 256
N,L = map(int,input().split())
*A, = map(int,input().split())

S = [0]*(N+1)
for i,a in enumerate(A): S[i+1] = S[i] + a
ans = []
i=0
j=N-1
while i<j:
    if S[j+1]-S[i] < L:
        print("Impossible")
        break
    if A[i]+A[i+1] <= A[j]+A[j-1]:
        ans.append(i+1)
        i+=1
    else:
        ans.append(j)
        j-=1
else:
    print("Possible")
    for a in ans: print(a)

Measured memory_bytes: 16768
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	string res = "NO";
	long N; cin >> N;
	long p[100] = {}; for (int i = 1; i <= N; i++) cin >> p[i];

    for (int k = 1; k <= N - 1; k++) if (p[k] > p[k + 1]) goto soko;
    res = "YES";
   soko:;
	for (int i = 1; i <= N; i++) {

		for (int j = i + 1; j <= N; j++) {
			long q[100]; for (int k = 1; k <= N; k++) q[k] = p[k];
			
			long t;
			t = q[i];
			q[i] = q[j];
			q[j] = t;

			for (int k = 1; k <= N - 1; k++) if (q[k] > q[k + 1]) goto koko;
			res = "YES";
            koko:;
		}
	}

	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    string S;
    cin >> S;

    bool flg = true;
    for(int i = 0; i < S.size(); i++) {
        if ((i+1) % 2 == 1) {
            if (S[i] == 'L') {
                flg = false;
                break;
            }
        }
        else {
            if (S[i] == 'R') {
                flg = false;
                break;
            }
        }
    }

    if (flg) cout << "Yes" << "\n";
    else cout << "No" << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int ,int >
#define pl pair<ll ,ll >
#define pb push_back
#define vl vector <long long int >
#define vi vector <int >
#define mod 1000000007
#define eps 1e-9
#define fi first
#define se second
#define _ <<" "<<
#define forn(x,	n) for(int x = 0; x < n ;++ x) 
#define forn1(x,n) for(int x = 1; x <= n ;++ x)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void scan(){}
template<typename F, typename... R> void scan(F &f,R&... r){cin>>f;scan(r...);}
int di_; string dnms_, co_ = ",";
void debug_(){cout<<endl;}
template<typename F, typename... R> void debug_(F &f, R&... r){while(dnms_[di_] != ',')cout<<dnms_[di_++];di_++;cout<<": "<<f<<",";debug_(r...);}
#define debug(...) dnms_=#__VA_ARGS__+co_,di_=0,debug_(__VA_ARGS__)

template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){
    return out<<"("<<a.first<<","<<a.second<<")";}
template<class A> ostream& operator<<(ostream& out, const vector<A> &a){
	out<<"";for(auto it=a.begin();it!=a.end();it++){if(it!=a.begin())out<<" ";out<<*it;}out<<"";
	return out;}
template<class A, class B> istream& operator>>(istream& in, pair<A,B> &a){in>>a.first>>a.second;return in;}
template<class A> istream& operator>>(istream& in, vector<A> &a){for(A &i:a)in>>i;return in;}

int main(){
	IOS

	int x,k;
	cin>>k>>x;
	int l = -1000000,r=1000000;
	l = max(x-k+1,l);
	r = min(x+k-1,r);
	for(int i=l;i<=r;i++)
		cout<<i<<" ";
 
	return 0;	
}

Measured memory_bytes: 256
import math

N, H = map(int, input().split())
A = []
B = []

for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

a_max = max(A)

B = sorted([x for x in B if x > a_max], reverse = True)

attack = 0

for damage in B:
    H -= damage
    attack += 1
    if H <= 0:
        break

if H > 0:
    attack += math.ceil(H / a_max)

print(attack)

Measured memory_bytes: 12860
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	long long int num[1024],n,m;
	for(int i=0;i<1024;i++){
		num[i] = 0;
		cin>>s;
		if (s=="0"){ 
			m = i;
			break;
		}
		for (int j = 0;; j++){
			if (s[j] == '\0'){
				break;
			}
			num[i] += (s[j] - '0');

		}
	}
	for (int i=0; i < m; i++){
		printf("%d\n",num[i]);
	}
	return 0;
}

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

int64_t sum_(vector<int> v){
  int64_t total=0;
  for (int v_:v){
   total+=v_;
  }
  return total;
}

int main(){
  int N;
  cin >> N;
  vector<int> cities(N+1);
  for(int n=0; n<N+1; n++){
    cin >> cities.at(n);
  }
  int64_t enemies = sum_(cities);
  vector<int> bravery(N);
  for(int n=0; n<N; n++){
    cin >> bravery.at(n);
  }
  
  for(int i=0; i<N; i++){
    int atk = bravery.at(i);
    cities.at(i)-= atk;
    if(cities.at(i)<0){
      cities.at(i+1)+=cities.at(i);
      cities.at(i)=0;
      if(cities.at(i+1)<0){
        cities.at(i+1)=0;
      }
    }
  }
  int64_t wins = sum_(cities);
  cout << enemies-wins << endl;
  
}

Measured memory_bytes: 1400
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;
typedef long long ll;
typedef long double ld;


int solve(void);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

int solve(void)
{
	ll N;
	cin >> N;
	vector<pair<ll,ll>> A(N);

	ll cnt = 1;
	for (auto& a : A) {
		a.second = cnt;
		cnt ++;
		cin >> a.first;
	}

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

	for (int i = 0; i < A.size(); i++) {
		if (i > 0) { cout << " "; }
		cout << A[i].second;
	}
	cout << endl;

	return 0;
}



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

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<int> ans(N);
    char now = 'R';
    int st1 = 0, st2 = 1;
    int left, right;
    for (int i = 1; i < N; i++){
        if (S[i] == 'R'){
            if (i%2 == 0){
                st2++;
            } else {
                st1++;
            }
            now = S[i];
        } else {
            if (now == 'R'){
                right = i-1;
                left = i;
                ans[i-1]++;
                ans[i]++;
                if (i%2 == 0){
                    ans[i] += st2;
                    ans[i-1] += st1-1;
                    st1 = 0;
                    st2 = 0;
                } else {
                    ans[i] += st1;
                    ans[i-1] += st2-1;
                    st1 = 0;
                    st2 = 0;
                }
            } else {
                if (i%2 == left%2){
                    ans[left]++;
                } else {
                    ans[right]++;
                }
            }
            now = S[i];
        }
    }

    rep(i, N){
        cout << ans[i];
        if (i != N-1){
            cout << " ";
        } else {
            cout << endl;
        }
    }
    return 0;
}

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

#define N_MAX 3000
class Point{
public:
  int x, y;
  Point(int x = 0, int y = 0):x(x), y(y){

  }
};

int N, K;
Point P[N_MAX];
Point T[N_MAX];

bool compX(const Point &p1, const Point &p2){
  if ( p1.x == p2.x ) return p1.y < p2.y;
  return p1.x < p2.x;
}

bool compA(const Point &p1, const Point &p2){
  return p2.x*p1.y < p1.x*p2.y;
}

bool eq(const Point &p1, const Point &p2){
  return p2.x*p1.y == p1.x*p2.y;
}

int check(int p, int M){
  sort(T, T + M, compA);
  int maxl = 1;
  int l = 1;
  Point pre = T[0];
  for ( int i = 1; i < M; i++ ){
    if ( eq(pre, T[i]) ){
      l++;
      maxl = max(maxl, l);
    } else {
      l = 1;
    }
    pre = T[i];
  }
  return maxl;
}


bool solve(){
  for ( int i = 0; i < N; i++ ){ // origin
    int k = 0;
    int v = 0;
    for ( int j = i+1; j < N; j++ ){
      if ( P[i].x == P[j].x ){
	v++;
      } else {
	T[k] = P[j];
	T[k].x -= P[i].x;
	T[k].y -= P[i].y;
	k++;
      }
    }
    if ( 1 + v >= K ) return true;
    if ( 1 + check(i, k) >= K ) return true;
  }

  return false;
}

main(){
  cin >> N >> K;
  for ( int i = 0; i < N; i++ ) cin >> P[i].x >> P[i].y;
  sort(P, P + N, compX);

  cout << solve() << endl;

  return 0;
}



Measured memory_bytes: 3172
S = input()[::-1]
a = ['maerd', 'remaerd', 'esare', 'resare']
i = 0
ans = 'YES'
while True:
    if i == len(S):
        break 
    if S[i:i+5] == 'maerd':
        i+=5
    elif S[i:i+5] == 'esare':
        i+=5
    elif S[i:i+6] == 'resare':
        i+=6
    elif S[i:i+7] == 'remaerd':
        i+=7   
    else:
        ans = 'NO'
        break
print(ans) 







Measured memory_bytes: 9272
use std::io::*;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();

    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();

    let p = 16;
    let success = "Yay!";
    let fail = ":(";

    let f_a = a > 8;
    let f_b = b > 8;

    let result = if (f_a || f_b) {
        fail
    } else {
        success
    };

    println!("{}", result);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using namespace std::literals;

struct S {
  int x;
  int y;
};
struct P {
  vector<S> s;
};

int count_bit(int x) {
  int count = 0;
  for (int i = 0; i < 16; ++i)
    if (x & (1 << i))
      count++;
  return count;
}

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

  vector<P> p(n);
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    p[i].s = vector<S>(a);
    for (int j = 0; j < a; ++j) {
      int x, y;
      cin >> x >> y;
      p[i].s[j].x = x - 1;
      p[i].s[j].y = y;
    }
  }

  int ans = -1;
  vector<int> eval = vector<int>(n, -1);
  vector<char> honest = vector<char>(n);

  for (int bit = 0; bit < (1 << n); ++bit) {
    //  if (count_bit(bit) <= ans)
    //    continue;

    for (int i = 0; i < n; ++i)
      honest[i] = (bit & (1 << i)) != 0;

    for (auto &e : eval)
      e = -1;

    bool bad = false;
    for (int i = 0; i < n; ++i) {
      if (!honest[i])
        continue; // ignore

      for (auto s : p[i].s) {
        if (honest[s.x] != s.y) {
          bad = true; // lying
          break;
        }
        if (eval[s.x] != -1) {
          if (eval[s.x] != s.y) {
            bad = true;
            break;
          }
        } else {
          eval[s.x] = s.y;
        }
      }
    }
    if (bad)
      continue;

    auto count = count_bit(bit);
    for (auto &h : honest)
      cerr << (h ? 1 : 0);
    cerr << " - OK " << count << "\n";

    ans = max(ans, count_bit(bit));
  }
  cout << max(0, ans);
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
int main(void)
{
    string s;
    int i, judge=0;
 
    cin >> s;
 
    for(i=0; i<s.size()-1; i++){
        if(s[i]=='A' && s[i+1]=='C'){
            judge=1;
            break;
        }
    }
 
    if(judge == 1){
        cout << "Yes" << endl;
    }
 
    else{
        cout << "No" << endl;
    }
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    // input
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    (U == S) ? cout << A - 1 << " " << B << endl : cout << A << " "  << B - 1 << endl;
    return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll M;
vector<ll> adj[100005];
multiset<ll> ms;
ll A, B;

int main() {
	scanf("%lld %lld", &N, &M);
	for(int i = 0; i < N; i++) {
		scanf("%lld %lld", &A, &B);
		adj[A].push_back(B);
	}
	ll ans = 0;
	for(int i = 1; i <= M; i++) {
		for(int j = 0; j < adj[i].size(); j++) {
			ms.insert(adj[i][j]);
			// cout << adj[i][j] << "\n";
		}
		if(!ms.empty()) {
			ans += *ms.rbegin();
			ms.erase(--ms.end()); 
		}
	}
	printf("%lld\n", ans);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 8192
N, W = gets.split.map(&:to_i)
WV = N.times.map { gets.split.map(&:to_i) }

dp = Array.new(W + 1, 0)

N.times do |n|
  w, v = WV[n]
  W.downto(w) do |w_lim|
    cur_v = dp[w_lim - w] + v
    dp[w_lim] = cur_v if cur_v > dp[w_lim]
  end
end

puts dp[W]


Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n),b(n),c(n);
  ll ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    c[i]=a[i]+b[i];
    ans-=b[i];
  }
  sort(c.begin(),c.end(),greater<ll>());
  for(int i=0;i<n;i++){
    if(i%2==0){
      ans+=c[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b) {
	return *(int*)a - *(int*)b;
}

int main() {
	int N, X[200000],Y[200000];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &X[i]);
		Y[i] = X[i];
	}
	qsort(Y, N, sizeof(int), compare);
	int d = Y[N / 2 - 1], u = Y[N / 2];
	for (int i = 0; i < N; i++) {
		if (X[i] <= d) printf("%d\n", u);
		else printf("%d\n", d);
	}
	return 0;
}

Measured memory_bytes: 3704
from bisect import bisect
S = input()
T = input()

cs = [[] for i in range(26)]
for i,s in enumerate(S):
    j = ord(s) - ord('a')
    cs[j].append(i)

for c in set(T):
    if not cs[ord(c) - ord('a')]:
        print(-1)
        exit()

rnd = 0
k = -1
for t in T:
    ti = ord(t) - ord('a')
    i = bisect(cs[ti], k)
    if i == len(cs[ti]):
        k = cs[ti][0]
        rnd += 1
    else:
        k = cs[ti][i]

print(rnd*len(S) + k + 1)

Measured memory_bytes: 54128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 


int main(){
  fastio
  ll x,k,d;
  cin>>x>>k>>d;
  ll dis = abs(x);
  ll ans;
  if(k < dis/d){
    ans = dis - k*d;    
  }
  else{
    ll steps = dis/d;
    ll far = dis-steps*d;
    ll moves = k - steps;
    if(moves%2==0){
      ans = far;
    }
    else {
      ans = abs(far-d);
    }
   
  }
  cout<<ans<<"\n";
  
  return 0; 
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	FOR0(i,n) cin>>a[i];
	ll dp[n+1][n+1];
	memset(dp, -1, sizeof(dp));
	FOR1(i,n) dp[i][i] = a[i-1];
	//ll tot = accumulate(a, a+n);
	for (int len = 2; len <= n; len++){
		FOR1(i,n){
			int j = len + i - 1;
			if (j>n || j<=0) continue;
			dp[i][j] = max(a[i-1]-dp[i+1][j], a[j-1]-dp[i][j-1]);
		}
	}	
	// FOR1(i,n) {
	// 	FOR1(j,n) cout << dp[i][j] << " ";
	// 	cout << endl;
	// }
	cout << dp[1][n] << endl;
}

Measured memory_bytes: 70656
#include <stdio.h>
#include <ctype.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,c,d=0;
	char b[13];
	scanf("%s",&b);
	a=(b[5]-'0')*10+(b[6]-'0');
	if(a>4){
		d=1;
	}
	if(d==0){
		printf("Heisei");
	}else{
		printf("TBD");
	}
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); 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; }

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

int main(){
    int h, w;cin >> h >> w;
    int ch, cw, dh, dw; cin >> ch >> cw >> dh >> dw; ch--, cw--, dh--, dw--;
    vector<string> grid(h);
    rep(i, h)cin >> grid[i];

    //BFS
    vector<vector<int>> C(h, vector<int>(w, INF)); C[ch][cw] = 0;
    vector<vector<int>> check(h, vector<int>(w)); check[ch][cw]=1;//1==walk, -1,warp
    queue<pii> que; que.push({ch, cw});
    while(!que.empty()){
        auto p = que.front(); que.pop();
        int y = p.first, x = p.second;
        queue<pii> que_walk; que_walk.push({y,x});
        //徒歩で移動できるだけ移動する。移動時に移動したマスをメモる。この処理は１度だけ行う
        vector<pii> memo; memo.push_back({y,x});
        while(!que_walk.empty()){
            auto q = que_walk.front(); que_walk.pop();
            rep(i, 4){
                int ny = q.first + dy[i], nx = q.second + dx[i];
                if(ny<0 or nx<0 or ny>=h or nx>=w or grid[ny][nx] == '#')continue;
                if(check[ny][nx]<=0 and C[ny][nx] > C[y][x]){
                    C[ny][nx] = C[y][x];
                    check[ny][nx] = 1;
                    que_walk.push({ny, nx});
                    memo.push_back({ny,nx});
                }
            }
        }
        //未踏域にワープする
        for(auto m: memo){
            int vy = m.first, vx = m.second;  
            for(int i=max(0, vy-2); i<=min(h-1, vy+2); i++){
                for(int j=max(0, vx-2); j<=min(w-1, vx+2); j++){
                    if(grid[i][j] == '.' and check[i][j]==0 and C[i][j] > C[y][x] + 1){
                        C[i][j] = C[y][x] + 1;
                        check[i][j] = -1;
                        que.push({i, j});
                    }
                }
             }
        }
    }
    /*rep(i, h){
        rep(j, w){
            cout << C[i][j] << " ";
        }cout << ln;
    }
    rep(i, h){
        rep(j, w){
            cout << check[i][j] << " ";
        }cout << ln;
    }*/

    int res = C[dh][dw];
    if(res == INF)res = -1;
    cout << res << ln;
}
    

 


Measured memory_bytes: 13468
#include<stdio.h>

int main(void)
{
  int i = -1, j, k, H[300], W[300], cnt = 0;

  do {
    i++;
    scanf("%d %d", &H[i], &W[i]);
    cnt++;
  } while(H[i] != 0 && W[i] != 0);

  for(k = 0; k < cnt - 1; k++) {
    for(i = 0; i < H[k]; i++) {
      for(j = 0; j < W[k]; j++) {
	if((i + j) % 2 == 0) {
	  printf("#");
	}else{
	  printf(".");
	}
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
#include<stdio.h>
int main(void){
    int a,ans;
    int value[a],cost[a];
    scanf("%d",&a);
    for(int i=0;i<a;i++){
    scanf("%d",&value[i]);
    }
    for(int i=0;i<a;i++){
    scanf("%d",&cost[i]);
    }
    ans = 0;
    for(int i=0;i<a;i++){
          if(value[i] > cost[i]) {
            ans += value[i] - cost[i];
          }
    }
 printf("%d",ans);
 return 0;
}

Measured memory_bytes: 128
N = int(input())
S1 = input()
S2 = input()
mod = 10 ** 9 + 7

# 番兵
S1 += '*'
P = []
i = 0
while i < N:
    if S1[i] == S1[i + 1]:
        P.append('横')
        i += 1
    else:
        P.append('縦')
    i += 1

ans = 0
if P[0] == '縦':
    ans = 3
    one_before = '縦'
elif P[0] == '横':
    ans = 6
    one_before = '横'

for p in P[1:]:
    if p == '縦' and one_before == '縦':
        ans = ans * 2 % mod
        one_before = p

    elif p == '縦' and one_before == '横':
        one_before = p

    elif p == '横' and one_before == '縦':
        ans = ans * 2 % mod
        one_before = p

    elif p == '横' and one_before == '横':
        ans = ans * 3 % mod
        one_before = p

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n;
vector<lli> a;
lli sum = 0;
int main(int argc, char const *argv[]) {
    cin >> n;
    a = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    lli j;
    for(lli i = 0;i < n;i++){
        if(sum * 2 < a[i]) j = i;
        sum += a[i];
    }
    cout << n-j << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  REP(i, N) {
    cin >> A[i];
  }
  int ret = K;
  REP(i, N) {
    int l = A[i];
    int r = i == N-1 ? K + A[0] : A[i+1];
    int tret = K - (r - l);
    ret = min(ret, tret);
  }
  cout << ret << endl;
}

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

int main() {
	long long N, A[100000], ans = 0;
	cin >> N >> A[0];
	ans = A[0] / 2;
	A[0] = A[0] % 2;
	for (int i = 1; i < N; i++) {
		cin >> A[i];
		if (A[i - 1]  == 1 && A[i] > 0) A[i]--, ans++;
		ans += A[i] / 2;
		A[i] = A[i] % 2;
	}
	cout << ans;
}

Measured memory_bytes: 1024
import sys
from heapq import heappush, heappop
input = sys.stdin.readline

def main():
    n,m=map(int,input().split())
    ab=[]
    for i in range(n):
        a,b=map(int,input().split())
        if a>m:
            continue
        ab.append((a,b))
    ab.sort(reverse=True)    
    q=[]
    ans=0
    for i in range(1,m+1):
        while ab and ab[-1][0]<=i:
            a,b=ab.pop()
            heappush(q,-b)
        if q:
            b=-heappop(q)
            ans+=b
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 17240
/*
    AUTHOR : TANMAY SINHA
    INORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(j,L,R) for(j=L;j<R;j++)
#define per(i,L,R) for(i=L;i>= R;i--)
#define all(con) (con).begin(),(con).end()
#define fi first
#define se second
#define foreach(iter,con) for(auto iter=(con).begin(); iter!=(con).end(); iter++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 1e5+10,MAX = 1e6+5;
#define sq(a) ((a)*(a))

int main()
{
   SPEED
   ld n;
   ll i,j;
   ld ans = 0;
   cin>>n;
   ld p =1.0;
   for(i=1;i<=n;i++)
   {
       p = (ld)p*i;
   }
   ld x[9],y[9];
   cin>>x[0]>>y[0];
   ld temp = p*(n-1);
   temp/= n*(n-1)/2;
   for(i=1;i<n;i++)
    cin>>x[i]>>y[i];
   ld t;
   for(i=0;i<n-1;i++)
   {
       for(j=i+1;j<n;j++)
       {
           ans+= (ld)(temp*sqrt(sq(x[i]-x[j])+sq(y[i]-y[j])));
       }
   }
   ans/=p;
   cout<<fixed<<setprecision(10)<<ans<<"\n";
}



Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string str;
  cin >> str;

  const int n = str.length() + 1;
  vector<int> height(n, 0);

  for (int i = 1, h = 0; i < n; ++i) {
    if (str[i-1] == '<') ++h;
    else h = 0;
    height[i] = max(height[i], h);
  }

  for (int i = n-2, h = 0; i >= 0; --i) {
    if (str[i] == '>') ++h;
    else h = 0;
    height[i] = max(height[i], h);
  }

  long long ans = 0;
  for (int val : height) ans += val;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2820
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	uint N;
	cin >> N;
	
	uint K = 1;
	uint ans = 0;
	for(uint i=0; i<N; i++) {
		uint A;
		cin >> A;
		if(K == A) {
			K++;
		} else {
			ans++;
		}
	}
	
	if(K == 1) {
		cout << -1;
	} else {
		cout << ans;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
void solve(){
    int n;
    cin>>n;
    vector<vector<int>> dp(n,vector<int>(3));
    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            cin>>dp[i][j];
    for(int i=1;i<n;i++){
        dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]+=max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    solve(); cout<<endl;
    return 0;
}

Measured memory_bytes: 8720
n= int(input())
a = 0
b = 0
ab = 0
ba = 0
for i in range(n):
    s = input()
    for j in range(len(s)-1):
        if s[j] == "A" and s[j+1] == "B":
            ab+=1
    if s[len(s)-1] == "A":
        a += 1
    if s[0] == "B":
        b += 1
    if s[0] == "B" and s[len(s)-1] == "A":
        ba +=1
if a == b and b == ba and a != 0:
    print(ab + a - 1)
else:
    print(ab + min(a,b))

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

public class Main {

	public static void main(String[] args)
			throws java.io.IOException{
		Scanner scan = new Scanner(System.in);
		int[] delta=new int[10];
		//int max;
		//int datanum = scan.nextInt();
		
			for(int j=0;j<10;j++){
				delta[j] = scan.nextInt();
				
			}
			Arrays.sort(delta);
			for(int i =delta.length -1;i>delta.length -4;i--){
				System.out.println(delta[i]);
			}
			}
			
			
		}
		
		

Measured memory_bytes: 12000
#include<bits/stdc++.h>  
using namespace std;
 
#define mod 1e9+7
 
typedef long long ll;
 
int main()
{
   	ll n,temp;
   	vector<ll> v;
   	map<ll,ll> mp;

   	cin>>n;

   	for(ll i=0;i<n;i++){
   		cin>>temp;
   		v.push_back(temp);
   		mp[temp]++;
   	}

   	
   	ll overallAns=0;

	for(auto it=mp.begin();it!=mp.end();it++){
		overallAns+=((it->second)*(it->second-1))/2;
	}


   	for(ll i=0;i<n;i++){
   		ll item_cnt=mp[v[i]];
   		ll normal_cnt=(item_cnt*(item_cnt-1))/2;
   		item_cnt--;
   		ll new_cnt=(item_cnt-1)*(item_cnt)/2;
   		ll ans=overallAns-normal_cnt+new_cnt;
   		cout<<ans<<endl;
   	}
   	

    return 0;
}
     

Measured memory_bytes: 12912
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
using namespace std;

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

int N, M, A;
bool b[1020][120];

int solve() {
  vector<int> v;
  rep(i,N) v.push_back(i+1);
  for (int h = 1010; h >= 0; --h) {
    for (int i = 0; i < N-1; ++i) {
      if (b[h][i]) {
        swap(v[i], v[i+1]);
        // printf("%d %d swaped\n", v[i+1], v[i]);
        ++i;
      }
    }
  }
  return distance(v.begin(), find(v.begin(), v.end(), A)) + 1;
}

int main() {
  while (scanf("%d%d%d", &N, &M, &A), N | M) {
    memset(b, 0, sizeof b);
    int h, p, q;
    rep(i,M) {
      scanf("%d%d%d", &h, &p, &q);
      --p;
      b[h][p] = true;
    }
    printf("%d\n", solve());
  }
  return 0;
}

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

using namespace std;

const int WMAX = 1e5;

typedef long long LL;

int N, W;
LL dp[WMAX + 5];

int main()
{
    cin >> N >> W;
    for(int i = 1; i <= N; i++)
    {
        int w, v;
        cin >> w >> v;
        for(int j = W; j >= w; j--)
            dp[j] = max(dp[j], dp[j - w] + v);
    }

    cout << dp[W];

    exit(0);
}

Measured memory_bytes: 1024
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let s: Vec<char> = input::<String>().chars().collect();

    let mut v = vec![vec![]];
    let mut i = 0;
    let mut j = 0;
    while i < s.len() {
        if s[i] == 'A' {
            v[j].push('A');
        } else if s[i] == 'B' {
            if i < s.len() - 1 && s[i + 1] == 'C' {
                v[j].push('B');
                i += 1;
            } else {
                v.push(vec![]);
                j += 1;
            }
        } else {
            v.push(vec![]);
            j += 1;
        }
        i += 1;
    }

    let mut ans = 0i64;
    for u in v {
        let mut c = 0;
        for i in (0..u.len()).rev() {
            if u[i] == 'A' {
                ans += c;
            } else {
                c += 1;
            }
        }
    }

    println!("{}", ans);
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  ll mi=1005,ma=0;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  rep(i,n){
    ll a; cin>>a;
    chmax(ma,a);
    chmin(mi,a);
  }
  cout<<ma-mi<<endl;
}

Measured memory_bytes: 3644
//
// Created by ?????°?????? on 2016/07/02.
//

#include<iostream>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
using namespace std;

static const int N = 4;
static const int N2 =16;

static const int dx[4] = {0,-1,0,1};
static const int dy[4] = {1,0,-1,0};
static const int dir[4] = {'r','u','l','d'};
int MDT[N2][N2];

struct Puzzle{
    int f[N2],space,MD;
    int cost;

    bool operator < (const Puzzle &p) const{
        for (int i = 0; i < N2 ; ++i) {
            if(f[i] == p.f[i]) continue;
            return f[i] < p.f[i];
        }
        return false;
    }
};

struct State{
    Puzzle puzzle;
    int estimated;
    bool operator < (const State &s) const{
        return estimated > s.estimated;
    }
};

int getALLMD(Puzzle pz){
    int sum = 0;
    for (int i = 0; i < N2 ; ++i) {
        if(pz.f[i] == N2) continue;
        sum += MDT[i][pz.f[i] - 1];
    }
    return sum;
}

int astar(Puzzle s){
    priority_queue<State> PQ;
    s.MD = getALLMD(s);
    s.cost = 0;
    map<Puzzle,bool> V;
    Puzzle u,v;
    State initial;
    initial.puzzle = s;
    initial.estimated = getALLMD(s);
    PQ.push(initial);

    while (!PQ.empty()){
        State st = PQ.top(); PQ.pop();
        u = st.puzzle;

        if (u.MD == 0) return u.cost;
        V[u] = true;

        int sx = u.space / N;
        int sy = u.space % N;

        for (int r = 0; r < 4 ; ++r) {
            int tx = sx + dx[r];
            int ty = sy + dy[r];
            if (tx < 0 || ty < 0 || tx >= N || ty >= N) continue;
            v = u;

            v.MD -= MDT[tx * N + ty][v.f[tx * N +ty] - 1];
            v.MD += MDT[sx * N + sy][v.f[tx * N +ty] - 1];

            swap(v.f[sx * N + sy],v.f[tx * N + ty]);
            v.space = tx * N + ty;
            if(!V[v]){
                v.cost ++;
                State news;
                news.puzzle = v;
                news.estimated = v.cost + v.MD;
                PQ.push(news);
            }
        }
    }
    return -1;
}

int main(){
    for (int i = 0; i < N2 ; ++i) {
        for (int j = 0; j < N2 ; ++j) {
            MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
         }
    }
    Puzzle in;

    for (int i = 0; i < N2 ; ++i) {
        cin >> in.f[i];
        if (in.f[i] == 0){
            in.f[i] = N2;
            in.space = i;
        }
    }
    cout << astar(in) << endl;
    return 0;
}

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

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	for(int p = 1; p<= 1300; p++)
	{
		int p1 = p*0.08;
		int p2 = p*0.1;
		if(p1==a && p2==b){
			cout << p << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a;
  cin >> a;
  int sum = 0;
  string ans;
  int tmp = a;
  while(tmp > 0){
    sum += tmp % 10;
    tmp /= 10;
  }
  if (a % sum == 0) ans = "Yes";
  else ans = "No";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main() {
  string S;
  cin >> S;
  vector<long long> dp(2019,0);
  vector<int> a(S.length()+1),b(S.length()+1);
  a[0] = 1;
  b[0] = 0;
  int i,j;
  for(i=1;i<=S.length();i++) {
    a[i] = (a[i-1]*202)%2019;
    b[i] = ((b[i-1]-a[i]*(S[i-1]-'0'))%2019+2019)%2019;
  }
  long long cnt = 0;
  for(i=0;i<S.length();i++) {
    dp[((long long)a[i+1]*(S[i]-'0')+b[i+1])%2019] += 1;
    cnt += dp[b[i+1]];
  }
  cout << cnt << endl;
}

Measured memory_bytes: 5172
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define PI 3.141592653589793238462643L
int K[100000];
long double SIN(long double b) { return sinl(b * PI / 180.0L); }
int main() {
	int N, cnt = 0; long double a, sum, s[2], V;
	while (true) {
		for (int i = 0; i < 2; i++) {
			cin >> N; V = 0.0L; sum = 0.0L; if (N == 0) { goto E; }
			for (int i = 0; i < N - 1; i++) { cin >> a; sum += SIN(a); V += a; }
			sum += SIN(360.0L - V); s[i] = sum;
		}
		if (fabs(s[0] - s[1]) < 1e-9) { cout << '0' << endl; }
		else if (s[0] > s[1]) { cout << '1' << endl; }
		else if (s[0] < s[1]) { cout << '2' << endl; }
	}
E:;
	return 0;
}

Measured memory_bytes: 1224