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

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

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

    vector<int> student(N);
    for (int i = 0; i < N; i++)
    {
        // int x = A[i];
        student[A[i] - 1] = i + 1;
    }
    
    for (int i = 0; i < N; i++)
    {
        cout << student[i];
        if (i < N - 1)
        {
            cout << " ";
        } else
        {
            cout << endl;
        }
        
        
    }
    
    return 0;
    
}

Measured memory_bytes: 1664
from operator import add
n,m,x = map(int,input().split())
matrix = []
sum_list = [0 for i in range(m+1)]
for i in range(n):
    tmp = list(map(int,input().split()))
    matrix.append(tmp)
def tansaku(l,s):
    #一番前の参考書を入れる入れないで再起して、入れる参考書で得られるリストを返す、もうなければ全部が閾値を超えてるかを判断して超えてれば
    if len(l) == 0:
        if min(s[1:]) >= x:
            return s[0]
        else:
            return 10 ** 8
    else:
        tmp1 = tansaku(l[1:],s)
        s = list(map(add,s,l[0]))
        tmp2 = tansaku(l[1:],s)
        return min(tmp1,tmp2)
ans = tansaku(matrix,sum_list)
if ans == 10**8:
    print(-1)
else:
    print(ans)

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

int main() {
	int c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}
	if (c[0][0] - c[0][1] + c[1][1] - c[1][0] == 0 && c[0][0] - c[0][1] + c[2][1] - c[2][0] == 0 && c[0][0] - c[0][2] + c[1][2] - c[1][0] == 0 && c[0][0] - c[0][2] + c[2][2] - c[2][0] == 0) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

using namespace std;

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

string name[101];

bool isvowel(char c){
  return (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o');
}

string getCode(string s, int k){
  string ans;
  ans = s[0];
  int len = s.size() - 1;
  REP(i, 0, len){
    if(isvowel(s[i])){
      ans += s[i+1];
    }
  }
  if((int)ans.size() < k) return ans;
  
  return ans.substr(0, k);
}

int check(int n){
  bool flag;
  
  REP(k, 1, 51){
    flag = true;
    map<string, bool> mp;
    rep(i, n){
      string s = getCode(name[i], k);
      if(mp.count(s) == 0){
        mp[s] = true;
      }else{
        flag = false;
        break;
      }
    }
    if(flag) return k;
  }
  return -1;
}

int main(){
  int n;

  while(cin >> n, n){
    rep(i, n){
      cin >> name[i];
    }
    int ret = check(n);
    cout << ret << endl;
  }
}

Measured memory_bytes: 3184
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var m = s.Count();
        var n = t.Count();
        var dp = new int[m + 1, n + 1];

        for (int x = 1; x <= m; x++)
        {
            for (int y = 1; y <= n; y++)
            {
                if (s[x - 1] == t[y - 1])
                {
                    dp[x, y] = dp[x - 1, y - 1] + 1;
                }
                else
                {
                    dp[x, y] = Math.Max(dp[x - 1, y], dp[x, y - 1]);
                }
            }
        }

        int p = m, q = n;
        var chars = new List<char>();
        while (p > 0 && q > 0)
        {
            if (dp[p, q] == dp[p - 1, q])
            {
                p--;
            }
            else if (dp[p, q] == dp[p, q - 1])
            {
                q--;
            }
            else
            {
                p--;
                q--;
                chars.Add(s[p]);
            }
        }

        chars.Reverse();
        Console.WriteLine(string.Join("", chars));
    }
}

