akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
N = int(input())
H = list(map(int,input().split()))

ans = 'Yes'
diff = 0

for i in range(N - 1):
	diff = H[i + 1] - H[i]

	if diff >= 1:
		H[i + 1] -= 1
	elif diff < 0:
		ans = 'No'

print(ans)

Measured memory_bytes: 14252
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        if(sc.nextInt() + sc.nextInt() + sc.nextInt() <= 21){
            System.out.println("win");
        }else{
            System.out.println("bust");
        }
    }
}

Measured memory_bytes: 21972
N=int(input())
a=list(map(int,input().split()))
A=sorted(a,reverse=True)
if N%2==1:
    s=A[0]+A[(N-1)//2]
    for i in range((N-1)//2-1):
        s+=A[i+1]*2
    print(s)
else:
    s=A[0]
    for i in range(N//2-1):
        s+=A[i+1]*2
    print(s)

Measured memory_bytes: 93932
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    while (true)
    {
        c -= b;
        if (c <= 0) {
            cout << "Yes";
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No";
            break;
        }
    }



    return 0;
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

const int MAXN = 100005;
vector<int> g[MAXN], v1, v2;

bool visited[MAXN];

void dfs1(int v)
{
    visited[v] = true;
    v1.PB(v);
    for (auto to : g[v])
    {
        if (visited[to]) continue;
        dfs1(to);
        break;
    }
}

void dfs2(int v)
{
    visited[v] = true;
    v2.PB(v);
    for (auto to : g[v])
    {
        if (visited[to]) continue;
        dfs2(to);
        break;
    }
}

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

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n, m;
    cin >> n >> m;
    for (int i=0;i<m;i++)
    {
        int u, v;
        cin >> u >> v;
        g[v].PB(u);
        g[u].PB(v);
    }
    dfs1(1);
    dfs2(1);
    reverse(v2.begin(), v2.end());
    v2.pop_back();
    vector<int> ans;
    for(auto cur: v2)
    {
        ans.PB(cur);
    }

    for(auto cur: v1)
    {
        ans.PB(cur);
    }

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



Measured memory_bytes: 10296
n = int(input())%26
alp = list(input())

num = []
alpha2num = lambda c: ord(c) - ord('A') + 1
num2alpha = lambda c: chr(c+64)

for i in range(0,len(alp)):
    num.append(alpha2num(alp[i]))
    num[i]+=n
    if num[i]>26:
        num[i]=num[i]-26
    alp[i]=num2alpha(num[i])

ans = "".join(alp)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#define ill long long
#define rep(i, a, b) for(ill i = (ill)(a); i < (ill)(b); i++)
#define fcout cout << fixed << setprecision(10)
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && c <= b) cout << "Yes\n";
  else cout << "No\n";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod 1000000007
#define pb emplace_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    string s;
    cin>>s;
    ll arr[3]={0};
    for(auto v:s)
    	arr[v-'a']++;
    sort(arr,arr+3);
    if(arr[2]-arr[0]<=1)
    	cout<<"YES";
    else
    	cout<<"NO";
    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

#define A first
#define B second

ll n, a[3005];
vector<int> g[3005];
int m[3005][3005];

void dfsdown(int v, int f = -1) {
	for (int u : g[v]) {
		if (u == f)
			continue;
		dfsdown(u, v);
		if (a[u] >= a[v])
			m[v][u] = 2;
		else {
			m[v][u] = 1;
			for (int w : g[u]) {
				if (w == v)
					continue;
				if (m[u][w] == 1)
					m[v][u] = 2;
			}
		}
	}
}

void dfsup(int v, int f = -1) {
	for (int u : g[v]) {
		if (u == f)
			continue;
		if (a[u] <= a[v])
			m[u][v] = 2;
		else {
			m[u][v] = 1;
			for (int w : g[v]) {
				if (w == u)
					continue;
				if (m[v][w] == 1)
					m[u][v] = 2;
			}
		}

		dfsup(u, v);
	}
}

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

	for (int i = 0; i < n-1; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;

		g[a].push_back(b);
		g[b].push_back(a);
	}

	dfsdown(0);
	dfsup(0);

	for (int i = 0; i < n; ++i) {
		bool y = 0;
		for (int u : g[i])
			if (m[i][u] == 1)
				y = 1;
		if (y)
			cout << i+1 << ' ';
	}

	cout << endl;
}

Measured memory_bytes: 34816
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * https://atcoder.jp/contests/abc173/submissions/15455890 を参考に実装したソースコード
 */
public class Main {

	private static final long MOD = 1_000_000_007L;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), k = scanner.nextInt();
			long[] a = IntStream.range(0, n).mapToLong(i -> scanner.nextLong()).sorted().toArray();
			int left = 0, right = n - 1;
			long answer = (1 == (k & 1)) ? a[right--] : 1L;
			long sign = (answer < 0) ? -1 : 1;
			while (k > 1) {
				if (sign * a[left] * a[left + 1] >= sign * a[right] * a[right - 1]) {
					answer = answer * a[left++] % MOD;
					answer = answer * a[left++] % MOD;
				} else {
					answer = answer * a[right--] % MOD;
					answer = answer * a[right--] % MOD;
				}
				k -= 2;
			}
			System.out.println((answer + MOD) % MOD);
		}
	}
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> v;
  int sum = 0;
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
    sum += tmp;
  }
  sort(v.rbegin(), v.rend());
  bool flg = true;
  for(int i = 0; i < M; i++){
    if(v[i] * 4 * M < sum) {
      flg = false;
      break;
    }
  }
  
  cout << (flg ? "Yes" : "No" ) << endl;
  
}
  


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

