akhauriyash/Code-Regression huggingface dataset:
s = input()
ans = []
now = "R"
rcount = 0
lcount = 0
for i in range(len(s)):
    if now == "R":
        if s[i] == "R":
            rcount += 1
        else:
            now = "L"
            lcount += 1
    else:
        if s[i] == "L":
            lcount += 1
        else:
            now = "R"
            for j in range(rcount-1):
                ans.append(0)
            if (rcount + lcount) % 2 == 0:
                ans.append((rcount + lcount)//2)
                ans.append((rcount + lcount)//2)
            else:
                if rcount > lcount:
                    if rcount % 2 == 0:
                        ans.append((rcount + lcount)//2)
                        ans.append((rcount + lcount)//2+1)
                    else:
                        ans.append((rcount + lcount)//2+1)
                        ans.append((rcount + lcount)//2)
                else:
                    if lcount % 2 == 0:
                        ans.append((rcount + lcount)//2+1)
                        ans.append((rcount + lcount)//2)
                    else:
                        ans.append((rcount + lcount)//2)
                        ans.append((rcount + lcount)//2+1)
            for j in range(lcount-1):
                ans.append(0)
            rcount = 1
            lcount = 0


for j in range(rcount-1):
    ans.append(0)
if (rcount + lcount) % 2 == 0:
    ans.append((rcount + lcount)//2)
    ans.append((rcount + lcount)//2)
else:
    if rcount > lcount:
        if rcount % 2 == 0:
            ans.append((rcount + lcount)//2)
            ans.append((rcount + lcount)//2+1)
        else:
            ans.append((rcount + lcount)//2+1)
            ans.append((rcount + lcount)//2)
    else:
        if lcount % 2 == 0:
            ans.append((rcount + lcount)//2+1)
            ans.append((rcount + lcount)//2)
        else:
            ans.append((rcount + lcount)//2)
            ans.append((rcount + lcount)//2+1)
for j in range(lcount-1):
    ans.append(0)

print(" ".join(map(str, ans)))


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

namespace ConsoleApplication1
{
    class Node
    {
        internal List<int> target;
        internal int inDegree;
        internal bool isVisit;

        public Node()
        {
            target = new List<int>();
        }
    }

    class SearchOrder
    {
        Node[] list;
        List<int> result;

        public SearchOrder(int m)
        {
            list = Enumerable.Range(0, m).Select(a => new Node()).ToArray();
            result = new List<int>();
        }

        public void MakeList(int s, int t)
        {
            list[s].target.Add(t);
            list[t].inDegree++;
        }

        public void Print()
        {
            TopologicalSort(list);

            StringBuilder sb = new StringBuilder();
            foreach (int node in result)
            {
                sb.AppendLine((node + 1).ToString());
            }
            Console.Write(sb);
        }

        private void TopologicalSort(Node[] NL)
        {
            for (int i = 0; i < NL.Length; i++)
            {
                if (NL[i].inDegree == 0 && !NL[i].isVisit)
                {
                    BFS(NL, i);
                }
            }
        }

        private void BFS(Node[] NL, int s)
        {
            Queue<int> que = new Queue<int>();
            que.Enqueue(s);

            while (que.Count > 0)
            {
                int u = que.Dequeue();

                NL[u].isVisit = true;
                result.Add(u);

                for (int i = 0; i < NL[u].target.Count; i++)
                {
                    int v = NL[u].target[i];
                    NL[v].inDegree--;

                    if (NL[v].inDegree == 0 && !NL[v].isVisit)
                    {
                        que.Enqueue(v);
                    }
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int m = int.Parse(Console.ReadLine());
            int n = int.Parse(Console.ReadLine());

            SearchOrder S = new SearchOrder(m);

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int x = int.Parse(input[0]) - 1;
                int y = int.Parse(input[1]) - 1;

                S.MakeList(x, y);
            }
            S.Print();
        }
    }
}

Measured memory_bytes: 10592
#include <algorithm>
#include <iostream>

using namespace std;

int A[100] = {0};

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

  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    sum += A[i];
  }
  int floor = sum / N;
  int ceil = (sum - 1) / N + 1;

  int ans = 0;
  int ans2 = 0;
  for (int i = 0; i < N; ++i) {
    ans += (A[i] - floor) * (A[i] - floor);
    ans2 += (A[i] - ceil) * (A[i] - ceil);
  }
  cout << min(ans, ans2) << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))



def solve(N,B):
    ans = []
    for _ in range(N):
        m = max(B)
        if m > len(B):
            return [-1]
        for i in range(m,0,-1):
            if B[i-1]==i:
                B.pop(i-1)
                ans.append(i)
                break
        else:
            return [-1]
    return ans
ans = solve(N,B)

print(*ans[::-1], sep='\n')

Measured memory_bytes: 3064
N, M = map(int, input().split())
H = list(map(int, input().split()))
LIST = [ 1 for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    if H[A-1] >= H[B-1]: LIST[B-1] = 0
    if H[A-1] <= H[B-1]: LIST[A-1] = 0
print(sum(LIST))

Measured memory_bytes: 20108
#include <bits/stdc++.h>
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

int main(void) {
    string s,t;cin>>s>>t;
    unordered_map<char, vector<ll> > mp;
    unordered_map<char, ll> mp2;
    ll n = s.size(),m=t.size();
    rep(i,n){
        mp[s.at(i)].push_back(i);
        mp2[s.at(i)]++;
    }
    rep(i,m){
        if(mp2[t.at(i)]==0){
            cout << -1 << endl;
            return 0;
        }
    }
    ll res = 0;
    ll now = 0;
    ll cur = 0;
    rep(i,m){
        auto valcur = lower_bound(mp.at(t.at(i)).begin(), mp.at(t.at(i)).end(), res%n);
        DEBUG{
            cout << t.at(i) << " ";
        }
        if(valcur == mp.at(t.at(i)).end()){
            DEBUG{
                printf("next\n");
            }
            res += n + mp.at(t.at(i)).at(0) - res % n;
        }else{
            DEBUG{
                printf("same\n");
            }
            res += *valcur - res % n;
        }
        DEBUG{
            cout << res << endl;
        }
        res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
int main() {
	ll n;
	cin>>n;
	vector<ll>q;
	vector<ll>p;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			q.push_back(i);
			q.push_back(n/i);
		}
	}
	for(ll i=1;i*i<=n-1;i++){
		if((n-1)%i==0){
			p.push_back(i);
			p.push_back((n-1)/i);
		}
	}	
	set<ll>ans;
	for(ll i=0;i<q.size();i++){
		ll k=q[i];
		if(k==1){
			continue;
		}
		ll now=n;
		while(now%k==0){
			now/=k;
		}
		now%=k;
		if(now==1){
			ans.insert(k);
			//cout <<k<<endl;
		}
	}
	for(ll i=0;i<p.size();i++){
		ll k=p[i];
		if(k==1){
			continue;
		}
		if((n-1)%k==0){
			ans.insert(k);
		}
	}
	cout << ans.size();
	// your code goes here
	return 0;
}

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

int main() {
	int t,c=0;
  cin>>t;
  while(t--)
  {
    int a,b;
    cin>>a>>b;
    if(a==b)
      c++;
      else
      c=0;
    if(c>=3)
    break;
  }
  if(c>=3)
    cout<<"Yes\n";
  else
    cout<<"No\n";
	
	
	return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNext()) {
			int cycle = scanner.nextInt();
			if(cycle == 0) return;
			
			int count;
			int target;
			
			String text = scanner.next();
			StringBuffer sb = new StringBuffer();
			
			for(int i = 0; i < cycle; i++) {
				sb.setLength(0);
				count = 1;
				target = Integer.valueOf(text.substring(0, 1));
				
				for(int p=1; p<text.length(); p++) {
					if (target == Integer.valueOf(text.substring(p, p+1))) {
						count++;
					} else {
						sb.append(count);
						sb.append(target);
						
						count = 1;
						target = Integer.valueOf(text.substring(p, p+1));
					}
				}
				sb.append(count);
				sb.append(target);
				
				text = sb.toString();
			}
			System.out.println(text);
		}
	}
}

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

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

#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find(all(v), i) != (v).end())
#define ERASE(v,i) (v).erase(remove(all(v), i), (v).end())
#define INDEX(v,i) (find(all(v), i) - (v).begin())
#define rep(i,n) for(int i = 0; i < (int)n; ++i)
#define debug(x) cerr << #x << " = " << (x) << endl;

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

const int INF = 100000000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int main() {
	vector<int> arr(5);
	rep(i,5) cin >> arr[i];
	sort(arr.rbegin(), arr.rend());
	cout << arr[0];
	for(int i = 1; i < 5; i++) cout << " " << arr[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
using System;

static class abc120a
{
    static void Main()
    {
        var t = Console.ReadLine().Split();
        var A = int.Parse(t[0]);
        var B = int.Parse(t[1]);
        var C=int.Parse(t[2]);
        Console.WriteLine(Math.Min(B/A, C));
    }
}

Measured memory_bytes: 11092
// 未解決

#include <bits/stdc++.h>

#include <iostream>
using namespace std;

#define EACH(i, a) for (auto &&i : a)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RFOR(i, a, b) for (int i = (int)b - 1; i >= (int)a; --i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREPS(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <class T>
void pv(T a, T b) {
  for (T i = a; i != b; ++i) cout << *i << " ";
  cout << endl;
}
template <class T>
void pvp(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << "(" << i->first << ", " << i->second << ") ";
  cout << endl;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}

using ll = long long;
#define int ll

template <typename Sequence, typename BinaryPredicate>
struct IndexCompareT {
  IndexCompareT(const Sequence &seq, const BinaryPredicate comp)
      : seq_(seq), comp_(comp) {}
  bool operator()(const size_t a, const size_t b) const {
    return comp_(seq_[a], seq_[b]);
  }
  const Sequence seq_;
  const BinaryPredicate comp_;
};

template <typename Sequence, typename BinaryPredicate>
IndexCompareT<Sequence, BinaryPredicate> IndexCompare(
    const Sequence &seq, const BinaryPredicate comp) {
  return IndexCompareT<Sequence, BinaryPredicate>(seq, comp);
}

template <typename Sequence, typename BinaryPredicate>
std::vector<size_t> ArgSort(const Sequence &seq, BinaryPredicate func) {
  std::vector<size_t> index(seq.size());
  for (int i = 0; i < index.size(); i++) index[i] = i;

  std::sort(index.begin(), index.end(), IndexCompare(seq, func));

  return index;
}
//**********

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

  int n, m;
  cin >> n >> m;

  if (n % 2 == 1) {
    // odd: easy
    REP(i, m) { cout << i + 1 << " " << n - i << endl; }
  } else {
    // even: hard
    int c_odd = (m + 1) / 2;
    int c_even = m / 2;
    REP(i, c_odd) {
      // diff 1, 3, 5,...
      cout << n - c_odd - i << " " << n - c_odd + 1 + i << endl;
    }
    REP(i, c_even) {
      // diff 2, 4, 6,...
      cout << c_even - i << " " << c_even + 2 + i << endl;
    }
  }
  return 0;
};


Measured memory_bytes: 3644
// Problem : C - A x B + C
// Contest : AtCoder - AtCoder Beginner Contest 179
// URL : https://atcoder.jp/contests/abc179/tasks/abc179_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、 
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	ll ans=0;
	FOR(x,1,N)
	{
		FOR(y,1,N)
		{
			if(x*y>=N)
				break;
			ans++;
		}
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3648
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

int main() {
    string S;
    cin >> S;
    if(S=="ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }


    return 0;
}


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

int main()
{
    vector<int> a(3);
    for (int i = 0; i < 3;i++){
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    cout << a.at(2) * 10 + a.at(1) + a.at(0) << endl;
}


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

using namespace std;

#ifdef ACMTUYO
struct RTC{~RTC(){cerr << "Time: " << clock() * 1.0 / CLOCKS_PER_SEC <<" seconds\n";}} runtimecount;
#define DBG(X) cerr << #X << " = " << X << '\n';
#else
struct RTC{};
#define DBG(X)
#endif

#define fast_io() ios_base::sync_with_stdio(false)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(c) (c).begin(),(c).end()
#define forn(i, n) for (int i = 0; i < (n); i++)
typedef long long int ll;
const int maxn = 200010;
const ll mod = 1000000007LL;
int main() {
  int n;
  scanf("%d", &n);
  ll sum = 0, ans = 0;
  forn (i, n) {
    ll x;
    scanf("%lld", &x);
    ans = (ans + sum * x) % mod;
    sum = (sum + x) % mod;
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main(){
  while(1){
  int n;
  cin >> n;
  if(!n) break;
  vector<int> train(24*60*60,0);
  for(int i=0; i<n; i++){
    int h,m,s;
    scanf("%d:%d:%d",&h,&m,&s);
    int from = h*60*60 + m*60 + s;
    scanf("%d:%d:%d",&h,&m,&s);
    int to = h*60*60 + m*60 + s;
    for(int i=from; i<to; i++){
      train[i] ++;
    }
  }
  cout << *max_element(train.begin(),train.end()) << endl;
  }
}

Measured memory_bytes: 1572
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
 
int main() {
	ll n;
	cin >> n;
  	ll odd = 0;
	vector<ll> A(n);
	rep(i, n) {
		cin >> A[i];
	}
	rep(i, n) {
		if(A[i] % 2 != 0) ++odd;
	}
  	if(odd % 2 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

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

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    vector<bool> visited(n);

    int i;
    int cnt = 0;
    for (i = 0; i != 1 && !visited[i]; i = a[i]) {
        visited[i] = true;
        cnt++;
    }

    cout << (i == 1 ? cnt : -1) << endl;


    return 0;
}


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

void dfs(int node, vector<int> adj[], int dp[], bool vis[]) 
{ 
	vis[node] = true; 

	for (int i = 0; i < adj[node].size(); i++) { 

		if (!vis[adj[node][i]]) 
			dfs(adj[node][i], adj, dp, vis); 

		
		dp[node] = max(dp[node], 1 + dp[adj[node][i]]); 
	} 
} 


void addEdge(vector<int> adj[], int u, int v) 
{ 
	adj[u].push_back(v); 
} 


int findLongestPath(vector<int> adj[], int n) 
{ 
	// Dp array 
	int dp[n + 1]; 
	memset(dp, 0, sizeof dp); 
	bool vis[n + 1]; 
	memset(vis, false, sizeof vis);  
	for (int i = 1; i <= n; i++) { 
		if (!vis[i]) 
			dfs(i, adj, dp, vis); 
	} 

	int ans = 0; 
	for (int i = 1; i <= n; i++) { 
		ans = max(ans, dp[i]); 
	} 
	return ans; 
} 

 
int main() 
{ 
	int n, m;
	cin>>n>>m; 
	vector<int> adj[n + 1]; 
	int x,y;
	while(m--){
		cin>>x>>y;
		addEdge(adj, x, y);
	}


	cout << findLongestPath(adj, n); 
	return 0; 
} 


Measured memory_bytes: 12832
import bisect

n, m = map(int, input().split())
l = []

for _ in range(m):
  a, b = map(int, input().split())
  l.append((a,b))
  
l_ = sorted(l, key=lambda x:x[1])

ans = 0
rb = 0

for d in l_:
  if not d[0] <= rb < d[1]:
    rb = d[1]-1
    ans += 1
    
print(ans)

Measured memory_bytes: 18972
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

int main()
{
    char s[60];
    while(cin>>s)
    {
        int len=strlen(s);
        for(int i=0;i<len-8;i++){
            printf("%c",s[i]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
CHTに帰着
*/

template<typename T>
class ConvecHullTrick {
private:
	// 直線群(配列)
	std::vector<std::pair<T, T>> lines;
	// 最小値(最大値)を求めるxが単調であるか
	bool isMonotonicX;
	// 最小/最大を判断する関数
	std::function<bool(T l, T r)> comp;

public:
	// コンストラクタ ( クエリが単調であった場合はflag = trueとする )
	ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc = [](T l, T r) {return l >= r; })
		:isMonotonicX(flagX), comp(compFunc)  {
		lines.emplace_back(0, 0);
	};

	// 直線l1, l2, l3のうちl2が不必要であるかどうか
	bool check(std::pair<T, T> l1, std::pair<T, T> l2, std::pair<T, T> l3) {
		if (l1 < l3) std::swap(l1, l3);
		return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
	}

	// 直線y=ax+bを追加する
	void add(T a, T b) {
		std::pair<T, T> line(a, b);
		while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
			lines.pop_back();
		lines.emplace_back(line);
	}

	// i番目の直線f_i(x)に対するxの時の値を返す
	T f(int i, T x) {
		return lines[i].first * x + lines[i].second;
	}

	// i番目の直線f_i(x)に対するxの時の値を返す
	T f(std::pair<T, T> line, T x) {
		return line.first * x + line.second;
	}

	// 直線群の中でxの時に最小(最大)となる値を返す
	T get(T x) {
		// 最小値(最大値)クエリにおけるxが単調
		if (isMonotonicX) {
			static int head = 0;
			while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
				++head;
			return f(head, x);
		}
		else {
			int low = -1, high = lines.size() - 1;
			while (high - low > 1) {
				int mid = (high + low) / 2;
				(comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
			}
			return f(high, x);
		}
	}
};

ll n,c,h[200010],dp[200010];

int main(void){
	cin>>n>>c;
	rep(i,n)cin>>h[i];
	ConvecHullTrick<ll> cht(true);
	rep(i,n)dp[i]=1e18;
	dp[0]=0;
	cht.add(-2*h[0],dp[0]+h[0]*h[0]);
	reg(i,1,n-1){
		dp[i]=cht.get(h[i])+h[i]*h[i]+c;
		cht.add(-2*h[i],dp[i]+h[i]*h[i]);
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 9456
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
    string S;
    cin >> S;
    int key = 0;
    long long ans=0;
    for(int i = 0;i < S.size();i++){
        if(S[i] == 'W'){
            ans += i - key;
            key++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
S = list(input())
if 1 <= int(''.join(S[:2])) <= 12 and 1 <= int(''.join(S[2:])) <=12:
    print('AMBIGUOUS')
elif 1 <= int(''.join(S[2:])) <=12:
    print('YYMM')
elif 1 <= int(''.join(S[:2])) <= 12:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;


int main(void){
    string S;cin>>S;
    string ans;
    REP(i,S.size()){
        if(S[i]!='B'){
            ans.push_back(S[i]);
        }else if(ans.size()!=0){
            ans.pop_back();
        }
    }

    cout<<ans<<endl;
}




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

using namespace std;
int minHeight(int arr[], vector<int> &dp, int index)
{
  int len = dp.size();
  if(index >= len)
  {
    return 0;
  }
  if(dp[index] == -1)
  {
   	int t1,t2;
    dp[index] = min( abs( arr[index] - arr[index - 1] ) + minHeight(arr, dp, index - 1), abs( arr[index] - arr[index - 2] ) + minHeight(arr, dp, index - 2) );
  }
  return dp[index];                 
}

int main()
{
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++)
  {
   	cin >> arr[i];
  }
  vector<int> ans(n,-1);
  ans[0] = 0;
  ans[1] = abs( arr[1] - arr[0] );
  minHeight(arr, ans, n-1);
  cout<< ans[n-1] <<endl;
}


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

int main(){
  long long int s,c;
  long long int ans;
  cin >> s >> c;

  if(s >= c/2){
    cout << c/2 << endl;
  }else{
    ans = s;
    c -= s*2;
    ans += c/4;
    cout << ans << endl;
  }
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define sqr(x) (x)*(x)
#define endl "\n"
#define mod 1000000007

int main()
{
    string str;
    cin>>str;
    if(str[0]=='7' || str[1]=='7' || str[2]=='7') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int nxt[500010],n,x,y,a[500010],p[500010],b[500010],ans,hed[500010],too[500010],nedge,dep[500010];
void ae(int x,int y){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
}
void dfs(int x,int l){
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		dep[y]=dep[x]+1;
		dfs(y,x);
	}
}
bool cmp(int x,int y){
	return (dep[x]>dep[y]);
}
int main(){
	cin>>n;
	FOR(i,2,n){
		getint(x),getint(y);
		ae(x,y),ae(y,x);
	}
	FOR(i,1,n) getint(a[i]);
	sort(a+1,a+n+1);
	dfs(1,0);
	FOR(i,1,n) p[i]=i;
	sort(p+1,p+n+1,cmp);
	FOR(i,1,n){
		int x=p[i];
		b[x]=a[i];
		if (i<n) ans+=b[x];
	}
	cout<<ans<<endl;
	FOR(i,1,n) printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  int n;	cin >> n;
  vector<int>	p(n);
  rep(i,n)	cin >> p[i];
  
  int ans=0;
  for(int i=1;i<n-1;i++){
    if(min(p[i-1],p[i+1])<p[i]&&p[i]<max(p[i-1],p[i+1]))	ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int N = Integer.parseInt(sl[0]);
            int K = Integer.parseInt(sl[1]);

            System.out.println(N % K == 0 ? 0 : 1);
        }
    }
}


Measured memory_bytes: 22868
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

int X[30];
int main(){
    string A;
    cin >> A;
    int N = A.length();
    ll ans = 0;
    REP(i, N){
        char a = A[i];
        int x = X[a - 'a'];
        ans += max(0, i-x);
        X[a - 'a']++;
    }

    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
#define N 200005
char str[N];

int main()
{
    int a,b,c,s,k;
    LL ans;
    while(~scanf("%d%d",&k,&s)){
        ++k;
        ans=0;
        rep(i,0,k){
            rep(j,i,k){
                rep(l,j,k){
                    if(i+j+l==s){
                        if(i==j&&j==l) ++ans;
                        else if(i==j||j==l) ans+=3;
                        else ans+=6;
                    }
                }
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef complex<double> P;
double toRad(double agl){return agl*M_PI/180.0;}
P rotate(P a, double r){return P(a.real()*cos(r)-a.imag()*sin(r),a.real()*sin(r)+a.imag()*cos(r));}
P rotate2(P a, P b, double r){a-=b;a=rotate(a,r);a+=b;return a;}

void Main() {
  P p,q;
  double x1,x2,y1,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  p=P(x1,y1);
  q=P(x2,y2);
  P p2=rotate2(p,q,toRad(270));
  P q2=rotate2(q,p,toRad(90));
  p2=P(round(p2.real()),round(p2.imag()));
  q2=P(round(q2.real()),round(q2.imag()));
  pr((ll)p2.real(),(ll)p2.imag(),(ll)q2.real(),(ll)q2.imag());
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 640
import collections

n = int(input())

res = []

for _ in range(n):
  res.append(input())

c = collections.Counter(res)
aa = c.most_common()

ss = aa[0][1]
res2 = []

aa.sort()
for i in aa:
  if i[1] == ss:
    res2.append(i[0])

for i in res2:
  print(i)

Measured memory_bytes: 47032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

int main(){
    int n;
    cin >> n;
    map<string, int>m;
    rep(i, n){
        string s; cin >> s;
        m[s]++;
    }

    int MAX = 0;
    for (auto mm : m){
        chmax(MAX, mm.second);
    }

    vector<string> vs;
    for (auto mm : m){
        if(mm.second==MAX){
            vs.emplace_back(mm.first);
        };
    }

    sort(vs.begin(), vs.end());
    
    rep(i, vs.size()){
        cout << vs[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 26868
N=int(input())
S=input()

dpL=[0 for _ in range(N)]
dpR=[0 for _ in range(N)]

for i in range(1,N):
  if S[i-1]=='W':
    dpL[i]=dpL[i-1]+1
  else:
    dpL[i]=dpL[i-1]

for i in range(1,N):
  if S[N-i]=='E':
    dpR[N-i-1]=dpR[N-i]+1
  else:
    dpR[N-i-1]=dpR[N-i]

ans=10**6
for i in range(N):
  ans=min(ans,dpR[i]+dpL[i])
  
print(ans)

Measured memory_bytes: 17860
let h, w = Scanf.scanf "%d %d\n" (fun a b -> a, b)
let ar = Array.init h (fun _ -> Scanf.scanf "%s\n" (fun x -> x))
let b = Buffer.create (h * w)
let d = [0,1;1,1;1,0;1,-1;0,-1;-1,-1;-1,0;-1,1]

let search pos =
  List.fold_left (fun acc (x, y) ->
      let ni, nj = fst pos + y, snd pos + x in
      if (match ni, nj with
          | a, _ when a < 0 || h <= a -> false
          | _, b when b < 0 || w <= b -> false
          | _, _ -> true)
      then
        (if ar.(ni).[nj] = '#' then acc + 1 else acc)
      else acc
    )  0 d

let () =
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      if ar.(i).[j] = '#' then Buffer.add_char b '#'
      else Buffer.add_string b (search (i,j) |> string_of_int)
    done ;
    Buffer.add_string b "\n"
  done ;
  Buffer.contents b |> print_string

Measured memory_bytes: 2432
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>

int main()
{
  
  int m,min,max;
  while(scanf("%d%d%d",&m,&min,&max)==3){
      if(m==0&&min==0&max==0){
          break;
      }
      else
      {
          int a[100000];
          int count = 0;
          for(int i=0;i<m;i++){
              scanf("%d",&a[i]);
          }
          int step = 0;
          for(int i=min;i<=max;i++){
              if(a[i-1]-a[i]>=step){
                 step = a[i-1]-a[i];
                 count = i;
              }
          }
          printf("%d\n",count);
              
          
      }
      
  }
    return 0;
}



Measured memory_bytes: 2728
(* Vicfred
 * https://atcoder.jp/contests/abc136/tasks/abc136_c
 * greedy
 * *)
let n = Scanf.scanf "%d\n" ( + ) 0
let h = Array.init n @@ fun _ -> Scanf.scanf " %d" ( + ) 0
let maxima = ref @@ h.(0) - 1
let main =
    for i = 1 to n - 1 do
        if !maxima > h.(i) then ( print_endline "No"; exit 0);
        maxima := h.(i) - if !maxima < h.(i) then 1 else 0
    done;
    print_endline "Yes"



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

int main(){
  ll N;
  cin >>N;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){
    cin >>vec[i];
  }
  sort(vec.rbegin(),vec.rend());
  ll ans=0,t=N-1;
  for(int i=0;i<N;i++){
    ll lim=2;
    if(i==0){
      lim=1;
    }
    for(int j=0;j<lim;j++){
      if(t>0){
       ans+=vec[i];
       t--;
      }
    }
  }
  cout << ans <<endl;
}

    
  

Measured memory_bytes: 4852
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#include <time.h>
#include <chrono>
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>b;i--)
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,l,r) for(int i=(1);i<(r);i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (1LL << 31) - 1;
const ll mod = 1e9 + 7;

ll N;
string S;
ll sum[200001];//白の数
ll ans = mod;


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


	cin >> N;
	cin >> S;
	ll Red = 0;

	FOR(i, 0, N) {
		if (S[i] == 'R')Red++;

		sum[i+1] = (i + 1) - Red;//iまでのwhilteの数
	}
	FOR(i, 0, N + 1) {
		if (i == 0)ans = min(ans, Red);
		else {
			ll rightred = Red - i + sum[i];
			ll leftwhite = sum[i];

			if (leftwhite >= rightred) ans = min(leftwhite, ans);
			else ans = min(rightred, ans);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5328
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

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

int ice[14][14];
int num[10000];
int gx,gy;

int ans = 0;
int ccc = 0;
void dfs(int x,int y,int C,int px,int py){
  if( c[y][x] == '#' || c[y][x] == '*') return;
  if( C + abs(x-gx) + abs(y-gy) >= ans ) return;
  if( c[y][x] == 'G'){ans = C; return; }

  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( px == tx && ty == py ) continue;
    if( c[ty][tx] == '*' ) return;
  }
  char cur = c[y][x];
  c[y][x] = '*';
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' ){
      int b = ice[ty][tx];
      if( num[b] > 0 ){
	num[b]--;
	dfs(tx,ty,C+1,x,y);
	num[b]++;
      }
    }else{
      dfs(tx,ty,C+1,x,y);
    }
  }
  c[y][x] = cur;
  return;
}
void grouping(int x,int y,int k){
  ice[y][x] = k;
  num[k]++;
  for(int i = 0 ; i < 4 ; i++){
    int tx = x + dx[i];
    int ty = y + dy[i];
    if( c[ty][tx] == 'X' && ice[ty][tx] < 0 )grouping(tx,ty,k);
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  int W,H;
  while(cin >> W >> H && W){
    memset(ice,-1,sizeof(ice));
    rep(i,14)rep(j,14) 
      c[i][j] = '#';
    int sx , sy;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
	cin >> c[i+1][j+1];
	if(c[i+1][j+1] == 'S'){
	  c[i+1][j+1] = '.';
	  sx = j+1 , sy = i+1;
	}else if(c[i+1][j+1] == 'G' ){
	  gx = j+1 , gy = i+1;
	}
      }
    }
    int k = 0;
    for(int i = 1 ; i <= H ; i++){
      for(int j = 1 ; j <= W ; j++){
	if( c[i][j] == 'X' && ice[i][j] < 0){
	  num[k] = 0;
	  grouping(j,i,k);
	  num[k] /= 2;
	  k++;
	}
      }
    }
    ans = 1e7;
    dfs(sx,sy,0,-1,-1);
    cout << ans << endl;
    
  }
}

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

using namespace std;

int A[2020];
int N;
int l, r;

bitset<4040404> B;

int main() {
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", &A[i]);

	int s = 0;

	for(int i = 1; i <= N; i++) {
		B |= (B << A[i]);
		B[A[i]] = 1;
		s += A[i];
	}
	s = s + 1 >> 1;

	for(int i = 0; i <= 2000; i++) {
		if(B[s + i]) { printf("%d\n", s + i); break; }
	}
	return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  char a[h][w];
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      cin >> a[i][j];
    }
  }
  for(int i = 0;i < h;i++){
    for(int j= 0;j < w;j++){
      if(a[i][j] == '#'){
        break;
      }
      if(j == w-1){
        for(int k = 0;k < w;k++){
          a[i][k] = '0';
        }
      }
    }
  }
  for(int i = 0;i < w;i++){
    for(int j= 0;j < h;j++){
      if(a[j][i] == '#'){
        break;
      }
      if(j == h-1){
        for(int k = 0;k < h;k++){
          a[k][i] = '0';

        }
      }
    }
  }
  string ans = "";
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      if(a[i][j] == '0'){
        continue;
      }
      ans += a[i][j];
    }
    if(ans == ""){
      continue;
    }
    cout << ans << endl;
    ans = "";
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    rep(i, 1, n) {
        int x;
        cin >> x;
        if(x & 1) continue;
        if(x % 3 && x % 5) {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}


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

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

    reverse(L.begin(), L.end());
    long long M = 1000000007;
    vector<long long> X(L.size());
    vector<long long> Y(L.size());    
    if (L[0]=='0')
    {
        X[0] = 1;
        Y[0] = 3;
    }
    else
    {
        X[0] = 3;
        Y[0] = 3;
    }
    for (int i=1; i<(int)L.size(); i++)
    {
        if (L[i]=='0')
        {
            X[i] = X[i-1];
            Y[i] = 3*Y[i-1]%M;
        }
        else
        {
            X[i] = (2*X[i-1] + Y[i-1])%M;
            Y[i] = 3*Y[i-1]%M;
        }
    }
    cout<<X.back()<<endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  int res = 0;
  for(int i = 0; i < N; ++i){
    int tmp;
    cin >> tmp;
    res += 2 * min(tmp, K-tmp);
  }
  cout << res << endl;
    
}


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

int main(){
  int a, b, ans = 0;
  cin >> a >> b;
  while(a <= b){
    if(a / 10000 == a % 10 &&(a / 1000 - (a / 10000) * 10) == (a % 100 - a % 10) / 10){
      ans++;
    }
    a++;
  }
  cout << ans;
}

Measured memory_bytes: 3552
// Author: Jashan Bansal
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second	
#define mp make_pair
#define int long long
#define ll long long
#define pii pair<int,int>
#define all(arr) arr.begin(), arr.end()
#define sz(arr) ((long long)arr.size())
// const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
#define log1(x) cout << x << '\n'
#define log2(x,y) cout << x << " " << y <<'\n'
#define log3(x,y,z) cout << x <<" " << y <<" " << z << '\n'
#define logarr(arr,n) for(int __=0; __ < n; __++)	cout << arr[__] << " "; cout << '\n'

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

string lcs(int x, int y, string s1, string s2){
    vector<vector<int>> dp(x+1, vector<int>(y+1,0));
    
    for(int i=1; i<= x; i++){
        for(int j=1; j<=y; j++){
            if(s1[i-1] == s2[j-1]){
                dp[i][j] = dp[i-1][j-1] + 1;
            }   
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string ans = "";

    int i=x, j=y;

    while(i>0 && j>0){
    	if(s1[i-1] == s2[j-1]){
    		ans = s1[i-1] + ans;
    		i--;
    		j--;
    	}
    	else if(dp[i-1][j] > dp[i][j-1]){
    		i--;
    	}
    	else{
    		j--;
    	}
    }

    return ans;
}


void solve(){
	string s1, s2;
	cin >> s1;
	cin >> s2;
	
	int x = s1.size();
	int y = s2.size();

	string ans = lcs(x,y,s1,s2);

	cout << ans << '\n';
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	// cin>>t;
	while(t--)
		solve();
	return 0;
}	



Measured memory_bytes: 70784
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a = IL()
l = a[0]+a[1]
r = a[2]+a[3]

if l > r:
	print("Left")
elif l == r:
	print("Balanced")
else:
	print("Right")

Measured memory_bytes: 12108
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N=0;
    long long zahyo[100005];
    long long kingaku[100005];
    long long print=0;
    long long tmp=0;
    long long  sum=0,ans=0;
    cin>>N;

    zahyo[0]=0;
    zahyo[N+1]=0;

    for(int i=1;i<=N;i++){
        cin>>zahyo[i];
        kingaku[i]=abs(zahyo[i]-zahyo[i-1]);
        ans+=kingaku[i];
    }
        kingaku[N+1]=abs(zahyo[N]);
        ans+=kingaku[N+1];
    

    for(int i=1;i<=N;i++){
        print=ans-kingaku[i]-kingaku[i+1]+abs(zahyo[i+1]-zahyo[i-1]);


        cout<<print<<endl;
    }

}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    deque<int> d;
    rep(i, n){
        if((i % 2 == 0) ^ (n % 2 == 0)){
            d.push_front(a[i]);
        }else{
            d.push_back(a[i]);
        }
    }
    rep(i, n){
        cout << d[i];
        if(i == n - 1){
            cout << endl;
        }else{
            cout << " ";
        }
    }
    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

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

    string s, t; cin >> s >> t;
    for (char c = 'a'; c <= 'z'; c++) {
        if (s+c == t) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3656
n, W = list(map(int, input().split()))
w = [0 for i in range(n + 1)]
v = [0 for i in range(n + 1)]
for i in range(n):
    w[i + 1], v[i + 1] = list(map(int, input().split()))
dp = [[0 for i in range(W+1)] for j in range(n+1)]
for i in range(1,n+1):
    for j in range(1,W+1):
        if w[i] > j:
            dp[i][j] = dp[i - 1][j]
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i])
print(int(dp[n][W]))

Measured memory_bytes: 171400
#include <stdio.h>


int main(){
  int i,j,monsatp[40000],a,b,cn,flag,mon;
  monsatp[0] = 6;
  cn = 0;
  for(i=1;((7*i+1) < 300000) ||  (7*i+6 < 300000);i++){
    a = 7*i+1,b = 7*i+6;
    flag = 1;
    if(a < 300000){
      for(j=0;monsatp[j]*monsatp[j] <= a;j++){
        if (a % monsatp[j] == 0) flag = 0;
      }
    }
    if(flag) monsatp[++cn] = a;
    flag = 1;
    if(b < 300000){
      for(j=0;monsatp[j]*monsatp[j] <= b;j++){
        if (b % monsatp[j] == 0) flag = 0;
      }
    }
    if(flag) monsatp[++cn] = b;
  }

  while(1){
    scanf("%d",&mon);
    if(mon == 1) break;
    printf("%d:",mon);
    for(i=0;i<=cn;i++){
      if(mon % monsatp[i] == 0) printf(" %d",monsatp[i]);
      }
     printf("\n");
  }

  return 0;
}

Measured memory_bytes: 560