akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int price=0;
  for(int i=0;i<k;i++){
    price=price+vec.at(i);
  }
  cout<<price<<endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
	int a1=0,a2=0,b1=0,b2=0,c1=0,c2=0,d1=0,d2=0;
	float l,r;
		while(scanf("%f %f",&l,&r)==2){
		if(l>=1.1)
			a1++;
		else if(l>=0.6)
			b1++;
		else if(l>=0.2)
			c1++;
		else
			d1++;
		if(r>=1.1)
			a2++;
		else if(r>=0.6)
			b2++;
		else if(r>=0.2)
			c2++;
		else
			d2++;
	}
	printf("%d %d\n%d %d\n%d %d\n%d %d\n",a1,a2,b1,b2,c1,c2,d1,d2);
	return 0;
}

Measured memory_bytes: 1052
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long T, long X) {
    return format("%.6f", cast(double) T / X);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long T;
    T = input.front.to!long;
    input.popFront;

    long X;
    X = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(T, X);
    else
        solve(T, X).writeln;
}


Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

w = tx - sx
h = ty - sy
S = ''
S += 'U' * h
S += 'R' * w
S += 'D' * h
S += 'L' * w
S += 'L'
S += 'U' * (h + 1)
S += 'R' * (w + 1)
S += 'D'
S += 'R'
S += 'D' * (h + 1)
S += 'L' * (w + 1)
S += 'U'
print(S)

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

int max(int a,int b){
  if(a>b) return a;
  else return b;
}
double min(double a,double b){
  if(a<b) return a;
  else return b;
}
int absolute(int a,int b){
  if(a-b<0) return -(a-b);
  else return a-b;
}

int main(void){
  string s,t; cin >> s >> t;
  
  bool OK = false;
  for(int i=0;i<s.size();i++){
    int temp = 0;
    if(s==t) OK = true;
  	for(int j=0;j<s.size();j++){
      if(j==s.size()-1) s.at(j) = temp;
      else{
        if(j==0) temp = s.at(0);
        s.at(j) = s.at(j+1);
      }
    }
  }
  if(OK) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

namespace Atcoder
{
    class AtCodeeeeeeeeeeeeeeeeeeeer
    {
        static void Main(string[] args)
        {
            int[] s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int H = s[0];
            int W = s[1];
            char[,] glid = new char[H, W];
            //8方向を作成
            int[] xi = { 1, 1, 1, 0, -1, -1, -1, 0 };
            int[] yi = { 1, 0, -1, -1, -1, 0, 1, 1 };
            for (int i = 0; i < H; i++)
            {
                string str = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    glid[i, j] = str[j];
                }
            }


            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    if (glid[h,w]!='#')
                    {
                        int ans = 0;
                        for (int i = 0; i < 8; i++)
                        {
                            int Hnext = h + xi[i];
                            int Wnext = w + yi[i];
                            if (H > Hnext && Hnext >= 0 && W > Wnext && Wnext >= 0)
                            {
                                if (glid[Hnext, Wnext] == '#')
                                {
                                    ans++;
                                }
                            }
                            
                        }
                        glid[h, w] = char.Parse(ans.ToString());
                    }
                }
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    Console.Write(glid[i, j]);
                }
                Console.Write("\n");
            }
        }
    }
}


