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

int main(){
    int n;
    cin>>n;
    vector<int> v(n);

    for(int i=0;i<n;i++)
        cin>>v[i];

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

    cout<<fixed<<setprecision(6);

    double long ans = v[0];

    for(int i=1; i<n; i++){
        ans = (ans + v[i])/2;
    }

    cout<<ans<<endl;

}


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

def z_advanced(s):
    # Taken from https://ivanyu.me/blog/2013/10/15/z-algorithm/
    """An advanced computation of Z-values of a string."""
 
    Z = [0] * len(s)
    Z[0] = len(s)
 
    rt = 0
    lt = 0
 
    for k in range(1, len(s)):
        if k > rt:
            # If k is outside the current Z-box, do naive computation.
            n = 0
            while n + k < len(s) and s[n] == s[n+k]:
                n += 1
            Z[k] = n
            if n > 0:
                lt = k
                rt = k+n-1
        else:
            # If k is inside the current Z-box, consider two cases.
 
            p = k - lt  # Pair index.
            right_part_len = rt - k + 1
 
            if Z[p] < right_part_len:
                Z[k] = Z[p]
            else:
                i = rt + 1
                while i < len(s) and s[i] == s[i - k]:
                    i += 1
                Z[k] = i - k
 
                lt = k
                rt = i - 1
    return Z

best = 0
for i in range(N):
    lst = z_advanced(S[i:])
    for j, longest in enumerate(lst):
        best = max(best, min(j, longest))
print(best)


Measured memory_bytes: 54052
while( ( n = gets.to_i ) != 0 )
  l = (0...n).inject(Array.new){|a| a << gets.to_i}
  puts (0..n).inject(-999999){|m, i| (i...n).inject(0){|s, ii| s+=l[ii]; m = [m, s].max; s}; m}
end

Measured memory_bytes: 6108
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int num = sc.nextInt();
    static int[] h = new int[num];
    static int[] dp = new int[num];

    public static void main(String[] args) {
        for (int i = 0; i < num; i++){
            h[i] = sc.nextInt();
            dp[i] = 2147483647;
        }
        System.out.println(check(num - 1));
    }
    public static int check(int i){
        if(dp[i] < 2147483647)
            return dp[i];
        if (i == 0)
            return 0;
        if (i == 1)
            return Math.abs(h[1] - h[0]);
        dp[i] = chmin(check(i - 1) + Math.abs(h[i] - h[i - 1]), check(i - 2) + Math.abs(h[i] - h[i - 2]));
        return dp[i];
    }
    public static int chmin(int a, int b){
        if(a > b){
            return b;
        }else{
            return a;
        }
    }
}


Measured memory_bytes: 72584
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    int N;
    cin >> N;
    bool ok = false;
    map<int, bool> mp;
    for(int i = 0; i < N; i++){
        int a;  cin >> a;
        if(mp.find(a) == mp.end()){
            mp[a] = true;
        }
        else{
            ok = true;
        }
    }

    if(ok){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }



    return 0;
}


Measured memory_bytes: 9600
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<utility>
#include<algorithm>
#include<sstream>
using namespace std;
#define ll int64_t
#define REP(i, n) for (int i=0; i<n; i++)

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

    string S;
    cin >> S;

    ll first = stoi(S.substr(0,2));
    ll second = stoi(S.substr(2));

    if ((1 <= first) && (first <= 12) && (1 <= second) && (second <= 12)){
        cout << "AMBIGUOUS" << "\n";
    } else if ((1 <= first) && (first <= 12)){
        cout << "MMYY" << "\n";
    } else if ((1 <= second) && (second <= 12)){
        cout << "YYMM" << "\n";
    } else {
        cout << "NA" << "\n";
    }
}

Measured memory_bytes: 256
import re

S = input()
K = int(input())

def main():
    global K
    m = re.search(r'[2-9]', S)
    if m:
        i = m.start()
        index = min([m.start(), K - 1])
        ans = list(S).pop(index)
    else:
        ans = 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
long long a[100001];
long long ans;

