akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>

using namespace std;

#define MAX_LEN 50000
#define BIG 2000000000

class MergeSort
{
private:
	vector<pair<int, char> > tmp;
	void merge(vector<pair<int, char> > &data, int l, int m, int h)
	{
		for (int i = l; i < h; ++i)
			tmp[i] = data[i];

		int i = l, j = m, idx = l;
		while (i < m && j < h)
		{
			if (tmp[i].first <= tmp[j].first)
				data[idx++] = tmp[i++];
			else
				data[idx++] = tmp[j++];
		}

		while (i < m) data[idx++] = tmp[i++];
		while (j < h) data[idx++] = tmp[j++];
	}

	void do_sort(vector<pair<int, char> > &data, int l, int h)
	{
		if (l < h - 1)
		{
			int m = l + (h - l) / 2;
			do_sort(data, l, m);
			do_sort(data, m, h);
			merge(data, l, m, h);
		}
	}

public:
	void sort(vector<pair<int, char> > &data)
	{
		tmp.assign(data.begin(), data.end());
		do_sort(data, 0, data.size());
	}
};
class QuickSort
{
private:
	int partition1(vector<pair<int, char> > &data, int l, int h)
	{
		pair<int, char> tmp = data[h];
		while (l < h)
		{
			while (l < h && data[l].first <= tmp.first) l++;
			if (l < h) data[h--] = data[l];

			while (l < h && data[h].first >= tmp.first) h--;
			if (l < h) data[l++] = data[h];
		}
		data[l] = tmp;

		return l;
	}

	int partition2(vector<pair<int, char> > &data, int l, int h)
	{
		pair<int, char> tmp = data[h];

		int i = l;
		for (int j = l; j <= h; ++j)	{
			if (data[j].first <= tmp.first)	{
				std::swap(data[i++], data[j]);
			}
		}
		return i - 1;
	}

	void do_sort(vector<pair<int, char> > &data, int l, int h)
	{
		if (l < h)
		{
			int pos = partition2(data, l, h);
			do_sort(data, l, pos - 1);
			do_sort(data, pos + 1, h);
		}
	}
public:
	void sort(vector<pair<int, char> > &data)
	{
		do_sort(data, 0, data.size() - 1);
	}
};

void readData(vector<pair<int, char> > &data)
{
	int num;
	cin >> num;
	data.resize(num);

	char c;
	int v;
	for (int i = 0; i < num; ++i)
	{
		cin >> c >> v;
		data[i] = make_pair(v, c);
	}
}

int main()
{
	vector<pair<int, char> > data;
	readData(data);
	vector<pair<int, char> > data_ms(data), data_qs(data);

	MergeSort ms;
	ms.sort(data_ms);

	QuickSort qs;
	qs.sort(data_qs);

	string s = "Stable";
	for (int i = 0; i < data.size(); ++i)
	{
		if (data_ms[i] != data_qs[i])
		{
			s = "Not stable";
		}
	}
	cout << s << endl;

	for (pair<int, char> &v : data_qs)
		cout << v.second << " " << v.first << endl;
}

Measured memory_bytes: 5844
#include <bits/stdc++.h>
using Int = long long;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
using namespace std;
struct Data {
    Int x, y, h;
    Int valid(Int cx, Int cy, Int ch) {
        return max(ch - abs(cx - x) - abs(cy - y), 0LL) == h;
    }
};

int main() {
    int n;
    cin >> n;
    auto v = vector<Data>();
    auto maxH = 0LL;
    Int px, py;
    rep(i, n) {
        Int x, y, h;
        cin >> x >> y >> h;
        v.push_back(Data{x, y, h});
        if (h > maxH) {
            maxH = h;
            px = x;
            py = y;
        }
    }
    rep(cx, 101) {
        rep(cy, 101) {
            auto ch = maxH + abs(cx - px) + abs(cy - py);
            auto flag = true;
            for (auto d : v) {
                if (!d.valid(cx, cy, ch)) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                printf("%d %d %lld\n", cx, cy, ch);
                return 0;
            }
        }
    }
}

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