Measured memory_bytes: 13268
a = list(map(int,input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1,y1=[int(i) for i in input().split()]
    x.append((x1,y1))

max_tup = max(x, key = lambda x:x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

for i in range(1,len(dp)):
  dp[i] = min(dp[i-a] + b for a,b in x)

print(dp[HP])

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

const int mn=15;
int a[mn][mn],s[mn],c[mn],b[mn],ans=2e9;
int n,m,k;

void dfs(int x)
{
	if(x==n+1) {
		int sum=0;
		for(int i=1;i<=m;++i) s[i]=0;
		for(int i=1;i<=n;++i) if(b[i]) {
			sum+=c[i];
			for(int j=1;j<=m;++j) s[j]+=a[i][j];
		}
		for(int i=1;i<=m;++i) if(s[i]<k) return ;
		ans=min(ans,sum);
		return ;
	}
	b[x]=0;
	dfs(x+1);
	b[x]=1;
	dfs(x+1);
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;++i) {
		scanf("%d",c+i);
		for(int j=1;j<=m;++j) scanf("%d",&a[i][j]);
	}
	dfs(1);
	if(ans==(int)2e9) puts("-1");
	else cout<<ans;
}

Measured memory_bytes: 3764
let [| A; B; C; D |] = stdin.ReadLine().Split() |> Array.map int64

let rec gcd a b =
    match (a, b) with
    | (x, 0L) -> x
    | (0L, y) -> y
    | (a, b) -> gcd b (a % b)

let lcm a b = a * b / (gcd a b)

let resolver x = x - x / C - x / D + x / (lcm C D)

resolver B - resolver (A - 1L) |> stdout.WriteLine


Measured memory_bytes: 13268
fun main(args: Array<String>) {
    val (n, qn) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val qlist = (1..qn).map { readLine()!!.split(" ").map { it.toInt() } }

    val tArray = Array(n){0}
    for(i in 0 until n - 1){
        tArray[i+1] = tArray[i] + if(s.substring(i, i + 2) == "AC") 1 else 0
    }

    for(q in qlist){
        val (l, r) = q
        val ans = tArray[r-1] - tArray[l-1]
        println(ans)
    }
}

Measured memory_bytes: 64984
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

class drink {
   public:
    int p;
    int x;
    drink() {}
    drink(int p, int x) : p(p), x(x) {}
};

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

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

    int m;
    cin >> m;
    vector<drink> ds(m);
    for (int i = 0; i < m; i++) {
        cin >> ds[i].p >> ds[i].x;
        ds[i].p--;
    }

    int sum_t = 0;
    for (int t : ts) {
        sum_t += t;
    }

    for (int i = 0; i < m; i++) {
        cout << (sum_t - ts[ds[i].p] + ds[i].x) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
	int H,W;
	while(1){
		std::cin >> H >> W;
		
		if(H == 0 && W ==0){break;}

		//??????????¨?
		for(int a=0;a<W;a++){
			std::cout << "#";
		}
		std::cout << std::endl;
		//??????????¨?

		//??????
		for(int i=1;i<H-1;i++){
			std::cout << "#";
		for(int j=1;j<W-1;j++){
			std::cout << ".";
		}
		std::cout << "#" << std::endl;
		}

		for(int b=0;b<W;b++){
		std::cout << "#";
		}
		std::cout << std::endl << std::endl;
	}
}

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

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

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

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

    cin>>n;
    ans_1 = n + (n * n) + (n * n * n);
    cout<<ans_1<<endl;

    return;
}

int main()
{
    Ok();

    return 0;
}


Measured memory_bytes: 3596
n = int(input())
res = 0
for i in range(111, 1000):
    s = str(i)
    if '0' in s:
        continue
    flag = True
    for c in s:
        if not (1 <= int(c) <= n):
            flag = False
    if flag:
        res += 1
print(res)

Measured memory_bytes: 3060
h, w = map(int,input().split())
grid = []
grid.append('#' * (w+2))
for _ in range(h):
    grid.append('#' + input().rstrip() + '#')
grid.append('#' * (w+2))
            
from collections import deque
import sys
sys.setrecursionlimit(1000000)


def flatten_2dim(array):
    return [item for sublist in array for item in sublist]

maxstep = 0
step = [[-1] * (w+2) for _ in range(h+2)]
def bfs():
    global maxstep
    dy = [1, 0, -1, 0]
    dx = [0, 1, 0, -1]
    
    que = deque([])
    que.append((s_y, s_x))
    step[s_y][s_x] = 0
    
    while que:
        y, x = que.popleft()

        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if step[ny][nx] == -1 and grid[ny][nx] != "#":
                que.append((ny, nx))
                step[ny][nx] = step[y][x] + 1

    maxstep = max(max(flatten_2dim(step)), maxstep)
    
for i in range(h+2):
    for j in range(w+2):
        if grid[i][j] == ".":
            s_y, s_x = i, j
            bfs()
            step = [[-1] * (w+2) for _ in range(h+2)]
print(maxstep)


Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
ll K;

int C[25];
int T[50005];

int main()
{
	int m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&C[i]);

	for(int i=0;i<=n;i++)T[i]=99999999;
	T[0] = 0;

	for(int i=1;i<=m;i++){
		for(int j=C[i];j<=n;j++){
			T[j] = min(T[j],T[j-C[i]]+1);
		}
	}

	printf("%d\n",T[n]);
	return 0;
}



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

int n,m;
string obj[222];
unordered_map<int,int> memo;

int rec(int state){
  if(memo.count(state))return memo[state];

  int cnt = 0, tmp = state;
  vector<int> col(m);
  rep(i,m){ col[i] = tmp%3; tmp/=3; }

  rep(i,n){
    bool f = true;
    rep(j,m){
      if(col[j] == 1 && obj[i][j] == '1')f = false;
      if(col[j] == 2 && obj[i][j] == '0')f = false;
      if(!f)break;
    }
    if(f)cnt++;
  }
  if(cnt<=1)return memo[state] = 0;

  int res = m;
  rep(i,m){
    if(col[i]==0){
      int maxv = 0;

      for(int k=1;k<=2;k++){
	col[i] = k;
	int nstate = 0;
	for(int j=m-1;j>=0;j--)nstate = nstate*3 + col[j];
	maxv = max(maxv, rec(nstate));
      }
      res = min(res, maxv);
      col[i] = 0;
    }
  }
  return memo[state] = res+1;
}