int main(){
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 0; i < n + 1; ++i){
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i){
		long long b; 
		cin >> b;
		ans += min(b , a[i]);
		b -= min(a[i] , b);
		ans += min(b , a[i + 1]);
		a[i + 1] -= min(b , a[i + 1]);		
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl;

using namespace std;
const int inf = 1e18;
vector<int> primes;
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	const int N = 1e6+1;
	bool visit[N] = {0};
	for(int i=2;i<N;i++){
		if(visit[i]) continue;
		primes.push_back(i);
		for(int j=2;j*i<N;j++){
			visit[i*j] = true;
		}
	}
	int n;
	cin>>n;
	int ans = 0;
	for(auto i:primes){
		int cnt = 0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		int j=1;
		for(;j<N;j++){
			if(cnt<j) break;
			cnt-=j;
		}
		ans += j-1;
	}
	if(n>1) ans++;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
int a[200005];
long long cnt[1000005];//For counting how many balls have x written on it
 
 
int main() {
  int n;
  cin>>n;
  for(int i=0;i<n;i++) {
    cin>>a[i];
    cnt[a[i]]++;
  }
  long long ans=0;
  for(int i=1;i<=n;i++) {
    ans+=cnt[i]*(cnt[i]-1)/2;
  }
  for(int k=0;k<n;k++) {
    cout<<ans-(cnt[a[k]]-1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x;
		if(a > b) {
			x = a;
			a = b;
			b = x;
		}
		if(b > c) {
			x = b;
			b = c;
			c = x;
		}
		if(a > b) {
			x = a;
			a = b;
			b = x;
		}
		System.out.printf("%d %d %d\n", a, b, c);
	}
}



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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int N;
vint B, C, G, sumB;
vector<string> A;
vector< vector<string> > D;
map<string, int> mp;
int ans;

void dfs(int idx, int sum, int bit) {
  chmax(ans, sum);
  if(idx == N) return;
  if(sum+sumB[idx] <= ans) return;
  dfs(idx+1, sum, bit);
  if(!((bit>>idx)&1)) dfs(idx+1, sum+B[idx], bit|G[idx]);
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N, N) {
    resz(A, N);
    resz(B, N);
    resz(C, N);
    resz(D, N);
    resz(sumB, N);
    mp.clear();
    rep(i, N) {
      cin >> A[i] >> B[i] >> C[i];
      mp[A[i]] = i;
      rep(j, i+1) sumB[j] += B[i];
      resz(D[i], C[i]);
      rep(j, C[i]) cin >> D[i][j];
    }

    resz(G, N);
    rep(i, N) {
      G[i] |= 1LL<<i;
      rep(j, C[i]) G[i] |= 1LL<<mp[D[i][j]];
    }

    ans = 0;
    dfs(1, B[0], G[0]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3324
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string S;
int N;
int main(){
  cin >> S;
  N = S.size();
  int ans =-1;
  for(int i=0; i<N; i++){
      int counter =0;
    for(int j=i; j<N; j++){
      bool flag =true;
      if (S[j] == 'A' ||S[j] == 'G' ||S[j] == 'C' ||S[j] == 'T'){
        counter++;
      }
      else flag =false;
      if (!flag) break;
    }
    ans = max(ans, counter);
  }
  cout << ans << endl;
  return 0;
}

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

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;

	
	public static void Main(string[] args)
	{
		const string t = "CODEFESTIVAL2016";
		var s = Console.ReadLine();
		int wa = 0;
		for(int i = 0; i < s.Length; i++)
		{
			if(s[i] != t[i])
				wa++;
		}
		Console.WriteLine(wa);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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 ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vl a(n);
  REP(i, n) cin >> a[i];
  sort(all(a));
  if (a[0] == 0) {
      cout << 0 << endl;
      return 0;
  }
  ll ans = 1;
  bool ok = true;
  REP(i, n) {
    ll tmp = ans;
    ans *= a[i];
    if (ans > INF || tmp >= LONG_MAX/a[i]) {
      ok = false;
    }
  }
  if(ok) cout << ans << endl;
  else cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 3996
#include<stdio.h>

int main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d = (int)(a/b);
	r = a%b;
	f = (double)(a)/(double)(b);
	
	printf("%d %d %.5f\n",d,r,f);
	
	
	return 0;
	
}

Measured memory_bytes: 636
ansMax = 0
S = input()
sLen = len(S)
for i in range(sLen):
    for j in range(i, sLen):
        if all('ACGT'.count(k) == 1 for k in S[i: j + 1]):
            ansMax = max([ansMax, j - i + 1])

print(ansMax)

Measured memory_bytes: 3064
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n), b(n);
    cin >> a >> b;
    vi ca(n + 1), cb(n + 1);
    rep(i, n) {
        ca[a[i]]++;
        cb[b[i]]++;
    }
    rep(i, n) {
        if (ca[i + 1] + cb[i + 1] > n) {
            Yes(0);
            return 0;
        }
        ca[i + 1] += ca[i];
        cb[i + 1] += cb[i];
    }
    int mx = -inf;
    rep(i, n) chmax(mx, ca[i + 1] - cb[i]);
    vi ans(n);
    rep(i, n) {
        int pos = ((i + mx) % n + n) % n;
        ans[pos] = b[i];
    }
    Yes(1);
    rep(i, n) {
        cout << ans[i] << (i == n - 1 ? '\n' : ' ');
    }
}

Measured memory_bytes: 7152
#include<bits/stdc++.h>
#define maxn 205050

using namespace std;
typedef long long ll;
ll dp[maxn],n,W,k,w[maxn],v[maxn];
int main(){
    cin >> n >> W;
    for (int i=1;i<=n;i++) cin >> w[i] >> v[i];
    for (int i=1;i<=n;i++)
        for (int j=W;j>=w[i];j--)
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    cout << dp[W] << endl;
}


Measured memory_bytes: 2304
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

int powM(int x, int n){
    if(n == 0){
        return 1;
    }
    if(n % 2 == 0){
        return powM(x * x % MOD, n / 2);
    }
    return powM(x, n-1) * x % MOD;
}

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

    int n = s.length();
    vector<int> a(n+1), c(n+1), q(n+1);
    a[0] = c[0] = q[0] = 0;
    rep(i, n){
        a[i+1] = a[i];
        c[i+1] = c[i];
        q[i+1] = q[i];
        if(s[i] == 'A'){
            a[i+1]++;
        }
        if(s[i] == 'C'){
            c[i+1]++;
        }
        if(s[i] == '?'){
            q[i+1]++;
        }
    }

    int ans = 0;
    rep(i, n){
        if(s[i] != 'B' && s[i] != '?'){
            continue;
        }
        int qq = q[n];
        if(s[i] == '?'){
            qq--;
        }

        int aa = a[i];
        int cc = c[n] - c[i+1];

        int tmp = aa * cc % MOD * powM(3, qq)  % MOD;
        if(qq > 0){
            tmp = (tmp + aa * (q[n] - q[i+1]) % MOD * powM(3, qq - 1) % MOD) % MOD;
            tmp = (tmp + q[i] * cc % MOD * powM(3, qq - 1) % MOD) % MOD;
        }
        if(qq > 1){
            tmp = (tmp + q[i] * (q[n] - q[i+1]) % MOD * powM(3, qq - 2) % MOD) % MOD;
        }
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2880
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef double ld;

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

	int n;
	cin >> n;

	vll arr(n);
	vector<vll> dp(n, vll(n, 0));

	for (int i = 0; i < n; i++) cin >> arr[i];

	for (int i = n-1; i >= 0; i--)
	{
		for (int j = i; j < n; j++)
		{
			if (i == j)
			{
				dp[i][j] = arr[i];
			}
			else
			{
				dp[i][j] = max(arr[i] - dp[i + 1][j], arr[j] - dp[i][j - 1]);
			}
		}
	}

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

	return 0;

}

Measured memory_bytes: 73408
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
//ll ;
//ld ;
string s;
 
int main() {
  cin >> s;
  ll hugs = 0;
  ll n = s.length();
  for(ll i=0; i<floor(n/2); i++){
    if(s[i] != s[n-1-i]) hugs++;
  }
  cout << hugs << endl;
  return 0;
}

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

#define endl "\n"
#define ll long long
#define ar array

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

	int t=1;
	//cin >> t;
	while(t--) {
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		if(s[0]==s[2]) cout << "No";
		else cout << "Yes" ;
	}

	return 0 ;
}



Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll H, W, A, B;
	cin >> H >> W >> A >> B;
	rep(i, H) {
		rep(j, W) {
			if (i < B && j < A)cout << 0;
			else if (i >= B && j >= A)cout << 0;
			else cout << 1;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,k,zero=0;
    cin>>n>>k;
    vector<int>x,y;
    rep(i,n){
        int a;
        cin>>a;
        if(a>0)x.pb(a);
        if(a<0)y.pb(a);
        if(a==0)zero++;
    }
    sort(all(x));
    sort(all(y));
    int cx=0,cy=0;
    while(cy+1<y.size()&&cy+2<=k){
        cy+=2;
    }
    cx=k-cy;
    if(cx<=x.size()){
        int pos=x.size()-cx-1;
        for(int i=cy-1;i>=0&&pos-1>=0;i-=2,pos-=2){
            if(x[pos]*x[pos-1]>y[i]*y[i-1]){
                cy-=2;
            }
            else break;
        }
        int ans=1;
        for(int i=pos+1;i<x.size();i++){
            ans*=x[i];
            ans%=mod;
        }
        rep(i,cy){
            ans*=y[i];
            ans%=mod;
        }
        cout<<ans<<endl;
        return 0;
    }
    if(zero){
        cout<<0<<endl;
    }
    else{
        for(int &i:y){
            i=-i;
            x.pb(i);
        }
        sort(all(x));
        int ans=1;
        rep(i,k){
            ans*=x[i];
            ans%=mod;
        }
        cout<<mod-ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 6164
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


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

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


void strings()
{
  string s, t;
  cin >> s >> t;

  cout << t + s << "\n";
}


void yen_conins()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 - x >= 0) cout << "Yes\n";
  else cout << "No\n";
}


void tap_dance() 
{
  string s;
  cin >> s;

  int flag = 1;
  for (int i = 1; i <= s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L') flag = 0;
    }
    else
    {
      if (s[i] == 'R' ) flag = 0;
    }
  }
  if (flag) cout << "Yes\n";
  else cout << "No\n";
}


void roller_coaster()
{
  int n, k;
  cin >> n >> k;

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << "\n";
}


void takoyaki_festival2019()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];

  int v_sum = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      v_sum += d[i] * d[j];
    }
  }
  cout << v_sum << "\n";
}