int main() {
  int n;
  int k;
  cin >> n >> k;
  vector<int> d(10, 0);
  for(int i = 0; i < k; i++){
    int a;
    cin >> a;
    d.at(a) = 1;
  }
  
  int ans;
  for(int i = n; i < n * 10 + 1; i++){
    int t = i;
    bool ok = true;
    while(t > 0){
      int a = t % 10;
      for(int j = 0; j < 10; j++){
        if(!d.at(j)) continue;
        if(a == j){
          ok = false;
          break;
        }
      }
      t /= 10;
    }
    if(ok){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
}

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

using namespace std;

int counter[100001];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    counter[a]++;
    counter[a + 1]++;
    if (a > 0) counter[a - 1]++;
  }
  int res = 0;
  for (int i = 0; i <= 100000; i++) {
    res = max(res, counter[i]);
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://vjudge.net/contest/241120#problem/E>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(ll n){
    ll res = 0;
    vector<ll> h(n+1); for(auto& in:h) cin >> in;
    for(int i = 0; i <= n;i++){
        vector<ll> H;
        for(int j = 0; j <= n;j++){
            if(i == j) continue;
            H.push_back(h[j]);
        }
        ll D = H[1] - H[0];
        bool ok = true;
        for(int j = 1; j < H.size();j++){
            if(H[j] - H[j-1] == D) continue;
            ok = false;
        }
        if(ok) return h[i];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    ll n;
    while(cin >> n,n){
        cout << solve(n) << endl;
    }
    return 0;
}



Measured memory_bytes: 3220
# coding: utf-8
# Your code here!
from collections import deque
S=list(input())
Q=int(input())
r=0

d=deque(S)

for _ in range(Q):
    temp=list(input().split())
    if len(temp)==1:
        r^=1
    else:
        if r==0:
            if temp[1]=="1":
                d.appendleft(temp[2])
            else:
                d.append(temp[2])
        else:
            if temp[1]=="1":
                d.append(temp[2])
            else:
                d.appendleft(temp[2])
ans=list(d)
print("".join(ans) if r==0 else "".join(ans[::-1]))


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

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n),ans(n);
    rep(i,n)cin>>a[i];
    int s=0;
    rep(i,n)s^=a[i];
    rep(i,n)ans[i]=s^a[i];
    rep(i,n)cout<<ans[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll 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;}}
long long 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;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int a,b;
  cin>>a>>b;
  int ja=b-a;
  int ans=ja*(ja+1)/2;
  cout<<ans-b<<endl;
}    


Measured memory_bytes: 3520
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int n, k, i;
	int r, s, p;
	unordered_map<char, int> mp;
	string t;
	ll answer = 0;

	cin >> n >> k;
	cin >> r >> s >> p;
	mp['s'] = r;
	mp['p'] = s;
	mp['r'] = p;
	vector<bool> check(n, false);
	cin >> t;

	for (i = 0; i < n; i++) {
		if (i < k) {
			answer += mp[t[i]];
			check[i] = true;
			continue;
		}
		if (t[i - k] == t[i] &&
			check[i - k] == true)
			continue;
		else {
			answer += mp[t[i]];
			check[i] = true;
		}
	}

	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 512
#include <cstdio>

typedef long long ll;

ll n , x;

template < typename T >
inline T gcd(T a , T b) {
	return b ? gcd(b,a%b) : a;
}