int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  while(cin >> m >> n, m){
    rep(i,n)cin >> obj[i];

    memo.clear();
    cout << rec(0) << endl;
  }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

int did[505050];
vector<ll> lef,cand;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	vector<pair<int,int>> V;
	FOR(i,N) {
		cin>>x>>y;
		V.push_back({y,x});
	}
	sort(ALL(V));
	reverse(ALL(V));
	
	ll cur=0;
	int num=0;
	FOR(i,N) {
		if(i<K) {
			cur+=V[i].first;
			if(did[V[i].second]==0) {
				num++;
				did[V[i].second]=1;
			}
			else {
				lef.push_back(V[i].first);
			}
		}
		else {
			if(did[V[i].second]==0) {
				cand.push_back(V[i].first);
				did[V[i].second]=1;
			}
		}
	}
	
	sort(ALL(lef));
	sort(ALL(cand));
	reverse(ALL(cand));
	x=min(lef.size(),cand.size());
	lef.resize(x);
	cand.resize(x);
	
	
	ll ret=cur+1LL*num*num;
	FOR(i,x) {
		if(i) {
			lef[i]+=lef[i-1];
			cand[i]+=cand[i-1];
		}
		ret=max(ret,cur-lef[i]+cand[i]+1LL*(num+i+1)*(num+i+1));
	}
	cout<<ret<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 2420
#include<vector>
#include<queue>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<vector<int>>vii;
typedef vector<vector<char>>vvc;
typedef vector<vector<ll>>vll;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef vector< pair<int, int>>vpi;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

int mod=1000000007;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
void outp(vii &ou)
{
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cout << ou[i][j] << ' ';
		}
		cout << '\n';
	}
}
int bp(int x, int y)
{
	if (y == 0)
	{
		return 1;
	}
	int a = 0;
	if (!(y % 2))
	{
		a = bp(x, y / 2);
	}
	return (y % 2) ? mlt(bp(x, y - 1), x) : mlt(a, a);
}
int obr(int x)
{
	return bp(x, mod - 2);
}
const int maxn = 10000007;
int fact[1000007], ofact[1000007];
void prec()
{
	fact[0] = 1;
	ofact[0] = 1;
	for (int i = 1; i < maxn; i++)
	{
		fact[i] = mlt(fact[i - 1], i);
	}
	//cerr << "sdsds" << endl;
	ofact[maxn - 1] = obr(fact[maxn - 1]);
	for (int i = maxn - 2; i > 0; i--)
	{
		ofact[i] = mlt(ofact[i + 1], i + 1);
	}
}
int c(int a, int b)
{
	return ((a <= b) && (a >= 0)) ? mlt(fact[b], mlt(ofact[a], ofact[b - a])) : 0;
}
void rebuild(int fir, int sec, int &mn, int &smallest_max, int &mid_max)
{
	//знак - <, min в 0
	int new_sm, new_mm;
	if (sec >= fir)
	{
		new_sm = smallest_max;
		new_mm = max(mid_max, new_sm + sec - fir);
	}
	else
	{
		int dif = fir - sec;
		if (smallest_max >= dif)
		{
			new_sm = smallest_max - dif;
			new_mm = max(smallest_max, mid_max - dif);
		}
		else
		{
			mn++;
			new_sm= max(smallest_max, mid_max - dif);
			new_mm = sec;
		}
	}
	smallest_max = min(sec,new_sm);
	mid_max = min(sec,new_mm);
}
void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	cin >> n;
	vi  a(n+2);
	//cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i + 1];
	n += 2;
	int mn = 0, sm = 0, mm = 0;
	for (int i = 1; i < n; i++)
		rebuild(a[i - 1], a[i], mn, sm, mm);
	cout << mn << endl;
}
int main()
{
	//prec();
	//cerr << "Here" << endl;
	solve();
	int n;
	cin >> n;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll N;
vector<ll> imos;

int main() {
	cin >> N;
	imos.resize(1e5 + 3,0);
	for (ll n = 0; n < N; n++) {
		ll a;
		cin >> a;
		imos[max(a - 1, (ll)0)]++;
		imos[a + 2]--;
	}
	for (ll n = 1; n <= 1e5; n++) {
		imos[n] += imos[n - 1];
	}
	ll ans = 0;
	for (ll n = 1; n <= 1e5; n++) {
		if (imos[n] > imos[ans])ans = n;
	}
	cout << imos[ans] << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        if(N%2==0){
            System.out.println(0.5);
        }
        else{
            int x=N/2+1;
            double y=x;
            System.out.println(y/N);
        }
    }
}

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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<long>;
using vll = vector<ll>;
using vb  = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vector<int> >;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

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

    vi p(n);
    rep(i, 0, n-1) cin >> p[i];
    sort(btoe(p));

    int ans = 0, ptr = 0;
    while(k--) {
        ans += p[ptr];
        ptr++;
    }

    cout << ans << nl;
    return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll n, k, x, c, ans, a[100005];

