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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

typedef long long ll;

int main(){
  int N, K;
  string s;
  cin >> N >> K;
  cin >> s;
  vector<int> cnt(1,0);
  int first = s[0] - '0';
  char pre = s[0];
  int idx = 0;
  REP(i, N){
    if(s[i] == pre){
      cnt[idx]++;
    }
    else{
      idx++;
      cnt.push_back(1);
      pre = s[i];
    }
  }
  vector<int> sum(idx+2);
  sum[0] = 0;
  int ans = 0;
  FOR(i,1, idx+2){
    sum[i] = sum[i-1] + cnt[i-1];
    ans = max(ans, cnt[i-1]);
  }
  if(first){
    for(int i=0; i+2*K-1 <= idx; i+=2){
      if(i+2*K <= idx){
        ans = max(ans, sum[i+K*2+1] - sum[i]);
      }
      else{
        ans = max(ans, sum[i+K*2] - sum[i]);
      }
    }
  }
  else{
    if(2*K <=idx)
      ans = max(ans, sum[2*K]);
    for(int i=1; i+2*K-1 <= idx; i+=2){
      if(i+2*K <= idx){
        ans = max(ans, sum[i+K*2+1] - sum[i]);
      }
      else{
        ans = max(ans, sum[i+K*2] - sum[i]);
      }
    }
  }
  if(2*K >= idx && first){
    ans = max(ans, sum[idx+1]);
  }
  else if( 2*K-1 >=idx&& !first)
    ans = max(ans, sum[idx+1]);
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
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; }
ll mod= 1e9 + 7;

