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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

struct town{
    ll x,y,id;
};

struct edge{
    ll u, v, cost;
};

bool comp_c(const edge& e1, const edge& e2){
    return e1.cost < e2.cost;
}
bool comp_x(const town& t1, const town& t2){
    return t1.x < t2.x;
}
bool comp_y(const town& t1, const town& t2){
    return t1.y < t2.y;
}

edge es[200001];
town towns[100001];
int par[100001];
int ran[100001];

void init_union_find(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        ran[i] = 0;
    }
}
int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)  return;
    if(ran[x] < ran[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ran[x] == ran[y])    ran[x]++;
    }
}
bool same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> towns[i].x >> towns[i].y;
        towns[i].id = i;
    }

    sort(towns, towns+n, comp_x);
    for(int i = 1; i < n; i++){
        es[i-1].cost = towns[i].x-towns[i-1].x;
        es[i-1].u = towns[i].id;
        es[i-1].v = towns[i-1].id;
    }
    
    sort(towns, towns+n, comp_y);
    for(int i = 1; i < n; i++){
        es[i+n-2].cost = towns[i].y-towns[i-1].y;
        es[i+n-2].u = towns[i].id;
        es[i+n-2].v = towns[i-1].id;
    }


    sort(es, es+2*n-2, comp_c);
    init_union_find(n);
    int res = 0;
    for(int i = 0; i < 2*n-2; i++){
        edge e = es[i];
        if(!same(e.u, e.v)){
            unite(e.u, e.v);
            res += e.cost;
        }
    }
    cout << res << endl;

    
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    if(n % k == 0){
        cout << 0 << endl;
        return 0;
    }
    int ans = n % k == 0 ? 0: 1;
    cout << ans << endl;
    return 0;
}

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

#define INF 0x7fffffffffff
typedef long long int LLI;

int N;
int M;
LLI ts[1145];
LLI ss[1145];
LLI vs[3145];
LLI hs[3145];
LLI dp[1145][3145];

int main() {
  scanf("%d%d", &N, &M);

  for (int i=1; i<=N; i++) {
    scanf("%lld%lld", &vs[i], &hs[i]);
  }

  for (int i=1; i<=M; i++) {
    scanf("%lld%lld", &ts[i], &ss[i]);
  }

  for (int i=0; i<=M; i++) {
    for (int j=0; j<=N; j++) {
      dp[i][j] = -INF;
    }
  }
  
  dp[0][0] = 0;
  for (int i=1; i<=M; i++) {
    LLI accv = 0;
    for (int j=0; j<=N; j++) {
      accv += vs[j];
      if (accv > ts[i]) break;
      if (j >= 1) dp[i][j] = max(dp[i][j], dp[i-1][j-1]);
      if (j >= 2) dp[i][j] = max(dp[i][j], dp[i][j-1] + llabs(hs[j-1]-hs[j]));
    }

    LLI acch = 0;
    for (int j=0; j<=N; j++) {
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
      acch += hs[j];
      if (acch+dp[i][j] < ss[i]) dp[i][j] = -INF; 
    }
  }

  for (int i=0; i<=N; i++) {
    if (dp[M][i] >= 0) {
      LLI ans = ts[M];
      for (int j=1; j<=i; j++) ans -= vs[j];
      assert (ans >= 0);
      printf("%lld\n", ans);
      return 0;
    }
  }

  puts("-1");
}

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = INT_MAX / 2;