void echo()
{
  int n;
  string s;
  cin >> n >> s;

  if (n % 2 != 0)
  {
    cout << "No\n";
    return;
  }

  for (int i = 0; i < n / 2; ++i)
  {
    if (s[i] != s[i + n / 2])
    {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
}


void rot_n()
{
  int n;
  string s;
  cin >> n >> s;

  for (int i = 0; i < s.size(); ++i)
  {
    s[i] = 'A' + (s[i] - 'A' + n) % 26;
  }
  cout << s << "\n";
}


void palindrom_philia()
{
  string s;
  cin >> s;

  int cnt = 0;
  for (int i = 0; i < s.size() / 2; ++i)
  {
    if (s[i] != s[s.size() - i - 1]) ++cnt;
  }
  cout << cnt << "\n";
}



int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  //round_one();
  //strings();
  //yen_conins();

  //tap_dance();
  //roller_coaster();
  //takoyaki_festival2019();
  //echo();
  //rot_n();
  palindrom_philia();
}

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

using namespace std;

int main ()
{

   int a500,b100,c50,ans;
   int i,j,k,sum,c=0;

    scanf("%d %d %d %d",&a500,&b100,&c50,&ans);

    for(i=0;i<=a500;i++)
    {
        for(j=0;j<=b100;j++)
        {
            for(k=0;k<=c50;k++)
            {
                sum = 500*i + 100*j + 50*k;

                if (ans==sum)
                    c++;
            }
        }
    }

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

    return 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;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int x[300000],y[300000];
int p[300000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d%d",&x[i],&y[i]);x[i]--;y[i]--;
		p[y[i]]=x[i];
	}
	stack<P>st;
	UnionFind uf(n);
	for(int i=n-1;i>=0;i--){
		int Max=p[i];
		while(!st.empty()&&st.top().first>p[i]){
			Max=max(Max,st.top().first);
			uf.unite(i,st.top().second);
			st.pop();
		}
		st.push(P(Max,i));
	}
	rep(i,n){
		printf("%d\n",uf.size(y[i]));
	}
}

Measured memory_bytes: 7280
from copy import deepcopy

def getInput():
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    return n, a

def insertionSort(n, a, g):
    cnt = 0
    for i in range(n):
        v = a[i]
        j = i-g
        while((j>=0)&(v<a[j])):
            a[j+g] = a[j]
            j -= g
            cnt += 1
        a[j+g] = v
    return a, cnt

def genG(n):
    G = []
    i = 0
    while 3*i+1 <= n:
        i = 3*i+1
        G.append(i)
    return G[::-1]

def shellSort(n, a):
    G = genG(n)
    cnt = 0
    print(len(G))
    print(" ".join([str(i) for i in G]))
    for g in G:
        a, cnt_g = insertionSort(n, deepcopy(a), g)
        cnt += cnt_g
    print(cnt)
    return a

n, a = getInput()
a = shellSort(n, deepcopy(a))
for i in a:
    print(i)


Measured memory_bytes: 71484
// 2011/07/20 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int w;
		cin >> w;
		if(w==-1)
			break;

		int bil;
		if(w<=10)
			bil = 1150;
		else if(w<=20)
			bil = 1150+(w-10)*125;
		else if(w<=30)
			bil = 1150+10*125+(w-20)*140;
		else
			bil = 1150+10*125+10*140+(w-30)*160;

		cout << 4280-bil << endl;	// ツづづ個つュツづァツつ「ツ静淞姪アツづつォツつスツつゥ
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
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;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll dp[100010];

int main()
{
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    rep(i, 100010) dp[i] = INF;
    dp[0] = 0;
    rep(i, n)
    {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
        // if (i == 2)
        // {
        //     COUT(dp[i + 1]);
        //     COUT(h[i]);
        //     COUT(h[i + 1]);
        //     COUT(dp[i + 2]);
        //     COUT(h[i + 2]);
        // }
        // if (i == 3)
        // {
        //     COUT(dp[i + 1]);
        //     COUT(h[i]);
        //     COUT(h[i + 1]);
        //     COUT(dp[i + 2]);
        //     COUT(h[i + 2]);
        // }
    }
    //for (auto it : dp) COUT(it);
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>
 
int main(void){
  int a[10];
  int i,j,temp;
  for(i = 0;i < 10;i++)
    scanf("%d",&a[i]);
  for(i = 0;i < 10;i++){
    for(j= i + 1;j < 10;j++)
      if(a[j] > a[i]){
      temp = a[i];
      a[i] = a[j];
      a[j] = temp;
      }
  }

  for(i = 0;i < 3;i++)
    printf("%d\n",a[i]);
 
  return 0;
}

Measured memory_bytes: 600
// https://atcoder.jp/contests/abc064/tasks/abc064_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int t = a * 100 + b * 10 + c;
    if (t % 4 == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}


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

long long s;

int ke(long long x)
{
	int c = 0;
	while (x >= 9) {
		c++;
		x /= 10;
	}
	c++;

	return c;
}

bool check(long long x)
{
	bool b[3] = { };
	int c = 0;
	while (x >= 9) {
		c++;
		int a = x % 10;
		if (a == 3)
			b[0] = true;
		else if (a == 5) {
			b[1] = true;
		}
		else if (a == 7) {
			b[2] = true;
		}
		x /= 10;
	}
	if (x == 3)
		b[0] = true;
	else if (x == 5) {
		b[1] = true;
	}
	else if (x == 7) {
		b[2] = true;
	}

	if (b[0] && b[1] && b[2])
		return true;
	else
		return false;
}

void comb(int& max_k,long long x, int k, std::vector<long long>& v)
{
	if (x == 0) {
		comb(max_k, 3, 1, v);
		comb(max_k, 5, 1, v);
		comb(max_k, 7, 1, v);

		return;
	}

	if (k >= 3) {
		if (x <= s && check(x))
			v.push_back(x);
	}

	if (max_k > k) {
		x *= 10;
		comb(max_k, x + 3, k + 1, v);
		comb(max_k, x + 5, k + 1, v);
		comb(max_k, x + 7, k + 1, v);
	}
}

int main()
{
	std::cin >> s;

	std::vector<long long> k;
	int keta = ke(s);

	comb(keta, 0, 0, k);

	std::cout << k.size();
}

Measured memory_bytes: 888
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int count = 1;
  std::sort(a, a + n);
  for (int i = 0; i < n - 1; i++) {
    if (a[i] == a[i + 1]) {
      printf("NO\n");
      count = 0;
      break;
    }
  }
  if (count == 1) {
    printf("YES\n");
  }
}

Measured memory_bytes: 896
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();

		boolean isContinue = true;

		int intSumNum = 0;

		while(isContinue){

			//????????????????????????
			int n = scan.nextInt();
			int x = scan.nextInt();

			if(n == 0 && x == 0){
				scan.close();
				break;

			}else{

				//???????????????????????°????????????????????°
				int intCount = 0;
				for(int i = 1; i <= n; i++){

					for(int j = i + 1; j <= n; j++){

						for(int k = j + 1; k <= n; k++ ){

							intSumNum = i + j + k;
							//System.out.println(intSumNum);
							if(intSumNum == x){
								intCount++;
							}
							/*System.out.print(" " + i);
							System.out.print(" " + j);
							System.out.print(" " + k);
							System.out.print("/");*/

						}
						//System.out.println();
					}
					//System.out.println();
				}
				//intCount?????????????´?
				list.add(intCount);
			}
		}//end while
		//??????
		for(int i = 0; i < list.size(); i++){
			System.out.println(list.get(i));
		}
	}
}

