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

using namespace std;

const int N = 50000;

int n, L, R, ans;
char s[N]; 

struct Hash{
	long long h[N], bin[N];
	long long base, mod;
	void initialize(long long _x){
		base = 26; mod = _x;
	}
	int build(){
		bin[0] = 1;
		for (int i = 1; i <= n; ++i){
			h[i] = (h[i-1] * base + s[i] - 'a') % mod;
			bin[i] = bin[i - 1] * base % mod;
		}
	}
	long long cal(int p, int q){
		return ((h[q] - h[p - 1] * bin[q - p + 1]) % mod + mod) % mod;
	}
} hash1,hash2;

int equal(int x){
	map <pair<int,int>,int> mp;
	mp.clear();
	for (int i = 1; i <= n; ++i){
		int p = hash1.cal(i, i + x - 1);
		int q = hash2.cal(i, i + x - 1);
		if (mp.count(make_pair(p,q))){
			int pos = mp[make_pair(p,q)];
			if (pos + x <= i) return 1;
		}
		else mp[make_pair(p,q)] = i;
	}
	return 0;
}

int main(){
	scanf("%d",&n);
	scanf("%s",s + 1);
	hash1.initialize(998244353);
	hash2.initialize(1000000007);
	hash1.build(); hash2.build();
	L = 0; R = n;
	while (L <= R){
		int mid = (L + R) >> 1;
		if (equal(mid)) L = mid + 1, ans = mid;
		else R = mid - 1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int n,num[9],f[9];
double ans;
struct node
{
	int x,y;
	void read(){
		scanf("%d%d",&x,&y);
	}
}e[9];
double cal(node a,node b)
{
	return sqrt(1.0*(a.x-b.x)*(a.x-b.x)+1.0*(a.y-b.y)*(a.y-b.y));
}
int main()
{
	scanf("%d",&n);
	f[0]=1;
	for(int i=1;i<=n;++i)
	{
		f[i]=f[i-1]*i;
		num[i]=i;
		e[i].read();
	}
	do
	{
		double t=0;
		for(int i=1;i<n;++i)
		t+=cal(e[num[i]],e[num[i+1]]);
		ans+=t;
	}while(next_permutation(num+1,num+n+1));
	printf("%.11lf\n",ans/(1.0*f[n]));
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

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

int main(){
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    cout << (2 + (n-1)) * (n - 2) / 2 + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////




int main() {

	ll A, B, C;
	cin >> A >> B >> C;

	if (A + B + C >= 22) { cout << "bust"; }
	else { cout << "win"; }
	
	
	
	system("PAUSE");
}

Measured memory_bytes: 504
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int k=Integer.parseInt(br.readLine());
        Queue<Long> queue=new LinkedList<>();
        for(int i=1;i<=9;i++)
        queue.add((long)i);
        long temp=0;
        for(int i=1;i<=k;i++)
        {
            temp=queue.poll();
            if(temp%10!=0)
            {
                queue.add(10*temp+(temp%10)-1);
            }
            queue.add(10*temp+(temp%10));
            if(temp%10!=9)
            queue.add(10*temp+(temp%10)+1);
        }
        pw.println(temp);
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 33876
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll shokin[222]={300000ll,200000ll,100000ll};

int main(void){
	int x,y;
	ll ans = 0ll;
	cin >> x >> y; --x; --y;
	ans = shokin[x]+shokin[y];
	if(!(x||y)){
		ans += 400000ll;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
namespace bst = boost;

int main() {
  string S;

  cin >> S;
  
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
    return 0;
  }
  if (S == "Cloudy") {
    cout << "Rainy" << endl;
    return 0;
  }
  if (S == "Rainy") {
    cout << "Sunny" << endl;
    return 0;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int n;
VL a;
vector<VL> memo;
ll solve(int l, int r){
    if(r < l)return 0LL;
    if(memo[l][r] != -1)return memo[l][r];

    ll ret = 0;
    if((r - l) % 2 != n % 2){
        ret = max(solve(l + 1, r) + a[l], solve(l, r - 1) + a[r]);
    }
    else{
        ret = min(solve(l + 1, r) - a[l], solve(l, r - 1) - a[r]);
    }
    
    return memo[l][r] = ret;
}

int main() {
    init();

    cin >> n;
    a.resize(n); cin >> a;
    memo = defvec<ll>(-1, n, n);
    cout << solve(0, n - 1) << "\n";
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

ll x,y,z,k,a[1010],b[1010],c[1010];
vector<ll> ans;

int main(void){
	cin>>x>>y>>z>>k;
	rep(i,x)cin>>a[i];
	rep(i,y)cin>>b[i];
	rep(i,z)cin>>c[i];
	sort(a,a+x);
	reverse(a,a+x);
	sort(b,b+y);
	reverse(b,b+y);
	sort(c,c+z);
	reverse(c,c+z);
	rep(i,min((ll)70,x))rep(j,min((ll)70,y))rep(l,min((ll)70,z)){
		ans.push_back(a[i]+b[j]+c[l]);
	}
	reg(i,min((ll)70,x),x-1)rep(j,min((ll)10,y))rep(l,min((ll)10,z))ans.push_back(a[i]+b[j]+c[l]);
	rep(i,min((ll)10,x))reg(j,min((ll)70,y),y-1)rep(l,min((ll)10,z))ans.push_back(a[i]+b[j]+c[l]);
	rep(i,min((ll)10,x))rep(j,min((ll)10,y))reg(l,min((ll)70,z),z-1)ans.push_back(a[i]+b[j]+c[l]);
	sort(ans.begin(),ans.end());
	reverse(ans.begin(),ans.end());
	rep(i,k)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 10604
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int n;
    cin >> n;
    int res = n;
    for(int i = 0; i <= n; i++){
        int cc = 0;
        int t = i;
        while(t > 0) cc += t%6, t/=6;
        t = n-i;
        while(t > 0) cc += t%9, t/=9;
        if(res > cc) res = cc;
    }
    cout << res << endl;
}

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

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        System.out.println(solve(in));
        
      }
      
      public static String solve(Scanner in) {
       String s = in.next();

        if (s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5)) return "Yes";
        return "No";
      }
      
    
}

Measured memory_bytes: 21844
count = 0
n = int(input())

def judge(a):
    ans = True
    for ai in a:
        if ai % 2 != 0:
            ans = False
            break
    return ans

a = list(map(int, input().split()))

while judge(a):
    for (i, ai) in enumerate(a):
        a[i] = ai / 2
    count += 1

print(count)

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
//#inlcude<stringstream>
#define ll long long
#define MODD 1000000007
using namespace std;
ll arr[1000000]={0};
ll brr[1000000]={0};
int main() {

    ll a,b,k;cin >>a>>b>>k;
    ll small = 0,big = 0;
    for(ll i=a;i<=b;i++){
        if(small<k)arr[small++]=i;
        else if(i>b-k&&(b-k)>0&&big<k)brr[big++]=i;
    }
    for(ll i=0;i<min(k,(abs(a-b)+1));i++)cout<<arr[i]<<endl;
    for(ll i=0;i<k;i++){if(brr[i]==0){break;}cout<<brr[i]<<endl;}
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
24
1 2 3 4
1 2 4 3
1 3 2 4
1 3 4 2
1 4 2 3
1 4 3 2
2 1 3 4
2 1 4 3
2 3 1 4
2 3 4 1
2 4 1 3
2 4 3 1
3 1 2 4
3 1 4 2
3 2 1 4
3 2 4 1
3 4 1 2
3 4 2 1
4 1 2 3
4 1 3 2
4 2 1 3
4 2 3 1
4 3 1 2
4 3 2 1
)");
#define cin input
#endif

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

bool calc(ll a, ll b, ll c, ll d)
{
	if (d < b)
		return false;
	if (a < b)
		return false;
	a -= b * (a / b);
	d -= b * (d / b);
	if (a > c)
		return false;
	if (d && gcd(b, d) + c < b)
		return false;
	return true;
}

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

	REP (i, t)
	{
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << (calc(a, b, c, d) ? "Yes" : "No") << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
struct Card{
  char suit;
  int value;
  int key;
};

struct Card A[N];

int Partition(int p,int r)
{
  int x,i,j;
  struct Card tmp;
  x=A[r].value;
  i=p-1;
  for(j=p;j<=r-1;j++)
    {
      if(A[j].value<=x)
	{
	  i++;
	  tmp=A[i];
	  A[i]=A[j];
	  A[j]=tmp;
	}
    }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}

void Quicksort(int p,int r)
{
  int q;
  if(p<r)
    {
      q=Partition(p,r);
      Quicksort(p,q-1);
      Quicksort(q+1,r);
    }
}


main()
{
  int n,i;
  char ch;
  scanf("%d%c",&n,&ch);
  for(i=1;i<=n;i++)
    {
      scanf("%c%c%d%c",&A[i].suit,&ch,&A[i].value,&ch);
      A[i].key=i;
    }
  Partition(1,n);
  Quicksort(1,n);
  for(i=1;i<=n;i++)
    {
      if(A[i].value==A[i+1].value&&A[i].key>A[i+1].key)
	{
	  printf("Not stable\n");
	  break;
	}
    }
  if(i==n+1)
    {
      printf("Stable\n");
    }
  for(i=1;i<=n;i++)
    {
      printf("%c %d\n",A[i].suit,A[i].value);
    }
return 0;
}

Measured memory_bytes: 1776
using static System.Console;

class Program {
	static void Main() {
		var S = ReadLine();
		WriteLine(Judge(S) ? "AC" : "WA");
	}
	static bool Judge(string S) {
		var i = 0;
		var flg = false;
		foreach (var c in S) {
			if (i == 0) {
				if (S[0] != 'A') {
					return false;
				}
			} else if (1 <= i && i < S.Length) {
				if (S[i].ToString().ToUpper() == S[i] + "") {
					if (i == 1 || i == S.Length - 1 || flg) {
						return false;
					}
					flg = true;
				}
			}
			i++;
		}
		return flg ? true : false;
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a > b){ a = b; return 1; } return 0; }

const long long inf = 1LL << 60;

long long dp[100010];

int main(){
  int n;
  int i;
  cin >> n;
  vector<int> h(n);

  for(i=0;i<n;++i){
    cin >> h[i];
  }

  for(i=0;i<100010;++i){
    dp[i]=inf;
  }

  dp[0]=0;

  for(i=1;i<n;++i){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    if(i>1) {
      chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));

    }
  }

  cout << dp[n-1] << endl;
  return 0;

}

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

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	long long sum = 0;
	if (a % 2 == 1 && b % 2 == 1 && c % 2 == 1) {
		if (a >= b && a >= c) {
			sum = b * c;
			cout << sum << endl;
		}
		else if (b >= a && b >= c) {
			sum = a * c;
			cout << sum << endl;
		}
		else if (c >= b && c >= a) {
			sum = a * b;
			cout << sum << endl;
		}
	}
	else {
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    S = str(input())
    word_list = ['dream', 'dreamer', 'erase', 'eraser']
    rev_S = S[::-1]
    word_list = list(map(lambda x : x[::-1], word_list))

    answer = 'YES'
    while len(rev_S) >= 1:
        for i in range(len(word_list)):
            word = word_list[i]
            if rev_S.startswith(word):
                rev_S = rev_S[len(word)::]
                break
            elif i == len(word_list)-1:
                answer = 'NO'
                break
        if answer == 'NO':
            break

    print(answer)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define E esit(0)
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
const int N=1e5+5;
const int INF=1e9+7;
int dp[3001][3001];
string s,s1,ans;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>s>>s1;
    ll n=s.size(),m=s1.size();
    s=" "+s;
    s1=" "+s1;
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            if (s[i]==s1[j]) {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    while (n!=0 && m!=0) {
        if (s[n]==s1[m]) {
            ans+=s[n];
            n--;
            m--;
        }
        else {
            if (dp[n-1][m]>dp[n][m-1]) n--;
            else m--;
        }
    }
    for (int i=ans.size()-1;i>=0;i--) {
        cout<<ans[i];
    }
}

Measured memory_bytes: 38836
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long res = 0;
  for (int i=1; i<=n; i++) {
    if (i%3 != 0 && i%5 != 0) res += i;
  }
  cout << res << endl;
  return 0;
}


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

int main() {
	int n, x; cin >> n >> x;
	vector<int>a(n); for (auto&& xx : a)cin >> xx;
	long long ans = 0;
	if (a[0] > x) { long long diff = a[0] - x; a[0] -= diff; ans += diff; }
	for (int i = 0; i < n - 1; i++) {
		if (a[i] + a[i + 1] > x) {
			long long diff = a[i] + a[i + 1] - x;
			ans += diff; a[i + 1] -= diff;
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

pair<int, int> d[11111];
int a[11];
int main() {
	int n, m;
	int b[] = { 0,2,5,5,4,5,6,3,7,6 };
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++) {
		d[i].first = -1e9;
		for (int j = 0; j < m; j++) {
			int l = i < b[a[j]] ? -1e9 : d[i - b[a[j]]].first + 1;
			d[i] = max(d[i], { l,a[j] });
		}
	}
	for (int i = n; i;) {
		cout << d[i].second;
		i -= b[d[i].second];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

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

	int N, r = 0, max = 0;
	std::cin >> N;
	std::vector<int> H(N);

	for (auto &h : H) {
		std::cin >> h;
		if (max <= h) {
			r++;
			max = h;
		}
	}

	std::cout << r << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ary = new int[n];
        for (int i=0; i<n; i++) {
            ary[i] = sc.nextInt();
        }
        
        for (int i=0; i<n; i++) {
            int val = ary[i];
            for (int j=i-1; j>-1; j--) {
                if (ary[j+1] < ary[j]) {
                    ary[j+1] = ary[j];
                    ary[j] = val;
                } else {
                    break;
                }
            }
            for (int k=0;k<n;k++) {
                System.out.print(ary[k]);
                if (k!=n-1) {
                    System.out.print(" ");
                } else {
                    System.out.println("");
                }
            }
        }
    }
}

Measured memory_bytes: 33948
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		String ssc = sc.nextLine();
		String[] assc = ssc.split(" ");
		int ih = Integer.parseInt(assc[0]);
		int iw = Integer.parseInt(assc[1]);
		int[][] igmb = new int[ih][iw];
		ssc = "";
		for(int x=0;x<ih;x++){
			ssc = sc.nextLine();
			for(int y=0;y<iw;y++){
				if(ssc.charAt(y)=='#'){
					igmb[x][y] = -1;
					if(x!=0&&y!=0)igmb[x-1][y-1] = (igmb[x-1][y-1])!=-1 ? (igmb[x-1][y-1])+1 : -1;
					if(y!=0)igmb[x][y-1] = (igmb[x][y-1])!=-1 ? (igmb[x][y-1])+1 : -1;
					if(x!=ih-1&&y!=0)igmb[x+1][y-1] = (igmb[x+1][y-1])!=-1 ? (igmb[x+1][y-1])+1 : -1;
					if(x!=0)igmb[x-1][y] = (igmb[x-1][y])!=-1 ? (igmb[x-1][y])+1 : -1;
					if(x!=ih-1)igmb[x+1][y] = (igmb[x+1][y])!=-1 ? (igmb[x+1][y])+1 : -1;
					if(x!=0&&y!=iw-1)igmb[x-1][y+1] = (igmb[x-1][y+1])!=-1 ? (igmb[x-1][y+1])+1 : -1;
					if(y!=iw-1)igmb[x][y+1] = (igmb[x][y+1])!=-1 ? (igmb[x][y+1])+1 : -1;
					if(x!=ih-1&&y!=iw-1)igmb[x+1][y+1] = (igmb[x+1][y+1])!=-1 ? (igmb[x+1][y+1])+1 : -1;
				}
			}
		}
		for(int x=0;x<ih;x++){
			for(int y=0;y<iw;y++){
				if(igmb[x][y]!=-1){
					System.out.print(igmb[x][y]);
				}
				else{
					System.out.print('#');
				}
			}
			System.out.println("");
		}
    }
}


Measured memory_bytes: 23252
// 2次元グラフで、座標(sx,sy)から各座標までの最短距離を求める(O(N+M))
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using Graph = vector<vector<int>>;

int main(void)
{
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    ll H, W, i, j, cnt=0;
    char A[1010][1010];

    cin >> H >> W;

    // BFSのためのデータ構造
    queue<pair<int,int>> que; // 橙色頂点(発見済みだが未訪問な頂点)の座標を格納するキュー

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            cin >> A[i][j];

            if(A[i][j]=='#') que.push({i,j});
        }
    }

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        queue<pair<int,int>> que2;
        cnt++;

        while(!que.empty()){
            pair<int,int> p = que.front();
            int y = p.first; int x = p.second;
            que.pop();

            // 隣接頂点を探索
            for(int d=0; d<4; d++){
                int nx = x+dx[d];
                int ny = y+dy[d];

                if(ny<1 || ny>H || nx<1 || nx>W) continue;

                if(A[ny][nx]=='.'){
                    A[ny][nx] = '#';
                    que2.push({ny,nx});
                }
            }
        }

        que = que2;
    }

    std::cout << cnt-1 << endl;

    return 0;
}

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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 4e5 + 5;
const int inf = 1e16 + 2;

int a[3001] , cache[3001][3001][2] , n , vis[3001][3001][2];
int dp(int l , int r , int cur) {
    if(l > r) return 0;
    int &ans = cache[l][r][cur];
    if(vis[l][r][cur]) return ans;
    vis[l][r][cur] = 1;
    if(cur) {
        ans = min(-a[l] + dp(l + 1 , r , cur^1 ) , -a[r] + dp(l , r - 1 , cur^1));
    }
    else {
         ans = max(a[l] + dp(l + 1 , r , cur^1 ) , a[r] + dp(l , r - 1 , cur^1 ));
    }
    return ans;
}
void solve(int Case) {
    cin >> n ;
    for(int i = 0 ; i < n ; i ++) cin >> a[i] ;
    cout << dp(0 , n - 1 , 0) << '\n';
    
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case ++);
    }
    return 0;
}
 



