akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

bool dp[8001][40000];
int solve(vector<int> a, int x){
	fill((bool*)dp, (bool*)(dp+8001) , 0);
	dp[0][20000] = 1;
	int n = a.size();
	for(int i = 0;i < n;i++){
		for(int j = 0;j < 40000;j++){
			if(j+a[i] < 40000)dp[i+1][j+a[i]] = max(dp[i+1][j+a[i]], dp[i][j]);
			if(j-a[i] >= 0)dp[i+1][j-a[i]] = max(dp[i+1][j-a[i]], dp[i][j]);
		}
	}
	if(dp[n][20000+x] == true)return 1;
	return 0;
}

int main(){
	vector<int> a, b;
	string str;
	int f = 0, sum = 0, from, x, y;
	cin >> str >> x >> y;
	str.push_back('T');
	
	for(from = 0;from < str.size();from++){
		if(str[from] == 'T')break;x--;
	}
	for(int i = from;i < str.size();i++){
		if(str[i] == 'T' && sum){
			if(f == 0)a.push_back(sum);
			else b.push_back(sum);
			sum = 0;
		}
		if(str[i] == 'F')sum++;
		if(str[i] == 'T')f = !f;
	}
	
	int t1 = solve(a, x);
	int t2 = solve(b, y);
	if(t1 && t2)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 312956
/**
 *    author:  tourist
 *    created: 28.06.2020 20:31:30       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int MAX = 1000010;
  vector<int> cnt(MAX);
  for (int i = 0; i < n; i++) {
    cnt[a[i]] += 1;
  }
  vector<bool> good(MAX, true);
  int ans = 0;
  for (int i = 1; i < MAX; i++) {
    if (cnt[i] != 0) {
      for (int j = i + i; j < MAX; j += i) {
        good[j] = false;
      }
    }
  }
  for (int i = 0; i < MAX; i++) {
    if (good[i] && cnt[i] == 1) {
      ++ans;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 8224
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int zalgorithm_modified(string s);

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int maxlen = 0;
    for (int i = 0; i < n; i++) {
        string s2 = s;
        for (int j = 0; j < i; j++) {
            s2.erase(s2.begin());
        }
        int len = zalgorithm_modified(s2);
        maxlen = max(maxlen, len);
    }
    cout << maxlen << endl;
}

// 
int zalgorithm_modified(string s) {
    int maxlen = 0;
    vector<int> A(s.size());
    int i = 1, j = 0;
    while (i < s.size()) {
        while (i + j < s.size() && s[j] == s[i + j]) ++j;
        A[i] = j;
        if (j == 0) { ++i; continue; }
        int k = 1;
        while (i + k < s.size() && k + A[k] < j) {
            A[i + k] = A[k];
            k++;
        }
        i += k;
        j -= k;
    }
    for (int l = 1; l < s.size(); l++) {
        int len = min(l, A[l]);
        maxlen = max(maxlen, len);
    }
    return maxlen;
}

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

using namespace std;

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

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

  int a=0;
  for(auto v : s){
    if(v=='R'){
      a++;
    }else if(a!=0 && v!='R'){
      break;
    }
  }

  cout << a << endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

#define LL long long
#define N 1000010
#define M 1010

using namespace std;

struct Edge {
    int from, to; 
}e[N]; 

int n,num,cnt,tot,ans;
int head[N],a[M][M],node[M][M];
int inq[N],t[N],day[N]; 

inline void add_edge(int x,int y) {
    e[++cnt].from = y;
    e[cnt].to = head[x];
    head[x] = cnt;
}
void topsort() {
    for(int i = 1; i <= tot; i++) {
        int u = t[i]; 
        for(int j = head[u]; j; j = e[j].to) {
            int v = e[j].from; 
            day[v] = day[u] + 1; 
            inq[v]--; 
            if(!inq[v])t[++tot] = v; 
        }
    }
    for(int i = 1; i <= num; i++)
        ans = max(ans, day[i]); 
}

int main() {
    scanf("%d",&n); 
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j < n; j++) {
            scanf("%d",&a[i][j]); 
            if(!node[i][j] && !node[j][i])
                node[i][j] = node[j][i] = ++num; 
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 2; j < n; j++) {
            add_edge(node[i][a[i][j-1]], node[i][a[i][j]]); 
            inq[node[i][a[i][j]]]++; 
        }
    }
    for(int i = 1; i <= num; i++) {
        if(!inq[i]) {
            t[++tot] = i; 
            day[i] = 1; 
        }
    }
    topsort(); 
    if(tot != num) puts("-1"); 
    else printf("%d\n", ans); 
    //system("pause");
    return 0; 
}

Measured memory_bytes: 31488
def solve(n, g):
    mod = 10 ** 9 + 7

    order = []
    parent = [-1] * n

    stack = [0]
    checked = [0] * n
    checked[0] = 1

    while stack:
        v = stack.pop()
        order.append(v)

        for u in g[v]:
            if checked[u]:
                continue
            checked[u] = 1
            stack.append(u)
            parent[u] = v

    order.reverse()

    dp_w = [1] * n
    dp_b = [1] * n

    checked = [0] * n

    for v in order:
        checked[v] = 1
        p = parent[v]

        if p == -1:
            continue

        dp_w[p] *= (dp_w[v] + dp_b[v])
        dp_w[p] %= mod

        dp_b[p] *= dp_w[v]
        dp_b[p] %= mod

    v = order[-1]
    return (dp_w[v] + dp_b[v]) % mod


if __name__ == '__main__':
    import sys

    input = sys.stdin.readline

    n = int(input())
    g = tuple(set() for _ in range(n))
    for _ in range(n - 1):
        x, y = (int(j) - 1 for j in input().rstrip().split())
        g[x].add(y)
        g[y].add(x)
    print(solve(n, g))

# トポロジカルソート
# 葉から根に向かう
# 親の状態数に子の状態数を掛け算していく
# 子が更新され尽くしている（子の子をすべて辿っている）必要があるので、トポロジカルソートする


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

int main(){
  int n; cin>>n;
  long long a[n],b[n],c[n],countA[n+1],countB[n+1];
  for(int i=0;i<n;i++){
    cin>>a[i];
    countA[i]=0;
    countB[i]=0;
  }for(int i=0;i<n;i++){
    cin>>b[i];
  }for(int i=0;i<n;i++){
    cin>>c[i];
  }sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  reverse(a,a+n);
  reverse(b,b+n);
  reverse(c,c+n);
  countA[n]=0; countB[n]=0;
  for(int i=0;i<n;i++){
    countB[i+1]=countB[i];
    for(int j=countB[i];j<n;j++){
      if(c[j]>b[i]) countB[i+1]++;
      else break;
    }
  }
  long long ans=0;
  int now=0;
  for(int i=0;i<n;i++){
    countA[i+1]=countA[i];
    for(int j=now;j<n;j++){
      if(b[j]>a[i]){
        countA[i+1]+=countB[1+j];
        now++;
      }
      else break;
    }
    ans+=countA[i+1];
  }cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;

bool check(ll n, vector<ll>& d) {
    while (n > 0) {
        ll t = n % 10;
        for (auto& e: d) {
            if (t == e) {
                return false;
            }
        }
        n /= 10;
    }
    return true;
}

int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> d(k);
    for (ll i = 0; i < k; i++) {
        cin >> d[i];
    }
    while (!check(n, d)) {
        n++;
    }
    cout << n << endl;
    return 0;
}

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

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

    for(int i = 0; i < m; i++){
        int k;
        scanf("%d", &k);
        n -= k;
    }

    if (n < 0) printf("-1\n");
    else printf("%d\n", n);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> p(n);
  for(int i = 0; i < n; i++){
    int x, y;
    cin >> x >> y;
    p.at(i) = {x, y};
  }
  
  sort(p.begin(), p.end());
  pair<int, int> lu = {p.at(0).first, p.at(0).second}, ld = {p.at(0).first, p.at(0).second};
  pair<int, int> ru = {p.at(0).first, p.at(0).second}, rd = {p.at(0).first, p.at(0).second};
  for(int i = 0; i < n; i++){
    int x = p.at(i).first, y = p.at(i).second;
    if(-(x - lu.first) + (y - lu.second) > 0) lu = {x, y};
    if(-(x - ld.first) - (y - ld.second) > 0) ld = {x, y};
    if((x - ru.first) + (y - ru.second) > 0) ru = {x, y};
    if((x - rd.first) - (y - rd.second) > 0) rd = {x, y};
    //cout << lu.first << " " << lu.second << " " << ld.first << " " << ld.second << " ";
    //cout << ru.first << " " << ru.second << " " << rd.first << " " << rd.second << endl;;
  }
  
  int ans = abs(lu.first - rd.first) + abs(lu.second - rd.second);
  ans = max(ans, abs(ld.first - ru.first) + abs(ld.second - ru.second));
  
  cout << ans << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <memory>
#include <cstring>
#include <cassert>
#include <numeric>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define REP2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(S) (S).begin(), (S).end()

template <typename T, typename E>
ostream &operator<<(std::ostream &os, const std::pair<T, E> &p){
  return os << "(" << p.first << ", " << p.second << ")";
}

typedef long long ll;

int main(){
  ios::sync_with_stdio(false);

  int n;
  while (cin >> n && n){
    vector<vector<pair<int, int> > > G(n);
    vector<int> par(n - 1);
    vector<int> cost(n - 1);
    REP(i, n - 1) cin >> par[i];
    REP(i, n - 1) cin >> cost[i];
    REP(i, n - 1){
      par[i]--;
      G[i + 1].push_back(make_pair(par[i], cost[i]));
      G[par[i]].push_back(make_pair(i + 1, cost[i]));
    }

    int res   = 0;
    int start = -1;
    
    REP(i, n - 1){
      int u = i + 1;
      int v = par[i];
      if (G[u].size() == 1 || G[v].size() == 1){
        res += cost[i];
      } else {
        res += 3 * cost[i];
        start = G[u].size() == 1 ? v : u;
      }
    }

    if (start >= 0){
      vector<int> dist(n, -1);
      queue<int> que;
      que.push(start);
      dist[start] = 0;
      int last = start;
      
      while (!que.empty()){
        int v = que.front(); que.pop();
        if (dist[v] > dist[last]) last = v;
        for (const auto &p : G[v]){
          if (G[p.first].size() != 1 && dist[p.first] == -1){
            dist[p.first] = dist[v] + p.second;
            que.push(p.first);
          }
        }
      }

      fill(ALL(dist), -1);
      que.push(last);
      dist[last] = 0;

      while (!que.empty()){
        int v = que.front(); que.pop();
        for (const auto &p : G[v]){
          if (G[p.first].size() != 1 && dist[p.first] == -1){
            dist[p.first] = dist[v] + p.second;
            que.push(p.first);
          }
        }
      }
      res -= *max_element(ALL(dist));
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1284
N, M = [int(x) for x in input().split()]
a = [None for i in range(M)]
b = [None for i in range(M)]

for i in range(M):
  a[i], b[i] = [int(x) - 1 for x in input().split()]

for i in range(N):
  num = 0
  for j in range(M):
    if a[j] == i or b[j] == i:
      num += 1
  print(num)

Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

#include <queue>
#include <cstdio>

#include <list>
#include <set>
#include <map>


#define PI (3.14159265358979323846)
#define INF (1e+9)
#define DIV_NUM (1000000007)

using namespace std;


bool seen[501][501];

int N, M;
int X, Y, Z;

int con;
//    string S;


char field[501][501];
int  dist[501][501];

typedef pair<int, int> P;
queue<P> que;


//typedef vector<vector<int>> v;
vector<double> ai;
vector<double> wi;


set<int> s1;
map<string, int> m1;
map<string, int> m2;

int weight[110], value[110];
int dp[110][10010];


int main(){
  
  
    //string ss ;


    cin >> N >> M ;
    double a = 0;
    double sum = 0;

    con = 0;
    //        std::cout << m1[ss] << ss  << "\n";

    for (int i = 0; i < N; ++i) {
        cin >> a;
        ai.push_back(a);
        sum = sum + a;
    }


    for (int i = 0; i < N; ++i) {
        if (ai[i] >= (sum / 4 / M)) {
            con++;
        }
    }

    if (con >= M) {
        std::cout << "Yes" << "\n";
    }else {
        std::cout << "No" << "\n";
    }

   

        return 0;

}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    string str;
    cin >> str;

    int N = str.size();
    vector<array<int, 27>> nxt(N + 2);

    fill(all(nxt[N+1]), N + 1);
    fill(all(nxt[N]), N + 1);

    for (int i = N - 1; i >= 0; i--) {
        int v = str[i] - 'a' + 1;

        nxt[i][v] = i + 1;

        for (int j = v + 1; j <= 26; j++)
            nxt[i][j] = nxt[nxt[i][j-1]][j-1];

        nxt[i][0] = nxt[nxt[i][26]][26];

        for (int j = 1; j < v; j++)
            nxt[i][j] = nxt[nxt[i][0]][j];
    }

    vector<array<int, 20>> zero(N + 2);
    fill(all(zero[N+1]), N + 1);
    fill(all(zero[N]), N + 1);

    for (int i = N - 1; i >= 0; i--) {
        zero[i][0] = nxt[i][0];
        for (int l = 1; l < 20; l++)
            zero[i][l] = zero[zero[i][l-1]][l-1];
    }

    int Q, l, r;
    cin >> Q;
    for (int q = 0; q < Q; q++) {
        cin >> l >> r;
        l--;

        for (int i = 19; i >= 0; i--)
            if (zero[l][i] <= r)
                l = zero[l][i];
        cout << (l == r ? "Yes" : "No") << "\n";
    }

    return 0;
}



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

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

    // costs to get to prev to prev, prev and cur stone
    int pprev = 0, prev = abs(a[1] - a[0]), cur = prev;

    for (int i = 2; i < n; ++i) {
        cur = min(abs(a[i] - a[i - 1]) + prev, abs(a[i] - a[i - 2]) + pprev);
        pprev = prev;
        prev = cur;
    }
    cout << cur << endl;

    return 0;
}

Measured memory_bytes: 4020
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int K = sc.nextInt();
        int S = sc.nextInt();
        
        int ans = 0;
        for (int x = 0; x <= K; x++) {
        	for (int y = 0; y <= K; y++) {
        		if (x+y > S)
        			break;
        		
        		if (S - (x + y) <= K) {
        			ans++;
        		}
        	}
        }
        
        System.out.println(ans);
    }
}	

Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
char s[210],t[210];
int n;
int main(){
	scanf("%s%s",s+1,t+1);
	n=strlen(s+1);
	rep(i,n+1,2*n){
		s[i]=s[i-n];
	}
	bool flag=0;
	rep(i,0,n-1){
		int tmp=1;
		rep(j,1,n){
			if(t[j]!=s[i+j]){
				tmp=0;
				break;
			}
		}
		if(tmp){
			flag=1;break;
		}
	}
	if(flag)	puts("Yes");
	else	puts("No");
	return 0;
}


Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val w = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" ").map(_.toInt))
    .toArray
    .sortBy(e => e(1))

  val res = w./:(0,true) { (acc, e) =>
    val c = e(0)
    val l = e(1)
    val v = acc._1 + c
    (v, acc._2 && (v <= l))
  }._2

  val ans = if(res) "Yes" else "No"
  println(ans)
}

Measured memory_bytes: 97180
import heapq
[n, k] = list(map(int, input().split()))
Healths = list(map(int, input().split()))
sum = 0
hh = heapq.nlargest(k, Healths)
for h in hh:
  sum+=h

sum2=0
for h in Healths:
  sum2+=h

print(sum2 - sum)

Measured memory_bytes: 33216
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int solve(const int n, int a[200])
{
  int cnt = 0;
  bool flg = true;
  while (flg) {
    REP(i, n) {
      if (a[i] % 2 == 0)
        a[i] = a[i] / 2;
      else
        flg = false;
    }
    if (flg)
      cnt++;
  }
  return cnt;
}

int main()
{
  int n, a[200];
  cin >> n;
  REP(i, n) cin >> a[i];
  cout << solve(n, a) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a[10],i,j,tmp;
	for(i=0;i<5;i++) scanf("%d ",&a[i]);
	for(i=0;i<5;i++){
		for(j=i+1;j<5;j++){
			if(a[i]<=a[j]){
				tmp=a[i]; a[i]=a[j]; a[j]=tmp;
			}
		}
	}
	for(i=0;i<5;i++){
		printf("%d",a[i]);
		if(i!=4)printf(" ");
		else printf("\n");
	}
	return 0;
}

Measured memory_bytes: 604
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
typedef vector<vector<int> > VVI;
const int INF = 1e9;
const double EPS = 1e-6;
int MOD = 256;

double calc(vector<int> &I, int N, int S, int A, int C)
{
	int R = S;
	double res = 0;
	vector<int> occur(256);
	
	for (int i=0; i<N; i++) {
		R = (A*R + C) % MOD;
		occur[(I[i]+R)%MOD]++;
	}
	
	for (int i=0; i<256; i++) {
		if (occur[i]>0) {
			res -= (double)occur[i]/N*log((double)occur[i]/N);
		}
	}
	
	return res;
}

int main()
{
	int N;
	while (cin>>N, N) {
		vector<int> I(N);
		rep(i, N) cin>>I[i];
		
		double min_e = INF;
		int ans[3] = {};
		for (int S=0; S<16; S++) {
			for (int A=0; A<16; A++) {
				for (int C=0; C<16; C++) {
					double now = calc(I, N, S, A, C);
					if (min_e - EPS> now) {
						min_e = now;
						ans[0] = S, ans[1] = A, ans[2] = C;
					}
				}
			}
		}
		
		cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	}
}

Measured memory_bytes: 1240
list1 = [int(a) for a in input().split()]
list1_0 = list1[0] #A駅B駅のX
list1_1 = list1[1] #B駅C駅のY

if (list1_0 + (list1_1 // 2)) <1000:
    print(list1_0 + (list1_1 // 2))
else:
    print(list1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,x=0;
  cin >> n >> k;
  long long a[n],b[n];
  pair<long long,long long> p[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    p[i]=make_pair(a[i],b[i]);
  }
  sort(p,p+n);
  for(int i=0;i<n;i++){
    x+=p[i].second;
    if(x>=k){
      cout << p[i].first << endl;
      return 0;
    }
  }
}


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

int main(){
  int a, b, d, r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = (double)a / b;
  cout << d << " " << r << " " << fixed << setprecision(10) << f << endl;
  return 0;
}


Measured memory_bytes: 3284
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    string s;
    cin>>s;
    ll w=0;
    while(s.size()>0 && (s[s.size()-1]=='\\' || s[s.size()-1]=='_')){s.pop_back();}
    reverse(s.begin(),s.end());
    while(s.size()>0 && (s[s.size()-1]=='/' || s[s.size()-1]=='_')){s.pop_back();}
    reverse(s.begin(),s.end());
    if(s.size()==0){cout<<0<<endl<<0<<endl; return 0;}
    
    vector<ll> a(s.size(),0),b(s.size(),0);
    vector<ll> h(s.size()+1,0);
    for(int i=0;i<h.size();i++){
        h[i]=w;
        if(i+1==h.size()){break;}
        if(s[i]=='/'){w++;}
        else if(s[i]=='\\'){w--;}
    }
    w=0;
    for(int i=0;i<a.size();i++){
        w=max(w,h[i]);
        a[i]=w;
    }
    w=h[h.size()-1];
    for(ll i=b.size()-1;i>=0;i--){
        w=max(w,h[i+1]);
        b[i]=w;
    }
    //if(s.size()==3){return 0;}
    vector<ll> lake(s.size(),0);
    for(int i=0;i<s.size();i++){
        if(s[i]=='/' && a[i]>=h[i+1]){
            lake[i]=(min(a[i],b[i])-h[i+1])*2+1;
        }
        else if(s[i]=='\\' && b[i]>=h[i]){
            lake[i]=(min(a[i],b[i])-h[i])*2+1;
        }
        else if(a[i]>h[i] && b[i]>h[i]){lake[i]=(min(a[i],b[i])-h[i])*2;}
    }
    ll count=0;
    ll sum=0;
    vector<ll> L;
    for(int i=0;i<s.size();i++){
        //cout<<lake[i]<<" ";
        if(lake[i]){
            sum+=lake[i];
            count+=lake[i];
        }
        else if(count>0){L.push_back(count/2); count=0;}
        if(count>0 && h[i+1]>=min(a[i],b[i])){L.push_back(count/2); count=0;}
    }
    //cout<<endl;
    if(count>0){L.push_back(count/2);}
    cout<<sum/2<<endl<<L.size();
    for(int i=0;i<L.size();i++){
        cout<<" "<<L[i];
    }
    cout<<endl;
    
    
    
    return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<algorithm>
#include<climits>
#include<map>
#include<unordered_map>
#define ll long long

bool isPrime(ll n){
    if(n<=1)  return false;
    if(n<=3)  return true;
    if(n%2==0 || n%3==0) return false;
    for(ll i=5;i*i<=n;i=i+6)
        if(n%i==0||n%(i+2)==0)
           return false;
    return true;
}

#define w(t) ll t,tt=1;	cin>>t;		while(t--)
#define ps(x,y) fixed<<setprecision(y)<<x
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

#define vi vector<int>
#define vll vector<ll>
#define mii map<ll,ll>
#define umii unordered_map<ll,ll>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>

#define mod 1e9+7
#define inf 1e18

#define lln ll n; cin>>n
#define intn int n; cin>>n
#define YES cout<<"YES"
#define NO cout<<"NO"
#define strr    string str; cin>>str;
#define strn   n=str.length()
#define fr(a,n) for(ll i=a;i<n;i++)
#define loop for(ll i=0;i<n;i++)

using namespace std;

void solve (){
    intn;
    strr;
    int R=count(str.begin(),str.end(),'R');
    int X=count(str.begin(),str.begin()+R,'W');
    int Y=count(str.begin()+R,str.end(),'R');
    cout<<X+Y-min(X,Y);
}

int main(){
    IOS
    solve();
    return 0;
}


Measured memory_bytes: 3776
n=int(input())
MAX_N=n
MEMO = [None] * (MAX_N + 1)
def f(n):
    if n==0:
        return 1
    if n==1:
        return 1
    if MEMO[n]:
        return MEMO[n]
    r=f(n-1)+f(n-2)
    MEMO[n]=r
    return r
    
print(f(n))


Measured memory_bytes: 5600
//082 B - Two Anagrams 2017/12/16
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
  string s, t; cin >> s >> t;
  sort(s.begin(),s.end());  
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if (s < t) cout << "Yes";
  else cout << "No";
  cout << endl;
}

Measured memory_bytes: 256
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

n,m=map(int, input().split())
uf1=UnionFind(n)
p=list(map(int,input().split()))
for i in range(m):
    a,b=map(int, input().split())
    uf1.union(a-1,b-1)

for i in range(n):uf1.find(i) 
ans=0
for i in range(n):
    if uf1.par[i]==uf1.par[p[i]-1]:
        ans+=1
print(ans)

Measured memory_bytes: 25140
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
x1, y1, x2, y2 = gets.chomp.split.map(&:to_i)

dx = x2 - x1
dy = y2 - y1

puts [x2-dy, y2+dx, x2-dy-dx, y2+dx-dy].join(' ')

Measured memory_bytes: 2172
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << endl;
#else
#define DBG(X)
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

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

	vector<int> a(n);

	for(auto& elem: a)
		cin >> elem;

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

	int j = n / 2, i = n / 2 - 1;

	cout << a[j] - a[i] << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include <string>

using namespace std;
#define ll long long int
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string s;
	cin >> s;
	int i = s.length();
	if (s[i - 1] == 's') {
		cout << s << "es";
	} else {
		cout << s << "s";
	}


	return 0 ;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N][2];
int n;
ll GetManhattan(int n, int dem)
{
    ll ans=0,Min,Max;
    int i,j,k;
    for(i = 0;i<(1<<(dem));i++) {
        Min=1e18,Max=-1e17;
        for(j=0;j<n;j++){
            ll sum = 0;
            for(k=0;k<2;k++){
                if(i&(1<<k)) sum+=a[j][k];
                else sum-=a[j][k];
            }
            if(sum>Max) Max=sum;
            if(sum<Min) Min=sum;
        }
        ans=max(ans,Max-Min);
    }
    return ans;
}

int main() {
    scanf("%d", &n);
    for(int i=0;i<n;i++)
        for(int j=0;j<2;j++)
            scanf("%lld", &a[i][j]);
    ll ans=GetManhattan(n,2);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 6956
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];


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

    int gou=0;
    rep(i,N){
        int A;
        cin >> A;
        gou += A;
    }
    if(H <= gou)cout <<"Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	vector<pair<int, int>> x(n);
	rep(i, 0, n - 1)
	{
		int a; cin >> a;
		x[i] = { a,i + 1 };
	}
	sort(all(x));
	rep(i, 0, n - 1)
	{
		cout << x[i].second << endl;
	}
}

Measured memory_bytes: 1536
define = [1]
def dekiru(numbers):
  t, x, y = map(int, numbers.split())
  time_x = t - x
  time_y = time_x - y
  if time_y%2 == 0 and time_y >=0:
    define.append(1)
  else:
    define.append(-1)
N = int(input())
count = 0
while count < N:
  dekiru(input())
  count += 1

if define.count(1) == N+1:
  print('Yes')
else:
  print('No')

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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;

int main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b)%24<<endl;
}



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

using namespace std;

vector<long long> div(long long n) {
    vector<long long > res;
    for (long long i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}

int main() {

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

    vector<long long> divs = div(accumulate(a.begin(),a.end(), 0LL));

    long long ans = 0;
  
    for(auto & e : divs){
      
        vector<long long> mods(n);
        for(int i=0;i<n;i++) mods[i] = a[i] % e;
      
        sort(mods.begin(),mods.end());

        vector<long long> minus(n + 1);
        for(int i=0;i<n;i++) minus[i + 1] = minus[i] + mods[i];

        vector<long long> plus(n + 1);
        for(int i=n-1;i>=0;i--) plus[i] = plus[i + 1] + e - mods[i];

        for (long long i = 0; i <= n; ++i) {
            if (max(plus[i], minus[i]) <= k) ans = max(ans, e);
        }
    }
    cout << ans << endl;
   
}


Measured memory_bytes: 256
//matrix.cpp
#include<iostream>
using namespace std;

int main()
{
    int n,m,l,i,j,k;
    cin>>n>>m>>l;
    long a[n][m],b[m][l],c[n][l];
    for ( i = 0; i < n; i++)
    {
        for ( j = 0; j < m; j++) cin>>a[i][j];
    }
    for ( i = 0; i < m; i++)
    {
        for ( j = 0; j < l; j++) cin>>b[i][j];
    }
    for ( i = 0; i < n; i++)
    {
        for ( j = 0; j < l-1; j++)
        {
            c[i][j]=0;
            for ( k = 0; k < m; k++) c[i][j]+=a[i][k]*b[k][j];
            cout<<c[i][j]<<" ";
        }
        c[i][l-1]=0;
        for ( k = 0; k < m; k++) c[i][l-1]+=a[i][k]*b[k][l-1];
        cout<<c[i][l-1]<<endl;
    }
}


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

int main() {
	int n, a, b, c, A, B, C;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		A = a * a;
		B = b * b;
		C = c * c;

		if (A + B == C || A + C == B || B + C == A) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}


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

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

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

  int n;
  cin >> n;

  ll ans = 0;
  for (int i = 1; i < n+1; i++)
  {
    for (int j = 1; j < n+1; j++)
    {
      for (int k = 1; k < n+1; k++)
      {
        int tmp = gcd(i, j);
        ans += gcd(tmp, k);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3656
#include<iostream>

using namespace std;

int main() {
    while(1){
      int n;
      cin >> n;
      if(n==0) break;
      int min = 1000000;
      int fee;
      for(int a=0;a<=n/200+1;a++){
	for(int b=0;b<=n/300+1;b++){
	  for(int c=0;c<=n/500+1;c++){
	    if(a*200+b*300+c*500==n){
	      fee=a*380+b*550+c*850;
	    if(a>=5) fee+=((a/5)*5*380)*0.8-(a/5*5*380);
	  if(b>=4) fee+=((b/4)*4*550)*0.85-(b/4*4*550);
	if(c>=3) fee+=((c/3)*3*850)*0.88-(c/3*3*850);
      if(min>fee) min=fee;
	    }
	  }
	}
      }	
      cout << min <<endl;
     } 
   return 0;
    }



Measured memory_bytes: 2964
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
    string S;
    cin >> S;

    char color = S[0];
    int ans = 0;
    for (int i = 1; i < S.length(); i++) {
        if (color != S[i]) {
            ans += 1;
            color = S[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
n,m = list(map(int,input().split()))
h = list(map(int,input().split()))
bridges = [list(map(int,input().split())) for i in range(m)]
cnt = [0]*n
for i in range(0,m):
  a, b = map(int, bridges[i])
  if h[a-1] == h[b-1]:
    cnt[a-1] += 1
    cnt[b-1] += 1
  elif h[a-1] > h[b-1]:
    cnt[b-1] += 1
  else:
    cnt[a-1] += 1
    
print(cnt.count(0))
    

Measured memory_bytes: 32024
#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost		    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;


/*

bool bs(LL l,LL r)
{
    int mid,res=-1;

    while(l<=r)
    {
        mid=l+(r-l)/2;



    }

    return res;
}


*/

//--------------------------code starts here---------------------------------------

int main()
{
    int n,k;
    sii(n,k);

    int a[n];


    Rep(i,0,n-1)
    {
        si(a[i]);
    }

    sort(a,a+n);

    int sum=0;
    Rep(i,0,k-1)
    {
        sum+=a[i];
    }

    printf("%d\n",sum);


    return 0;

}


Measured memory_bytes: 3832
#include <stdio.h>

// Euclidean Algorithm
int gcd(int x, int y) {
    return y ? gcd(y, x % y) : x;
}

int main() {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", gcd(x, y));
    return 0;
}



Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int cnt(pair<int, int> stert,bool g[22][22]){
    int x[] = {1,-1,0,0},y[] = {0,0,1,-1};
    int ans = 0;
    queue<pair<int, int>> next,now,empty;
    next.push(stert);
    do {
        ++ans;
        now = next;
        next = empty;
        while (!now.empty()) {
            g[now.front().first][now.front().second] = false;
            rep0(i, 4){
                if(g[now.front().first + x[i]][now.front().second + y[i]]){
                    next.push(make_pair(now.front().first + x[i], now.front().second + y[i]));
                    g[now.front().first + x[i]][now.front().second + y[i]] = false;
                }
            }
            now.pop();
        }
    } while (!next.empty());
    return ans - 1;
}

int main()
{
    int h,w;
    cin >> h >> w;
    bool G[22][22],G2[22][22];
    rep0(i, 22)rep0(j, 22)G[i][j] = false;
    rep0(i, h + 2){
        rep0(j, w + 2){
            if(i == 0 || i == h + 1 || j == 0 || j == w + 1)G[i][j] = false;
            else{
                char a;
                cin >> a;
                if(a == '#')G[i][j] = false;
                else G[i][j] = true;
            }
        }
    }
    int ans = 0;
    rep1(i, h){
        rep1(j, w){
            rep0(i, 22)rep0(j, 22)G2[i][j] = G[i][j];
            if(!G[i][j])continue;
            ans = max(ans, cnt(make_pair(i, j), G2));
        }
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(input()for _ in[0]*n)
b=list(input()for _ in[0]*m)
s=0
for i in range(n-m+1):
    for j in range(n-m+1):
        f=1
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:f=0
        s+=f
print("Yes"if s else"No")


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	int a, b;
	
	scanf("%d %d", &a, &b);
	int nilai[a];
	for(int i = 0; i<a; i++){
		scanf("%d", &nilai[i]);
	}
	for(int i=b;i<a;i++){
        if(nilai[i-b]<nilai[i]){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
    }
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
  }
  else if(N == 2) {
    int A, B;
    cin >> A >> B;
    cout << A + B << endl;
  }
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n+1) {
		if (i*i <= n)ans = i*i;
		if (i*i > n)break;
	}
	c(ans);
	ed;
	return 0; 
}



Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 1e15 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

int n ;
ll a[N], dp[N] ;

signed main(){
	scanf("%d", &n) ;
	for (int i = 1; i <= n; i++) scanf("%lld", &a[i]) ;
	for (int i = 0; i <= n; i++) dp[i] = linf ;
	dp[1] = 0ll ;
	for (int i = 2; i <= n; i++)
	dp[i] = min(dp[i], min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]))) ;
	printf("%lld\n", dp[n]) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))