Measured memory_bytes: 19680
N = int(input())

number_of_1st_digit = N % 10

hons = [2, 4, 5, 7, 9]
pons = [0, 1, 6, 8]
bons = [3]
if number_of_1st_digit in hons:
    answer = 'hon'
elif number_of_1st_digit in pons:
    answer = 'pon'
elif number_of_1st_digit in bons:
    answer = 'bon'

print(answer)


Measured memory_bytes: 9104
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	bool k[24][60]={};
	cin>>n;
	for(int i=0;i<n; i++){
		int a,b;
		cin>>a>>b;
		k[a][b]=true;
	}
	cin>>m;
	for(int i=0;i<m; i++){
		int a,b;
		cin>>a>>b;
		k[a][b]=true;
	}
	bool f=false;
	for(int i=0; i<24;i++){
		for(int j=0; j<60; j++){

			if(k[i][j]){
				if(j<10){
					if(f){
						cout<<" ";
					}else{
						f=true;
					}
						cout<<i<<":0"<<j;
				}
				else{
					if(f){
						cout<<" ";
					}else{
						f=true;
					}
					cout<<i<<":"<<j;
				}
			}
		}
	}
	cout<<endl;
}


Measured memory_bytes: 3108
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::*;

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parsing")
}

fn main() {
  let (_, m): (usize, usize) = (read::<usize>(), read::<usize>());

  let mut ans: Vec<bool> = vec![false; 100000];
  let mut nga: Vec<usize> = vec![0; 100000];

  for _ in 0..m {
    let number = read::<usize>();
    let res = read::<String>();

    if res == String::from("WA") {
      if ans[number] == false {
        nga[number] = nga[number] + 1;
      }
    } else if res == String::from("AC") {
      ans[number] = true;
    }
  }

  let mut ok_ans: usize = 0;
  let mut ng_ans: usize = 0;

  let mut i :usize = 0;
  for t in ans {
    if t {
      ok_ans = ok_ans + 1;
      ng_ans = ng_ans + nga[i];
    }
    i = i + 1;
  }
  println!("{} {}", ok_ans, ng_ans);
}