ll f(ll p) {
	ll re = 0;
	for(ll i=0; i<n; i++) {
		re += (a[i]>>p & 1);
	}
	return re;
}

int main() {
	ll i;
	cin >> n >> k;
	for(i=0; i<n; i++) scanf("%lld", &a[i]);
	for(i=40; i>=0; i--) {
		if(x + (1LL<<i) <= k) {
			c = f(i);
			if(2*c < n) x += 1LL<<i;
		}
	}
	for(i=0; i<n; i++) ans += a[i] ^ x;
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        String S = stdIn.next();
	String[] s={"SUN","MON","TUE","WED","THU","FRI","SAT"};
	for(int i=0;i<s.length;i++){
	    if(S.equals(s[i])){
		System.out.println(7-i);
	    }
	}
    }
}


Measured memory_bytes: 22868
object Main extends App {
  @scala.annotation.tailrec
  def loop(ints: List[Int], x: Int, count: Int): Int = ints match {
    case List() => 0
    case y :: _ if x < y => count.min(ints.length)
    case _ :: ys => loop(ys, x, count + 1)
  }
  val sc = new java.util.Scanner(System.in)
  val n, m, x = sc.nextInt()
  val as = List.fill(m)(sc.nextInt())
  println(loop(as, x, 0))
}


Measured memory_bytes: 55256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next();
        int len = str.length();
        if (len % 2 == 0) {
            System.out.println("No");
            return;
        }

        for (int i = 0; i < len/2; i ++){
            if (str.charAt(i) != str.charAt(len - i - 1)){
                System.out.println("No");
                return;
            }
        }
        for (int i = 0; i < (len - 1)/2; i ++){
            if (str.charAt(i) != str.charAt(len/2 - i - 1)){
                System.out.println("No");
                return;
            }
        }
        for (int i = (len+3)/2 - 1; i < len; i ++){
            if (str.charAt(i) != str.charAt(len - i - 1)){
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");
    }

}


Measured memory_bytes: 21844
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    ops = {"+": lambda a, b: b + a,
       "-": lambda a, b: b - a,
       "*": lambda a, b: b * a}
    stack = []
    for s in input().split():
        if s in ops:
            stack.append(ops[s](stack.pop(), stack.pop()))
        else:
            stack.append(int(s))
    print(stack[-1])
    


Measured memory_bytes: 7328
#[allow(unused_macros)]
macro_rules! invec {
    ( $t:ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s.trim().split_whitespace().map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }}
}

#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($(
            {
                 splits.next().unwrap().parse::<$t>().unwrap()
            },
        )*)
    }}
}

fn divisors(n: u64) -> Vec<u64> {
    let mut res = vec![];

    for i in (1..(((n as f64).sqrt().floor() as u64) + 1)).rev() {
        if n % i == 0 {
            res.insert(0, i);
            if i != n / i {
                res.push(n / i);
            }
        }
    }

    return res;
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(u64);

    let divisors = divisors(n);
    let mut total = 0;

    for div in &divisors[1..divisors.len()] {
        let candidate = div - 1;
        if n / candidate == n % candidate {
            total += candidate;
        }
    }

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

fn main() {
    solve();
}


Measured memory_bytes: 4476
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, ans = 0; cin >> n;
	for (int h = 1; h <= n; h++) {
		cin >> a;
		ans += a - 1;
	}
	cout << ans << endl;
	cin >> n;
}

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

using namespace std;

#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define MP make_pair
#define PB push_back
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

#define int long long
#define trace(x) cerr << #x << ": " << x << " " << endl;


inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((int) a * b %MOD);}


#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int dp[20][2];