count = 0

flag = 1
while flag:
    flag = 0
    for i in range(N-1, 0, -1):
        if A[i] < A[i-1]:
            A[i], A[i-1] = A[i-1], A[i]
            count += 1
            flag = 1

print(*A)
print(count)



Measured memory_bytes: 5604
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n = read::<u32>();
    let s = read::<String>().chars().collect::<Vec<_>>();
    
    let ans = s.iter().map(|&x| {
        std::char::from_u32('A' as u32 + (x as u32 - 'A' as u32 + n) % 26).unwrap()
    }).collect::<String>();

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

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  int b[30];
  for(int i=0; i < m; i++) cin >> b[i];
  int count = 0;
  for(int i=0 ;i < n; i++) {
    int total = c;
    for(int j=0; j < m; j++) {
      int a; cin >> a;
      total += b[j]*a;
    }
    if(total > 0) count++;
  }
  cout << count << endl;
}


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

void print(int *begin, int *end)
{
    for (int *i = begin; i != end; i++)
    {
        cout << *i << " ";
    }
    cout << endl;
}

bool back(int *begin, int *end)
{
    int *i = end - 1;
    while (i != begin)
    {
        // 順番がおかしいものを発見
        if (*(i - 1) > *i)
        {
            int *j = i;
            while (j != end)
            {
                if (*j > *(i - 1))
                    break;
                j++;
            }
            swap(*(i - 1), *(--j));
            std::reverse(i, end);
            return true;
        }
        i--;

        //print(begin, end);
    }

    return false;
}