// マクロ
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス
using lint = long long;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;

int main() {

	int N, X;
	cin >> N >> X;

	cou((N * 500 >= X ? "Yes" :"No"));
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int x,y,z;
  x = a + b;
  y = a - b;
  z = a * b;

  int max;
  max = x;
  if(max < y){
    max = y;
  }
  if(max < z){
    max = z;
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<algorithm>
#include<cstdlib>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;

using namespace std;
bool solve(deque<int> toAdd, deque<int> l,deque<int> r){
	if(toAdd.size()==0)return true;
	bool flag = false;
	if(l[l.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		l.push_back(j);
		flag = flag || solve(toAdd,l,r);
		//back to original problem
		toAdd.push_front(j);
	        l.pop_back();
	}
	if(flag)return true;
	if(r[r.size()-1]<toAdd.front()){
		int j = toAdd.front();
		toAdd.pop_front();
		r.push_back(j);
		flag = flag || solve(toAdd,l,r);
	}
	return flag;
}
int main(){
	int n;
	cin>>n;
	while(n-->0){
		deque<int> balls;
		for(int x=0;x<10;++x){
			int j;cin>>j;
			balls.push_back(j);
		}
		deque<int> sol;sol.push_back(0);
		if(solve(balls,sol,sol)){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1212
/**
 * Created at 17:39 on 2019/03/07
 */

import java.io.*;
import java.util.*;

public class Main {

  static FastScanner sc = new FastScanner();

  public static void main(String[] args) {

    int[] n = new int[3];
    int maxIndex = 0;
    for (int i=0; i<3; i++) {
      n[i] = sc.nextInt();
      if (n[i] > n[maxIndex]) {
        maxIndex = i;
      }
    }

    int sum = 0;

    for (int i=0; i<3; i++) {
      if (i == maxIndex) {
        sum += 10 * n[i];
      } else {
        sum += n[i];
      }
    }

    System.out.println(sum);


  }

  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      return (int) nextLong();
    }
  }

}


Measured memory_bytes: 22484
#include<iostream>
#include <vector>
#include <string>
#include <limits.h>
#include <algorithm>

#define ll long long int
using namespace::std;

ll check(ll le, ll lw, ll re, ll rw){
	return lw + re;
}

ll count(ll& num, string& list){
	ll east = 0, west = 0;
	for (ll i = 0; i < num; ++i){
		if (list[i] == 'E'){
			east++;
		}
		else{
			west++;
		}
	}
	ll le = 0, lw = 0, rw = west, re = east;
	ll min_op = LLONG_MAX;
	for (ll i = 0; i < num; ++i){
		if (list[i] == 'E'){
			re--;
			min_op = min(min_op, check(le, lw, re, rw));
			le++;
		}
		else{
			rw--;
			min_op = min(min_op, check(le, lw, re, rw));
			lw++;
		}
	}
	return min_op;
}

int main(){
	ll num;
	cin >> num;
	string list;
	cin >> list;
	cout << count(num,list) << endl;
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
        for (auto &u : v) os << u << endl;
        return (os);
}


template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
        for (auto &u : v) is >> u;
        return (is);
}

int main() {
    int N, M;
    int A[305][305];

    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j]; --A[i][j];
        }
    }

    int ng = -1, ok = N + 1;
    while (abs(ok - ng) > 1) {
        int m = (ok + ng) / 2;
        set<int>dame;
        int surface[305] = {};
        while (dame.size() < M) {
            int cnt[305] = {};
            for (int i = 0; i < N; i++) cnt[A[i][surface[i]]]++;
            bool flag = false;
            for (int i = 0; i < M; i++) {
                if (cnt[i] > m) { flag = true; dame.insert(i); break; }
            }
            if (!flag) { ok = m; break; }
            for (int i = 0; i < N; i++) {
                while (surface[i] < M && dame.find(A[i][surface[i]]) != dame.end()) {
                    surface[i]++;
                }
            }
        }
        if (ok != m) ng = m;
    }
    cout << ok << endl;
    return (0);
}