signed main()
{
    IOS
    #define int unsigned long long
    int n;
    cin >> n;
    if(n&1)
    {
        cout << 0;
        return 0;
    }
    n = n/2;
   int ct = 0;
   while(n)
   {
       ct+=n/5;
       n=n/5;
   }
   cout << ct;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;
int main() {
    int A, B;
    int result;
    cin >> A >> B;
    if(A>B){
       result = A+A-1;
    }else if(A<B){
        result = B+B-1;
    }else{
        result = A+B;
    }
    cout << result << endl;
    return 0;
}

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

int main(){

    int n,d,cont=0,cont_total=0;

    scanf("%d",&n);

    for(int i=105;i<=n;i++){
        for(int j=1;j<=n;){
            if(i%j==0){
                cont++;
            }
            j+=2;
        }
        if(cont==8){
            cont_total++;
            cont=0;
        }else cont=0;
    }

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

    return 0;
}


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



template <typename Monoid, bool COMMUTATIVE = false>
class SegmentTree{
  using value_type = typename Monoid::value_type;
  
protected:
  const int depth, size, hsize;
  std::vector<value_type> data;

public:
  SegmentTree(int n):
    depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1),
    size((1 << depth) - 1),
    hsize(size / 2 + 1),
    data(size + 1, Monoid::id())
  {}

  inline auto operator[](int i) const {return at(i);}
  inline auto at(int i) const {return data[hsize + i];}
  
  inline auto get(int x, int y) const { // [x,y)
    std::vector<int> memo;
    value_type ret = Monoid::id();
    
    int l = x + hsize, r = y + hsize;
    while(l < r){
      if(r & 1){
        if(COMMUTATIVE) ret = Monoid::op(ret, data[--r]);
        else memo.push_back(--r);
      }
      if(l & 1) ret = Monoid::op(ret, data[l++]);
      l >>= 1, r >>= 1;
    }

    if(not COMMUTATIVE){
      std::reverse(memo.begin(), memo.end());
      for(auto i : memo) ret = Monoid::op(ret, data[i]);
    }
    
    return ret;
  }

  inline void update(int i, const value_type &x){
    i += hsize;
    data[i] = x;
    while(i > 1) i >>= 1, data[i] = Monoid::op(data[i << 1 | 0], data[i << 1 | 1]);
  }

  template <typename T>
  inline void init_with_vector(const std::vector<T> &val){
    data.assign(size + 1, Monoid::id());
    for(int i = 0; i < (int)val.size(); ++i) data[hsize + i] = val[i];
    for(int i = hsize-1; i >= 1; --i) data[i] = Monoid::op(data[i << 1 | 0], data[i << 1 | 1]);
  }

  template <typename T>
  inline void init(const T &val){
    init_with_vector(std::vector<value_type>(hsize, val));
  }  

  auto debug(){
    return data;
  }
};



template <typename T>
struct MaxMonoid{
  using value_type = T;

  static value_type NINF;

  constexpr inline static value_type id(){
    return NINF;
  }

  constexpr inline static value_type op(const value_type &a, const value_type &b){
    return std::max(a, b);
  }
};

template <> int64_t MaxMonoid<int64_t>::NINF = std::numeric_limits<int64_t>::min();

using Mon = MaxMonoid<int64_t>;

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

  std::vector<int64_t> h(N), a(N);
  for(int i = 0; i < N; ++i) scanf("%lld", &h[i]);
  for(int i = 0; i < N; ++i) scanf("%lld", &a[i]);

  SegmentTree<Mon,true> seg(N+1);
  seg.init(0);

  for(int i = 0; i < N; ++i){
    int64_t t = seg.get(0, h[i] + 1);
    seg.update(h[i], t + a[i]);
  }

  printf("%lld\n", seg.get(0, N+1));
  

  return 0;
}


Measured memory_bytes: 9472
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)

vector<int> a[MAXN];
int n, q;
int v[MAXN];
int val[MAXN];
int ret[MAXN];

void dfs(int cur, int sum) {
	if (v[cur]) {
		return;
	}
	v[cur] = 1;
	sum += val[cur];
	ret[cur] = sum;
	for (auto& e : a[cur]) {
		dfs(e, sum);
	}
}

int main() {
	cout << fixed << setprecision(12);	
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	for (int i = 0; i < q; i++) {
		int t1, t2;
		cin >> t1 >> t2;
		val[t1] += t2;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		cout << ret[i] << " ";
	}
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 43032
//by (111110101)2
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long a,b;
int main()
{
	cin>>a>>b;
	cout<<a*b/__gcd(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N),B(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		B[A[i] - 1] = i + 1;
	}
	for (int i = 0; i < N; i++) {
		cout << B[i] << " ";
	}
	cout << endl;
	return 0;
} 

Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[n];
    int c=0,d=0;
    for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++){
        if(a[i] == (i+1)){
            c++;
        }
        if(a[i] != (i+1)){
            d++;
        }
    }
    if(c==n){
        printf("YES\n");
    }
    else if(d<=2){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
    return 0;
}

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