Measured memory_bytes: 4352
#include <stdio.h>
int main()
{
  int n,k,x,y,t;
  scanf("%d",&n);
  scanf("%d",&k);
  while(k>0){
    scanf("%d%d",&x,&y);
    if(n % 2 == 0){
      if(x > n/2) x = n - x + 1;
      if(y > n/2) y = n - y + 1;
    }else{
      if(x > n/2+1) x = n - x + 1;
      if(y > n/2+1) y = n - y + 1;
    }
    if(y>x){
      t = y;
      y = x;
      x = y;
    }
    printf("%d\n", (y-1) % 3 + 1);
    k--;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main() {
	int n, p = 0;
	int x[50], y[50], z[50];
	cin >> n;
	for(int i = 0; i < n; i++){
	    cin >> x[i];
	}
	for(int i = 0; i < n; i++){
	    cin >> y[i];
	}
	for(int i = 0; i < n - 1; i++){
	    cin >> z[i];
	}
	for(int i = 0; i < n; i++){
	    if(x[i] == x[i+1] - 1){
	        p += z[x[i] - 1];
	    }
	    p += y[x[i] - 1];
	}
	cout << p;
}

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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    set<int> d;
    for(int i = 0; i< n; i++){
        int a;
        cin >> a;
        d.insert(a);
    }
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MOD = 10000;

// dp[day][last][second]
int dp[100][3][2];
int plan[100];

int main() {
    int N, K;
    cin >> N >> K;
    fill_n(plan, N, -1);
    for(int i = 0; i < K; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        plan[a] = b;
    }

    if(plan[0] == -1) {
        dp[0][0][0] = dp[0][1][0] = dp[0][2][0] = 1;
    }
    else {
        dp[0][plan[0]][0] = 1;
    }
    for(int day = 1; day < N; ++day) {
        if(plan[day] == -1) {
            for(int sauce = 0; sauce < 3; ++sauce) {
                for(int prev = 0; prev < 3; ++prev) {
                    if(prev != sauce) {
                        dp[day][sauce][0] += dp[day-1][prev][0] + dp[day-1][prev][1];
                    }
                    else {
                        dp[day][sauce][1] += dp[day-1][prev][0];
                    }
                }
            }
        }
        else {
            int sauce = plan[day];
            for(int prev = 0; prev < 3; ++prev) {
                if(prev != sauce) dp[day][sauce][0] += dp[day-1][prev][0] + dp[day-1][prev][1];
                else dp[day][sauce][1] += dp[day-1][prev][0];
            }
        }
        for(int sauce = 0; sauce < 3; ++sauce) {
            dp[day][sauce][0] %= MOD;
            dp[day][sauce][1] %= MOD;
        }
    }
    int sum = 0;
    for(int sauce = 0; sauce < 3; ++sauce) {
        sum += dp[N-1][sauce][0] + dp[N-1][sauce][1];
    }
    cout << sum%MOD << endl;
    return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define inf 1e9
#define INF 1000000000000000000

const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int N, K;
    cin >> N >> K;
    int red_in = N - K + 1;
    COMinit();

    if (N == K) {
    }
    rep(i, K) {
        ll ans = 0;
        ans = COM(K - 1, K - i - 1) * COM(red_in, i + 1) % MOD;
        cout << ans << endl;
    }
}

Measured memory_bytes: 12160
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] h = new int[n];
        int min = 100;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            h[i] = temp;
            min = Math.min(min, temp);
        }
        int ans = min;
        for (int i = 0; i < n; i++) {
            h[i] -= min;
        }
        boolean allZ = false;
        while (!allZ) {
            int start = 0;
            int end = 0;
            boolean isNum = false;
            while (start < n) {
                min = 101;
                boolean isNum2 = false;
                for (int i = start; i < n; i++) {
                    end = i;
                    if (h[i] > 0) {
                        isNum = true;
                        isNum2 = true;
                    }
                    if (h[i] == 0 && isNum2) {
                        break;
                    }
                    end = i + 1;
                }
                if (!isNum) {
                    allZ = true;
                    break;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    min = Math.min(min, h[i]);
                }
                if (min != 101) {
                    ans += min;
                }
                for (int i = start; i < end; i++) {
                    if (h[i] == 0) {
                        continue;
                    }
                    h[i] -= min;
                }
                start = end + 1;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;

/**
 * Party
 */
public class Main {

	static int count;
	static boolean[][] friends;
	static HashSet<Integer> invited;
	static LinkedList<Integer> queue;
	static int[] depth;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = Integer.parseInt(line);
			int m = Integer.parseInt(br.readLine());
			if ((n | m) == 0) {
				break;
			}

			friends = new boolean[n + 1][n + 1];
			invited = new HashSet<Integer>();
			queue = new LinkedList<Integer>();
			depth = new int[n + 1];

			int p, q;
			for (int i = 0; i < m; i++) {
				line = br.readLine();
				p = Integer.parseInt(line.substring(0, line.indexOf(' ')));
				q = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
				friends[p][q] = friends[q][p] = true;
			}
			count = 0;
			bfs(1, n);
			System.out.println(count);
		}
	}

	static void bfs(int s, int n) {
		queue.add(s);
		while (!queue.isEmpty()) {
			int f = queue.removeFirst();
			if (depth[f] < 2) {
				for (int ff = 1; ff < n + 1; ff++) {
					if (friends[f][ff]) {
						if (depth[ff] == 0) {
							count++;
							depth[ff] = depth[f] + 1;
							queue.add(ff);
							friends[f][ff] = friends[ff][f] = false;
						}
					}
				}
			}
		}
	}
}