Measured memory_bytes: 640
n=int(input())
build=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
for i in range(n):
    b,f,r,v=map(int,input().split())
    build[b-1][f-1][r-1]+=v

for k in range(4):
    for j in range(3):
        print(" "+" ".join([str(x) for x in build[k][j]]))
    if k!=3:
        print("#"*20)


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

int main(){
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==b&&c==d&&a!=c){
    cout<<"Yes";
    }else if(a==c&&b==d&&a!=b)cout<<"Yes";
    else if(a==d&&b==c&&a!=b)cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define printd(x) printf("%.12f\n", ans);
#define print(x) cout << (x) << endl;
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;


vector<vector<bool>> vvi(15, vector<bool>(15, false));

int main(void) {
    int n, m, k;
    cin >> n >> m >> k;

    vector<bool> ok(n * m + 1, false);

    if (k % n == 0 || k % m == 0) {
        Yes();
        return 0;
    }

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            ok[i * (n - j) + (m - i) * j] = true;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            ok[i * (m - j) + (n - i) * j] = true;
        }
    }
    cout << (ok[k] ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int dp[100005][3];
int a[100005],b[100005],c[100005];

int main() {
	int n;
	cin>>n;
	for (int i = 0; i < n ; i++) {
	    cin>>a[i]>>b[i]>>c[i];
	}
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	
	for(int i=1;i<n;i++)
	{
	    dp[i][0]=(a[i]+max(dp[i-1][1],dp[i-1][2]));
	    dp[i][1]=(b[i]+max(dp[i-1][0],dp[i-1][2]));
	    dp[i][2]=(c[i]+max(dp[i-1][1],dp[i-1][0]));
	}
	cout<< max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  for(int x=0;x<=N;x++){
    for(int y=0;y<=N;y++){
      int sum = 10000*x + 5000*y + 1000*(N-x-y);
      if(N-x-y<0) continue;
      if(sum==Y){
        cout << x << " " << y << " " << N-x-y << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int L,R,d;
   cin >> L >> R >> d;
   int r=R/d;
   int l=(L-1)/d;
   cout << r-l <<endl;
   return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int a[26];
    for (int i = 0; i < 26; i++) a[i] = 0;
    bool occur = true;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        a[s[i] - 97]++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (a[i] == 0)
        {
            occur = false;
            cout << char(i + 97);
            break;
        }
    }
    if (occur == true) cout << "None";
}

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

int main() {
  int N;
  cin >> N;
  string types[] = {"AC", "WA", "TLE", "RE"};
  map<string, int> m;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    m[str]++;
  }
  for (int i=0; i<4; i++) {
    cout << types[i] << " x " << m[types[i]] << endl;
  }
  return 0;
}

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

ll dp [61][2][2][2];

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  ll l, r;
  cin >> l >> r;

  constexpr ll mod = 1e9 + 7;
  dp[60][0][0][0] = 1;
  for (int i = 59; i >= 0; --i) {
    int lb = (l >> i) & 1;
    int rb = (r >> i) & 1;
    rep(j, 2) {
      rep(k, 2) {
        rep(s, 2) {
          rep(x, 2) {
            ll pre = dp[i+1][j][k][s];
            rep(y, 2) {
              if (x && !y) continue; 
              int nj = j, nk = k, ns = s; 
              if (!s && x != y) continue;
              if (x && y) ns = 1; 
              if (!j && !x && lb) continue;
              if (x && !lb) nj = 1;
              if (!k && y && !rb) continue;
              if (!y && rb) nk = 1;
              dp[i][nj][nk][ns] += pre;
              dp[i][nj][nk][ns] %= mod;
            }
          }
        }
      }
    }
  }
  ll ans = 0;
  rep(j, 2) {
    rep(k, 2) {
      rep(s, 2) {
        ans += dp[0][j][k][s];
        ans %= mod;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

const int N = 105;

int n, m;
bool A[N][N], mr[N], mc[N];

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) {
        char c; scanf(" %c", &c);
        A[i][j] = c == '#';
    }
    for(int i = 1; i <= n; ++i) {
        bool st = true;
        for(int j = 1; j <= m; ++j) st &= !A[i][j];
        if(st) mr[i] = true;
    }
    for(int i = 1; i <= m; ++i) {
        bool st = true;
        for(int j = 1; j <= n; ++j) st &= !A[j][i];
        if(st) mc[i] = true;
    }
    for(int i = 1; i <= n; ++i) if(!mr[i]) {
        for(int j = 1; j <= m; ++j) if(!mc[j]) printf("%c", A[i][j] ? '#' : '.');
        puts("");
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

using PII = pair<int, int>;

int main() {
	int n, m, a, b;
	cin >> n >> m;

	priority_queue<PII, vector<PII>, greater<PII>> que;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		que.push(make_pair(a, b));
	}

	long long ans = 0;
	while (m > 0) {
		auto p = que.top();
		que.pop();

		int buy = min(p.second, m);
		// cout << "check: " << p.first << " " << p.second << " " << buy << endl;
		ans += 1LL * p.first * buy;

		m -= buy;
	}

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


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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, K;
    cin >> N; cin >> K;

    string S;
    cin >> S;

    int res = 0;
    bool flag = false;
    int c1 = 0;
    int c2 = 0;
    REP(i, N-1) {
        if (S[i] == S[i+1]) {
            ++res;
        } else {
            ++c1;
            if (flag) {
                ++c2;
                flag = false;
            } else {
                flag = true;
            }
        }
    }

    if (c2 >= K) {
        res += 2 * K;
    } else {
        res += 2 * c2;
        K -= c2;
        res += min(K, c1 - 2 * c2);
    }

    cout << res << endl;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vll A,B;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
		B.pb(a);
	}
	for(int i=1;i<N;i++)
		A[i]+=A[i-1];
	for(int i=N-2;i>=0;i--)
		B[i]+=B[i+1];
	//[0,n)の最適な分断点
	int tes[SIZE]={};
	int t=0;
	for(int h=1;h<N;h++){
		while(t<h-1 && abs(A[h]-2*A[t])>abs(A[h]-2*A[t+1]))
			t++;
		tes[h]=t;
	}
	//(n,N-1]の最適な分断点
	int ket[SIZE]={};
	int h=N-1;
	for(t=N-2;t>=0;t--){
		while(t+1<h && abs(B[t]-2*B[h])>abs(B[t]-2*B[h-1]))
			h--;
		ket[t]=h;
	}
	ll ans=INF;
	for(int i=1;i<N-2;i++){
		ans=min(ans,max({A[tes[i]],A[i]-A[tes[i]],A[ket[i+1]-1]-A[i],A[N-1]-A[ket[i+1]-1]})-min({A[tes[i]],A[i]-A[tes[i]],A[ket[i+1]-1]-A[i],A[N-1]-A[ket[i+1]-1]}));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5092
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool comp(pair<int,int>a,pair<int,int>b){
	return a.first<b.first;
}
void solve(){
	int n;cin>>n;
	vector<pair<int,int>>a(n);int x;
	for(int i=0;i<n;i++) {
		cin>>x;
		a[i]={x,i+1};
	}
	sort(a.begin(),a.end());
	for(int i=0;i<a.size();i++) cout<<a[i].second<<" ";
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);	 
	int T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4740
import bisect

A,B,Q = map(int,input().split())

shira = [-100000000000] + [int(input()) for _ in range(A)] + [10000000000000]
temp = [-100000000000] + [int(input()) for _ in range(B)] + [10000000000000]

shira.sort()
temp.sort()

for _ in range(Q):
    x = int(input())
    shira_s = bisect.bisect_left(shira,x)
    temp_s = bisect.bisect_left(temp,x)
    ans = 100000000000
    for i in [shira_s-1,shira_s]:
        for j in [temp_s-1,temp_s]:
            ans = min(ans, abs(shira[i]-x)+abs(shira[i]-temp[j]))
            ans = min(ans, abs(temp[j]-x)+abs(temp[j]-shira[i]))
    print(ans)

Measured memory_bytes: 91232
/*
  AUTHOR:SOURABH
  CREATED:31:05:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pii , null_type, less< pii >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

const ll L=1e18;

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

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,n,i,q,f,ans;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        f=1;
        vll a(n);
        fn(i,n)
        {cin>>a[i];if(!a[i])f=0;}
        if(!f){cout<<0;return 0;}
        ans=1;
        fn(i,n)
        {
            q=L/ans;
            if(a[i]>q)
            {ans=-1;break;}
            else
                ans=ans*a[i];
        }
        cout<<ans;
    }
    return 0;
}








Measured memory_bytes: 3960
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    for i in 1..2000 {
        if i * 8 / 100 == a && i * 10 / 100 == b {
            println!("{}", i);
            return;
        }
    }
    println!("-1");
    return;
}

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 read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;

int main() {
  long double a, b, x;
  cin >> a >> b >> x;

  long double h, ans;
  if (a * a * b / 2 <= x) {
    h = 2 * b - 2 * x / (a * a);
    ans = atan2(h, a) * 180 / M_PI;
  }
  else {
    h = 2 * x / (a * b);
    ans = 90 - (atan2(h, b) * 180 / M_PI);
  }

  cout << setprecision(10) << ans << endl;

  

  
  return 0;
}


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

int x1, y1, x2, y2;
int main() {
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 + (y1 - y2);
    int y3 = y2 + (x2 - x1);
    int x4 = (x1 + x3) - x2;
    int y4 = (y1 + y3) - y2;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

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


int main(){
	/*input*/
	long long n;
	vector <long long>vec;
	int k;
	int tmp = 0;
	cin >> n >> k;

	while(n!=0){
		tmp = n % k;
		n /= k;
		vec.push_back(tmp);

	}


	/*calc*/

	/*output*/
	int ans = vec.size();
	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    sort(all(A));
    vector<l_l> v;
    rep(i,N)rep(j,N){
        if(i < j){
            v.emplace_back(i,j);
        }
    }
    dump(A);
    ll ans = 0;
    for(auto [i, j] : v){
        ll l = abs(A[i]-A[j]);
        ll r = abs(A[i]+A[j]);
        dump(i, j);
        dump(l+1, r);
        ll cnt = lower_bound(all(A), r) - lower_bound(all(A), l+1);
        if(l < A[i] && A[i] < r)cnt--;
        if(l < A[j] && A[j] < r)cnt--;
        dump(cnt);
        ans += cnt;
    }
    cout << ans/3 << endl;
}


Measured memory_bytes: 36260
//
//  main.cpp
//  ALDS1_4_A
//
//  Created by ptyuan on 2018/10/22.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>
using namespace std;

int linearSearch(int *array, int n, int key) {
    *(array + n ) = key;
    int i = 0;
    while (array[i] != key) {
        i++;
    }
    return i == n ? -1 : i;
}

int main(int argc, const char * argv[]) {
    int n = 0;
    int S[10000 + 1] = {0};
    int q = 0;
    int sum = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", S + i);
    }
    
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int key = 0;
        scanf("%d", &key);
        if (-1 != linearSearch(S, n, key)) {
            sum++;
        }
    }
    printf("%d\n", sum);
    
    return 0;
}



Measured memory_bytes: 3276
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int a,b;
	cin>>a>>b;
	string s[a][b];
	rep(i,a)rep(j,b){
		cin>>s[i][j];
		if(s[i][j]=="snuke"){
			cout<<(char)('A'+j);
			cout<<i+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  ll n,k;
  cin>>n>>k;
  pair<int,int> p[n];
  rep(i,0,n) cin>>p[i].first>>p[i].second;
  sort(p,p+n);
  rep(i,0,n){
    k-=p[i].second;
    if(k<=0){
      co(p[i].first);
      break;
    }
  }
  
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
using namespace std;
struct DOBERMAN{
char c[61],s[61];
int g;
};
DOBERMAN doberman[1000000]={0},q[1000000]={0},t;
int main(){
int i,j,n,f,m,u=0,o=0,r,l,b=0,jc,jk,js;
static int p[1000000]={0};
char d[61][61];
scanf("%d%d",&n,&f);
for(i=0;i<n;i++){
	scanf("%d",&m);
	for(j=0;j<m;j++){
		cin>>d[j];
	}
	for(j=0;j<m;j++){
		for(r=j+1;r<m;r++){
			o=0;
			//printf("%s %s\n",d[j],d[r]);
			for(l=0;l<u;l++){
				if((strcmp(d[j],doberman[l].c)==0&&strcmp(d[r],doberman[l].s)==0)||(strcmp(d[r],doberman[l].c)==0&&strcmp(d[j],doberman[l].s)==0)){
					//printf("%d:%d\n%d:%d\n",strcmp(d[j],doberman[l].c),strcmp(d[r],doberman[l].s),strcmp(d[r],doberman[l].c),strcmp(d[j],doberman[l].s));
					o=1;
					doberman[l].g++;
					if(doberman[l].g>=f&&p[l]==0){
						q[b]=doberman[l];
						p[l]=1;
						b++;
					}
					break;
				}
			}
			if(o==0){
				//printf("MorishitaSHINE\n");
				js=0;
				for(jc=0;jc<min(strlen(d[j]),strlen(d[r]));jc++){
					if(d[j][jc]-'a'>d[r][jc]-'a'){
						js=1;
						break;
					}
					if(d[j][jc]-'a'<d[r][jc]-'a'){
						js=2;
						break;
					}
				}
				if(js==1){
					strcpy(t.c,d[r]);
					strcpy(t.s,d[j]);
					t.g=doberman[u].g+1;
				}
				else{
				strcpy(t.c,d[j]);
				strcpy(t.s,d[r]);
				t.g=doberman[u].g+1;
				}
				doberman[u]=t;
				//printf("%s %s %d\n",doberman[u].c,doberman[u].s,doberman[u].g);
				if(doberman[u].g>=f&&p[u]==0){
					q[b]=doberman[u];
					p[u]=1;
					b++;
				}
				u++;
			}
		}
	}
}
for(i=0;i<b;i++){
	for(j=i+1;j<b;j++){
		js=0;
		for(jc=0;jc<min(strlen(q[i].c),strlen(q[j].c));jc++){
			if(q[i].c[jc]-'a'>q[j].c[jc]-'a'){
				js=1;
				break;
			}
			if(q[i].c[jc]-'a'<q[j].c[jc]-'a'){
				js=2;
				break;
			}
		}
		if(js==0){
		for(jc=0;jc<min(strlen(q[i].s),strlen(q[j].s));jc++){
			if(q[i].s[jc]-'a'>q[j].s[jc]-'a'){
				js=1;
				break;
			}
			if(q[i].s[jc]-'a'<q[j].s[jc]-'a'){
				js=2;
				break;
			}
		}
		}
		if(js==1){
			t=q[i];
			q[i]=q[j];
			q[j]=t;
		}
	}
}
printf("%d\n",b);
for(i=0;i<b;i++){
	cout<<q[i].c<<' '<<q[i].s<<endl;
}
return 0;
}


Measured memory_bytes: 4308
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

const ll MAX=200000;

ll fac[MAX],finv[MAX],inv[MAX];

void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for (int i=2; i<MAX; i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;

    }
}

ll com(ll n, ll k){
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){

    cominit();

    ll N,M;
    cin>>N>>M;
    vector<ll> ex;
    //素因数分解
    for(int i=2; i*i<=M; i++){
        ll count=0;
        while(M%i==0){
            count++;
            M/=i;
        }
        ex.push_back(count);
    }
    if(M!=1) ex.push_back(1);


    ll ans=1;
    ll indexnum=ex.size();
    rep(i,indexnum){
        ans*=com(N-1+ex[i],ex[i]);
        ans%=mod;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 8452
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

lists = []

def dfs(li, nums):
    if len(nums) == 0:
        lists.append(li)
        return
    for num in nums:
        new = li[::]
        new.append(num)
        new_nums = nums[::]
        new_nums.remove(num)
        dfs(new, new_nums)
dfs([], [i for i in range(1, N+1)])

p_idx = 0
q_idx = 0

for i in range(len(lists)):
    li = lists[i]
    if P == li:
        p_idx = i
    if Q == li:
        q_idx = i
print(abs(p_idx - q_idx))

Measured memory_bytes: 10228
#include <stdlib.h>
#include <iostream>
#include <climits>
using namespace std;

int partition(int *array, int left, int right, int pivot_pos);
void swap(int *a, int *b);
void print_array(int *array, int left, int right);
int main(){
	int n;

	cin >> n;

	int* array = (int*)malloc(n * sizeof(int));

	if(n < 1){
		return 0;
	}

	for(int i = 0; i < n; i++){
		cin >> array[i];
	}
	int pos = partition(array, 0, n, n-1);
	print_array(array, 0, pos);
	cout << " [" << array[pos] << "] ";
	print_array(array, pos+1, n);
	cout <<  endl;
	return 0;
}
int partition(int *array, int left, int right, int pivot_pos){
	int x = array[pivot_pos];
	int i = left - 1;
	for(int j = left; j < right-1; ++j){
		if(array[j] <= x){
			++i;
			swap(array[i], array[j]);
		}
	}
	swap(array[i+1], array[pivot_pos]);
	return i+1;
}

void swap(int *a, int *b){
	int temp = *b;
	*b = *a;
	*a = temp;
}

void print_array(int *array, int left, int right){
	for(int i = left; i < right; i++){
		cout <<  array[i];
		if(i != right - 1){
		cout << " " ;
		}
	}
}

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

#define ll long long
#define FOR(i, a, b) for(ll i = (a); i < (b); i++)

ll abs(ll x) {
	if (x < 0) return -x;
	else return x;
}

int main() {
	int n, k; scanf("%d%d", &n, &k);
	vector<ll> X;
	FOR(i, 0, n) { ll t; scanf("%lld", &t); X.push_back(t); }

	ll ans = 0; int l = 0; bool flag = true;

	while (true) {
		int r = l + k - 1;
		ll t1 = abs(X[l]) + abs(X[l] - X[r]);
		ll t2 = abs(X[r]) + abs(X[r] - X[l]);
		ll t = t1 < t2 ? t1 : t2;
		if (flag || t < ans) ans = t;
		if (r == n - 1) break;
		else { l++; flag = false; }
	}

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1400
#include<iostream>
using namespace std;
int gcd(int a,int b){
    do{
        int c=a%b;
        a=b;
        b=c;
    }while(b);
    return a;
}
int main(){
  int a,b;
  cin>>a>>b;
  cout<<gcd(a,b)<<endl;
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main(){
  int a[5];
  for(int i=0;i<5;i++) cin >> a[i];
  sort(a,a+5,greater<int>());
  for(int i=0;i<5;i++) cout << a[i] << (i==4?"\n":" ");
  return 0;
}

Measured memory_bytes: 1176
// Author: droftware
#include <bits/stdc++.h>

#define forn(i,a,n) for(int i=a;i<n;i++)
#define DRT()  int t; cin>>t; while(t--)

#define TRACE
#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
using namespace std;

const int N = 105, NV = 1e5+5;
long long INF=1e11+5;
long long dp[N][NV];
int val[N], wts[N];


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,w;
	cin>>n>>w;
	int totv = 0;
	forn(i,1,n+1){
		cin>>wts[i]>>val[i];
		totv += val[i];
	}
	dp[0][0] = 0;
	forn(i,1,totv+1)
		dp[0][i] = INF;
	forn(i,1,n+1)
		dp[i][0] = 0;
	forn(i,1,n+1){
		forn(j,1,totv+1){
			if(j - val[i] >= 0){
				dp[i][j] = min(dp[i-1][j - val[i]] + wts[i], dp[i-1][j]);
			} else {
				dp[i][j] = dp[i-1][j];
			}
			// trace3(i,j,dp[i][j]);
		}
	}
	int res = 0;
	forn(i,0,totv+1){
		// trace1(dp[n][i])
		if(dp[n][i] <= w)
			res = max(res, i);
	}
	cout<<res<<endl;

}
	
	



Measured memory_bytes: 80128
import collections

N = int(input())
A = list(map(int, input().split()))

C = collections.Counter(A)
count = 0
for i in C.values():
    count += i * (i-1) // 2

for i in A:
    n = C[i]
    if n >= 2:
        print(count - n  + 1)
    else:
        print(count)

Measured memory_bytes: 26780
n=int(input())
b=list(map(int,input().split()))
a=b[:]

cnt=0
wa=0
condition='plus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt1=cnt
a=b[:]
cnt=0
wa=0
condition='minus'
for i in range(n):
  wa+=a[i]
  if condition == 'plus':
    condition='minus'
    if wa<=0:
      cnt+=abs(wa)+1
      a[i]+=abs(wa)+1
      wa+=abs(wa)+1
  elif condition == 'minus':
    condition='plus'
    if wa>=0:
      cnt+=abs(wa)+1
      a[i]-=abs(wa)+1
      wa-=abs(wa)+1

cnt2=cnt
print(min(cnt1,cnt2))

Measured memory_bytes: 14332
// 作者：杨成瑞先生
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

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

        long k = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();

        long biscuits = 1;

        if(b - a <= 2) {
            biscuits += k;
        }
        else {
            biscuits += a - 1;
            k -= a - 1;

            biscuits += k / 2 * (b - a);
            k %= 2;
            biscuits += k;
        }

        pw.println(biscuits);
        pw.close();
	}

}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int N = s.size();
    int l = 0, r = N - 1;
    while (l < N && s[l] != 'A') {
        l += 1;
    }

    while (r >= 0 && s[r] != 'Z') {
        r -= 1;
    }
    
    cout << max(0, r - l + 1) << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int h, w;
    cin >> h >> w;
    vs c(2*h);
    rep(i, h) cin >> c[i];

    //cout << "foo" << endl;
    rep(i, 2*h) {
        rep(j, w) {
            char a = c[(i+2)/2-1][j]; 
            cout << a;
            if(i >= h) c[i].push_back(a);
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int dp[101][101][700];
signed main(){
  int n;
  while(cin>>n,n){
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    memset(dp,-1,sizeof(dp));
    dp[0][0][0]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	for(int k=0;k<650;k++){
	  if(dp[i][j][k]<0) continue;
	  for(int a=0;a<7;a++){
	    int tmp=0,flg=0;
	    tmp=1000*a-p[i];
	    if(tmp>=0) tmp%=1000;
	    if(dp[i][j][k]+tmp<0) continue;
	    if(dp[i][j][k]+tmp>=500){
	      tmp-=500;
	      flg=1;
	    }
	    dp[i+1][j+flg][k+a]=max(dp[i+1][j+flg][k+a],dp[i][j][k]+tmp);
	  }
	  dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
	}
      }
    }
    /*//
    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++){
	for(int k=0;k<650;k++){
	  if(dp[i][j][k]<0) continue;
	  cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
	}
      }
    }
    //*/
    int c=0,s=0;
    for(int j=0;j<=n;j++){
      for(int k=0;k<650;k++){
	if(dp[n][j][k]<0) continue;
	int tmp=1000*k-500*j-dp[n][j][k];
	if(c<j) c=j,s=tmp;
	if(c==j) s=min(s,tmp);
      }
    }
    cout<<c<<" "<<s<<endl;
  }
  return 0;
}

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

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d || (abs(a-b <= d && abs(b-c) <= d))) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256