Measured memory_bytes: 167364
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n,k;
  cin>>n>>k;

  vector<ll> h(n);
  rep(i,n) cin>>h[i];
  ll ans=0;
  rep(i,n){
    if(k<=h[i]) ans++;
  }
  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 1024
import time
s_time = time.time()


n = int(input())
a = [list(map(int, input().split())) for i in range(n)]

memo = {}
for i in range(n):
    memo[i] = 0

cnt = 0
while True:
    visited = [False] * n
    flag = False
    for i in range(n):
        if memo[i] == len(a[0]):
            continue
        if visited[i] or visited[a[i][memo[i]] - 1]:
            continue
        visited[i] = True
        if i + 1 == a[a[i][memo[i]] - 1][memo[a[i][memo[i]] - 1]]:
            visited[a[i][memo[i]] - 1] = True
            flag = True
            tmp = memo[i]
            memo[i] += 1
            memo[a[i][tmp] - 1] += 1
    if flag:
        cnt += 1
    else:
        for i in memo:
            if memo[i] != len(a[0]):
                print(-1)
                exit()
        break
    if abs(s_time - time.time()) > 1.7:
        print(n*(n-1) //2)
        exit()
print(cnt)


Measured memory_bytes: 55768
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl;
#define pno cout << "no" << endl;
#define pYe cout << "Yes" << endl;
#define pNo cout << "No" << endl;
#define pYE cout << "YES" << endl;
#define pNO cout << "NO" << endl;;
#define prin(num) cout << num << endl;
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define mp make_pair
#define INF 100000000000
#define MOD 1000000007LL
#define MAX 200005
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

int main(void) {
    ll H, W, N;
    cin >> H >> W >> N;
    //vector<ll> a(N), b(N);
    ll a, b;
    ll i, j, k;
    map<P, ll> map;
    for(i=0; i<N; i++) {
        cin >> a >> b;
        a--; b--;
        
        for(j=a-1; j<=a+1; j++) {
            for(k=b-1; k<=b+1; k++) {
                if(j<=0 || k<=0 || j>=H-1 || k>=W-1) continue;
                map[mp(j, k)]++;
            }
        }
        
    }
    ll cnt[10]={0};
    cnt[0]=(H-2)*(W-2);
    for(auto it=map.begin(); it!=map.end(); it++) {
        cnt[it->second]++;
    }
    
    for(i=1; i<10; i++) {
        cnt[0]-=cnt[i];
    }
    
    for(i=0; i<10; i++) {
        prin(cnt[i]);
    }
    
}

Measured memory_bytes: 56448
X,Y,Z,K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

import heapq

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
m = A[0]+B[0]+C[0]

counted=set([])
in_heap=set([])

hp = []
heapq.heapify(hp)
heapq.heappush(hp, (0, (0,0,0)))

#print(hp)

for _ in range(K):
  x = heapq.heappop(hp)
  print(m-x[0])
  counted.add(x[1])
  a,b,c = x[1]
  if (a+1, b,c) not in counted and (a+1, b,c) not in in_heap and a<len(A)-1:
    heapq.heappush(hp, (m-A[a+1]-B[b]-C[c], (a+1,b,c)))
    in_heap.add((a+1, b, c))
  if (a, b+1,c) not in counted and (a, b+1,c) not in in_heap and b<len(B)-1:
    heapq.heappush(hp, (m-A[a]-B[b+1]-C[c], (a,b+1,c)))
    in_heap.add((a,b+1,c))
  if (a, b,c+1) not in counted and (a, b,c+1) not in in_heap and c<len(C)-1:
    heapq.heappush(hp, (m-A[a]-B[b]-C[c+1], (a,b,c+1)))
    in_heap.add((a,b,c+1))


Measured memory_bytes: 5476
import std.stdio, std.conv, std.string;

void main() {
	long N;
	long [] a;
	N = readln().chomp().to!(long);
	a = readln().chomp().split().to!(long[]);
	int res = 0;
	foreach(long i; a) {
		int cnt = 0;
		while(i % 2 == 0) {
			cnt++;
			i /= 2;
		}
		res += cnt;
	}
	writefln("%d",res);
}


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

int main(){
  string s;
  cin >> s;
  
  int len=s.size();
  if(len==2&&s=="hi"){
    cout << "Yes";
  }else if(len==4&&s=="hihi"){
    cout << "Yes";
  }else if(len==6&&s=="hihihi"){
    cout << "Yes";
  }else if(len=8&&s=="hihihihi"){
    cout << "Yes";
  }else if(len=10&&s=="hihihihihi"){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
use std::collections::*;

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()
}

fn main() {
    let v: Vec<usize> = read_vec();
    let (h, w) = (v[0], v[1]);
    let mut maze = vec![vec![false; h]; w];
    let mut white_count = 0;
    for y in 0..h {
        let s: String = read();
        for (x, c) in s.chars().enumerate() {
            if c == '.' {
                maze[x][y] = true;
                white_count += 1
            }
        }
    }
    // println!("{:?}", maze);
    let mut que = VecDeque::new();
    let mut checked = vec![vec![false; h]; w];
    checked[0][0] = true;
    let mut last_cnt = -1;
    que.push_back((0usize, 0usize, 1i32));

    while let Some((cur_x, cur_y, cnt)) = que.pop_front() {
        if cur_x == w - 1 && cur_y == h - 1 {
            last_cnt = cnt;
            break;
        }
        if cur_x != 0 && !checked[cur_x - 1][cur_y] && maze[cur_x - 1][cur_y] {
            checked[cur_x - 1][cur_y] = true;
            que.push_back((cur_x - 1, cur_y, cnt + 1));
        }
        if cur_y != 0 && !checked[cur_x][cur_y - 1] && maze[cur_x][cur_y - 1] {
            checked[cur_x][cur_y - 1] = true;
            que.push_back((cur_x, cur_y - 1, cnt + 1));
        }
        if cur_x != w - 1 && !checked[cur_x + 1][cur_y] && maze[cur_x + 1][cur_y] {
            checked[cur_x + 1][cur_y] = true;
            que.push_back((cur_x + 1, cur_y, cnt + 1));
        }
        if cur_y != h - 1 && !checked[cur_x][cur_y + 1] && maze[cur_x][cur_y + 1] {
            checked[cur_x][cur_y + 1] = true;
            que.push_back((cur_x, cur_y + 1, cnt + 1));
        }
    }
    // println!("{:?}", (white_count, last_cnt));
    if last_cnt == -1 {
        println!("-1");
    } else {
        println!("{:?}", white_count - last_cnt);
    }
}


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

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

        int num[n];
        for(int i=0; i<n; i++){ cin >> num[i]; /*scanf("%d ",&num[i]);*/ }
        cout << num[n-1];
        for(int i=1; i<n; i++){ cout << " " << num[n-i-1]; }
        cout << endl;
 
        return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<vector<int>> to(n);
   rep(i, 0, n) {
      int u, k;
      cin >> u >> k;
      u--;
      rep(j, 0, k) {
         int v;
         cin >> v;
         v--;
         to[u].push_back(v);
      }
   }
   vector<int> d(n), f(n), color(n);
   int t = 0;
   function<void(int)> dfs = [&](int u) {
      if (color[u] != 0) return;
      color[u] = 1;
      d[u] = ++t;
      for (int i = 0; i < to[u].size(); i++) {
         if (color[to[u][i]] == 0) {
            dfs(to[u][i]);
         }
      }
      color[u] = 2;
      f[u] = ++t;
   };
   rep(i, 0, n) dfs(i);
   rep(i, 0, n) printf("%d %d %d\n", i + 1, d[i], f[i]);
   return 0;
}


Measured memory_bytes: 3268
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
*/

using namespace std;
/*
int gcd(int x, int y)
{
    if (x % y == 0)
        return (y);
    else
        return (gcd(y, x % y));
}*/
unsigned gcd(unsigned a, unsigned b)
{
    if (a < b)
        gcd(b, a);
    unsigned r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    int x, y;
    cin >> x >> y;
    cout << gcd(x, y) << endl;
}


Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
    int x,y,h,w,n,i,j,k,money;
    int count[6];

    while(scanf("%d",&n),n){
        money=0;
        for(i=0;i<6;i++) count[i]=0;
        for(i=0;i<n;i++){
            scanf("%d%d%d%d",&x,&y,&h,&w);
            if(x+y+h<=60){
                if(w<=2) count[0]++;
                else {
                    for(j=0;j<5;j++){
                        if(5*j<w&&w<=5*j+5) count[j+1]++;
                    }
                }
            } else {
                for(j=0;j<5;j++){
                    if(60+j*20<x+y+h&&x+y+h<=80+j*20){
                        for(k=j;k<5;k++){
                            if(k==j) if(5*k>=w) count[k+1]++;
                            if(5*k<w&&w<=5*k+5) count[k+1]++;
                        }
                    }
                }
            }
        }

        for(j=0;j<6;j++) money+=(600+j*200)*count[j];
        printf("%d\n",money);
    }
    return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cctype>

using namespace std;

int main(){
    int c;
    int count[26] = { 0 };
    
    while((c = getchar()) != EOF){
        if(isalpha(c)){
            if(isupper(c)){
                c = tolower(c);
            }
            
            ++count[c - 'a'];
        }
    }
    
    for(int i = 0; i < 26; ++i){
        printf("%c : %d\n", 'a' + i, count[i]);
    }
    
    return 0;
}


Measured memory_bytes: 2608
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define all(v) v.begin(), v.end()
int main()
{
  	ll n; cin>>n;
    string s="";
    while(n--) 
    {
		  s+=(char)('a'+n%26);
		  n/=26;		  
	}
		reverse(all(s));
		cout<<s<<endl;     
}


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

#include <bits/stdc++.h>
using namespace std;

bool isPal(string &s) {
  int n = s.length();
  for (int i = 0; i * 2 < s.length(); ++i) {
    if (s[i] != s[n - i - 1])
      return false;
  }
  return true;
}
class BStringPalindrome {
 public:
  void solveOne(int caseNumber, std::istream &in, std::ostream &out) {
    string s;
    in >> s;
    int n = s.size();
    string s1 = s.substr(0, (n - 1) / 2);
    string s2 = s.substr(((n + 3) / 2) - 1);

    //out << s << " " << s1 << " " << s2 << endl;
    if (isPal(s) && isPal(s1) && isPal(s2))
      out << "Yes" << endl;
    else
      out << "No" << endl;

  }
  void solve(std::istream &in, std::ostream &out) {
    int nt = 1;
    for (int i = 0; i < nt; ++i)
      solveOne(i + 1, in, out);
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  BStringPalindrome solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool has_key(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll a(N);
        vll cnt(100100, 0);
        rep(i, 0, N) cin >> a[i];
        rep(i, 0, N) {
                cnt[a[i]]++;
        }
        ll mx = 0;
        rep(i, 0, 100010) {
                chmax(mx, cnt[i] + cnt[i+1] + cnt[i+2]);
        }
        cout << mx << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
  ll x,k,d,res;
  cin >> x >> k >> d;
  x=abs(x);
  if(x/d>=k-1){
    res=abs(x-k*d);
  }else{
    k-=x/d;
    res=x%d;
    if(k%2==1)
      res=d-res;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <set>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <map>

using namespace std;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n-1; ++i) {
		int c = n - 1 - i;
		vector<int> d(c,0);
		int level = 1;
		while (true) {
			int phase = 0;
			for (int i = 0; i < c; ++i) {
				if (d[i] == 0) {
					if (phase == 0) {
						d[i] = level;
						phase = 1;
					}
					else {
						phase = 0;
					}
				}
			}
			bool flag = true;
			for (int i = 0; i < c; ++i) {
				flag = flag & (d[i] != 0);
			}
			if (flag) break;
			else level += 1;
		}
		for (int j = 0; j < n - 1 - i; ++j) {
			cout << d[j];
			if (j + 1 == n - 1 - i) cout << endl;
			else cout << " ";
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}
ll myceil(ll x,ll y){//yがいくつ集まったらx以上になるか
	if(x<=y) return 1;
	else if(x%y==0) return x/y;
	else return x/y+1;
}

//a,b x
int main(){
	string s; cin>>s;
	bool A=false;
	bool Z=false;
	ll AP,ZP;
	rep(i,s.sz){
		if(A==false && s[i]=='A'){
			AP=i;
			A=true;
		}
	}
	for(int i=s.sz-1;i>0;i--){
		if(Z==false && s[i]=='Z'){
			ZP=i;
			Z=true;
		}
	}
	cout<<ZP-AP+1;
}

Measured memory_bytes: 644
#include <cstdio>
#include <algorithm>

int n, p;
long long int even, odd;
long long int ans;

long long int c(int n, int k){
	long long int res = 1;
	for(int i=0; i<k; ++i){
		res *= (n-i);
		res /= i+1;
	}
	return res;
}

int main(){
	scanf("%d %d", &n, &p);
	for(int i=0; i<n; ++i){
		int a;
		scanf("%d", &a);
		if(a % 2 == 0) ++even;
		else ++odd;
	}
	for(int i=0; 2*i+p<=odd; ++i){
		ans += c(odd, 2*i+p) * ((long long int)1 << even);
	}
	printf("%lld\n", ans);
}

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

const int INFTY =1<<21;
int L[200000],R[200000];

void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1] =R[n2]=INFTY;
    int i=0,j=0;
    for(int p=left;p<right;p++){
        if(L[i]<=R[j]) A[p]=L[i++];
        else A[p]=R[j++];
    }
}

void sort(int A[],int left,int right){
    if(left+1<right){
        int mid=(left + right)/2;
        sort(A,left,mid);
        sort(A,mid,right);
        merge(A,left,mid,right);
    }
}

int main(){
    int n;
    int A[100005];
    cin>>n;
    for(int i=0;i<n;i++) cin>>A[i];
    sort(A,0,n);
    cout<<A[n/2]-A[n/2-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
/*
    Prodigia comploratus,
    silens, oro:
    "Regnet exitium."
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 5e5 + 5, MOD = 1e9 + 7;
const ll inf = 1e15;
int n, a[N];
///if current prefix xor is x
///it is known that the that i need for the rest to have xor of 0

int easy(int val){
    int ans[2] = {}, x;
    ans[0] = 1;
    for(int i = 1; i <= n; i++){
        int col = -1;
        if(a[i] == 0)col = 0;
        else if(a[i] == val)col = 1;
        if(~col){
            x = ans[col^1];
            ans[col] += x;
            if(ans[col] >= MOD)ans[col] -= MOD;
        }
    }
    return x;
}
int acc[N];
vector<int> go[1<<20];
int hard(int val){
    if(val == 0){
        int ret = 1;
        for(int j = 0; j + 1 < acc[n]; j++){
            ret = ret + ret;
            if(ret >= MOD)ret -= MOD;
        }
        return ret;
    }
    int ret = 0;
    vector<int> v = go[val];
    int ans[2] = {};    ans[0] = 1;
    for(int i = 0; i < v.size(); i++){
        ans[1] += ans[0];
        if(ans[1] >= MOD)ans[1] -= MOD;
        ////update ans[0]
        if(i + 1 != v.size()){
            int toNxt = acc[v[i+1]] - acc[v[i]];
            ans[0] += 1ll * ans[1] * toNxt % MOD;
            if(ans[0] >= MOD)ans[0] -= MOD;
        }
    }
    return ans[1];
}
int main(){

    scanf("%d", &n);

    for(int i = 1; i <= n; i++){
        scanf("%d", a + i), a[i] ^= a[i-1];
    }   
    if(a[n]){
        cout << easy(a[n]) << '\n';
    }   else {
        vector<int> vals;
        for(int i = 1; i <= n; i++){
            vals.push_back(a[i]);
            acc[i] = (a[i] == 0);
            acc[i] += acc[i-1];
            go[a[i]].push_back(i);
        }
        sort(vals.begin(),vals.end());
        vals.resize(unique(vals.begin(),vals.end()) - vals.begin());
        int ans = 0;
        for(auto x : vals){
            ans += hard(x);
            if(ans >= MOD)ans -= MOD;
        }
        cout << ans << '\n';
    }


    return 0;
}


Measured memory_bytes: 40304
#coding: UTF-8

while True:
    N, X = map(int, input().split())
    if N == 0 and X == 0:
        break
    ans = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            if i >= j:
                continue
            c = X - (i + j)
            if c > j and c <= N:
                ans += 1
    print("%d"%(ans))



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll arr1[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    sort(arr1,arr1+n);
    ll ans=0,store;
    ll pos=0;
    for(;pos<n;pos+=2)
    {
        if(pos==(n-1))
        {
            break;
        }
        store=arr1[pos]+arr1[pos+1];
        if(store>=0)
        {
            ans+=store;
            pos+=2;
            break;
        }
        ans-=store;
    }
    for(;pos<n;pos++)
    {
        ans+=arr1[pos];
    }
    cout<<ans;
    return 0;
}

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

using namespace std;

int main() {
    int N = 0;
    cin >> N;
    int W;
    cin >> W;
    vector<int> A(110,0);
    vector<int> B(110,0);
    for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    cin >> B.at(i);
    }
    vector<vector<int> > dp(110,vector<int> (10010,0));
   // for (size_t i = 0; i < W; i++)dp.at(0).at(i) = 0;
    
    

    for (size_t i = 0; i < N; i++)
    {   
        for (size_t j = 0; j <= W; j++)
        {
           // cout << i << ',' << j << '/' << dp.at(i).at(j) << endl;
            if (B.at(i) > j)
            {
                dp.at(i + 1).at(j) = dp.at(i).at(j);
            }else if (dp.at(i).at(j-B.at(i))+A.at(i) >= dp.at(i).at(j))
            {
                dp.at(i + 1).at(j) = dp.at(i).at(j-B.at(i))+A.at(i);
            }else
            {
                dp.at(i + 1).at(j) = dp.at(i).at(j);
            }
            
            
        }
        
    }
    cout << dp.at(N).at(W) << endl;
    //cout << dp.at(4).at(4) << endl;
                
    

    return 0;
}


Measured memory_bytes: 7124
#include <bits/stdc++.h>
#define INF 1e+9
#define MOD (int)1e9+7
#define debug(x) cerr << #x << ": " << x << "\n";
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void){
    int N, Y; cin >> N >> Y;
    int a = -1, b = -1, c = -1;

    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N - i; j++){
            int k = N - i - j;
            if(i*10000 + j*5000 + k*1000 == Y){
                 a = i; b = j; c = k;
            }
        }
    }

    cout << a << ' ' << b << ' ' << c << '\n';
    return 0;
}

Measured memory_bytes: 256