Measured memory_bytes: 24928
#include<bits/stdc++.h>
#include <iostream>
#define mod 1000000007
using namespace std;
int row,col;

bool valid(int i, int j){
    if(i<0 || i>row || j<0 || j>col)
        return 0;
    return 1;
}

int dfs(int i, int j, vector<vector<int>>&dp, vector<vector<char>>&mat ){
    //cout<<i<<" "<<j<<"\n";
    if(!valid(i,j) || mat[i][j]=='#')
        return 0;

    if(i==row && j==col)
        return 1;
    
    if(dp[i][j]!=-1)
        return dp[i][j];
    else{
        long long int r,d;
        r = dfs(i, j+1, dp, mat)%mod;
        d = dfs(i+1, j, dp, mat)%mod;
        return (dp[i][j]=(d+r)%mod);
    }
}
int main() {
    int r,c;
    cin>>r>>c;
    row=r-1;
    col=c-1;
    vector<vector<int>>dp(r, vector<int>(c,-1));
    vector<vector<char>>mat(r, vector<char>(c,'.'));
    
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            cin>>mat[i][j];
        }
    }
    // for(auto i: dp){
    //     for(auto j: i)
    //         cout<<j<<" ";
    //     cout<<"\n";
    // }
    cout<<dfs(0, 0, dp, mat)%mod;
    return 0;
}