vector<pair<ll,ll> > prime_factorize(ll N) {
    vector<pair<ll,ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
  ll n,p;
  cin >>n >>p;
  ll ans=1;
  vector<pair<ll,ll>> d=prime_factorize(p);
  while(!d.empty()){
    pair<ll,ll> g=d.back();
    d.pop_back();
    if(g.second>=n)ans*=pow(g.first,g.second/n);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4040
#include<bits/stdc++.h>
using namespace std;
double EPS=1e-9;
int a,b,c,d,e,f,g,h;
int calc(int n){
	int ret=n/(2*b)*2;
	n%=(2*b);
	if(n>=h)ret++;
	if(n>=2*b-h)ret++;
	return ret;
}
int main(){
	scanf("%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&g,&h);
	c*=d;
	long long ret=0LL;
	int now=g-e;
	int at=0;
	while(now<=c){
		int x=(int)(sqrt((double)c*c-(double)now*now+EPS)+EPS);
		int r=f+x;
		int l=f-x;
		r+=500000000/b*b*2;
		l+=500000000/b*b*2;
		ret+=calc(r)-calc(l-1);
		if(at%2==0){
			now+=(a-g)*2;
		}else{
			now+=g*2;
		}
		at++;
	}
	now=-e-g;
	at=0;
	while(now>=-c){
		int x=(int)(sqrt((double)c*c-(double)now*now+EPS)+EPS);
		int r=f+x;
		int l=f-x;	
		r+=500000000/b*b*2;
		l+=500000000/b*b*2;
		ret+=calc(r)-calc(l-1);
		if(at%2==0){
			now-=(a-g)*2;
		}else{
			now-=g*2;
		}
		at++;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  ll n,a,b; cin >> n >> a >> b;
  if((b-a)%2) cout << min(a-1,n-b) + 1 + (b-a-1)/2 << endl;
  else cout << (b-a)/2 << endl;
}

Measured memory_bytes: 256
nums = list(map(int, input().split()))
N, Q = nums[0], nums[1]
S = input()
ls = []
rs = []
for i in range(Q):
    nums = list(map(int, input().split()))
    ls.append(nums[0])
    rs.append(nums[1])

pattern = 'AC'

import re

results = re.finditer(pattern, S)
S_cum = [0 for _ in range(N)]
for r in results:
    S_cum[r.span()[1]-1] = S_cum[r.span()[0]] + 1
import numpy as np
S_cum = np.cumsum(S_cum)
for i in range(Q):
    print(S_cum[rs[i]-1] - S_cum[ls[i]-1])


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

int main() {
  
  int n, k, c, x(1);
  cin >> n >> k >> c;
  char arr[n];
  int fores[n] = {}, backs[n] = {};
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < n; ++i) {
    if (arr[i] == 'o') {
      //marks[i]++;
      fores[i] = x++;
      i += c;
    }
  }
  for (int i = n - 1; i >= 0; --i){
    if (arr[i] == 'o') {
      backs[i] = k--;
      i -= c;
    }
  }
  for (int i = 0; i < n; ++i) {
    if (fores[i] && fores[i] == backs[i]) cout << i + 1 << '\n';
  }
  return 0;
}

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

using namespace std;

int main(){
	int N; cin >> N;
	int p[N];
	for(int i = 0; i < N; ++i) cin >> p[i];
	sort(p, p + N);
	p[N - 1] /= 2;
	cout << accumulate(p, p + N, 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                //ios_base::sync_with_stdio(false);
                //cin.tie(NULL);
                lli t,n,i,j,b,a,q,m;
                long double nn;
                cin>>n;
                long double d=1.01;
                lli dd=100;
                rep(i,100000){
                    lli g=d*dd;
                    dd*=d;
                    //cout<<dd<<endl;
                    if(g>=n){
                        cout<<i+1<<endl;
                        return 0;
                    }
                }

            }



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

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(){
  string s,t;
  cin >> s >> t;
  cout << t+s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<Int> a(5);
	for (Int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	
	Int k;
	cin >> k;

	Int flag = 0;
	for (Int i = 0; i < 4; i++) {
		for (Int j = i+1; j < 5; j++) {
			if (abs(a[i] - a[j]) > k)flag = 1;
		}
	}

	if (flag)cout << ":(" << endl;
	else cout << "Yay!" << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const ld eps = 1e-18;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

int main() {
	int n;	cin >> n;
	vector<ll> a(n);
	rep(i, n) 	cin >> a[i];
	vector<ll> sum(n + 1, 0);
	rep(i, n)	sum[i + 1] = sum[i] + a[i];
	ll ret = inf;
	rep(i, n-1) {
		ret = min(ret, (ll)labs(sum[i + 1] - (sum[n] - sum[i + 1])));
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];
  int ans = 0;
  REP(i,n){
    if(a[i]==i+1){
      ans++;
      if(i<n-1) swap(a[i], a[i+1]);
      else swap(a[i], a[i-1]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array_pad(array(), 2, 0);

rsort($a);

for ($i = 0; $i < $N; $i++) {
    $sum[$i % 2] += $a[$i];
}

echo $sum[0] - $sum[1] . "\n";

Measured memory_bytes: 4856
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int keta(ll a) {
  int tmp = 11;
  int ans = 1;
  for(ll i=1e10;i>0;i/=10) {
    if(a/i>0) {
      ans = tmp;
      break;
    }
    tmp--;
  }
  return ans;
}

int main() {
  ll N;
  cin>>N;
  int ans = inf;
  int tmp = inf;
  for(ll i=1;i*i<=N;++i) {
    if(N%i==0) {
      if(tmp>keta(N/i)-keta(i)) {
        tmp = keta(N/i)-keta(i);
        ans = keta(N/i);
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int t;

	while (cin >> t, t) {
		int n;
		cin >> n;

		int s, f;
		int time = 0;
		for (int i = 0; i < n; i++) {
			cin >> s >> f;
			time += f - s;
		}
		if (time >= t) {
			cout << "OK" << endl;
		} else {
			cout << t -time << endl;
		}
	}
		return 0;
}

Measured memory_bytes: 3088
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main(){
  ll n,k; cin>>n>>k;
  priority_queue<ll> q;
  rep(i,n){
    ll p; cin>>p;
    if(q.size() < k) q.push(p);
    else if(q.size() == k){
      if(q.top() > p){
        q.pop();
        q.push(p);
      }
    }
  }
  ll sum=0;
  while(!q.empty()){
    sum+=q.top();
    q.pop();
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int K; 
  cin >> K;

  queue<int> q;
  q.push(1);
  q.push(2);
  q.push(3);
  q.push(4);
  q.push(5);
  q.push(6);
  q.push(7);
  q.push(8);
  q.push(9);

  int p;
  while(K--){
    p = q.front(); q.pop();
    if(p%10 != 0) q.push(p*10+p%10-1);
    q.push(p*10+p%10);
    if(p%10 != 9) q.push(p*10+p%10+1);
  }

  cout << p << "\n";

  return 0;
}

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

namespace Regular80
{
    public class GridColor
    {
        private int height;
        private int width;
        private int N;
        private int[] nums;
        private int[] sums;
        public GridColor(int height, int width, int N, int[] nums)
        {
            this.height = height;
            this.width = width;
            this.N = N;
            this.nums = nums;
            sums = new int[N];
            for (int i = 0; i < N; i++)
            {
                sums[i] = nums.Take(i+1).Sum();
            }
        }

        public void Run()
        {
            var colorArray = GetColorArray();
            Write(colorArray);

        }
        public int[,] GetColorArray()
        {
            var colorRec = new int[height, width];
            int indicator = 0;
            for (int i = 0; i < height; i++)
            {
                bool isEven = i % 2 == 0;
                int j = isEven ? 0 : width - 1;
                int inc = isEven ? 1 : -1;
                int jStop = isEven ? width : -1;
                while (j != jStop)
                {
                    colorRec[i, j] = Coloring(indicator);
                    indicator++;
                    j += inc;
                }
            }
            return colorRec;
        }
        public int Coloring(int indicator)
        {
            foreach(var n in sums)
            {
                if (indicator < n)
                    return Array.IndexOf(sums, n) + 1;
            }
            return 0;
        }

        public void Write(int[,] colorArray)
        {
            for(int i = 0; i< height; i++)
            {
                for(int j = 0; j< width; j++)
                {
                    if (j < width - 1)
                        Console.Write("{0} ", colorArray[i, j]);
                    else
                        Console.WriteLine("{0}", colorArray[i, j]);
                }
            }
        }

    }


    class Program
    {
        static void Main(string[] args)
        {
            var gridLength = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var height = gridLength[0];
            var width = gridLength[1];
            var N = int.Parse(Console.ReadLine());
            var nums = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            if (nums.Count() != N)
                throw new ArgumentException("");

            var gridColor = new GridColor(height, width, N, nums);
            gridColor.Run();
        }
    }
}


Measured memory_bytes: 13356
#include<cstdio>
#include<queue>
#include<vector>
#include<algorithm>
#define maxn 2005
using namespace std;
typedef pair<int,int> PII;
int n,a[maxn],ans[maxn],deg[maxn];
bool G1[maxn][maxn],vis[maxn];
vector<int> G[maxn];
priority_queue<PII> q;
int gcd(int a,int b)
{
	if(!b) return a;
	return gcd(b,a%b);
}
void dfs(int u,int fa)
{
	vis[u]=true;
	for(int v=1;v<=n;v++)
		if(G1[u][v]&&!vis[v])
		{
			G[u].push_back(v); deg[v]++;
			dfs(v,u);
		}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(gcd(a[i],a[j])!=1) G1[i][j]=G1[j][i]=true;
	for(int i=1;i<=n;i++)
		if(!vis[i]) dfs(i,0);
	for(int i=1;i<=n;i++)
		if(!deg[i]) q.push(PII(a[i],i));
	int cnt=0;
	while(!q.empty())
	{
		PII u=q.top(); q.pop();
		ans[++cnt]=u.first;
		for(int i=0,siz=G[u.second].size();i<siz;i++)
		{
			int v=G[u.second][i]; deg[v]--;
			if(!deg[v]) q.push(PII(a[v],v));
		}
	}
	for(int i=1;i<cnt;i++) printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
}


Measured memory_bytes: 4480
//98tarunkumar

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

#define ll long long
#define pb push_back
#define lop(i,n) for(int i=0;i<n;i++)
#define rlop(i,n) for(int i=n;i>0;i--)
#define lli long long int
#define MOD 1000000007
#define f(i,a,b) for(i=a;i<b;i++)
#define ainp(a,n) for(int i=0;i<n;i++)cin>>a[i];
#define aout(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
#define ss ios::sync_with_stdio(false); cin.tie(NULL);
#define vi vector<int> 
#define ln cout<<"\n"


int main(){
	ss;
	/*#ifndef ONLINE_JUDGE
	freopen("cf_inp.txt","r",stdin);
	freopen("cf_oup.txt","w",stdout);
	#endif*/
	string s1,s2;
	cin>>s1>>s2;
	int n1=s1.size();
	int n2=s2.size();
	int dp[n2+1][n1+1];
	

	for(int i=0;i<=n2;i++){
		for(int j=0;j<=n1;j++){
			if(i==0||j==0)
				dp[i][j]=0;
			else if(s2[i-1]==s1[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else
				dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
		}
	}

	// to print lcs
	int index=dp[n2][n1];
	char lcs[index+1];
	lcs[index]='\0';

	int i=n2,j=n1;
	while(i>0&&j>0){
		if(s2[i-1]==s1[j-1]){
			lcs[index-1]=s2[i-1];
			i--;j--;index--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	cout<<lcs;


	/*
	for(int i=0;i<=n1;i++){
		dp[0][i]=0;
	}
	for(int i=0;i<=n2;i++){
		dp[i][0]=0;
	}
	for(int i=1;i<=n2;i++){
		for(int j=1;j<=n1;j++){
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	for(int i=0;i<=n2;i++){
		for(int j=0;j<=n1;j++){
			cout<<dp[i][j];
		}cout<<"\n";
	}*/
}


Measured memory_bytes: 35456
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[0]==s[2])
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
int a[4][3][10] = {0};
int main(){ //srand((unsigned)time(NULL));
  ll n;cin >> n;
  for (int i = 0; i < n; i++) {
    int b=0,f=0,r=0,v=0;
    cin >> b >> f >> r >> v;
    a[b-1][f-1][r-1] += v;
  }
  for (int b = 0; b < 4; b++) {
    for (int f = 0; f < 3; f++) {
      for (int r = 0; r < 10; r++) {
        cout << " " << a[b][f][r];
      }
      cout << endl;
    }
    if(b != 3){
      cout << "####################" << endl;
    }
  }
}



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

struct Paint {
    int i, d;
    Paint(int i, int d) : i(i), d(d) {}
};

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

    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N+1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> num(N+1, -1);
    vector<int> color(Q);
    vector<vector<Paint>> paint(N+1);
    vector<vector<Paint>> npaint(N+1);
    vector<unordered_set<int>> used(N+1);

    for (int i = 0; i < Q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        color[i] = c;
        paint[v].emplace_back(i, d);
    }

    for (int j = 0; j <= 10; j++) {
        for (int v = 1; v <= N; v++) npaint[v].clear();

        for (int v = 1; v <= N; v++) {
            if (paint[v].size() == 0) continue;

            sort(paint[v].begin(), paint[v].end(), [&](auto& p1, auto& p2) {
                return p1.i > p2.i;
            });

            vector<Paint> pv;
            for (auto& p : paint[v]) {
                if (used[v].count(p.i) > 0) continue;
                if (pv.size() == 0 || pv.back().d < p.d) {
                    pv.push_back(p);
                    used[v].insert(p.i);
                }
            }

            if (pv.size() == 0) continue;

            num[v] = max(num[v], pv[0].i);

            for (int u : G[v]) {
                for (auto& p : pv) {
                    if (p.d > 0) {
                        npaint[u].emplace_back(p.i, p.d - 1);
                    }
                }
            }
        }
        paint = npaint;
    }
    for (int v = 1; v <= N; v++) {
        if (num[v] == -1) cout << 0 << '\n';
        else cout << color[num[v]] << '\n';
    }
}

Measured memory_bytes: 84108
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main(){
  int n;
  cin >> n;
  mint ans = 1;
  vector<int> c(3, 0);
  rep(i, n){
    int in;
    cin >> in;
    int co = 0, index = -1;
    rep(j, 3){
      if(c.at(j) == in){
        if(index == -1) index = j;
        co++;
      }
    }
    if(index == -1){
      cout << 0 << endl;
      return 0;
    }
    ans *= co;
    c.at(index)++;
  }
  cout << ans.x << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string a;
	cin>>a;
	if(a=="abc"||a=="acb"||a=="bac"||a=="bca"||a=="cab"||a=="cba"){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define cu continue
#define br break
#define pb push_back
#define mod 1000000007
#define inf LLONG_MAX
#define pll pair <ll,ll>
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 
#define F first
#define S second
#define vll vector <ll>
#define dbg(n) cout<<#n<<' '<<n<<endl;

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


    cout<<fixed<<setprecision(20);
    ll r;
    cin>>r;
    double pi=3.14159265358979323846;
    cout<<2*pi*r<<'\n';
}      

Measured memory_bytes: 3820
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse = True)
q = sorted(list(map(int, input().split())), reverse = True)
r = sorted(list(map(int, input().split())), reverse = True)
S = sorted(p[:X] + q[:Y] + r[:X+Y], reverse = True)
print(sum(S[:X+Y]))

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

int N,K,i;
string a;


int main(){
    cin>>N>>K;
    for(i=1;i<=K+2;i++){
        cout<<"#";
    }
    cout<<endl;
    for(i=1;i<=N;i++){
        cin>>a;
        cout<<"#"<<a<<"#"<<endl;
    }
    for(i=1;i<=K+2;i++){
        cout<<"#";
    }
}

Measured memory_bytes: 3616
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		String[] a;
		int x,y;
		while(true){
			a=br.readLine().split(" ");
	        x=Integer.parseInt(a[0]);
	        y=Integer.parseInt(a[1]);
	        if(x==0&&y==0){
	        	break;
	        }else if(x>y){
	        	sb.append(y+" "+x+"\n");
	        }else{
	        	sb.append(x+" "+y+"\n");
	        }
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 25044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b)cout<<c<<endl;
	else if(b==c)cout<<a<<endl;
	else cout<<b<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int  a, b, c, d;
    cin >> a >>b >> c >> d;
    if(abs(c-a)<=d) cout << "Yes" <<endl;
    else if(abs(b-a)<=d && abs(c-b)<=d) cout <<"Yes" <<endl;
    else cout <<"No" <<endl;
    return 0;
}

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

int main() {
    int a , b , ma , mi;
    cin >> a >> b;
    ma = max(a , b);
    mi = min(a , b);
    for (int i = 0; i < ma; i++) {
        cout << mi;
    }
    cout << endl;
    
}

Measured memory_bytes: 256
/* author   : mpily :-()
    title : Competing.cpp
    time :Sat Oct 19 15:35:41 2019
     
    */
    #include<bits/stdc++.h>
    using namespace std;
   // int dp[1003];
    int dp[2003][1003];
    int main(){
    	int N;
    	cin>>N;
    	vector<int>arr(N);
    	for(int i = 0; i < N; i++){
    		cin>>arr[i];
    	}
    	sort(arr.begin(),arr.end());
    	long long fans = 0;
	for(int i = 0; i < 1003;i++)dp[0][i] = 0;
	for(int i = 1; i <= N; i++){			
		for(int j = 0; j < 1003; j++){
			dp[i][j] = dp[i-1][j];
			if(arr[i-1] < j)dp[i][j]+=1;
		}
	}

	for(int i = 0; i < N; i++){
		for(int j = i+1; j < N; j++){
			int ulim = min(1002,arr[i]+arr[j]);
			fans+=max(0,dp[N][ulim] - dp[j][ulim]);
			if(arr[j] < ulim)fans-=1;
		}
	}
	cout<<fans<<"\n";
	/*long long anans = 0;
	for(int i = 0; i < N; i++){
		for(int j = i+1; j < N; j++){
			for(int k = j+1; k < N; k++){
				if(arr[k] < (arr[i]+arr[j]))anans+=1;	
			}
		}
	}
	cout<<anans<<"\n";*/
    	return 0;
    }


Measured memory_bytes: 8192
#include <stdio.h>

#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MIN(X,Y) ((X)<(Y)?(X):(Y))

int main(void){
    int n;
    char s[100001];
    int animals[100001];
    
    scanf("%d %s", &n, s);
    for (int initial = 0; initial <= 3; initial++){
        animals[0] = initial & 1; // sheep:0, wolf:1
        animals[1] = initial >> 1;
        for (int i=2; i<n; i++){
            animals[i] = animals[i-2] ^ (s[i-1]=='x');
            if (animals[i-1] == 1){
                animals[i] = 1-animals[i];
            }
        }
        if (animals[n-2] ^ animals[n-1] ^ (s[n-1]=='x') == animals[0] &&
            animals[n-1] ^ animals[0] ^ (s[0] == 'x') == animals[1]){
//        if (1){
            for (int i=0; i<n; i++){
                putchar("SW"[animals[i]]);
            }
            puts("");
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Measured memory_bytes: 768
from collections import defaultdict

def main():
    H, W = map(int, input().split())
    A = list(list(input()) for _ in range(H) )
    d = defaultdict(int)
    for h in range(H):
        for w in range(W):
            d[A[h][w]] += 1

    odd = 0
    even = 0
    if H % 2 and W % 2:
        odd += 1
    if H % 2:
        even += W // 2
    if W % 2:
        even += H // 2

    for key, value in d.items():
        value %= 4
        if value % 2:
            odd -= 1
            value -= 1
        if value == 2:
            even -= 1
        if even < 0 or odd < 0:
            break

    if even < 0 or odd < 0:
        print('No')
    else:
        print('Yes')
        


if __name__ == "__main__":
    main()

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int D, T, S;
  cin >> D >> T >> S;
  if(D <= T*S){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

int main(){
    int a,d,n;
    vector<int> isp(1e6+1,1);
    isp[0]=0;
    isp[1]=0;
    for(int i=2;i<1e6+1;i++)
        if(isp[i]){
            for(int j=i*2;j<1e6+1;j+=i)
                isp[j]=0;

        }
    while(cin>>a>>d>>n,a&&d&&n){
        int cnt=0;
        int res;
        for(int i=0;i<1e6+1;i++){
            if(isp[a+i*d])
                cnt++;
            if(cnt==n){
                res=i;
                break;
            }

        }
        cout<<a+res*d<<endl;

    }
    return 0;
}

Measured memory_bytes: 6588
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 20;
typedef long long ll;

const int MOD = 1e9 + 7;

ll ksm(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) {
            ret = ret * a % MOD;
        }
        b /= 2;
        a = a * a % MOD;
    }
    return ret;
}
ll fac[MAXN], inv[MAXN];
int C(int n, int m) {
    return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
void init() {
    fac[0] = inv[0] = inv[1] = 1;
    for (int i = 1; i < MAXN; i++)
        fac[i] = 1ll * fac[i - 1] * i % MOD;
    for (int i = 2; i < MAXN; i++)
        inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
    for (int i = 1; i < MAXN; i++)
        inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
}
int main() {
    init();
    ll n;
    cin >> n;
    ll all = ksm(10, n);
    all -= ksm(8, n);
    all += MOD;
    all %= MOD;
    ll r = 0;
    for (int i = 1; i <= n; i++) {
        r += C(n, i) * ksm(8, n - i) % MOD;
        r %= MOD;
    }
    r *= 2;
    r %= MOD;
    all -= r;
    all += MOD;
    all %= MOD;
    cout << all << endl;
}



Measured memory_bytes: 19244
#include<bits/stdc++.h>
using namespace std;
 
int n;
long long arr[405],dp[405][405],cost[405][405],pre[405];
 
int main(){
	memset(cost,0,sizeof(cost));
	scanf("%d",&n);
	for (int i = 0;i<n;i++){
		scanf("%lld",&arr[i]);
		if(i==0){
			pre[i] = arr[i];
		} else{
			pre[i] = pre[i-1]+arr[i];
		}
		dp[i][i] = 0;
	}
	long long ans = 0;
	for (int iter  =n-1; iter>=1;iter--){
		for (int i= 0;i<iter;i++){
				int ii = i;
				int jj = n-iter+i;
				long long ret = 1000000000000000;
				for(int k =ii;k<jj;k++){
					long long tmp1 = pre[k]-(ii==0?0:pre[ii-1]);
					long long tmp2 = pre[jj]-(k+1==0?0:pre[k+1-1]);
					ret = min(ret,dp[ii][k]+dp[k+1][jj]+tmp1+tmp2);
				}
				dp[ii][jj] = ret;
		}
	}
	printf("%lld\n",dp[0][n-1]);
	return 0;
}

Measured memory_bytes: 2816
a, b, c = sorted(map(int, input().split()))

# 2 5 7
# 4 7 7    + c-b
# 6 7 7    + (b-a)//2
# 8 7 7
# 8 8 8    + 2
print((c - b) + ((b - a) // 2) + (2 if (b - a) % 2 else 0))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define INF (1e18+1)
#define LL long long
#define rep(i, c) for(int i=0;i<(int)(c);i++)
//ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;

int main()
{

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];

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

    int ans = 1001001001;
    for(int i = 0; i+k-1 < n; i++){
        if(h[i+k-1]-h[i] < ans) ans = h[i+k-1]-h[i];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3740
import sys
input = lambda: sys.stdin.readline().rstrip()

X, Y = map(int, input().split())

upto = 4 * X

if upto == Y:
    print("Yes")
    exit()
while X:
    upto -= 2
    if Y == upto:
        print("Yes")
        exit()
    X -= 1
print("No") 

Measured memory_bytes: 61908
def agc_030_a
    a,b,c = gets.chomp.split(/\s/).map{|x| x.to_i}

    t = 0

    if b >= c
        b -= c
        t += c * 2
        c = 0
    else
        c -= b
        t += b * 2
        b = 0
    end

    if c > 0
        if a >= c
            a -= c
            t += c
            c = 0
        else
            c -= a
            t += a
            a = 0
        end
    end

    if a > 0 && b > 0
        if a >= b
            a -= b
            t += b
            b = 0
        else
            b -= a
            t += a
            a = 0
        end
    end

    t += 1 if c > 0

    puts t
end

agc_030_a

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

int main(){
    string O, E;
    cin >> O;
    cin >> E;
    string ret = "";
    for(int i = 0; i < E.length(); i++){
        ret += O[i];
        ret += E[i];
    }
    if(O.length() != E.length()){
        ret += O.back();
    }
    cout << ret << endl;
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;


int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  REP(i, N){
    cin >> S[i];
  }
  map<string, int> mp;
  REP(i, N){
    mp[S[i]]++;
  }
  cout << mp.size() << endl;
  return 0;
}


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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

template<typename T>
struct Prefix {
    int n;
    vector<T> A;
    template<typename ParameterType>
    void buildup(vector<ParameterType>& B) {
        n = B.size();
        A.resize(n);
        for (int i = 0; i < n; i++)
            A[i] = B[i];
        for (int i = 1; i < n; i++)
            A[i] += A[i-1];
    }
    T query_sum_value(int x, int y) {
        T ans = A[y];
        if (x)
            ans -= A[x - 1];
        return ans;
    }
    vector<T> unwind() {
        vector<T> ans(n);
        for (int i = 0; i < n; i++)
            ans[i] = query_sum_value(i, i);
        return ans;
    }
};

Prefix<int> prefix;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    vector<int> A;
    cin >> n;
    A.resize(n);
    for (int i = 0; i < n; i++)
        cin >> A[i];
    prefix.buildup(A);
    int min_val = 1e9;
    for (int i = 0; i < n - 1; i++) {
        int left = prefix.query_sum_value(0, i);
        int right = prefix.query_sum_value(i + 1, n - 1);
        int val = abs(left - right);
        min_val = min(min_val, val);
    }
    cout << min_val << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <string>
typedef long long ll;

using namespace std;

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

    int x = 0;
    int res = 0;
    for (int i = 0; i < s.size(); i++){
	if (s[i] == 'I') x++;
	else if (s[i] == 'D') x--;

	res = max(res, x);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
dp = 1
for i in range(0, len(a)):
	dp = (dp | (dp << a[i]))

asum = 0
for i in range(0, len(a)):
	asum += a[i]

for i in range(int((asum + 1) / 2), asum + 1):
	if (dp >> i) & 1:
		print(i)
		break

Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const long double eps = 1e-12;
const int MAXN = 2e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;

bool vis[30];

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    char s[30];
    scanf("%s",s);
    mst(vis,false);
    int len = strlen(s);
    for(int i=0; i<len; i++) vis[s[i]-'a'] = true;
    if(len < 26) {
        printf("%s",s);
        for(int i=0; i<26; i++) {
            if(!vis[i]) {
                printf("%c\n",'a'+i);
                return 0;
            }
        }
    }
    for(int i=25; i>=0; i--) {
        vis[s[i]-'a'] = false;
        for(int j=0; j<26; j++) {
            if(!vis[j] && j > (s[i]-'a')) {
                s[i] = 'a' + j;
                s[i+1] = '\0';
                printf("%s\n",s);
                return 0;
            }
        }
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
class Program
{
 
  static void Main(string[] args)
  {
    var input = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
    
    long a = input[0];
    long b = input[1];
    long c = input[2];
    
    if (c-a-b <= 0)
    {
      Console.WriteLine("No");
      return;
    }
    
    long value = (a-b)*(a-b)-a*a + (b-c)*(b-c)-b*b+(c-a)*(c-a)-c*c;
    
    if (value > 0)
      Console.WriteLine("Yes");
    else
      Console.WriteLine("No");
  }
}

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

int main() {
	int n,k;
	cin >> n >> k;
	cout << n-k+1 << endl;
	return 0;
}


Measured memory_bytes: 256
//
// Created by file on 18/07/01.
//

#include <bits/stdc++.h>

using namespace std;

int main() {

    int a = 0, b = 0, judge = 0;
    float average = 0.0;

    cin >> a >> b;


    average = static_cast<float >(a + b) / 2;
    judge = average;
    if (average > judge) {
        judge++;
    }

    cout << judge << endl;

}

Measured memory_bytes: 256
#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(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    int n,q;
    int maxc = 0;
    cin >> n >> q;
    vector<int> c(n);
    REP(i,n) {
	cin >> c[i];
	maxc = max(c[i],maxc);
    }
    sort(ALL(c));
    REP(i,q){
	int m;
	int ans = 0;
	int j = 1;
	cin >> m;
	while(m*(j-1) <= maxc){
	    int l = lower_bound(ALL(c),m*j) - c.begin();
	    if(l > 0 ) ans = max(ans,c[l-1]%m);
	    ans = max(ans,c[l]%m);
	    if(l == n) ans = max(ans,c[l+1]%m);
	    j++;
	}
	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2324
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
int main(){
    int x,n;
    cin>>n;
    x=(n*100)/108+1;
    while((x*108)/100<=n) x++;
    if(((x-1)*108)/100==n) cout<<x-1<<endl;
    else cout<<":("<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=55,M=10010,del=5000;
int n,k,a[N];
ll dp[N][M],ans,tot[M];
inline int read(){
	int x=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f?-x:x;
}
int main(){
	n=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read()-k;
	//for(int i=1;i<=n;i++)printf("%d ",a[i]);
	memset(tot,0,sizeof tot);
	tot[del+a[1]]=dp[1][del+a[1]]=1;
	for(int i=2;i<=n;i++){
		for(int j=a[i];j<=10000;j++){
			dp[i][j]=tot[j-a[i]];
			//if(dp[i][j])printf("%d %d %lld\n",i,j,dp[i][j]);
		}
		dp[i][a[i]+del]+=1;
		for(int j=0;j<=10000;j++)tot[j]+=dp[i][j];
	}
	ans=0;
	for(int i=1;i<=n;i++)ans+=dp[i][del];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <stdio.h>

int main(void) {
	int A, B;
	if (scanf("%d%d", &A, &B) != 2) return 1;
	printf("%d\n", 1 <= A && A <= 9 && 1 <= B && B <= 9 ? A * B : -1);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B < C + D)
    cout << "Right" << endl;
  else if(A + B > C + D)
    cout << "Left" << endl;
  else 
    cout << "Balanced" << endl;
}

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

const int N = 1e5 + 5;
typedef long long LL;

int n, cnt[N], q;
LL ans;

int main() {
	cin>>n;
	for(int i = 1; i <= n; i++) {
		int x;
		cin>>x;
		cnt[x]++;
		ans += x;
	}
	cin>>q;
	for(int i = 1; i <= q; i++) {
		int x, y;
		cin>>x>>y;
		ans += (y - x)*cnt[x]; 
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3924
#include<iostream>
#include<cstdio>
int main(){
	long long s,c,ans=0;
	scanf("%lld%lld",&s,&c);
	long long cc=c/2;
	if(cc>s){
		ans+=s;
		c-=s*2;
	}
	else{
		ans+=cc;
		s-=cc;
		c-=cc*2;
	}
	ans+=c/4;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


S = input()
if len(S) % 2 != 0:
    print('No')
    exit(0)
for i, c in enumerate(S):
    if i % 2 == 0 and c != 'h':
        print('No')
        exit(0)
    if i % 2 != 0 and c != 'i':
        print('No')
        exit(0)
print('Yes')

Measured memory_bytes: 38256