int n;
int p[8];
int q[8];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    int a = 0;
    int b = 0;
    do
    {
        a++;
    } while (back(p, p + n));
    do
    {
        b++;
    } while (back(q, q + n));

    cout << abs(a - b) << endl;
}

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

int main() {
  int n;
  string s;
  int f = 0;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (s == "Y") {
      f = 1;
      break;
    }
  }
  
  if (f) {
    cout << "Four";
  }
  else {
    cout << "Three";
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(S: str, T: str):

    stdic = {}
    for s,t in zip(S,T):
        if s not in stdic:
            stdic[s] = t
        else:
            if stdic[s] != t:
                print(NO)
                return

    checkv = []
    for k,v in stdic.items():
        checkv.append(v)


    if len(checkv) == len(set(checkv)):
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    T = next(tokens)  # type: str
    solve(S, T)

if __name__ == '__main__':
    main()


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B, C, D, sum1, sum2;
    cin >> A >> B >> C >> D;
    sum1 = A * B;
    sum2 = C * D;
    if (sum1 >= sum2) {
        cout << sum1 << endl;
    } else {
        cout << sum2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n,y=map(int,input().split())
m=0
ans1=-1
ans2=-1
ans3=-1
for i in range(n+1):
    for j in range(n-i+1):
        k=n-i-j
        m=i*10000+j*5000+k*1000
        if m==y:
            ans1=i
            ans2=j
            ans3=k
            exit

print(ans1,ans2,ans3)

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl endl

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class DFloorFunction {
public:
  static void solve(std::istream &cin, std::ostream &cout) {
    int A, B, N;
    cin >> A >> B >> N;
    int ans = 0;
    for (int i = 1; B * i - 1 <= N; i++) {
      ans = max(ans, A * (B * i - 1) / B);
      break;
    }
    ans = max(ans, A * N / B - A * (N / B));
    cout << ans << endl;
  }
};


signed main() {
  DFloorFunction solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3684
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    string s[3];
    cin >> s[0]; s[0] += "A";
    cin >> s[1]; s[1] += "B";
    cin >> s[2]; s[2] += "C";
    ll p = 0, idx[3] = {};
    for(;;){
        char c = s[p][idx[p]];
        if('A' <= c && c <= 'C'){
            cout << c << endl;
            return 0;
        }
        idx[p]++;
        p = c - 'a';
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[200000];
map<long long,pair<long long,long long> > m1;
int main()
{
	int n;
	long long ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		m1[a[i]+i].first++;
		m1[i-a[i]].second++;
	}
	map<long long,pair<long long,long long> >::iterator it=m1.begin();
	for(it;it!=m1.end();it++)
	{
		ans+=((it->second.first)*(it->second.second));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 27820