Measured memory_bytes: 5376
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
const int MAXN = 2e5 + 5;
using namespace std;

int n;
char s[MAXN];

int main(void)
{
	scanf("%s",s+1);
	n = strlen(s+1);
	
	int ans=1;
	bool last=0;
	for(int i=2; i<=n; ++i)
	{
		if(!last && s[i]==s[i-1]) ++i,last=1;
		else if(last) last=0;
		if(i>n) --ans;
		++ans;
	}
	
	int ans2=1;
	last=1;
	for(int i=3; i<=n; ++i)
	{
		if(!last && s[i]==s[i-1]) ++i,last=1;
		else if(last) last=0;
		if(i>n) --ans2;
		++ans2;
	}
	
	printf("%d",max(ans,ans2));
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int N,G[2],M,i,j,k,t,c,R=0;
int B[2][505][505]={0},p[1000005][2][2],C[2]={0},mx[4]={1,0,1,1},my[4]={0,1,1,-1};

int dfs(int P,int y,int x,int my,int mx)
{
	if(y<0||y>=N||x<0||x>=N||!B[P][y][x])return 0;
	return dfs(P,y+my,x+mx,my,mx)+1;
}

int main()
{
	memset(p,-1,sizeof(p));
	scanf("%d%d%d%d",&N,&G[0],&G[1],&M);
	for(c=0;c<2;c++)
		for(i=0;i<N;i++)
			for(j=0;j<N;j++)
			{
				scanf("%d",&t);
				p[t][c][0]=i;
				p[t][c][1]=j;
			}
	for(i=0;i<M;i++)
	{
		scanf("%d",&t);
		for(c=0;c<2;c++)
		{
			if(p[t][c][0]!=-1)
			{
				B[c][p[t][c][0]][p[t][c][1]]=1;
				if(N==1)C[c]++;
				else
					for(k=0;k<4;k++)
						if(dfs(c,p[t][c][0],p[t][c][1],my[k],mx[k])+dfs(c,p[t][c][0],p[t][c][1],-my[k],-mx[k])>N)
							C[c]++;
			}
			if(G[c]<=C[c])R+=c+1;
		}
		if(R)break;
	}
	puts(R==1?"USAGI":R==2?"NEKO":"DRAW");
	return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    bool can = false;
    for (int i = 0; i < B; i++) {
        if (A * (i + 1) % B == C) {
            can = true;
            break;
        }
    }

    if (can) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
///******* In the name of Allah *******///

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

//long int ar[10013];
//long int gcd(long int a, long int b)
//{
//    if(b==0)
//        return a;
//    return gcd(b,a%b);
//}
//long int sieve(long long int a)
//{
//    long long int i,j,k = 0;
//    memset(ar,0,sizeof(ar));
//    ar[1] = 1;
//    for(i=2; i<=713; i++)
//    {
//        if(ar[i]==0)
//        {
//            for(j=i+i; j<=713; j+=i)
//            {
//                ar[j] = 1;
//            }
//        }
//    }
//    return ar[a];
//}

void Ok()
{
    long int a,b,c,d[100013],e,f,g,h,t,i,j,k,l,m,n;
    long int ans_1,ans_2,ans_3,cnt_1,cnt_2,cnt_3,Max,Min,flag_1,flag_2,temp,sum;
    double aa,bb,cc,dd,ee,ff,gg;
    char aaa,bbb,ccc,ddd;
    string spc,in,store[13];

    memset(d,0,sizeof(d));
    sum = 0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a;
        d[a]++;
        sum += a;
    }
    cin>>m;
    for(i=1;i<=m;i++)
    {
        cin>>b>>c;
        ans_1 = (d[b] * b);
        sum -= ans_1;
        ans_2 = (d[b] * c);
        sum += ans_2;
        d[c] += d[b];
        d[b] = 0;
        cout<<sum<<endl;
    }

    return;
}

int main()
{
    Ok();

    return 0;
}


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

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

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin>>n;
	long long int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	long long int sum=0;
	for(int i=1;i<n;++i)
	{
		if(a[i]<a[i-1])
		{
			sum+=(a[i-1]-a[i]);
			a[i]=a[i-1];
		}
	}
	cout<<sum<<"\n";
}

Measured memory_bytes: 5200
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const double eps = 1e-9;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];

  ll sum_all = 0;
  ll x = 0;
  ll y = 0;
  rep(i,n) {
    sum_all += a[i];
  }

  ll ans = INFLL;
  rep(i,n-1) {
    x += a[i];
    y = sum_all - x;
    ans = min(ans, abs(x-y));
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792