int main() {
	
	scanf("%lld%lld",&n,&x);
	
	printf("%lld\n",3*n-3*gcd(n,x));
	
	return 0;
	
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	ll n;
	cin >> n;

	ll ans = 1;
	for(int i=1; i<=n; i++){
		ans *= i;
		ans %= MOD;
	}

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


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

int t[100000+10];
string name[100000+10];

int main() {
	int n,q,t_time,x;
	queue<int> Q;
	cin >> n >> q;
	for (int i=1; i<=n; i++){
		cin >> name[i] >> t[i];
		Q.push(i);
	}
	while (!Q.empty()){
		if (t[Q.front()] > q){
			t[Q.front()] -= q;
			x = Q.front();
			Q.pop();
			Q.push(x);
			t_time += q;
		}else{
			t_time += t[Q.front()];
			cout << name[Q.front()] << ' ' << t_time << endl;
			Q.pop();
		}
	}
	return 0;
}

Measured memory_bytes: 6552
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  vector<int> l, r;
  
  scanf("%d", &n);
  llong res = 0;
  REP(i,n){
    int t1, t2;
    scanf("%d %d", &t1, &t2);
    res += t2 - t1 + 1;
  }

  printf("%lld\n", res);

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=2e5+5;
lli bit[N];

void update(lli idx, lli val)
{
	while(idx<N)
	{
		bit[idx]=max(bit[idx],val);
		idx+=idx&-idx;
	}
}

lli query(lli idx)
{
	lli ans=0;
	while(idx>0)
	{
		ans=max(ans,bit[idx]);
		idx-=idx&-idx;
	}
	return ans;
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,h[n],a[n],ans=0,dp;
    
    for(i=0;i<n;i++) cin>>h[i];
    for(i=0;i<n;i++) cin>>a[i];
    
    for(i=0;i<n;i++)
    {
        dp=query(h[i])+a[i];
        ans=max(ans,dp);
        update(h[i],dp);
    }
    cout<<ans;
    return 0;
}

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

int main()
{
  int n, x;
  cin >> n >> x;
  
  int min = 1001;
  int m;
  int donuts;
  rep(i, n)
  {
    cin >> m;
    x -= m;
    donuts ++;
    if (m < min) min = m;
  }
  
  donuts += x / min;
  cout << donuts;
  return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == a[i + 1]) {
			ans++;
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

bool is_palindromic_number(int n) {
    string str = to_string(n);
    int len = str.size();
    string s1 = str.substr(0, len / 2);
    string s2 = str.substr(len / 2 + len % 2);

    reverse(s2.begin(), s2.end());

    return s1 == s2;
}

int n;
int ans;
int main() {
    cin >> n;
    for (int i = 0; i <= 10001; i++) {
        if (is_palindromic_number(i)) {
            if (abs(n - i) < abs(n - ans)) {
                ans = i;
            } else if (abs(n - i) == abs(n - ans)) {
                ans = min(ans, i);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3280
#include <bits/stdc++.h>  // ver1.9.1
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  cout << fixed << setprecision(15);
  int n;
  cin >> n;
  Vi a(n);
  int qw;
  
  rep(i,0,n) {
    cin >> qw;
    qw--;
    a[i] = qw;
  }
  int ans=0;
  rep(i,0,n){
    qw = a[i];
    if(a[qw]==i) ans++;
  }
  
  cout << ans/2 << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int count=0;
		for(int i=0; i<s.length(); i++) {
			if(s.charAt(i)!=t.charAt(i)) {
				count++;
			}
		}
		System.out.println(count);
	}

}


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


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a >= c&&b<=d) {
		cout << b - a;
	}
	else if (a <= c && b >= d) {
		cout << d - c;
	}
	else if (a <= c && b <= d&&c<=b) {
		cout << b - c;
	}
	else if(a>=c&&b>=d&&a<=d){
		cout << d - a;
	}
	else {
		cout << 0;
	}
}

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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s == u) {
    cout << a -1 << " " << b << endl;
  }else {
    cout << a << " " << b- 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  for (auto &it : a)
    cin >> it;
  sort(a.begin(), a.end(), greater<int>());
  int ans = max(0, a[0] - (K - a[0]) - 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

struct Dice
{
	int mae;
	int ue;
	int migi;
	int hidari;
	int sita;
	int usiro;
};

struct Dice ROLL_E(struct Dice dice)
{
	
	int a = dice.ue;
	dice.ue = dice.hidari;
	dice.hidari = dice.sita;
	dice.sita = dice.migi;
	dice.migi = a;
	
	return dice;
}

struct Dice ROLL_N(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.mae;
	dice.mae = dice.sita;
	dice.sita = dice.usiro;
	dice.usiro = a;
	
	return dice;
}
struct Dice ROLL_S(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.usiro;
	dice.usiro = dice.sita;
	dice.sita = dice.mae;
	dice.mae = a;
	
	return dice;
}
struct Dice ROLL_W(struct Dice dice)
{
	int a = dice.ue;
	dice.ue = dice.migi;
	dice.migi = dice.sita;
	dice.sita =dice. hidari;
	dice.hidari = a;
	
	return dice;
}

struct Dice scan()
{
	struct Dice dice;
	
	scanf("%d\n",&dice.ue);
	scanf("%d\n",&dice.mae);
	scanf("%d\n",&dice.migi);
	scanf("%d\n",&dice.hidari);
	scanf("%d\n",&dice.usiro);
	scanf("%d\n",&dice.sita);
	
	return dice;
}
int main()
{
	int i,j;
	struct Dice dice;
	char move;
	
	dice = scan();
	
	while(1){
		scanf("%c",&move);
		if(move == 'E'){
			dice = ROLL_E(dice);
		}else if(move == 'N'){
			dice = ROLL_N(dice);
		}else if(move == 'S'){
			dice = ROLL_S(dice);
		}else if(move == 'W'){
			dice = ROLL_W(dice);
		}
		
		if(move == '\n'){
			break;
		}
	}
	
	printf("%d\n",dice.ue);
	
	return 0;
}

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

int main(){
#ifdef _DEBUG
	//freopen("_in" , "r", stdin );
	//freopen("_out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	s = "##" + s;
	for (int i = 2; i < s.size(); i++) {
		if (s[i] == s[i - 1]) {
			cout << i - 2 << ' ' << i - 1 << '\n';
			return 0;
		}
		if (s[i] == s[i - 2]) {
			cout << i - 3 << ' ' << i - 1 << '\n';
			return 0;
		}
	}
	
	cout << "-1 -1\n";
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
	int A,B,C,D,E,F,K;
	cin>>A>>B>>C>>K;
    if(K%2==0)cout<<A-B<<endl;
    else cout<<B-A<<endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	int s=0;
	for(int i=n,j=1;i>=1,j<=k;i--,j++)
	s+=a[i];
	cout<<s<<endl;
	return 0;
}

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



vector<ll>adj[100009];
ll vis[100009]={0};
ll c=0;



void dfs(ll val)
{
    vis[val]=1;
    for(auto i=adj[val].begin();i!=adj[val].end();i++)
    {
        if(vis[*i]==0)
        dfs(*i);
    }
}





int main() {
	ll n,m,a,b;
	cin>>n>>m;
	for(ll i=0;i<m;i++)
	{
	    cin>>a>>b;
	    adj[a].push_back(b);
	    adj[b].push_back(a);
	}
	for(ll i=1;i<=n;i++)
	{
	    if(vis[i]==0)
	    {
	        c++;
	        dfs(i);
	    }
	}
	cout<<c-1;
    
}


Measured memory_bytes: 11084
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n,a;
	vector<int>vec;
	int sum;
	while(true){
		cin>>n;vec.clear();
		if(n==0){break;}
		for(int i=0;i<n;i++){
			cin>>a;
			vec.push_back(a);
		}
		sort(vec.begin(),vec.end());
		sum=0;
		for(int i=0;i<vec.size();i++){
			sum+=vec[i];
		}
		cout<<(sum-vec[0]-vec[vec.size()-1])/(vec.size()-2)<<endl;
	}
}

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

int main() {
	int N, sum=0; cin >> N;
  	vector<int> b(N-1); for (int i = 0; i < N-1 ; i++)  cin >> b.at(i);
	 
 	sum += b.at(0);
  	sum += b.at(N-2);
  	for (int i = 1 ; i < N-1; i++) sum += min(b.at(i-1), b.at(i));        
    cout << sum << endl;
}

Measured memory_bytes: 256
from sys import stdin
import sys
sys.setrecursionlimit(10**6) 
import bisect

n = int(stdin.readline().rstrip())

li = [7,5,3]

if n < 357:
    print(0)
    exit()

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

kazu = 0
point = 0
k = "0"
while int(k) <= n:
    k = Base_10_to_n(kazu,4)
    k = k.replace("3","7").replace("1","3").replace("2","5")
    if all(k.count(c)>0 for c in "753")and k.count("0") == 0:
        if int(k) <= n:
            point += 1
    kazu += 1
print(point)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    char C;
    cin>>C;
    cout<<++C<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin >> n, n) {
        int count = 0;
        for (int i = 1; i < n; i++) {
            int sum = 0;
            for (int j = i; j < n; j++) {
                sum += j;
                if (sum == n) {
                    count++;
                    break;
                }
                if (sum > n)
                    break;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	int tmp,tmp1;
	vi v1,v2,v3;
	bool dp[8002][64000];
	bool ok(vi x,int x1){
		FOR(i,0,8002)FOR(i1,0,64000)dp[i][i1] = 0;
		dp[0][32000] = 1;
		FOR(i,0,x.size()){
			FOR(i1,0,64000){
				if(i1+x[i]>=64000)continue;
				if(dp[i][i1] == 0)continue;
				dp[i+1][i1-x[i]] = 1;
				dp[i+1][i1+x[i]] = 1;
			}
		}
		if(dp[x.size()][x1+32000] == 1)return 1;
		else return 0;
	}

	void solve(){


		ins(morty);
		ini(x,y);

		FOR(i,0,morty.size()+1){
			if(i!=morty.size() and morty[i] == 'F'){tmp++;}
			else{
				if(tmp1 == 0)v1.push_back(tmp);
				if(tmp1 == 1)v2.push_back(tmp);
				tmp = 0;tmp1^=1;
			}
		}
		x-=v1[0];
		FOR(i,1,v1.size())v3.push_back(v1[i]);
		if(ok(v3,x) and ok(v2,y))out("Yes");
		else out("No");










	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 500608
#include <bits/stdc++.h>
using namespace std;
int main() {
    int X, A, B;
    cin >> X >> A >> B;
    int kigen = B-A; //何日すぎたか
    string ans = "safe";
    if(kigen<=0) ans = "delicious";
    else if(kigen>=X+1) ans = "dangerous";
    cout << ans << endl;
}


Measured memory_bytes: 256
from bisect import bisect_left
from bisect import bisect_right

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


X = [bisect_left(A ,B[i]) for i in range(N)]
Y = [N - bisect_right(C ,B[i]) for i in range(N)]

total = 0

for x,y in zip(X, Y):
    total += x * y

print(total)

Measured memory_bytes: 23488
import itertools
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
for i,j in itertools.combinations([a,b,c,d,e], 2):
    if abs(i-j)>k:
        print(':(')
        exit()
print('Yay!')


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

int main() {
  string s, t;
  cin >> s >> t;
  int A, B;
  cin >> A >> B;
  string u;
  cin >> u;
  
  if ( s == u ){
    cout << (A - 1) << ' ' << B << endl;
  }
  else{
     cout << A << ' ' << (B - 1) << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n][3];
  
  for(int i=0;i<n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];

  for(int i=1;i<n;i++)
  {
	  a[i][0]=a[i][0]+max(a[i-1][1],a[i-1][2]);
	  a[i][1]=a[i][1]+max(a[i-1][0],a[i-1][2]);
	  a[i][2]=a[i][2]+max(a[i-1][0],a[i-1][1]);
  }
  cout<<max(a[n-1][0],max(a[n-1][1],a[n-1][2]));  
}
               

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

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    void solve() throws IOException {
        int n = nextInt();
        int[] arr = nextIntArr(n);
        int LIMIT = 1000 * 100 + 10;
        int[] hist = new int[LIMIT];
        long res = 0;
        for (int v : arr) {
            hist[v]++;
            res += v;
        }
        int q = nextInt();
        for (int i = 0; i < q; i++) {
            int b = nextInt();
            int c = nextInt();
            if (b == c || hist[b] == 0) {
                outln(res);
                continue;
            }

            int cnt = hist[b];
            hist[b] = 0;
            hist[c] += cnt;
            res -= 1L * b * cnt;
            res += 1L * c * cnt;
            outln(res);
        }
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root,Max;
void insert(int);
void inorder(Node);
void preorder(Node);
Node treeMaximum(Node);
Node treeSearch(Node,int);

Node treeMaximum(Node x)
{
  while(x->right != NIL){
    x=x->right;
  }
  return x;
}
Node treeSearch(Node x,int k)
{
  while(x!=NIL && k!=x->key)
    {
      if(k < x->key)x=x->left;
      else x=x->right;
    }
  return x;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL)
    {
      y = x;
      if(z->key < x->key)
        x = x->left;
      else
        x = x->right;
    }
  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void inorder(Node u){
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
       scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
     }
    else if( com[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }
    else if ( com[0] == 'p' ){
      Max = treeMaximum(root);
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 20476
#include<iostream>。
using namespace std;
int h[25];
int main()
{
    int n;
    cin>>n;
    int count=0;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        int flag=1;
        for(int j=0;j<i;j++)
        {
            if(h[j]>h[i])
            {
                flag=0;
                break;
            }
        }
        if(flag) count++;
    }
    cout<<count<<endl;
}


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

int main(void) 
{
  int i, n;
  int nowtemp, targettemp;
  int high[2000];
  int mindiff = 10000000;
  int minpoint;
  
  scanf("%d\n", &n);
  scanf("%d%d\n", &nowtemp, &targettemp);
  for (i = 0; i < n; i++) 
    scanf("%d", &high[i]);
  
  for (i = 0; i < n; i++) {
    if (mindiff > abs(1000 * nowtemp - high[i] * 6 - 1000 * targettemp)) {
       mindiff = abs(1000 * nowtemp - high[i] * 6 - 1000 * targettemp);
       minpoint = i;
    }
  }
  printf("%d", minpoint + 1);
  return 0;
}

Measured memory_bytes: 128
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
int up[200050][63];
signed main(void)
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		reg int x;
		read(x);
		up[i][0]=x;
	}
	for(int j=1;j<63;++j)
		for(int i=1;i<=n;++i)
			up[i][j]=up[up[i][j-1]][j-1];
	reg int pos=1;
	for(int i=62;i>=0;--i)
		if(k&(1ll<<i))
			pos=up[pos][i];
	cout<<pos<<endl;
	return 0;
}




Measured memory_bytes: 102076
#!/usr/bin/env python3
#dp3 #Vacation
import sys
def S(): return list(sys.stdin.readline())[:-1]
def LI(): return list(map(int,sys.stdin.readline().split()))
def c():
    n = int(input())
    dpa = [0]*n
    dpb = [0]*n
    dpc = [0]*n

    a,b,c = LI()
    dpa[0] = a
    dpb[0] = b
    dpc[0] = c
    for i in range(1,n):
        a,b,c = LI()
        dpa[i] = max(dpb[i-1] + a,dpc[i-1] + a)
        dpb[i] = max(dpa[i-1] + b,dpc[i-1] + b)
        dpc[i] = max(dpa[i-1] + c,dpb[i-1] + c)
    print(max(dpa[-1],dpb[-1],dpc[-1]))
if __name__ == '__main__':
    c()


Measured memory_bytes: 46060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>s;
    for(int i=2;i<s.size();i+=2){
        int f=0;
        for(int j=0;j<s.size()/2-i/2;j++){
            if(s[j]!=s[j+s.size()/2-i/2]){
                f=1;
            }
        }
        if(!f){
            cout<<s.size()-i<<endl;
return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

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

  double tan_l = (30 * h + 0.5 * m) * M_PI / 180;
  double tan_s = m * 6 * M_PI / 180;

  double len_n = pow(a * a + b * b - 2 * a * b * cos(tan_l - tan_s), 0.5);
  cout << fixed << setprecision(10) << len_n;
  return 0;
}


Measured memory_bytes: 4356
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 10000000000000000
typedef long long ll;

int main() {
    ll N,W;
    cin>>N>>W;
    
    map<ll,ll> now;
    now[0] = 0;
    
    rep(i,N){
        ll w, v; cin>>w>>v;
        if(w>W) continue;
        
        map<ll,ll> nxt;
        for(auto x:now){
            if( nxt.find(x.first)==nxt.end() || nxt[x.first] < x.second){
                nxt[x.first] = x.second;
            }
            if(x.first+w>W) continue;
            if( nxt.find(x.first+w)==nxt.end() || nxt[x.first+w] < x.second+v){
                nxt[x.first+w] = x.second+v;
            }
            
        }
        swap(now,nxt);
    }
    ll maxv=0;
    for(auto x:now){
        if(maxv<x.second) maxv = x.second;
    }
    
    cout<<maxv<<endl;
}

Measured memory_bytes: 512
#include<iostream>

int r=0,l=0;

int main(){
	int n;
	std::cin>>n;
	for(int i=0;i<n;++i){
		bool f=true;
		for(int j=0;j<10;++j){
			int a;
			std::cin>>a;
			if(r<a&&l<a){
				if(r<=l)l=a;
				else r=a;
			}else if(r<a)r=a;
			else if(l<a)l=a;
			else f=false;
			//std::cout<<r<<" "<<l<<" "<<f<<std::endl;
		}
		if(f)std::cout<<"YES"<<std::endl;
		else std::cout<<"NO"<<std::endl;
		r=0,l=0;
	}
	return 0;
}

Measured memory_bytes: 1152
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;
	double a, b ; 
	cin>>a>>b ; 
	cout<<setprecision(10)<<a/b ; 
}
//////
////////
///////////



Measured memory_bytes: 256
// 156-B

#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    string ans;
    while(n >= k){
        ans = to_string(n % k) + ans;
        n /= k;
    }
    ans = to_string(n % k) + ans;
    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

int main(){
  int a, b;
  cin >> a >> b;
  if(a > b) cout << "a > b" << endl;
  else if(a < b) cout << "a < b" << endl;
  else cout << "a == b" << endl;
  return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;

    bool flg = (x + r > w || x - r < 0 || y + r > h || y - r < 0);

    cout << (flg ? "No" : "Yes") << endl;
}



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

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>


int main(){
  int N;
  scanf("%d", &N);
  std::string s;
  std::cin >> s;
  std::vector<int > ans(N+4);
  // 1 sheep, 0 wolf
  int init1[4]={0, 0, 1, 1};
  int init2[4]={0, 1, 0, 1};
  
  for (int i=0; i<4; i++){
    ans[0]=init1[i];
    ans[1]=init2[i];
    for (int j=2; j<N; j++){
      if (s[j-1]=='o'){
	if (ans[j-1]==1){
	  ans[j]=ans[j-2];
	} else {
	  ans[j]=1-ans[j-2];
	}
      } else {
	if (ans[j-1]==1){
	  ans[j]=1-ans[j-2];
	} else {
	  ans[j]=ans[j-2];
	}
      }
    }
    // last check
    bool check=true;
    int index[2]={0, N-1};
    for (int j=0; j<2; j++){
      int i=index[j];
      if (s[i]=='o'){
	if (ans[i]==1){
	  if (ans[(i+N-1)%N]!=ans[(i+1)%N]){
	    check=false;
	  }
	} else {
	  if (ans[(i+N-1)%N]==ans[(i+1)%N]){
	    check=false;
	  }
	}
      } else {
	if (ans[i]==1){
	  if (ans[(i+N-1)%N]==ans[(i+1)%N]){
	    check=false;
	  }
	} else {
	  if (ans[(i+N-1)%N]!=ans[(i+1)%N]){
	    check=false;
	  }
	}
      }
    }
    if (check){
      for (int i=0; i<N; i++){
	printf("%c", ans[i]?'S':'W');
      }
      printf("\n");
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}

Measured memory_bytes: 960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    string s;
    cin >> s;
    int n;
    cin >> n;
    vector<string> vs;
    for(char j = 'a'; j <= 'z'; j++){
        for(int i = 0; i < s.size(); i++){
            if(s[i] == j){
                int cnt = 0;
                for(int k = 1; k < 8; k++){
                    auto itr = find(vs.begin(), vs.end(), s.substr(i,k));
                    if( itr == vs.end() ) {
                        vs.push_back(s.substr(i,k));
                    }
                }
            }
        }
        if(vs.size()>=n){break;}
    }
    sort(vs.begin(),vs.end());


    cout << vs[n-1] << endl;




    return 0;

}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	vector<bool>v(50030, true);
	v[0] = v[1] = false;
	rep(i, 2, sqrt(50030)) {
		if (v[i]) {
			for (int j = i + i; j < 50030; j += i) {
				v[j] = false;
			}
		}
	}
	int n;
	while (cin >> n) {
		for (int i = n-1;; i--) {
			if (v[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1;; i++) {
			if (v[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    ll ans = b/x - a/x;
    if(a%x==0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int data,old[10]={0};
        while(N--){
            cin>>data;
            data/=10;
            if(data>5)data=6;
            old[data]++;
        }
        for(int i=0;i<7;i++){
            cout<<old[i]<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn=1e5+105;
int dp[maxn];
int height[maxn];
int main()
{
	int n,k;
	cin>>n>>k;
	memset(height,inf,sizeof(height));
	memset(dp,0,sizeof(dp));
	
	for(int i=k+1;i<=k+n;i++)
	cin>>height[i]; 
	for(int i=k+2;i<=k+n;i++)
	{
		dp[i]=dp[i-k]+abs(height[i-k]-height[i]);
		for(int t=k;t>0;t--) 
		
	{
		
//			if(i==k+n)
//			{
//				cout<<dp[i-t]<<" "<<height[i-t]-height[i]<<" "<<dp[i-t-1]<<" "<<height[i-t-1]-height[i];
//			}
				//dp[i]=min(dp[i-t]+abs(height[i-t]-height[i]),dp[i-t-1]+abs(height[i-t-1]-height[i]));
				//不应该两两比较！！！！！！！ 
			dp[i]=min(dp[i-t]+abs(height[i-t]-height[i]),dp[i]);
	}
	//	cout<<dp[i]<<" "; 
	}
	//cout<<endl;
	
	//for(int i=k+2;i<=k+n;i++)
	//cout<<dp[i]<<" "; 
	
	//cout<<endl;
	cout<<dp[k+n];
	return 0;
} 

Measured memory_bytes: 1024
import numpy as np

N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

m = np.zeros((2, N)).astype(int)
m[0][0] = A1[0]
m[1][0] = A2[0] + A1[0] 

for i in range(1, N):
    m[0][i] = A1[i]+m[0][i-1]
    m[1][i] = max(A2[i]+m[1][i-1], A2[i]+m[0][i])
    
print(m[1][N-1])

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

int main (){
    int n;
    cin>>n;
    vector<double> v(n);
  
  for(int i=0; i<n; i++){
    cin>>v[i];
  }
  
  sort(v.begin(), v.end());
  
  for(int i=0; i<n-1; i++){
    v[i+1]=(v[i+1]+v[i])/2;
  }
  
  cout<<v[n-1]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  if(k<=a)
  {
    a-=k;
    cout<<a<<" "<<b;
  }
  else
  {
    k-=a;
    a=0;
    if(k<=b)
    b-=k;
	else b=0;
    cout<<a<<" "<<b;
  }
}


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

long long H, W, K;
string ban[10];

bool check(long long xset, long long yset) {
	long long num = 0;
	for(long long y = 0; y < H; y++) {
		for(long long x = 0; x < W; x++) {
			if(((xset>>x) & 1)) {
				continue;
			}
			if(((yset>>y) & 1)) {
				continue;
			}
			if(ban[y][x] == '#') {
				num++;
			}
		}
	}
	return num == K;
}



int main(){
	cin >> H >> W >> K;

	for(long long i = 0; i < H; i++){
		cin >> ban[i];
	}

	long long ans = 0;
	for(long long x = 0; x < (1<<W); x++) {
		for(long long y = 0; y < (1<<H); y++) {
			if(check(x, y)){
				ans++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define ll long long
#define inf 1000000007 //10^9+7
#define sort(vec) sort(vec.begin(),vec.end());
#define rever(vec) reverse(vec.begin(),vec.end());
#define unsort(vec) sort(vec); rever(vec);
#define gcd __gcd
using namespace std;

int main() {
  ll h,w;
  cin>>h>>w;
  char tab[h][w];
  ll cnt=0;
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      char a;
      cin>>a;
      tab[i][j]=a;
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(tab[i][j]=='.') {
        for(ll k=-1;k<=1;k++) {
          for(ll l=-1;l<=1;l++) {
            if(0<=i+k&&i+k<h&&0<=j+l&&j+l<w) {
              if(tab[i+k][j+l]=='#') {
                  cnt++;
              }
            }
          }
          tab[i][j]=cnt+'0';
        }
      }
      cnt=0;
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      cout<<tab[i][j];
    }
    cout<<endl;
  }
}

Measured memory_bytes: 256