bool check(string s, vector<char> &ds) {
	rep (i, s.size()) {
		rep (j, ds.size()) {
			if (ds[j] == s[i]) {
				return false;
			}
		}
	}
	return true;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	vector<char> ds(k);
	rep (i, k) {
		char d;
		cin >> d;
		ds.pb(d);
	}
	int ans;
	REP (i, n, 100000) {
		stringstream ss;
		ss << i;
		if (check(ss.str(), ds)) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())
okashi_set = set([])
for i in range(K):
    d_i = int(input())
    A_d = list(map(int, input().split()))
    for A_d_j in A_d:
        okashi_set.add(A_d_j)
print(N-len(okashi_set))

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

int main() {
  int N;
  cin >> N;
  vector<long> masu(N);
  for (int i = 0; i < masu.size(); i++) {
    cin >> masu[i];
  }
  if(masu.size() == 1){
    cout << "Yes" << endl;
    return 0;
  }

  long max = 0L;
  for (int i = 0; i < masu.size(); i++) {
    if(max < masu[i]){
      max = masu[i];
    }else if(max - masu[i] > 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 1024
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int main(){
  string trg="CODEFESTIVAL2016";
  string s;cin>>s;
  int res=0;
  REP(i,s.size()) if(s[i]!=trg[i]) ++res;
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	const int num[4] = {1,9,7,4};

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	vector<int> N(4, 0);
	rep (i, 4){
		cin >> N[i];
	} // end rep
	
	sort(ALL(N));
	bool res = false;

	do{
		bool ok = true;
		rep (i, 4){
			ok &= (num[i] == N[i]);
		} // end rep
		if (ok){
			res = true;
			break;
		} // end if
	}while(next_permutation(ALL(N)));

	cout << (res ? "YES" : "NO") << endl;

	return 0;
}

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

int main(){
  int N;
  string W;
  vector<string> v;
  cin >> N;
  cin >> W;
  v.push_back(W);
  for(int i=1; i<N; i++){
    cin >> W;
    if(v[i-1][v[i-1].size()-1]!=W[0] || find(v.begin(), v.end(), W)!=v.end()){
      cout << "No" << endl;
      return 0;
    }
    v.push_back(W);
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
    [sa, sb] <- words <$> getLine
    let a = read sa :: Int
        b = read sb :: Double
        b' = round (b * 100) :: Int
        ans = a * b' `div` 100
    print ans



Measured memory_bytes: 4088
def solve(n, a):
    D = [{0: 0}, {0:0}]
    for i in range(n):
        if not a[i] in D[i%2]:
            D[i%2][a[i]] = 0
        D[i%2][a[i]] += 1
    e = sorted(D[0].items(), key=lambda _:-_[1])
    o = sorted(D[1].items(), key=lambda _:-_[1])
    k_e0, v_e0 = e[0]
    k_o0, v_o0 = o[0]
    if k_e0 != k_o0:
        return n - v_e0 - v_o0
    else:
        _, v_e1 = e[1]
        _, v_o1 = o[1]
        return min(n - v_e0 - v_o1, n - v_e1 - v_o0)

assert solve(4, [3,1,3,2]) == 1
assert solve(6, [105,119,105,119,105,119]) == 0
assert solve(4, [1,1,1,1]) == 2
n = input()
a = map(int, raw_input().split())
print solve(n, a)



Measured memory_bytes: 24204
#include<bits/stdc++.h>
using namespace std;
int dfs(vector<int> adj[],int x,int *dp)
{
    //cout<<x<<" "<<dp[x]<<endl;
    if(dp[x]!=-1)return dp[x];
    if(adj[x].size()==0){
        dp[x] = 0;
        return dp[x];
    }

    for(int i=0;i<adj[x].size();i++)
    {
        dp[x] = max(dp[x],1+dfs(adj,adj[x][i],dp));
    }
    return dp[x];
}

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

    vector<int> adj[n+1];
    //Taking graph as input
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        adj[x].push_back(y);
    }

    int ans=0;
    int dp[n+1];
    memset(dp,-1,sizeof(dp));

    //Calling dfs for every vertex
    for(int i=1;i<=n;i++)
    {
        ans = max(ans,dfs(adj,i,dp));
    }
    cout<<ans;
}


Measured memory_bytes: 8192
C0 = map(int, input().split())
C0 = list(C0)

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

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


if (C0[0] - C0[1] == C1[0]-C1[1] == C2[0]-C2[1] and C0[0] - C0[2] == C1[0]-C1[2] == C2[0]-C2[2] and C0[0] - C1[0] == C0[1] - C1[1] == C0[2] - C1[2] and C0[0] - C2[0] == C0[1] - C2[1] == C0[2] - C2[2] ):

    print("Yes")
else:
    print("No")
 


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


int main() {
  ll n; cin>>n;
  string s="abcdefghijklmnopqrstuvwxyz";
  ll c=1;
  while(true){
    ll x=pow(26,c);
    if(n>x){n-=x;c++;}
    else{break;}
  }
  n--;
  rep(i,c){
    ll p=pow(26,c-i-1);
    ll r=n/p;
    n-=r*p;
    cout<<s.at(r);
  }
}
   

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

#define ll long long
#define ld long double
#define db double
#define str string
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define rall(v) rbegin(v),rend(v)
#define selp(a) for(auto i:a)cout<<i<<" ";cout<<nl;
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)
//ll MLG(ll n,ll b){ll a=0;while(n)a++,n/=b;return a-1;}

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const db pi=2*acos(0.0);

int main(){
    nimble
    int n;
    cin>>n;
    ll s=0;
    for(int i=1;i<=n;i++){
    if(i%3==0&&i%5==0){
        continue;
    }
    if(i%3==0)continue;
    if(i%5==0)continue;
    s+=i;
    }cout<<s;
    return 0;
}


Measured memory_bytes: 3652
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S, T;
	std::cin >> S >> T;
	int result = 0;
	for (int i = 0; i < 3; ++i)
		if (S[i] == T[i])
			++result;
	std::cout << result << "\n";
}


Measured memory_bytes: 512
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

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

  int sl = s.length();

  for (int i = 0; i < sl; ++i) {
    if (i+5 <= sl && s.substr(i, 5) == "dream") {

      if (i+5 == sl) i += 4;

      if (i+5 < sl && s[i+5] != 'e') {
        i += 4;
      } else if (i+5 < sl && s[i+5] == 'e') {
        if (i+8 <= sl && s.substr(i, 8) == "dreamera") {
          i += 4;
        } else if (i+7 <= sl && s.substr(i, 7) == "dreamer") {
          i += 6;
        } else {
          i += 4;
        }
      }

    } else if (i+5 <= sl && s.substr(i,5) == "erase") {

      if (i+5 == sl) i += 4;

      if (i+6 <= sl && s.substr(i, 6) == "eraser") {
        i += 5;
      } else {
        i += 4;
      }


    } else {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 512
def main():
    while True:
        S = input()
        if S == "-":
            break

        n_shuffle = int(input())
        hs = [int(input()) for _ in range(n_shuffle)]

        for h in hs:
            S = S[h:] + S[:h]

        print(S)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
#include <utility>
using namespace std;
typedef long long int lli;
lli mod = 1e9 +7;

lli dp[51][51][51][51];
bool used[51][51][51][51] = {};
lli solve(int a, int b, int c, int d, vector<int> &num){
	lli &ret = dp[a][b][c][d];
	if(used[a][b][c][d]) return ret;
	used[a][b][c][d] = true;
	if(a==0 && b==0 && c==0 && d==0){
		ret = 1;
		return ret;
	}
	ret = 0;
	int idx = a+b+c+d-1;
	if((num[idx] & 1) && a > 0) ret += solve(a-1, b, c, d, num);
	if((num[idx] & 2) && b > 0) ret += solve(a, b-1, c, d, num);
	if((num[idx] & 4) && c > 0) ret += solve(a, b, c-1, d, num);
	if((num[idx] & 8) && d > 0) ret += solve(a, b, c, d-1, num);
	ret %= mod;
	return ret;
}

int main(){
	int na,nt,ng,nc;
	cin >> na >> nt >> ng >> nc;
	int m;
	cin >> m;
	//入力をparse
	map<string, int> snum;
	int allchar = 0;
	cin.ignore();
	for(int i=0; i<m; i++){
		string buf;
		getline(cin, buf);
		stringstream ss(buf);
		string name;
		ss >> name;
		name.pop_back();
		int times = 1;
		if(i!=0){
			times = snum[name];
			allchar -= times;
		}
		while(ss >> name){
			snum[name] += times;
			allchar += times;
		}
		//長くなりすぎたら止める
		if(allchar > na+nt+ng+nc) break;
	}
	if(allchar != na+nt+ng+nc){
		cout << 0 << endl;
		return 0;
	}
	//ATGCのbit表現
	vector<int> num;
	for(auto p: snum){
		int comb=0;
		for(int i=1; i<(int)p.first.length()-1; i++){
			switch(p.first[i]){
				case 'A': comb |= 1; break;
				case 'T': comb |= 2; break;
				case 'G': comb |= 4; break;
				case 'C': comb |= 8; break;
			}
		}
		for(int i=0; i<p.second; i++){
			num.push_back(comb);
		}
	}
	cout << solve(na, nt, ng, nc, num) << endl;
	return 0;
}


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

int main () {
  int K,T;
  cin >> K >> T;
  
  if (T == 1){
    cout << K-1 << endl;
    return 0;
  }
  
  vector<int>a(T);
  for (int i = 0; i < T; i++) {
    cin >> a.at(i);
  }
  
  sort(a.begin(), a.end()); 
  int A = a.at(T-1);
  int half = (K+1)/2;
  
  if (T != 1){
    if (A <= half){
      cout << 0 << endl;
      return 0;
    }
    else {
      cout << a.at(T-1)-(K-a.at(T-1))-1 << endl;
      return 0;
    }
  }
}
  
  

  
  
  
 
  
  

Measured memory_bytes: 3632
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
#ifdef DEBUG
     #define debug(args...)            {dbg,args; cerr<<endl;}
#else
    #define debug(args...)              // Just strip off all debug tokens
#endif

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
#define MAXN 2000
LL t[MAXN+10],t2[MAXN+10];
void solve(long long N, long long K, long long Q, vector<long long> A){
	LL ans=INT_MAX;
	A.push_back(-1);
	for(int i=0; i<N; ++i) {
		int Min=A[i];
		int l=0;
		int c=0;
		for(int j=0; j<=N; ++j) {
			if (A[j]<Min) {
				int r=j-1;
				if (r-l+1>=K) {
					for(int p=l; p<=r; ++p) {
						t[p]=A[p];
					}
					int num=r-l+1-K+1;
					std::nth_element(t+l,t+(l+num-1),t+r+1);
					for(int p=l; p<=l+num-1; ++p) {
						t2[++c]=t[p];
					}
				} 
				l=j+1;
			}
		}
		if (c<Q) continue;
		std::nth_element(t2+1,t2+Q,t2+1+c);
		ans=min(ans,t2[Q]-Min);
	}
	cout<<ans<<endl;
}

int main(){	
#ifdef MDEBUG
	//freopen("in.txt","r",stdin);
#endif
	long long K;
	long long Q;
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	scanf("%lld",&K);
	scanf("%lld",&Q);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, K, Q, A);
	return 0;
}



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<functional>
using namespace std;

typedef pair<int,int> P;



int main(){
	int n,m;
	while(cin>>n>>m && n){
		vector<P> data;
		int ans=0;
		for(int i=0;i<n;i++){
			int d,p;
			cin>>d>>p;
			data.push_back(P(p,d));
			ans+=d*p;
		}
		sort(data.begin(),data.end());
		for(int i=data.size()-1;i>=0;i--){
			if(m>=data[i].second){
				m-=data[i].second;
				ans-=data[i].first*data[i].second;
			}
			else {
				ans-=data[i].first*m;
				break;
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
  int N;
  cin >> N;
  string ans;
  vector<int> A(N);
  bool a = true;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) % 2 == 0 && A.at(i) % 3 != 0 && A.at(i) % 5 != 0){
      a = false;
    }
  }
  if(a == true) {
    ans = "APPROVED";
  }
  else {
    ans = "DENIED";
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
const ll inf=(1LL<<62);
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A> inline A abs(A &a) { return (a < 0 ? -a : a); }
using namespace std;
ll dp[110][100100] = {0};
signed main() {
  ll n, w;
  ll we[1000], va[1000];


  cin >> n >> w;
  for (int i = 0; i < n; i++) {
    cin >>we[i] >> va[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= w; j++) {
      if (j - we[i] >= 0) {
        chmax(dp[i + 1][j], dp[i][j - we[i]] + va[i]);
      }
      chmax(dp[i + 1][j], dp[i][j]);
    }
  }
  cout << dp[n][w] << "\n";

  return(0);
}


Measured memory_bytes: 81756
/*input
0 10
*/

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define pb                push_back
#define pp                pop_back
#define nl                cout << "\n"
#define MIN(con)          (*min_element(ALL(con)))
#define MAX(con)          (*max_element(ALL(con)))
#define NX(cont)          next_permutation(ALL(cont))
#define PX(cont)          prev_permutation(ALL(cont))
#define prec(n)           cout << fixed << setprecision(n)
#define PI                3.14159265358979323846264338327951
#define all(c)            c.begin(),c.end()
#define rep(i,a,b)        for(ll i=a;i<b;i++)
#define sp                cout << " "
#define mod               1000000007    //9
#define ifalse            ios_base::sync_with_stdio(false),cin.tie(NULL)

using ll = long long;
using ld = long double;
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > T LCM(T a, T b)            { return (a * b) / GCD(a, b); }
template < typename T > string toString(T a)       { return to_string(a); }  // Convert int to string
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}  // Convert string to int

ll add(ll x, ll y) { x += y; if(x >= mod) x -= mod; return x; }
ll sub(ll x, ll y) { x -= y; if(x < 0) x += mod; return x; }
ll mul(ll x, ll y) { return ((x % mod) * (y % mod)) % mod; }

ll powr(ll a, ll b) {
    ll x = 1LL;
    while(b) {
        if(b & 1) x = mul(x, a);
        a = mul(a, a);
        b >>= 1;
    }
    return x;
}

ll inv(ll a) { return powr(a, mod - 2); }
const int inv2 = (mod + 1) >> 1;
const ll INF =  1e18;
const int inf = 1e9;

bool check(ll n)
{
    if(n == 1) return 0;
    if(n == 2 or n == 3) return 1;
    if(n % 2 == 0 or n % 3 == 0) return 0;
    for(ll i = 5; i * i <= n; i += 6) if(n % i == 0 or n % (i + 2) == 0) return 0;
    return 1;
}

/*********************************************START**************************************************************/

ll func(ll a)
{
    ll res[] = {a, 1, a + 1LL, 0LL};
    return res[a % 4];
}

int main()
{
    ifalse;
    ll a, b;
    cin >> a >> b;
    if(a == 0) {
        cout << func(b);
        return 0;
    }
    ll d = func(b) ^ (func(a - 1LL));    
    cout << d, nl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>



using namespace std;


int main() {
	int s = 0, s2 = 0;
	string a;
	cin >> a;
	int n = a.length();
	for (int i = 0; i <= n - 1; i++) {
		s += a[i] - '0';
		s2 = s2 * 10 + a[i] - '0';
	}
	if (s2 % s) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

ll CbyK(ll n, ll k){
    ll res=1;
    rep(i,k){
        res*=n-i;
        res/=i+1;
    }
    return res;
}
int main() {
    SS(ll,n)
    ll ans=1;
    rep(i,3)ans*=n;
    p(ans);
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        mut v: [u64; 5],
    }
    let mut ans = 0;
    let mut last = 0;
    v.sort_by(|x, y| (x % 10 + 1).cmp(&(y % 10 + 1)));
    for v_ in v {
        if last == 0 && v_ % 10 != 0 {
            ans += v_;
            last = 1;
        } else if v_ % 10 == 0 {
            ans += v_;
        } else {
            ans += ((v_ / 10) + 1) * 10;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import bisect
 
A, B, Q = map(int, input().split())
INF = float('inf')
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
 
for i in range(Q):
    x = int(input())
    b = bisect.bisect_right(s, x)
    d = bisect.bisect_right(t, x)
    ans = INF
    for S in [s[b-1], s[b]]:
        for T in [t[d-1], t[d]]:
            ans1 = abs(S-x) + abs(S-T)
            ans2 = abs(T-x) + abs(T-S)
            ans = min(ans, ans1, ans2)
    print(ans)

Measured memory_bytes: 100256
import sys
sys.setrecursionlimit(300000)

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
INF = float('inf')


N, M = MI()
AB = [tuple(MI()) for _ in range(N)]
CD = [tuple(MI()) for _ in range(M)]
for a, b in AB:
    min_dist = INF
    ans = 0
    for i, (c, d) in enumerate(CD):
        dist = abs(a - c) + abs(b - d)
        if dist < min_dist:
            min_dist = dist
            ans = i + 1
    print(ans)

Measured memory_bytes: 39280
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
// sort(v.rbegin(),v.rend());
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	ll ans = 0;
	for(int i=0;i<s.size;i++)
	{
		// int x = (int)s[i];

		ans = ans + ((int)s[i]-48);
	}	
	// cout<<ans<<endl;
	if(ans%9==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
}

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

	int main(){
      string S;
      cin >> S;
      int a[26]={};
      for (int i=0;i<S.size();i++){
        a[S[i]-'a']+=1;
        if (a[S[i]-'a']==2){
          cout << "no" <<endl;
          return 0;
        }
      }
      cout << "yes" <<endl;
    }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=jp

int N;
int A[10005];

int selection() {
    int cnt = 0;
    for (int i = 0; i < N-1; i++) {
        int minj = i;
        for (int j = i+1; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A[i], A[minj]);
            cnt++;
        }
    }
    return cnt;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    int c = selection();
    arrdump(N, A);
    cout << c << "\n";
    return 0;
}



Measured memory_bytes: 3068
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>

#define EPS (1e-8)
#define EQ(a,b) (abs((a)-(b))<EPS)
#define fs first
#define sc second
#define pb push_back
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;

const double PI = acos(-1);

P unit(P p){return p/abs(p);}
pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}
double dot(P x, P y){return real(conj(x)*y);}
double cross(P x, P y){return imag(conj(x)*y);}

double arg(double a,double b,double c){return acos( (b*b+c*c-a*a)/(2*b*c));}

P rotate(P v,double s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

int ccw(P a, P b, P c){
  b -= a; c -= a;
  if(cross(b,c)>EPS)return 1;
  if(cross(b,c)<-EPS)return -1;
  if(dot(b,c)<-EPS)return 2;
  if(abs(b)<abs(c))return -2;
  return 0;
}

double line_dis(L a,P x){return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);}

//for circle
bool in_cir(C c,P x){return (abs(x-c.fs) + EPS < c.sc);}
bool on_cir(C c,P x){return EQ(abs(x-c.fs),c.sc);}

vector<L> adj_line(C c,P p){
  vector<L> res;
  if(in_cir(c,p))return res;
  if(on_cir(c,p)){
    pair<P,P> n = norm(c.fs-p);
    res.pb(L(n.fs+p,p));
    return res;
  }
  double x,y,z;
  x = c.sc;
  z = abs(c.fs-p);
  y = sqrt(z*z-x*x);
  double s = arg(y,x,z);
  P v = unit(p-c.fs)*c.sc;

  res.pb(L(rotate(v,s)+c.fs,p));
  res.pb(L(rotate(v,-s)+c.fs,p));
  return res;
}

vector<L> common_adj_line(C a,C b){
  vector<L> res;
  if(a.sc+EPS<b.sc)return common_adj_line(b,a);
  if(EQ(real(a.fs),real(b.fs)) && EQ(imag(a.fs),imag(b.fs)) && EQ(a.sc,b.sc))return res;

  P pos = (b.fs-a.fs)*a.sc/(a.sc+b.sc)+a.fs;
  if(!in_cir(a,pos))res = adj_line(a,pos);

  if(EQ(a.sc,b.sc)){
    pair<P,P> n = norm(unit(b.fs-a.fs)*a.sc);
    res.pb(L(a.fs+n.fs,b.fs+n.fs));
    res.pb(L(a.fs+n.sc,b.fs+n.sc));
  }else{
    double c = abs(b.fs-a.fs);
    pos = unit(b.fs-a.fs)*( (a.sc*c)/(a.sc-b.sc) )+a.fs;
    if(!in_cir(a,pos)){
      vector<L> tmp = adj_line(a,pos);
      FOR(i,0,tmp.size())res.pb(tmp[i]);
    }
  }
  return res;
}

int main(){
  int n;
  C c1[100],c2[100];
  double x[100],y[100],r[100],m[100];
  vector<L> v,hoge;
 
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      cin >> x[i] >> y[i] >> r[i] >> m[i];
      c1[i] = C(P(x[i],y[i]),r[i]);
      c2[i] = C(P(x[i],y[i]),r[i]+m[i]);
    }

    int ans = 1;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	v = common_adj_line(c1[i],c1[j]);
	hoge = common_adj_line(c1[i],c2[j]);
	for(int k=0;k<(int)hoge.size();k++)v.pb(hoge[k]);
	hoge = common_adj_line(c2[i],c1[j]);
	for(int k=0;k<(int)hoge.size();k++)v.pb(hoge[k]);
	hoge = common_adj_line(c2[i],c2[j]);
	for(int k=0;k<(int)hoge.size();k++)v.pb(hoge[k]);

	for(int k=0;k<(int)v.size();k++){
	  int num = 0;
	  for(int l=0;l<n;l++){
	    double dis = line_dis(v[k],c1[l].fs);

	    if(r[l] < dis + EPS && dis < r[l]+m[l] +EPS)num++;
	  }
	  ans = max(ans,num);
	}
      }
    }
    cout << ans << endl;
  }	
}

Measured memory_bytes: 996
using System;

namespace ABC_159_A_Csharp_ver
{
    class Program
    {
        static void Main(string[] args)
        {
            var word = Console.ReadLine().Split(' ');
            int N = int.Parse(word[0]);
            int M = int.Parse(word[1]);
            Console.WriteLine(N * (N - 1) / 2 + M * (M - 1) / 2);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void) {
	int N, DB, DA;
	int judge = 0;
	//Db Dbefor Da Dafter
	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		scanf("%d %d", &DA, &DB);
		if (judge!=3) {
			if (DA == DB)
				judge++;
			else
				judge = 0;
		}
	}
	if (judge == 3)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define dbg(S) { int f=1; for(auto x:S) cerr<<(f?"[":", ")<<x, f=0; cerr<<"]\n"; }

using namespace std;

vector<vector<int>> T;
vector<int> path;

bool dfs1(int u,int p){
	if(u==T.size()-1){
		path.emplace_back(u);
		return true;
	}

	for(int v:T[u]) if(v!=p) {
		if(dfs1(v,u)){
			path.emplace_back(u);
			return true;
		}
	}
	return false;
}

int dfs2(int u,int p){
	int res=1;
	for(int v:T[u]) if(v!=p) res+=dfs2(v,u);
	return res;
}

int main(){
	int n; scanf("%d",&n);
	T.resize(n);
	rep(i,n-1){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		T[u].emplace_back(v);
		T[v].emplace_back(u);
	}

	dfs1(0,-1);
	reverse(path.begin(),path.end());

	int len=path.size();
	int l=path[(len-1)/2],r=path[(len+1)/2];
	puts(dfs2(l,r)>dfs2(r,l)?"Fennec":"Snuke");

	return 0;
}


Measured memory_bytes: 11004
a, b, c = map(int, input().split())
k = int(input())
if a >= b and a >= c:
	print(a * 2 ** k + b + c)
elif b >= a and b >= c:
	print(b * 2 ** k + a + c)
else:
	print(c * 2 ** k + b + a)


Measured memory_bytes: 2940
K=int(input())

def gcd(x,y):
    if x<y:
        temp=x
        x=y
        y=temp
    if x%y==0:
        return y
    else:
        nx=y
        ny=x%y
        return gcd(nx,ny)
ans=0
for a in range(1,K+1):
    for b in range(1,K+1):
        g=gcd(a,b)
        for c in range(1,K+1):
            ans+=gcd(g,c)

print(ans)

Measured memory_bytes: 76624
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
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; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
int main(){
  string s;  cin >> s;
  string t="";
  rep(i,0,s.size()){
    if(s[i]!='x') t+=s[i];
  }
  string t2 = t;
  reverse(all(t2));
  if(t2 != t){
    cout << -1 << endl;
    return 0;
  }
  vector<int> v(t.size()+1,0);
  int ite = 0;
  rep(i,0,s.size()){
    int j=i;
    while(j<s.size() && s[j]=='x') j++;
    v[ite++] = j-i;
    i = j;
  }
  ll sum = 0;
  for(int i=0 ; i<v.size()/2 ; i++){
    sum += max(v[i], v[v.size()-i-1]) - min(v[i], v[v.size()-i-1]);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int light=1;
  for (int i=0; i<N; i++){
    if (light*2<=light+K){
      light *= 2;
      continue;
    }
    if (light*2>light+K){
      light += K;
    }
  }
  cout << light << endl;
}

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

int main(){
	int n, T;
	scanf("%d%d", &n, &T);
	int cost[n], time[n];
	for(int i=0; i<n; i++){
		scanf("%d%d", &cost[i], &time[i]);
	}
	
	int min_cost=1023;
	for(int i=0; i<n; i++){
		if(time[i]<=T){
			if(cost[i]<min_cost){
				min_cost=cost[i];
			}
		}
	}
	if(min_cost>1000) printf("TLE");
	else printf("%d", min_cost);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll sum=0;
    ll best=0;
    for(int i=1;i<=n;i++){
        sum+=i;
        best++;
        if(sum>=n) break;
    }
    sum = n;
    for(int i=best;i>=1;i--){
        if(sum>=i){
            cout<<i<<endl;
            sum-=i;
        }
    }
}

Measured memory_bytes: 256
def main():
    S = list(input())

    Y = int(''.join(S[:2]))
    M = int(''.join(S[2:]))


    if Y == 0 or Y > 12:
        if M == 0 or M > 12:
            print("NA")
        else:
            print("YYMM")
    else:
        if M == 0 or M > 12:
            print("MMYY")
        else:
            print("AMBIGUOUS")

            

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void){
    int n, p, i;
    char S[205];
    scanf("%s", S);
    n=strlen(S)/2-1;
    p=0;
    while (p==0) {
        p=1;
        for (i=0; i<n; i++) {
            if (S[i]!=S[i+n]) {
                p=0;
                break;
            }
        }
        if (p==0) n--;
    }
    printf("%d", 2*n);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main(){
    string str;
    int K = 0;
    set<string> tree;
    cin >> str >> K;
    for(char head = 'a'; head - 'z' <= 0; ++head){
        for(int i = 0; i < (int)str.length(); ++i){
            if(str[i] != head) continue;
            for(int j = 1; i + j - 1 < (int)str.length() && j <= K; ++j){
                tree.insert(str.substr(i, j));
            }
        }
        if((int)tree.size() > K) break;
    }
    auto itr = tree.begin();
    for(int i = 0; i < K - 1; ++i){
        ++itr;
    }
    cout << *itr << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 

int  A(int x){
    if(x>=0)return x;
    else return -x;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x%N;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N)*(y%N) % N;
		k /= 2;
	}
	return res;
}

unsigned long long popCount64bitB(unsigned long long x) 
{ 
    x = ((x & 0xaaaaaaaaaaaaaaaaUL) >> 1) 
      +  (x & 0x5555555555555555UL); 
    x = ((x & 0xccccccccccccccccUL) >> 2) 
      +  (x & 0x3333333333333333UL); 
    x = ((x & 0xf0f0f0f0f0f0f0f0UL) >> 4) 
      +  (x & 0x0f0f0f0f0f0f0f0fUL); 
    x = ((x & 0xff00ff00ff00ff00UL) >> 8) 
      +  (x & 0x00ff00ff00ff00ffUL); 
    x = ((x & 0xffff0000ffff0000UL) >> 16) 
      +  (x & 0x0000ffff0000ffffUL); 
    x = ((x & 0xffffffff00000000UL) >> 32) 
      +  (x & 0x00000000ffffffffUL); 
    return x; 
} 


int main(void){
    int n,m;
    cin>>n>>m;
    vector<int>light(m);
    for(int i=0;i<m;i++){
        int k;
        cin>>k;
        light[i]=0;
        for(int j=0;j<k;j++){
            int s;
            cin>>s;
            light[i]+=(1<<(s-1));
        }
    }
    vector<int>p(m);
    for(int i=0;i<m;i++)cin>>p[i];
    int ans =0;
    for(int i=0;i<(1<<n);i++){
        bool flag = true;
        for(int j=0;j<m;j++){
            int digit = i&light[j];
            int num = popCount64bitB(digit);
            //cout<<num<<endl;
            if(num%2!=p[j])flag = false;
        }
        if(flag)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	char kata [25];
	scanf ("%[^\n]", kata);
	for (int i= 0; kata[i]!='\0';i++){
		if (kata[i]!=','){
			printf ("%c", kata[i]);	
		}else{
			printf (" ");
		}
	}
puts("");
	return 0;
}

Measured memory_bytes: 1588
#include <iostream>
using namespace std;
int main()
{
  int n,i;
  float sum=0;
  cin>>n;
  float a[n];
  for(i=0;i<n;i++)
  cin>>a[i];
    for(i=0;i<n;i++)
    sum=sum+(1/a[i]);
  sum=(1/sum);
  cout<<sum;
  return 0;
}

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

const int N = 5e5+6;
const int MOD = 1e9+7;
const int INF = 1e9+7;
const double eps = 1e-6;

inline int read() {
    int x=0,f=1;char c=getchar();
    for(; c<'0'||'9'<c; c=getchar())if(c=='-')f=-1;
    for(; '0'<=c&&c<='9'; c=getchar())x=(x<<3)+(x<<1)+c-'0';
    return x*f;
}

#define lal puts(" ***  ");
#define pii pair<int,int>
#define mp  make_pair
#define pb  push_back
#define x   first
#define y   second

/********************************************/
char s[222222];

int h[333];
int main(){
    memset(h,0,sizeof(h));
    scanf("%s",s);
    int sum = 0;LL ans=1;
    for(int i=0;s[i];i++){
        sum ++;
        h[s[i]]++;
        ans += sum-h[s[i]];
    }
    printf("%lld\n",ans );
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
    int n,p;
    string s;
    cin >> n;
    vector<pair<string, int>> S(n);
    map<int, int> mp;
    rep(i,n) {
        cin >> s >> p;
        S[i].first = s;
        S[i].second = -p;
        mp[-p] = i+1;
    }
    sort(all(S));
    rep(i,n) {
        cout << mp[S[i].second] << "\n";
    }
}


Measured memory_bytes: 256
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n):
    for j in range(i + 1, n):
        d2 = sum((y - z) ** 2 for y, z in zip(x[i], x[j]))
        if d2 ** 0.5 % 1 == 0:
            ans += 1
print(ans)



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

const int N=1e6+5;
int n,a[N],b[N];
int lis[N],tl,nw,tt;
int used[N],prime[N],ptot;

void init()
{
	scanf("%d",&n);int i;
	for(i=n;~i;--i) scanf("%d",&a[i]);
	
	nw=abs(a[n]);
	for(i=n-1;~i;--i) nw=__gcd(nw,abs(a[i]));
	tt=nw;
	for(i=2;i*i<=nw;++i)
	{
		if(nw%i) continue;
		lis[++tl]=i;
		while(nw%i==0) nw/=i;
	}
	if(nw>1) lis[++tl]=nw;
}

void prework()
{
	int i,j;used[1]=1;
	for(i=2;i<=n;++i)
	{
		if(!used[i]) prime[++ptot]=i;
		for(j=1;j<=ptot&&i*prime[j]<=n;++j)
		{
			used[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
}

int ok(int p)
{
	int i;
	for(i=n;~i;--i) b[i]=(a[i]%p+p)%p;
	for(i=n;i>=p;--i)
	{
		b[i-p+1]+=b[i];
		if(b[i-p+1]>=p) b[i-p+1]-=p;
		b[i]=0;
	}
	for(i=0;i<=n;++i) if(b[i]) return false;
	return true;
}

void work()
{
	int i;
	for(i=1;i<=ptot;++i)
		if(tt%prime[i]&&ok(prime[i]))
			lis[++tl]=prime[i];
	sort(lis+1,lis+tl+1);
	for(i=1;i<=tl;++i) printf("%d\n",lis[i]);
}

int main()
{
	init();prework();work();
	return 0;
}

Measured memory_bytes: 8576