int main() {
	int a,b;
	string s[1000];
	cin >>a>>b;
	for(int i=1;i<=a;i++){
		cin >>s[i];
	}
	for(int i=0;i<=a+1;i++){
		if(i==0||i==a+1){
			for(int j=0;j<b+2;j++){
				if(j+1==b+2){cout <<"#"<<endl;break;}
				cout<<"#";
			}
		}
		else{cout<<"#"<<s[i]<<"#"<<endl;}
	}
	return 0;
}

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

int main(){
  int N,K,x,sum=0;
  cin>>N>>K;
  for(int i=0;i<N;i++){
    cin>>x;
    if(K-x<x)
      sum+=2*(K-x);
    else
      sum+=2*x;
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string a, b, c; cin >> a >> b >> c;

    printf("%c%c%c\n",
           a.front() - 0x20,
           b.front() - 0x20,
           c.front() - 0x20);
}


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N;
    cin >> N;
    vector<int> s(N);
    vector<bool> dp(20000);
    rep(i,0,N) cin >> s[i];
    dp[0]=true;
    dp[s[0]]=true;
    rep(i,1,N){
        for(int j=20000-1; j>=0; --j){
            if(j-s[i]>=0 and dp[j-s[i]]) dp[j]=true;
        }
    }

    int ans=0;
    rep(i,0,20000) if(dp[i] and i%10) ans=max(ans,i);
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n = i_input()
    xs = i_list()

    min_list = []
    for i in range(1, 101):
        tmp = 0
        for x in xs:
            tmp += (i - x)**2
        min_list.append(tmp)

    print(min(min_list))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10388
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a * b % 2 == 0) {
      System.out.println("Even");
    } else {
      System.out.println("Odd");
    }
  }
}

Measured memory_bytes: 20820
import java.util.*

fun main(args: Array<String>?): Unit {
    val (width, height) = readLine()!!.trim().split(' ').map(String::toInt)
    val state = Array(height){ readLine()!!.trim().split(' ').map(String::toInt).toIntArray()}
    val queue = LinkedList<HexPoint>()
    for (h in 0 until height) {
        if (state[h][0] == 0) queue.push(HexPoint(0, h))
        if (state[h].last() == 0) queue.push(HexPoint(state[h].lastIndex, h))
    }
    for (w in 0 until width){
        if (state[0][w] == 0) queue.push(HexPoint(w, 0))
        if (state.last()[w] == 0) queue.push(HexPoint(w, state.lastIndex))
    }
    for (hp in queue) state[hp.y][hp.x] = 2
    while(queue.isNotEmpty()) {
        val current = queue.pop()
        for (next in current.neighbors()) if (next.x in 0 until width && next.y in 0 until height && state[next.y][next.x] == 0){
            state[next.y][next.x] = 2
            queue.push(next)
        }
    }
    println(
            (0 until width).sumBy{ x -> (0 until height).filter{y -> state[y][x] == 1}.sumBy { y -> HexPoint(x, y).neighbors().count{ hp -> hp.x !in 0 until width || hp.y !in 0 until height || state[hp.y][hp.x] == 2 } }}
    )

}
data class HexPoint(val x: Int, val y: Int) {
    fun neighbors(): List<HexPoint> = when(y % 2 == 0){
        true -> listOf(HexPoint(x, y - 1), HexPoint(x + 1, y - 1), HexPoint(x - 1, y), HexPoint(x + 1, y), HexPoint(x, y + 1), HexPoint(x + 1, y + 1))
        false -> listOf(HexPoint(x - 1, y - 1), HexPoint(x, y - 1), HexPoint(x - 1, y), HexPoint(x + 1, y), HexPoint(x - 1, y + 1), HexPoint(x, y + 1))
    }
}


Measured memory_bytes: 41408
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

vector<int> sieve_of_eratosthenes(int n = 200010) {
  vector<bool> is_prime(n+1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 0; i <= n; ++i) if (is_prime[i]) {
    for (int j = i+i; j <= n; j+=i) is_prime[j] = false;
  }
  vector<int> primes;
  for (int i = 2; i <= n; ++i) if (is_prime[i]) primes.push_back(i);
  return primes;
}

map<long long, int> prime_factorize(long long n, const vector<int> &primes) {
  map<long long, int> prime_factor;
  for (int p : primes) {
    if (n < (long long) p * p) break;
    while (n % p == 0) {
      prime_factor[p] += 1;
      n /= p;
    }
  }
  if (n != 1) prime_factor[n] += 1;
  return prime_factor;
}

vector<long long> calc_divisors(long long n, const map<long long, int> &prime_factor) {
  vector<long long> divisors(1, 1);
  for (auto it : prime_factor) {
    long long p; int k;
    tie(p, k) = it;
    int size = divisors.size();
    for (int i = 0; i < k; ++i) {
      for (int j = 0; j < size; ++j) divisors.push_back(divisors[i*size+j] * p);
    }
  }
  sort(divisors.begin(), divisors.end());
  return divisors;
}