Measured memory_bytes: 48224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	x := make([]int, n)
	for i := 0; i < n; i++ {
		x[i], _ = strconv.Atoi(stringLineScan())
	}
	ans := 100000000
	for i := 1; i <= 100; i++ {
		c := 0
		for _, j := range x {
			c += (i - j) * (i - j)
		}
		if c < ans {
			ans = c
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{   
    string s;
    cin >> s;
    long long int ans = 0;
    for(int bit = 0;bit < (1 << s.size() - 1);bit++)
    {
        long long int temp = s[0] - '0';
        for(int i = 0;i < s.size() - 1;i++)
        {
            if(bit & (1 << i))
            {
                ans += temp;
                temp = s[i + 1] - '0';
            }
            else
            {
                temp *= 10;
                temp += s[i + 1] - '0';
            }
        }
        ans += temp;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n, ac=0, wa=0, tle=0, re=0;
    string s;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=="AC") ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if(s=="RE") re++;
    }

    cout<<"AC x "<<ac<<"\n";
        cout<<"WA x "<<wa<<"\n";
            cout<<"TLE x "<<tle<<"\n";
    cout<<"RE x "<<re<<"\n";





    return 0;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;
typedef long long ll;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int N;
int T[110];
int V[110];


// double dp[110][210];
// bool used[110][210];

// double get_s(double lx, double ly, double rx, double ry, double upper_y){

//     // lxを0に合わせる
//     rx -= lx;
//     lx = 0;

//     double cx = (ry + rx - ly) / 2.0;
//     double cy = (ry + rx + ly) / 2.0;
//     double s = (ly + cy) * cx / 2.0 + (cy + ry) * (rx - cx) / 2.0;

//     // upper_yと交わる場合、引く
//     if(cy > upper_y){
//         double x1 = upper_y - ly;
//         double x2 = ry + rx - upper_y;
//         s -= (x2 - x1) * (cy - upper_y) / 2.0;
//     }

//     return s;
// }

// double rec(int pos, int src){
//     if(used[pos][src])
//         return dp[pos][src];

//     double res = 0;
//     if(pos == N){
//         res = 0;
//     }
//     else{
//         // [0, V[pos]]
//         for(int dst = 0; dst <= min(V[pos], V[pos+1]); dst++){
//             int time = T[pos];
//             if(abs(src - dst) > time) continue;
//             double s = get_s(0, src, time, dst, V[pos]);
//             res = max(res, s + rec(pos + 1, dst));
//         }
//     }

//     used[pos][src] = true;
//     return dp[pos][src] = res;
// }


vector<tpl> conds;
double v(double a){
    double res = 1 << 29;
    for(auto t : conds){
        int l = get<0>(t);
        int r = get<1>(t);
        int v = get<2>(t);
        if(a <= l){
            res = min(res, v + (l - a));
        }
        else if(a >= r){
            res = min(res, v + (a - r));
        }
        else{
            res = min(res, v*1.0);
        }
    }
    return res;
}


int main(){


    cin >> N;
    for(int i = 0; i < N; i++) cin >> T[i];
    for(int i = 0; i < N; i++) cin >> V[i];

    int t = 0;
    for(int i = 0; i < N; i++){
        int l = t;
        int r = t + T[i];
        conds.push_back(make_tuple(l, r, V[i]));
        t += T[i];
    }
    conds.push_back(make_tuple(0, 0, 0));
    conds.push_back(make_tuple(t, t, 0));


    double sum = 0;
    for(int i = 0; i < 2*t; i++){
        // [i / 2, (i + 1)/2] の範囲の台形を計算する
        double a = i/2.0;
        sum += 0.25 * (v(a) + v(a+0.5));
    }

    printf("%.10f\n", sum);

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main()
{
    int N; cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    vector<int> L(N), R(N);
    L[0] = A[0];
    FOR(i, 1, N-1) L[i] = gcd(L[i-1], A[i]);
    R[N-1] = A[N-1];
    for (int i = N-2; i >= 0; --i) {
        R[i] = gcd(R[i+1], A[i]);
    }
    int res = 0;
    REP(i, N) 
        chmax(res, gcd(L[i-1], R[i+1]));
    cout << res << endl;
}


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

int main(){
  int N;
  cin>>N;
  int M;
  cin>>M;
  vector<int> a(N,0);
  vector<pair<int,int>> p(M);
  bool frag=true;

  for(int i=0;i<M;++i){
    cin>>p[i].first>>p[i].second;
    a[p[i].first-1]=p[i].second;
    if(N>1 && p[i].first==1 && p[i].second==0) frag=false;
  }


  for(int i=0;i<M;++i){
    if(a[p[i].first-1]!=p[i].second) frag=false;
  }

  if(!frag) cout<<-1<<endl;
  else{
    if(N==1) cout<<a[0]<<endl;
    else if(a[0]==0){
      a[0]=1;
      for(int i=0;i<N;++i) cout<<a[i];
      cout<<endl;
    }
    else{
    for(int i=0;i<N;++i) cout<<a[i];
      cout<<endl;
    }
  }

}


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

int main(void) {
	string c[2];
	for (int i = 0; i < 2; i++) {
		cin >> c[i];
	}
	string ans = "YES";
	for (int i = 0; i < 3; i++) {
		if (c[0][i] != c[1][2 - i]) ans = "NO";
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3616
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
long long ng,r,g,b;

int main(){
	int N; string S; cin>>N>>S;
	for(int i=0; i<N; ++i)
		S[i]=='R'? r++: S[i]=='G'? g++: b++;

	for(int i=0; i<N-2; ++i){
		for(int d=1; d<=(N-1)/2; ++d){
			int j = i + d, k = j + d;
			if(k >= N) break;
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ng++;
		}
	}
	cout<< r*g*b - ng <<endl;
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <queue>
#include <random>
#include <map>
#include <set>
#include <boost/multiprecision/cpp_int.hpp>

#pragma warning(disable:4996)

using namespace std;

int main() {
  string s, ss;
  cin >> s;
  sort(s.begin(), s.end());
  unique_copy(s.begin(), s.end(), back_inserter(ss));
    cout << (s.size() == ss.size() ? "yes" : "no") << endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    map<ll, ll> m;
    rep(0, i, N)
    {
        ll a;
        cin >> a;
        m[a];
    }

    cout << m.size() << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N;


int cnt(int x){
	int res = 0;
	repif(i, 1, i*i<=x)
		if(x%i == 0) res++, (x/i != i ? res++ : 0);
	return res;
}


int solve(){
	int ans = 0;
	repe(i, 1, N){
		if(i%2 == 0) continue;
		if(cnt(i) == 8) ans++;
	}
	return ans;
}


signed main(){
	cin >> N;

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
work=[]
for i in range(N):
    a,b=map(int,input().split())
    work.append([a,b])

work.sort(key=lambda x:(x[1],x[0]))
t=0
ans='Yes'
for i in range(N):
    t+=work[i][0]
    if t>work[i][1]:
        ans='No'
        break
print(ans)

Measured memory_bytes: 50752
"""
challenge case

in:
3
1 3
2 3

out:
1
1
1
"""

from collections import deque

def main():
	N, *AB = map(int, open(0).read().split())
	B = AB[1::2]

	E = [[] for _ in range(N + 1)]
	for a, b in zip(*[iter(AB)] * 2):
		E[a].append(b)

	Q = deque([1])
	C = [0] * (N + 1)
	while Q:
		v = Q.popleft()
		c = 0
		for u in E[v]:
			c += 1 + (c + 1 == C[v])
			C[u] = c
			Q.append(u)

	print(max(C), *(C[b] for b in B))

main()


Measured memory_bytes: 25892
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vii vector<int, int>
#define po pop_back
#define hell 1000000007
#define PI 3.1415926535897
using namespace std;
 
void solve(){
	double n;
	cin>>n;
	cout<<2*n*PI;
}
 
int main(){
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3784
import java.util.*;
import java.util.Map.Entry;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char n[] = S.toCharArray();
        
        int maxCnt = 0;
        int cnt = 1;
        int bfr = -1;
        for(int i = 0; i < 4; i++ ) {
            int x = n[i] - 48;
            if( bfr == x ) {
                cnt++;
                maxCnt = Math.max( maxCnt, cnt );
            } else {
                cnt = 1;
                bfr = x;
            }
        }

        System.out.println( ( maxCnt >= 3 ) ? "Yes" : "No" );
    }
}


Measured memory_bytes: 35548
n,m,k=map(int,input().split())
mod=998244353
if m==1:print(0 if k!=n-1 else 1);exit()
fact=[1]*(n-1+1)
inv=[1]*(n-1+1)
for i in range(2,n-1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n-1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod
ans=0
po=pow(m-1,n-1,mod)*m%mod
ue=fact[n-1]
iii=pow(m-1,mod-2,mod)%mod
for i in range(k+1):
    ans+=comb(n-1,i)*po%mod
    po*=iii
    po%=mod
print(ans%mod)

Measured memory_bytes: 24588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a == b && b == c && a%2 == 0){
        cout << -1 << endl; return 0;
    }
    int cnt = 0;
    while(a%2 == 0 && b%2  == 0 && c%2 == 0){
        ll wa = a, wb = b, wc = c;
        a = wb/2 + wc/2; b = wa/2 + wc/2; c = wa/2 + wb/2;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
const ll N = 2000009;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
ll mod = 1e9+7;
ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
// ll fact[N];


// ll ncr(ll n,ll r){
//      return (((fact[n]*powm(fact[r],mod-2))%mod)*powm(fact[n-r],mod-2))%mod;
// }
 int main() {   
     ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
     // #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
     // #endif
     ll t = 1;
     // cin>>t;
     while(t--){
          ll n;cin>>n;
          string s;cin>>s;
          ll ct = 1;
          for(int i = 1;i<n;i++){
               if(s[i]!=s[i-1]){
                    ct++;
               }

          }
          cout<<ct;
     }
}            


Measured memory_bytes: 512
# coding:UTF-8
import sys
from math import factorial, ceil, floor

MOD = 10 ** 9 + 7
INF = 10000000000


def main():
    # ------ 入力 ------#
    n = int(input())    # 数字

    # ------ 処理 ------#
    result = 0
    for a in range(1, n+1):
        tmp = (n - 1) // a
        result += tmp

    # ------ 出力 ------#
    print("{}".format(result))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62580
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n,m;
  cin >> n >> m;
  
  vector<int> l(m,0);
  vector<int> r(m,0);
  vector<bool> can(n,true);
  
  REP(i,m)  cin >> l[i] >> r[i];
  
  sort(l.begin(), l.end());
  sort(r.begin(), r.end());
    
  REP(i,n){
    if(i < (l[m-1]-1) || (r[0]-1) < i){
      can[i] = false;
    }
  }
 
  
  
  int ans = 0;
  REP(i,n){
    if(can[i] == true){
      ans++;
    }
  }
  
  cout << ans << endl;
  
}

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

int main(){
  int n;
  int a[100010];
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> a[i];
  }

  sort(a,a+n);

  deque<int> que1;
  deque<int> que2;

  for(int i = 0;i < n;i++){
    que1.push_back(a[i]);
  }


  que2.push_back(que1.front());
  que1.pop_front();


  bool back = true;
  bool one = true;
  while(!que1.empty()){
    if(back){
      if(one){
        que2.push_front(que1.back());
        que1.pop_back();
        one = false;
      }else{
        que2.push_back(que1.back());
        que1.pop_back();
        one = true;
        back = false;
      }
    }else{
      if(one){
        que2.push_front(que1.front());
        que1.pop_front();
        one = false;
      }else{
        que2.push_back(que1.front());
        que1.pop_front();
        one = true;
        back = true;
      }
    }
  }


  int now = que2.front(); que2.pop_front();
  long long ans = 0;
  while(!que2.empty()){
    ans += abs(now - que2.front());
    now = que2.front();
    que2.pop_front();
  }


  for(int i = 0;i < n;i++){
    que1.push_back(a[i]);
  }

  que2.push_back(que1.back());
  que1.pop_back();

  back = false;
  one = true;
  while(!que1.empty()){
    if(back){
      if(one){
        que2.push_front(que1.back());
        que1.pop_back();
        one = false;
      }else{
        que2.push_back(que1.back());
        que1.pop_back();
        one = true;
        back = false;
      }
    }else{
      if(one){
        que2.push_front(que1.front());
        que1.pop_front();
        one = false;
      }else{
        que2.push_back(que1.front());
        que1.pop_front();
        one = true;
        back = true;
      }
    }
  }


  now = que2.front(); que2.pop_front();
  long long ans2 = 0;
  while(!que2.empty()){
    ans2 += abs(now - que2.front());
    now = que2.front();
    que2.pop_front();
  }

  cout << max(ans,ans2) << endl;

  return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n, x, y;
  cin >> n >> x >> y;
  x--; y --;
  vector<int> ans(n);
  rep(i, n) {
    vector<int> dist(n, INF);
    queue<int> que;
    auto push = [&](int v, int d) {
      if (dist.at(v) != INF) return;
        
      dist.at(v) = d;
      que.push(v);
    };
    
    push(i, 0);
    while(!que.empty()) {
      int v = que.front(); que.pop();
      int d = dist.at(v);
      
      if (v - 1 >= 0) push(v-1, d+1);
      if (v + 1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    rep(i, n) ans.at(dist.at(i))++;
  }
  reps(i, 1, n) cout << ans.at(i)/2 << endl;
  
  return 0;
}

Measured memory_bytes: 3624
s = input().rstrip()
t = input().rstrip()
ns = len(s)
nt = len(t)
ans = ns
for i in range(ns-nt+1):
    tmp = s[i:i+nt]
    n=0
    for j in range(nt):
         if tmp[j]!=t[j]:
                n+=1
    if ans>n:
        ans=n
print(ans)

Measured memory_bytes: 9052
N = int(input())
A = [0]*N
X = [0]*N
Y = [0]*N
for i in range(N):
    A[i] = int(input())
    Xsmall = [0]*A[i]
    Ysmall = [0]*A[i]
    for j in range(A[i]):
        Xsmall[j],Ysmall[j] = map(int,input().split())
    X[i] =Xsmall
    Y[i] = Ysmall

opinions = []
for i in range(N):
    opinion = [-1]*N
    for j in range(A[i]):
        if Y[i][j] == 0:
            opinion[X[i][j]-1] = 0
        elif Y[i][j] == 1:
            opinion[X[i][j]-1] = 1
    opinions.append(opinion)
answer = 0


for i in range(2**N):
    check = 0
    count = 0
    
    for j in range(N):
        if ((i >> (N-j-1)) & 1) == 1:
            count += 1
            for k in range(A[j]):
                num = X[j][k]
                if ((i >> (N-num)) & 1) == Y[j][k]:
                    
                    continue
                else:
                    check = -1
                    break
            
    
    if check == 0:
        answer = max(answer,count)
    
    
print(answer)

Measured memory_bytes: 73228
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    vec a(N), s(N);
    rep(i,N) {
        cin>>a[i];
        s[i] = a[i];
        if(i != 0) s[i] += s[i-1];
    }
    vec memo(4);
    ll ans = s[N-1];
    reps(i,1,N-2){ //ボーダー左のindex
        ll left = s[i], right = s[N-1] - s[i];
        ll l_index = lower_bound(s.begin(), s.end(), left/2) - s.begin();
        ll r_index = lower_bound(s.begin(), s.end(), left+right/2) - s.begin();
        //cout<<l_index<<' '<<r_index<<endl;
        memo[0] = s[l_index];
        if(l_index != 0){
            if(abs(memo[0] - left/2) > abs(s[l_index-1] - left/2)){
                memo[0] = s[l_index - 1];
            }
        }
        memo[1] = left - memo[0];
        memo[2] = s[r_index] - left;
        if(abs(memo[2] - right/2) > abs(s[r_index - 1] - left - right/2)){
            memo[2] = s[r_index - 1] - left;
        }
        memo[3] = right - memo[2];
        //rep(j,4) cout<<memo[j]<<' ';
        //cout<<endl;
        sort(memo.begin(), memo.end());
        ans = min(ans, memo[3] - memo[0]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
N, X = map(int, input().split())

bur = [1]
pati = [1]
for i in range(N):
    bur.append(bur[i] * 2 + 3)
    pati.append(pati[i] * 2 + 1)


def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + bur[N - 1]:
        return f(N - 1, X - 1)
    else:
        return pati[N - 1] + 1 + f(N - 1, X - 2 - bur[N - 1])


print(f(N, X))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    Scanner in = new Scanner(System.in);
    public static void main(String[] args) {
        new Main().solve();
    }

    void solve(){
        int k = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();

        for(int i = a; i <= b; i++)
            if(i % k == 0){
                System.out.println("OK");
                return;
            }
        System.out.println("NG");
    }
}


Measured memory_bytes: 35708
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-18-02.55.18 Tuesday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5+1000;
int n, k, h[maxn], dp[maxn];

int myabs(int a, int b) {return (a-b>0?a-b:b-a);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    ms(dp, 0x3f);
    cin >> n >> k;
    for1(i, n) {
        cin >> h[i];
    }
    dp[1] = 0;
    for1(i, n) {
        for (int j = i+1; j <= n && j <= i+k; ++j) {
            dp[j] = min(dp[j], dp[i]+myabs(h[i], h[j]));
        }
    }
    cout << dp[n] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

using namespace std;

#define INT_MAX 2147483647

int main( void ){


	string str;
	cin >> str;
	int ans = 0;
	int cnt = 0;
	for( int i = 0; i < str.size(); i++ ){

		if(str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T'){
			cnt++;
			if( ans < cnt ) ans = cnt;
		}else{
			cnt = 0;
		}
	}

	cout << ans;
	return 0;
}



Measured memory_bytes: 256
def main():
    H, W = map(int, input().split())
    C = tuple(tuple(map(int, input().split())) for _ in [0] * 10)
    A = ' '.join([input() for _ in [0] * H])

    a = []
    apnd = a.append
    for s in A.split():
        if s != '-1' and s != '1':
            apnd(int(s))

    dist = []
    apnd = dist.append
    for n in C:
        apnd(list(n))

    for k in range(10):
        for i in range(10):
            for j in range(10):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = 0
    for i in a:
        ans += dist[i][1]
    print(ans)

main()


Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node
{
    int shu;
    int ind;
} numo[100005],nume[100005];
int cmp(Node A,Node B)
{
    return A.shu>B.shu;
}
int main()
{
    int n;
    while(cin>>n)
    {
        memset(nume,0,sizeof(nume));
        memset(numo,0,sizeof(numo));
        for(int i=1; i<=n; i++)
        {
            int x;
            cin>>x;
            if(i&1)
            {
                numo[x].shu++;
                numo[x].ind=x;
            }
            else
            {
                nume[x].shu++;
                nume[x].ind=x;
            }
        }
        stable_sort(nume+1,nume+100001,cmp);
        stable_sort(numo+1,numo+100001,cmp);
        //printf("%d\n",nume[1].ind);
        if(nume[1].ind!=numo[1].ind)
        {
            printf("%d\n",n-numo[1].shu-nume[1].shu);
        }
        else
        {
            printf("%d\n",n-max(numo[1].shu+nume[2].shu,numo[2].shu+nume[1].shu));
        }

    }
    return 0;
}

Measured memory_bytes: 2304
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>
#include <fstream>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion

vector<vector<int>> to(100005), ot(100005);
vector<int> order;
vector<bool> seen(100005);

void dfs(int now)
{
	seen[now] = true;
	for (auto next : to[now])
	{
		if (seen[next])continue;
		dfs(next);
	}
	order.push_back(now);
}

int main()
{
	int n, m; cin >> n >> m;
	rep(i, n + m - 1)
	{
		int a, b; cin >> a >> b;
		to[a].push_back(b);
		ot[b].push_back(a);
	}
	for (int i = 1; i <= n; ++i)
	{
		if (seen[i])continue;
		dfs(i);
	}
	reverse(all(order));
	vector<int> depth(n + 1);
	rep(i, n)depth[order[i]] = i;
	vector<int> res(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		if (ot[i].size() == 0)continue;
		int mndepth = -1;
		int parent = 0;
		for (int p : ot[i])
		{
			if (chmax(mndepth, depth[p]))
			{
				parent = p;
			}
		}
		res[i] = parent;
	}
	for (int i = 1; i <= n; ++i)cout << res[i] << endl;
}

Measured memory_bytes: 18644
# 初期入力
N=int(input())
S = [list(map(int, input().split())) for i in range(N)]

#町のいく順番　順列
from itertools import permutations
import math
from statistics import mean
junban =[ t for t in permutations(range(N)) ]
#junban =junban_2[:len(junban_2)//2] # 逆順は考えなくていい
j_len =len(junban) # 順番の要素数
x =[] #距離
x_sum =[]
def kyori(a,b): 
    return math.sqrt(pow( S[a][0]-S[b][0],2) + pow( S[a][1] - S[b][1],2) )

# 各点の距離　　組み合わせ
from itertools import combinations
kumiawase = [t for t in combinations(range(N), 2)]
kyori_all ={i:kyori(i[0],i[1]) for i in kumiawase}

#
for i in junban:
    for ji,jv in enumerate(i[:-1]):
        if i[ji]<i[ji+1]:
            x.append(kyori_all[ i[ji],i[ji+1] ] )
        if i[ji+1]<i[ji]:
            x.append(kyori_all[ i[ji+1],i[ji] ] )

    y =sum(x)    
    x_sum.append(y)
    x.clear()
kotae =mean(x_sum) 

print(kotae)

Measured memory_bytes: 12956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


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

    int rcnt = 0;
    vector<char> C(N), D(N);
    for(int i=0; i<N; ++i)
    {
        cin >> C[i];
        D[i] = C[i];
        if(C[i] == 'R') ++rcnt;
    }

    int ans = 0;
    
    sort(D.begin(), D.end());
    for(int i=0; i<N; ++i)
    {
        if(D[i] == 'W')
        {
            break;
        }
        if(D[i] != C[i]) ++ans;
    }

    ans = min(ans, min(rcnt, N - rcnt));
    
    cout << ans << endl;
}

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

int main()
{
    long long N,A,B;
    long long r;
    long long blue;

    cin >> N >> A >> B;

    blue = 0;
    if(A != 0){
        blue = A*(N/(A+B));
     
        r = N % (A+B);
        blue = blue + min(r,A);
    }
    cout << blue;


    return 0;
    
}

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

#define ll  long long int

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>



void boost()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

ll mod=1e9+7;



int main()
{
    
    boost();
    ll n,i,j,t,x,y,m;
    cin>>n;
    ll a[n],dp[n]={0};
    for(i=0;i<n;i++)
        cin>>a[i];
    if(n==1)
    {
        cout<<"0";
        return 0;
    }
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    cout<<dp[n-1];
    return 0;
}

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

int main(){
	int n, a, b;
	cin >> n;
	b = n%100;
	n /= 100;
	a = n;
	int fy = 0;
	int fm = 0;
	if(a <= 12 && a >= 1) fm = 1;
	if(b <= 12 && b >= 1) fy = 1;
	if(fy == 1 && fm == 1){
		cout << "AMBIGUOUS" << endl;
	}else if(fy == 1){
		cout << "YYMM" << endl;
	}else if(fm == 1){
		cout << "MMYY" << endl;
	}else{
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,m;
  cin>>n>>m;
  vector<string> a(n);
  vector<string> b(m);
  for(int i=0; i<n; i++){
    cin>>a.at(i);
  }
  for(int i=0; i<m; i++){
    cin>>b.at(i);
  }

bool ok=false;
  for(int i=0; i<=n-m; i++){
    for(int l=0; l<=n-m; l++){
      bool pre=true;
      for(int j=0; j<m; j++){
        for(int k=0; k<m; k++){
          if(b.at(j)[k]!=a.at(j+i)[k+l]){
            pre=false;
            break;
          }
        }//k
        if(pre==false){
          break;
        }
      }//j
    if(pre){
      ok=true;
      break;
    }
    }//l
  }//i

  if(ok){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<string> data(H);
  for(int i=0;i<H;i++){
    cin>>data[i];
  }
  vector<vector<int>> dist(H,vector<int>(W,-1));
  using pir=pair<int,int>;
  queue<pir> que;
  dist[0][0]=0;
  que.push(pir(0,0));
  int dx[4]={0,0,1,-1};
  int dy[4]={1,-1,0,0};

  while(!que.empty()){
    auto v=que.front();
    que.pop();
    for(int i=0;i<4;i++){
      int nx=v.second+dx[i];
      int ny=v.first+dy[i];
      if(nx<0||nx>=W||ny<0||ny>=H)continue;
      if(data[ny][nx]=='#')continue;
      if(dist[ny][nx]!=-1)continue;
      dist[ny][nx]=dist[v.first][v.second]+1;
      que.push(pir(ny,nx));
    }
  }
  int all=H*W;
  int tmp=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data[i][j]=='#') tmp++;
    }
  }
  if(dist[H-1][W-1]==-1)cout<<-1<<endl;
  else{
    int ans=all-tmp-dist[H-1][W-1];
    cout<<ans-1<<endl;
  }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/15  Problem: 064_abc_d / Link: https://abc064.contest.atcoder.jp/tasks/abc064_d?lang=en ----- */
/* ------問題------

( と ) で構成される N 文字の文字列 S が与えられる。S にいくつかの ( または ) を挿入することで正しい括弧列を作りたい。
ただし、正しい括弧列は次のように定義されている：

() は正しい括弧列である。
X が正しい括弧列であるとき、(、X、) をこの順につなげたものは正しい括弧列である。
X、Y が正しい括弧列であるとき、X と Y をこの順につなげたものは正しい括弧列である。
それ以外の括弧列は正しくない。
そのとき、作れる最も文字数が少ない正しい括弧列を求めなさい。このようなものが複数ある場合は、辞書順最小のものを求めなさい。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	string s;
	cin >> s;
	stack<int>st1; // (
	stack<int>st2; // )
	FOR(i, 0, N) {
		if (s[i] == '(') {
			st1.push(1);
		}
		else { // )
			if (SZ(st1))st1.pop();
			else st2.push(1);
		}
	}
	FOR(i, 0, SZ(st2)) {
		cout << "(";
	}
	cout << s;
	FOR(i, 0, SZ(st1)) {
		cout << ")";
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
 
    long ans = 0;
 
    //Search for all i
    for (int i = 0; i < N; i++)
    {
        //Update the values of A[i+1] ... A[N]
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll long long int
#define endl "\n"
#define db(x) cout<<#x<<" ->"<<x<<endl
#define db2(x,y) cout<<#x<<"->"<<x<<", "<<#y<<" -> "<<y<<endl
#define db3(x,y,z) cout<<#x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define db4(w,x,y,z) cout<<#w <<" -> " << w << " , " << #x<<" -> "<<x<<" , "<<#y<<" -> "<<y<<" , "<<#z<<" -> "<<z<<endl
#define prt(x) for(auto it = x.begin(); it!=x.end(); it++) { cout<<*it<<" "; } cout<< endl
#define IN freopen("input.txt","r",stdin)
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = (int)1e5+5;

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
//    IN;
    string s;
    cin >> s;
    string ss = s;
    reverse(s.begin(),s.end());
    if(s!=ss){
        cout << "No" << endl;
        return 0;
    }
    ss = "";
    int N = s.size();
    int lim = (N-1) / 2;
    for(int i = 0;i < lim; i++ ){
        ss+=s[i];
    }
    string bal = ss;
    reverse(ss.begin(),ss.end());
    if(bal!=ss){
        cout << "No" << endl;
        return 0;
    }
    lim = (N+3) / 2;
    ss = "";
    for(int i = lim-1; i < N; i++){
        ss+=s[i];
    }
    bal = ss;
    reverse(ss.begin(),ss.end());
    if(bal!=ss){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


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

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

  bool even = true;
  ll ans = 0;
  int m = 1e9 + 1;
  rep(i,n)  cin >> a[i];

  vector<ll> dp[2];
  dp[0] = vector<ll>(n+1);
  dp[1] = vector<ll>(n+1);
  dp[0][0] = 0;
  dp[1][0] = - 1e15;

  rep(i,n) {
    dp[0][i+1] = max(dp[0][i] + a[i], dp[1][i] - a[i]);
    dp[1][i+1] = max(dp[0][i] - a[i], dp[1][i] + a[i]);
  }

  cout << dp[0][n] << endl;

  return 0;
}


Measured memory_bytes: 2176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<vector<char>, int>::iterator;

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

	vector<int> vA;
	for (int i = 0; i != N+1; i++) {
		int p = 0;
		cin >> p;
		vA.push_back(p);
	}

	vector<int> vB;
	for (int i = 0; i != N; i++) {
		int p = 0;
		cin >> p;
		vB.push_back(p);
	}

	long nAttack = 0;
	for (int i = 0; i != N; i++) {
		int j = 0;
		if (vA[i] < vB[i]) {
			nAttack += vA[i];
			j = vB[i] - vA[i];
			if (vA[i + 1] < j) {
				nAttack += vA[i + 1];
				vA[i + 1] = 0;
			}
			else {
				vA[i + 1] -= j;
				nAttack += j;
			}
			vA[i] = 0;
		}
		else {
			nAttack += vB[i];
			j = 0;
			vA[i] -= vB[i];
		}
	}

	cout << nAttack << endl;


	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
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
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int main(){
    int x, y;sc(x);sc(y);
    int b = y - 2*x;
    int flag=0;
    if (b<0 or b%2) flag=1;
    b/=2;
    int a = 4*x - y;
    if (a< 0 or a%2) flag=1;
    if (flag) cout<<"No\n";
    else cout<<"Yes\n";

    return 0;
}



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

const int INF = 1 << 30;

int main() {
    int n;
    while (cin >> n, n > 0) {
        vector<int> a(n);
        for (auto &i : a) {
            char c[100]; cin >> c;
            if (!strcmp("x", c)) i = INF;
            else i = atoi(c);
        }

        int l = -INF, u = INF;
        bool flag = false;
        for (int i = 0; !flag && i < n; i++) {
            if (i > 0 && a[i-1] == INF && a[i] == INF) flag = true;
            if (i % 2 && a[i-1] != INF && a[i] != INF && a[i] <= a[i-1]) flag = true;
            if (i + 1 < n && i % 2 == 0 && a[i+1] != INF && a[i] != INF && a[i] >= a[i+1]) flag = true;
            if (a[i] == INF) {
                if (i % 2) {
                    if (i > 0) l = max(l, a[i-1]+1);
                    if (i + 1 < n) l = max(l, a[i+1]+1);
                } else {
                    if (i > 0) u = min(u, a[i-1]-1);
                    if (i + 1 < n) u = min(u, a[i+1]-1);
                }
            }
        }

        if (flag || l > u) cout << "none" << endl;
        else if (l == u) cout << l << endl;
        else cout << "ambiguous" << endl;
    }

    return 0;
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/


//#define int int64_t
signed main()
{
    int n; cin >> n;
	vector<int> a(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i];
	vector<int> L(n,-1);
	L[0] = a[0];
	vector<int> R(n,-1);
	R[n-1] = a[n-1];	
	
	//cumGCD
	for(int l = 1; l < n; ++l){
		L[l] = GCD(L[l-1], a[l]);
	}
	for(int r = n-2; r >= 0; --r){
		R[r] = GCD(R[r+1], a[r]);
	}
	int ans = max(L[n-2], R[1]);
	for(int i = 1; i < n-1; ++i){
		int l = L[i-1];

		int r = R[i+1];

		amax(ans, GCD(l,r));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408