int main() {
  int n, m; cin>>n>>m;
  auto primes = sieve_of_eratosthenes();
  auto prime_factors = prime_factorize(m, primes);
  auto divisors = calc_divisors(n, prime_factors);

  int ans = 1;
  rep(i, divisors.size()) if (m/n >= divisors[i]) ans = divisors[i];
  print(ans);

  return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
ls0 = [list(map(int, input().split())) for _ in range(n)]
ls1 = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    x0, y0 = ls0[i]
    index = 0
    md = float('inf')
    for j in range(m):
        x1, y1 = ls1[j]
        d = abs(x0 - x1) + abs(y0 - y1)
        if d < md:
            md = d
            index = j
    print(index + 1)

Measured memory_bytes: 3064
import math

def insertion_sort(A, n, g):
    global count
    for i in range(g, n):
        val = A[i]
        j = i - g
        while j >= 0 and A[j] > val:
            A[j + g] = A[j]
            j = j - g
            count += 1
        A[j+g] = val

def shell_sort(A, n):
    G = []
    h = 1
    while h <= n:
        G.append(h)
        h = 3 * h + 1
    G.reverse()
    for g in G:
        insertion_sort(A, n, g)

    return G

if __name__ == "__main__":
    n = int(input())
    A = [int(input()) for _ in range(n)]
    count = 0
    G = shell_sort(A, n)

    print(len(G))
    print(" ".join([str(g) for g in G]))
    print(count)
    for i in range(n):
        print(A[i])



Measured memory_bytes: 45584
h,w,k = map(int, input().split())
s = [input() for _ in range(h)]
ans =0

for ib in range(1<<h):
    for jb in range(1<<w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if ib>>i&1: continue
                if jb>>j&1: continue
                if s[i][j] == '#':
                    cnt+=1
        if cnt == k:
            ans += 1

print(ans)

Measured memory_bytes: 9160
from heapq import *
n, k = map(int, input().split())
d = list(map(int, input().split()))

res = 0
num = min(k, n)
for i in range(num + 1):
    for j in range(num + 1 - i):
        l = min(k - (i + j), i + j)
        s = d[:i] + d[-j:] if j != 0 else d[:i]
        heapify(s)
        for _ in range(l):
            tmp = heappop(s)
            if tmp > 0:
                heappush(s, tmp)
        res = max(res, sum(s))
print(res)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
    int n, k, q, a, i, t[100001], j;
    cin >> n >> k >> q;
  
  for(i=0; i<n; i++)
    t[i]=k-q;
  
  for(i=0; i<q; i++){
      cin >> a;
    t[a-1]++;
  }
  
for(i=0; i<n; i++){
  if(t[i]>0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}



    return 0;
}


Measured memory_bytes: 1024
//未証明のそれっぽい貪欲。
//両端から作る。ペアが作れるなら愚直に作る。作れないときを考える。
//・(x以外) -- (x以外) … 不可能
//・(x以外) -- x, x -- (x以外) … 1回操作してx--xを作る。(x側のカーソルを移動）

#include <iostream>
#include <string>
using namespace std;

string s;

int main() {
	cin >> s;
	
	int l = 0, r = (int)s.length() - 1;
	int ans = 0;
	
	while (l < r) {
		if (s[l] == s[r]) { l++; r--; }
		else {
			if (s[l] == 'x') { l++; ans++; }
			else if (s[r] == 'x') { r--; ans++; }
			else { cout << -1 << endl; return 0; }
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(n>=k)
    {
        n%=k;
    }
    cout<<min(n,k-n);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int p = 0;
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    int h;
    cin >> h;
    ret += std::max(h - p, 0);
    p = h;
  }
  cout << ret << "\n";
  return 0;
}


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

int main() {
    string s;
    cin >> s;
    ll k;
    cin >> k;
    set<char> st;
    for(char c : s) st.insert(c);
    if(st.size()==1){
        cout << k*s.size()/2 << endl;
        return 0;
    } 
    ll a = 0;
    string t = s;
    for(int i = 1; i < t.size(); ++i) {
        if(t[i]==t[i-1]){
            a++;
            t[i]='#';
        }
    }
    ll b = 0;
    s+=s;
    for(int i = 1; i < s.size(); ++i){
        if(s[i]==s[i-1]){
            b++;
            s[i]='#';
        }
    }
    b-=a;
    cout << (k-1)*b + a << endl;
    return 0;
}

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

long long N, A[100100], idx, idx2;

int main() {
	// baca arraynya
    cin >> N;
    for(int i=1; i<=N; i++) {
        cin >> A[i];
    }
    
    // urutkan array naik A[1]..A[N]
    sort(A+1, A+N+1);

    for (int i=N; i>=2; i--){
        if(A[i]==A[i-1]){
            idx=i;
            break;
        }
    }
    
    for (int i=idx-2; i>=2; i--){
        if(A[i]==A[i-1]){
            idx2=i;
            break;
        }
    }
    cout << A[idx]*A[idx2] << endl;

    
}


Measured memory_bytes: 4328
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <cstdio>
#define rep(i,k,n) for(int i = k ; i < n ; i++ )
#define INF 10000000
int v[1001],w[1001];
int dp[1001][1001];

using namespace std;

int main(){
  int W,n;
  int cas = 1;
  while(cin >> W ,W){
    fill(v,v+1001,0);
    fill(w,w+1001,0);
    fill(dp[0],dp[1001],0);
	 cin >> n;
	 char c;
	 for(int i = 0 ; i < n ; i++ ){
	   cin >> v[i] >> c >> w[i];
	 }
	 for(int i = 0 ; i < n ; i++ ){
	   for(int j = 0 ; j <= W ; j++ ){
	     if(j < w[i]){
	       dp[i+1][j] = dp[i][j]; 
	     } else {
	       dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
	     }
	   }
	 }
	 int wight = 0,mx = 0;
	 for(int i = 0 ; i <= W ; i++ )if(dp[n][i] > mx)mx = dp[n][i],wight = i;
	 cout << "Case " << cas++ << ":"<<endl;
	 cout << dp[n][W] << endl;
	 cout << wight << endl;
	 }
      return 0;
  }

Measured memory_bytes: 5080
#include <bits/stdc++.h>
using namespace std;
string s,t;
int ans = 1e9;
int main(){

    cin>>s>>t;
    for(int i=0;i<s.size()-t.size()+1;i++){
        int tmp =0;
        for(int j=0;j<t.size();j++)
            tmp += (t[j] != s[i+j]);
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename x>
using ordered_set = tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>;
#define sorta(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n,greater<__typeof(a[0])>())
#define all(x) (x).begin(),(x).end()
#define ms0(x) memset((x),0,sizeof((x)))
#define ms1(x) memset((x),-1,sizeof((x)))
typedef pair<int,int> pi;
#define inarr(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define prinarr(arr) {for(int x:arr)cout<<x<<" ";} cout<<"\n";
#define cout1(a) cout<<a<<"\n";
#define cout2(a,b) cout<<a<<" "<<b<<"\n";
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define setpre(n) cout<<fixed<<setprecision(8)<<n<<"\n";
#define filldp(arr,n,m,k) for(int i=0;i<n;i++){for(int j=0;j<m;j++) arr[i][j]=k;}

#define mod 1000000007
#define mod1 998244353


vector<vector<int>> adj;
vector<int> dis;
vector<int> parent;
vector<bool> visited;

void newgr(int n){
    n+=10;
    adj=vector<vector<int>>(n);
    dis=vector<int>(n,0);
    //parent=vector<int>(n,-1);
    visited=vector<bool>(n,false);
}

void dfs(int s){
    visited[s]=true;
    for(auto u:adj[s]){
        if(!visited[u]){
            //parent[u]=s;
            dis[u]=dis[s]+1;
            dfs(u);
        }
    }
}

void bfs(int s){
    queue<int> q;
    q.push(s);
    visited[s]=true;
    dis[s]=0;
    while(!q.empty()){
        auto u=q.front();
        q.pop();
        for(auto x:adj[u]){
            if(!visited[x]){
                //parent[x]=u;
                visited[x]=true;
                dis[x]=dis[u]+1;
                q.push(x);
            }
        }
    }
}

long long power(long long x,long long y){  
    long long ans=1;
    x%=mod;
    while(y>0){
        if(y&1) ans=(ans*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return ans;
}

long long modinv(long long b){ 
    return power(b,mod-2);
}



int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    int u;
    for(int i=1;i<=n;i++){
        cin>>u;
        if(i%2){
            if(u%2){
                ans++;
            }
        }
    }
    cout1(ans);

    return 0;
}

Measured memory_bytes: 3652
if __name__ == '__main__':
    from sys import stdin
    from collections import defaultdict, deque
    import math
    input = stdin.readline

    # import random

    n, m = map(int, input().split())
    hh = list(map(int, input().split()))
    visited = [False]*n
    nodes = defaultdict(list)
    ok = [True]*n
    for _ in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        if hh[a] <= hh[b]:
            ok[a] = False
        if hh[b] <= hh[a]:
            ok[b] = False

    ans = 0
    
    for s in ok:
        if s:
            ans += 1

    print(ans)






Measured memory_bytes: 21380