akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){
    int n,k,v,p,tmp,tmp2;
    vector<pair<int,int> > vs;
    cin >> n >> k;
    vector<int> bs[n];
    bool bad[n+1];
    memset(bad, false, sizeof(bad));
    for(int i=0;i<k;i++){
        cin >> v;
        for(int j=0;j<v;j++){
            cin >> tmp;
            bs[i].push_back(tmp);
        }
    }
    cin >> p;
    for(int i=0;i<p;i++){
        cin >> tmp >> tmp2;
        vs.push_back(make_pair(tmp,tmp2));
    }

    for(int i=0;i<k;i++){
        for(int j=0;j<(int)bs[i].size();j++){
            for(int k=j+1;k<(int)bs[i].size();k++){
                for(int l=0;l<(int)vs.size();l++){
                    if((bs[i][j] == vs[l].first && bs[i][k] == vs[l].second) ||
                       (bs[i][j] == vs[l].second && bs[i][k] == vs[l].first)){
                        bad[bs[i][j]] = true;
                        bad[bs[i][k]] = true;
                    }
                }
            }
        }
    }
    int ret = 0;
    for(int i=0;i<=n;i++){
        if(bad[i]) ret++;
    }
    cout << ret << endl;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
ostream& operator << (ostream& out, vector<int>& v) {
	for (auto& x: v) out << x << ' ';
	return out;
}

ostream& operator << (ostream& out, pii& v) {
	out << v.fi << ", " << v.se;
	return out;
}

istream& operator >> (istream& in, pii& a) {
	in >> a.fi >> a.se;
	return in;
}

const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, x;
	cin >> n >> x;
	vector<int> goo (n);
	cinv (goo);
	vector<int> a = goo;
	int ans = 4e18;
	fr (i, n) {
		int res = i * x;
		dbg (i);
		fr (j, n) {
			chkmin (a[j], goo[(j - i + n) % n]);
			res += a[j];
			dbg (a[j]);
		}
		chkmin (ans, res);
	}
	cout << ans << '\n';






}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define re(n) for (int i = 0; i < (n); ++i)
#define rej(n) for (int j = 0; j < (n); ++j)

using namespace std;

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

const ld PI = acos((ld)-1);

int main() {
    #ifndef LOCALDEBUG
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #endif  // LOCALDEBUG
    int x, y;
    cin >> x >> y;
    if (x > 9 || y > 9) {
        cout << -1;
    } else {
        cout << x * y;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
# n = map(int, readline().split())
n = int(readline())

ls = []
rs = []

total = 0
S = list(map(lambda x: x.strip().decode(), readlines()))

for i in range(n):
    s = S[i]

    b = 0
    h = 0
    for c in s:
        if c == '(':
            h += 1
        else:
            h -= 1
            b = min(b, h)

    if h >= 0:
        ls.append((b, h))
    else:
        rs.append((b - h, -h))
    total += h

if total != 0:
    print("No")
    exit()

ls = sorted(ls, reverse=True)
rs = sorted(rs, reverse=True)

h = 0
OK = True
for p in ls:
    b = h + p[0]
    h += p[1]
    if b < 0:
        OK = False

h = 0
for p in rs:
    b = h + p[0]
    h += p[1]
    if b < 0 or h < 0:
        OK = False

if not OK:
    print("No")
else:
    print("Yes")




Measured memory_bytes: 117952
import Control.Applicative

main = do xs <- map (map read . words) . lines <$> getContents
          putStr . unlines . filter (/= "") $ map solve xs

solve :: [Int] -> String
solve (n:x:_) | n==0 && x==0 = ""
              | otherwise = show $ sum [1| a<-[1..n],b<-[(a+1)..n],c<-[(b+1)..n], a+b+c == x]    

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

int main() {
  int N;
  cin >> N;
  string S[N];
  bool ans=true;
  for(int i=0;i<N && ans;i++){
    cin >> S[i];
    if(i>0){
      if(S[i][0]!=S[i-1][S[i-1].length()-1]){
        ans=false;
        break;
      }
      for(int j=0;j<i;j++){
        if(S[i]==S[j]){
          ans=false;
          break;
        }
      }
    }
  }
  if(ans)cout << "Yes";
  else cout << "No";
}




Measured memory_bytes: 256
EPS = 1e-10
for q in range(int(input())):
    l = list(map(float, input().split()))
    if abs((l[3] - l[1]) * (l[6] - l[4]) - (l[7] - l[5]) * (l[2] - l[0])) < EPS:
        print('YES')
    else:
        print('NO')



Measured memory_bytes: 5604
day = input()

if day == "SUN":
  print(7)
elif day == "MON":
  print(6)
elif day == "TUE":
  print(5)
elif day == "WED":
  print(4)
elif day == "THU":
  print(3)
elif day == "FRI":
  print(2)
else:
  print(1)
  


Measured memory_bytes: 2940
#include<stdio.h>
 
int main(){
  int i, j, n, m[100][100], p[100], a, l, k, q=0;
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    if(i < n - 1) scanf("%d%d", &p[i], &a);
    else scanf("%d%d", &p[i], &p[i + 1]);
  }
 
  for(i = 1; i <= n; i++){
    for(j = 1; j <= n; j++){
      m[i][j] = 0;
    }
  }
 
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      j = i + l - 1;
      m[i][j] = 100000;
      for(k = i; k < j; k++){
    q = m[i][k] + m[k + 1][j] + p[i - 1]*p[k]*p[j];
    if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
 
  printf("%d\n", m[1][n]);
 
  return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#define MAX 1000001
using namespace std;

class element{
private:
	int key;
	element *next;
	element *previous;

public:
	element(int K,element *N,element *P){
		key = K;
		next = N;
		previous = P;
	}

	int getKey(){
		return key;
	}

	element(int K){
		key = K;
	}

	element *getNext(){
		return next;
	}

	element *getPrevious(){
		return previous;
	}

	void setNext(element *N){
		next = N;
	}

	void setPrevious(element *P){
		previous = P;
	}
};

class DoublyLinkedList{
private:
	element *head;
	element *tail;
	int num_of_elements;
public:
	DoublyLinkedList(){
		head = NULL;
		tail = NULL;
		num_of_elements = 0;
	}
	int num(){
		return num_of_elements;
	}

	element *getHead(){
		return head;
	}

	element *getTail(){
		return tail;
	}

	void insertx(int x){
		if(num_of_elements == 0){
			element *X;
			X = new element(x);
			X->setNext(X);
			X->setPrevious(X);
			num_of_elements++;
			head = X;
			tail = X;
		}else{//num_of_elements > 0
			element *X;
			X = new element(x);
			//こっからの書き順がちょっと複雑！
			head->setNext(X);
			tail->setPrevious(X);
			X->setNext(tail);
			X->setPrevious(head);
			num_of_elements++;
			head = X;
		}
	}

	
	void deleteFirst(){
		if(num_of_elements == 1){
			delete head;//head == tail
			tail = NULL;
			num_of_elements--;
		}else{
			element *next_head = head->getPrevious();
			next_head->setNext(tail);
			tail->setPrevious(next_head);
			delete head;
			head = next_head;
			num_of_elements--;
		}
	}

	void deleteLast(){
		if(num_of_elements == 1){
			delete tail;//tail == head
			tail = NULL;
			num_of_elements--;
		}else{
			element *next_tail = tail->getNext();
			next_tail->setPrevious(head);
			head->setNext(next_tail);
			delete tail;
			tail = next_tail;
			num_of_elements--;
		}
	}

	void deletex(int x){
		element *pos = head;
		while(true){
			if(pos->getKey() == x){
				if(pos == head){
					//delete pos;←これやるとheadがdeleteされる
					deleteFirst();
					return;
				}else if(pos == tail){
					//delete pos;
					deleteLast();
					return;
				}else{
					(pos->getNext())->setPrevious(pos->getPrevious());
					(pos->getPrevious())->setNext(pos->getNext());
					delete pos;
					num_of_elements--;
					return;
				}
			}else/*(pos->getKey() != x)*/{
				if(pos == tail){
					//cout <<"error:no such element" <<endl;
					return;
				}else{
					pos = pos->getPrevious();//nextでないことに注意！
				}
			}
		}
	}

};
int main(){
	DoublyLinkedList DLL;

	int num_of_input;
	char input_string[20];
	int input_num;
	cin >>num_of_input;

	for(int i=0;i<num_of_input;i++){
		scanf("%s",&input_string);
		if(input_string[0] == 'i'){
			scanf("%d",&input_num);
			DLL.insertx(input_num);
		}else if(input_string[6] =='F'){
			DLL.deleteFirst();
		}else if(input_string[6] == 'L'){
			DLL.deleteLast();
		}else{
			scanf("%d",&input_num);
			DLL.deletex(input_num);
		}
	}

	element *pos = DLL.getHead();
	for(int i=0;i<num_of_input;i++){
		if(pos == DLL.getTail()){
			cout <<pos->getKey() <<endl;
			break;
		}else{
			cout <<pos->getKey() <<" ";
			pos = pos->getPrevious();
		}
	}
	
	return 0;
}
//とりあえず挿入だけは一回やった

Measured memory_bytes: 32292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
template<class T> void add(T &a, T b) { a = (a + b) % MOD; }

ll dp[101010][2];
int main() {
  string S; cin >> S;
  dp[0][0] = 1;
  rep(i, 0, S.size()) {
    // i桁目を0にする
    if(S[i] == '0') {
      add(dp[i+1][0], dp[i][0]);
      add(dp[i+1][1], dp[i][1]);
    } else {
      add(dp[i+1][1], dp[i][0]);
      add(dp[i+1][1], dp[i][1]);
    }
    // i桁目を1にする
    if(S[i] == '0') {
      add(dp[i+1][1], dp[i][1] * 2);
    } else {
      add(dp[i+1][0], dp[i][0] * 2);
      add(dp[i+1][1], dp[i][1] * 2);
    }
  }
  ll ans = 0;
  add(ans, dp[S.size()][0] + dp[S.size()][1]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2048
n=int(input())
A=[int(i) for i in input().split()]
AA=[A[0]]
for i in range(1,n):
  AA.append(AA[-1]+A[i])
tot=AA[-1]
import bisect
ans=float("inf")
for i in range(1,n-2):
  cur=AA[i]
  l=bisect.bisect_left(AA,cur//2)
  if l==0:
    L1=[0,float("inf")]
  else:
    L1=[AA[l-1],cur-AA[l-1]]
  L2=[AA[l],cur-AA[l]]
  
  r=bisect.bisect_left(AA,cur+(tot-cur)//2)
  if r-1==i:
    R1=[0,float("inf")]
  else:
    R1=[AA[r-1]-cur,tot-AA[r-1]]
  R2=[AA[r]-cur,tot-AA[r]]
  A11=L1+R1
  A12=L1+R2
  A21=L2+R1
  A22=L2+R2
  a11=max(A11)-min(A11)
  a12=max(A12)-min(A12)
  a21=max(A21)-min(A21)
  a22=max(A22)-min(A22)

  ans=min(ans,a11,a12,a21,a22)
print(ans)

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

typedef struct Tree{
  int key;
  struct Tree *parent;
  struct Tree *left;
  struct Tree *right;
}Tree; 

Tree *t;
void Print1(Tree*);
void Print2(Tree*);
void Insert(int);
void Find(int);

int main(){
  int m,i,key;
  char comma[7];
  scanf("%d",&m);
  t=(Tree*)malloc(sizeof(Tree)*1);
  t->parent=t->left=t->right=NULL;
  t->key=2000000001;
  for(i=0;i<m;i++){
    scanf("%s",comma);
    if(strcmp(comma,"insert")==0){
      scanf("%d",&key);
      Insert(key);
     }
    else if(strcmp(comma,"print")==0){
      Print1(t);
      printf("\n");
      Print2(t);
      printf("\n");
    }
    else if(strcmp(comma,"find")==0){
      scanf("%d",&key);
      Find(key);
      printf("\n");
    }
  }
  free(t);
  return 0;
}

void Insert(int key){
  Tree *y;
  Tree *x;
  Tree *hoge;
  if(t->key==2000000001){
    t->key=key;
    return;
  }
  x=t;
  y=NULL;
  hoge=(Tree*)malloc(sizeof(Tree)*1);
  hoge->key=key;
  hoge->parent=hoge->left=hoge->right=NULL;
  while(x!=NULL){
    y=x;
    if(key<x->key)
      x=x->left;
    else
      x=x->right;
    hoge->parent=y;
  }
  if(hoge->key<y->key)
    y->left=hoge;
  else
    y->right=hoge;
}

void Print1(Tree *x){
  if(x==NULL)
    return;
  else{
    Print1(x->left);
    printf(" %d",x->key);
    Print1(x->right);
  }
}

void Print2(Tree *x){
  if(x==NULL)
    return;
  else{
    printf(" %d",x->key);
    Print2(x->left);
    Print2(x->right);
  }
}

void Find(int key){
  Tree *x;
  x=t;
  while(x!=NULL){
    if(x->key==key){
      printf("yes");
      return;
    }
    else if(x->key<key)
      x=x->right;
    else
      x=x->left;
  }
    printf("no");
    return;
}

Measured memory_bytes: 19352
import math
import bisect
import collections

N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)
A = sorted(list(C.keys()))
#print(C)
#print(A)

ans = 0
for i in range(len(A)-1,-1,-1):
  a = A[i]
  b = (1<<(int(math.log(a,2))+1))-a
  if a == b:
    ans += C[a]//2
    C[a] -= C[a]//2*2
  else:
    r = bisect.bisect_left(A, b)
    if r < i and A[r] == b:
      mn = min(C[a],C[A[r]])
      ans += mn
      C[a] -=  mn
      C[A[r]] -= mn
print(ans)


Measured memory_bytes: 111828
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;

int main() {

	int K, X; cin >> K >> X; K--;

	for (int i = X - K; i <= X + K; i++) cout << i << " ";

}

Measured memory_bytes: 256
main = do
  [c1, c2, c3, c4] <- getLine
  let x = read [c1, c2]
  let y = read [c3, c4]
  let x' = 0 < x && x < 13
  let y' = 0 < y && y < 13
  putStrLn $ case (x', y') of
    (True, True) -> "AMBIGUOUS"
    (False, True) -> "YYMM"
    (True, False) -> "MMYY"
    _ -> "NA"


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

int main(){
	int n;
	cin >> n;
	
	int a[25];
	for(int i=0; i<n; i++) cin >> a[i];
	int b[55];
	for(int i=0; i<n; i++) cin >> b[i];
	int c[55];
	for(int i=0; i<n; i++) cin >> c[i];
	
	int bsum;
	for(int i=0; i<n; i++) bsum +=b[i];
	
	int cnt=0;
	for(int i=0; i<n-1; i++){
		if(a[i]-a[i+1] == -1) cnt += c[a[i]-1];
	}
	cout << bsum+cnt << endl;
}

Measured memory_bytes: 256
def split(datum)
  datum.include?('_') ? datum.split('_') : (datum.split(/([A-Z][a-z]*)/) - [""])
end

loop do
  datum, cmd = gets.split
  case cmd
  when 'L'
    head, *tail = split(datum)
    puts head.downcase + tail.map(&:capitalize).join
  when 'U'
    puts split(datum).map(&:capitalize).join
  when 'D'
    puts split(datum).map(&:downcase).join("_")
  when 'X'
    break
  end
end



Measured memory_bytes: 6884
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val K = sc.nextLong()
    val A = Array.fill(N)(sc.nextInt())

    // 左の数の方が大きい数になっている個数
    // 全部見ていくと間に合わない
    // 一旦無視すると,
    // ある数 aiについて
    // aiより大きい数の数を AiC とする
    // aiより左にある大きい数の数を AiCL とする
    // aiより右にある大きい数の数を ACiR とする, ACiR = AiC - AiCL
    // ここで K = 1なら, AiCLであり
    // K = 2なら, AiCL + AiCL + AiCR = AiC + AiCL であり,
    // K >= 3なら, (AiC * (AiC + 1) / 2) - AiC
    // つまり AiCR は必要ない

    val Inf = 1000000000 + 7

    val AiC = new Array[Int](N)
    val AiCL = new Array[Int](N)

    var i = 1
    while (i < N) {
      var j = 0
      while (j < i) {
        if (A(j) > A(i))
          AiCL(i) += 1
        j += 1
      }
      i += 1
    }

    i = 0
    while (i < N) {
      var j = 0
      while (j < N) {
        if (i != j && A(j) > A(i))
          AiC(i) += 1
        j += 1
      }
      i += 1
    }

    var r = BigInt(0)
    i = 0
    while (i < N) {
      r += BigInt(K * (K - 1L) / 2L) * AiC(i).toLong + AiCL(i).toLong * K
      i += 1
    }

    println(r % Inf.toLong)
  }

}


Measured memory_bytes: 29592
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i,m,n) for(ll i=m ; i<n ; i++)
#define forr(i,m,n) for(ll i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N =1e5+5;
using namespace std;
int main()
{
    ios_base:: sync_with_stdio(0);
	cin.tie(0);
    int n,mx=0; cin>>n;
    map<string,int>mp;
    rep(i,0,n){
    string s; cin>>s;
    mp[s]++;
    }
    for(auto i:mp){
        mx=max(mx,i.second);
    }

    for(auto i:mp){
        if(i.second==mx)
            cout<<i.first<<endl;

    }

}


Measured memory_bytes: 23808
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){
  int d;
  cin >> d;
  if(d==22){
    cout << "Christmas Eve Eve Eve" << endl;
  }else if(d==23){
    cout << "Christmas Eve Eve" << endl;
  }else if(d==24){
    cout << "Christmas Eve" << endl;
  }else if(d==25){
    cout << "Christmas" << endl;
  }

  return 0;
}



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

using namespace std;
typedef long long ll;
int r,c,a1,a2,b1,b2;
ll p=1;
ll mod=100000007;
ll dp[1001][1001];
int main(void){
	scanf("%d%d%d%d%d%d",&r,&c,&a1,&a2,&b1,&b2);
	int dx=min(abs(a1-b1),r-abs(a1-b1));
	int dy=min(abs(a2-b2),c-abs(a2-b2));
	if(abs(a1-b1)==r-abs(a1-b1))p*=2;
	if(abs(a2-b2)==c-abs(a2-b2))p*=2;
	dp[0][0]=1;
	for(int i=0;i<=dy;i++){
		for(int j=0;j<=dx;j++){
			dp[j+1][i]+=dp[j][i];
			if(dp[j+1][i]>=mod)dp[j+1][i]%=mod;
			dp[j][i+1]+=dp[j][i];
			if(dp[j][i+1]>=mod)dp[j][i+1]%=mod;
		}
	}
	printf("%lld\n",dp[dx][dy]*p%mod);
	return 0;
}

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

int main() {
  int N,K;
  string S;
  cin>>N>>K>>S;
  S[K-1]+=32;
  cout<<S<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b[100],c,max=0,i,min;
	scanf("%d",&a);
	for(i=0;i<a;i++){
			scanf("%d",&b[i]);
			if(i==0) min=b[i];
			if(max<b[i]) max=b[i];
			if(min>b[i]) min=b[i];
	}
	printf("%d\n",max-min);

}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 n, k;
	cin >> n >> k;
	vector<int64> a, b;
	a.push_back(0);
	b.push_back(0);
	REP(i, n){
		int64 x;
		cin >> x;
		if(x >= 0) a.push_back(x);
		else b.push_back(abs(x));
	}
	sort(all(b));
	int64 res = INF_LL;
	REP(i, k+1){
		if(a.size() <= i || b.size() <= k-i) continue;
		res = min({res, a[i]*2+b[k-i], a[i]+b[k-i]*2});
	}
	cout << res << endl;

}


Measured memory_bytes: 1656
a, b, q = [int(i) for i in input().split()]

INF = 10**18

temple = []
shrine = []
ques = []

for i in range(a):
    dist = int(input())
    temple.append(dist)
for i in range(b):
    dist = int(input())
    shrine.append(dist)
for i in range(q):
    ques.append(int(input()))

temple.sort()
shrine.sort()

temple = [-INF] + temple + [INF]
shrine = [-INF] + shrine + [INF]


def binary_insert(array,x):
    left = 0
    right = len(array) - 1
    while left <= right:
        mid = (left + right) // 2
        if array[mid] > x:
            right = mid - 1
        else:
            left = mid + 1
    return left



for i in range(q):
    score = 10**18
    y = ques[i]
    idx_temple = binary_insert(temple,y)
    idx_shrine = binary_insert(shrine,y)
    left_t = temple[idx_temple-1]
    right_t = temple[idx_temple]
    left_s = shrine[idx_shrine-1]
    right_s = shrine[idx_shrine]
    t = [left_t,right_t]
    s = [left_s,right_s]
    for ts in t:
        for ss in s:
            scoret = abs(y - ts) + abs(ts - ss)
            scores = abs(y - ss) + abs(ts - ss)
            score = min(score,scores,scoret)
    print(score)


Measured memory_bytes: 16768
#include <iostream>
#include <cmath>
#include <vector>
using ll = long long int;
using namespace std;
//絶対値
int abs(int x) {
				return max(x,-x);
}
  
int main() {
  ll a,b,c,k;
  cin >>a>>b>>c>>k;
  if (abs(a-b)>=pow(10,18))  {
	cout << "Unfair";
  }
  else {
  if (k%2==0) cout <<a-b;
	else cout <<b-a;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int n;
    int k;
    int pk=0;
    vector<int> x;
    vector<int> y;
    int a=0;
    cin>>n;
    rep2(1,i,n+1){
        cin>>k;
        if(k!=i){
            a++;
            x.pb(k);
            y.pb(i);
        }
    }
    
    bool check=true; 

    if(a>2)check=false;
    else if(a==2){
        if(x[0]==y[1] &&x[1]==y[0] ){
            check=true;
        }else{
            check=false;
        }
    }

    string ans=(check)?"YES":"NO";

    cout<<ans<<endl;
    
    return 0;
}

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

vector<vector<ll>> cost(50);
void dfs(ll c, int num, int start, int goal) {
    if (start == goal) {
        cost[num].push_back(c);
    }
    else {
        for (int i = 1; i <= start; i++) {
            if (start%i == goal || start%i > goal*2) {
                dfs(c+(1LL<<i), num, start%i, goal);
            }
        }
    }
    return;
}

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++) cin >> b[i];
    for (int i = 0; i < N; i++) {
        dfs(0, i, a[i], b[i]);
    }
    for (int i = 0; i < N; i++) {
        if (cost[i].empty()) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll ans = 0;
    for (int i = 50; i >= 1; i--) {
        ll d = ans + (1LL << i)-1;
        bool need = false;
        for (int j = 0; j < N; j++) {
            bool check = true;
            for (ll c : cost[j]) {
                if ((d | c) == d) {
                    check = false;
                    break;
                }
            }
            if (check) {
                need = true;
                break;
            }
        }
        if (need) ans = d + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3

def inner_product(v1, v2):
    return v1.real * v2.real + v1.imag * v2.imag


# ????????????b???????????????a??????????????´????????£?°???±???????????????????????????
def projection(a, b):
    return a * inner_product(a, b) / (abs(a) ** 2)


def solve(p0, p1, p2):
    a = p1 - p0
    b = p2 - p0
    pro = projection(a, b)
    t = p0 + pro
    return t


def main():
    x_p0, y_p0, x_p1, y_p1 = map(float, input().split())
    p0 = complex(x_p0, y_p0)
    p1 = complex(x_p1, y_p1)
    q = int(input())
    for _ in range(q):
        p2 = complex(*map(float, input().split()))
        t = solve(p0, p1, p2)
        print("{:.10f} {:.10f}".format(t.real, t.imag))


if __name__ == '__main__':
    main()

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using T = int;
  static T op(const T& a, const T& b) { return max(a, b); }
  static constexpr T e() { return -1; }

  const int n;
  V<T> t;
  SegmentTree(int n) : n(n), t(2 * n, e()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  T acc(int l, int r) const {
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  void set(int i, const T& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  SegmentTree st(n + 2);
  st[0] = st[n + 1] = n + 1;
  for (int i = 1; i <= n; ++i) {
    cin >> st[i];
  }
  st.build();

  auto fl = [&](int i, int x) -> int {
    int ng = -1, ok = i - 1;
    while (ok - ng > 1) {
      int mid = ng + ok >> 1;
      (st.acc(mid + 1, i) <= x ? ok : ng) = mid;
    }
    return ok;
  };
  auto fr = [&](int i, int x) -> int {
    int ok = i + 1, ng = n + 2;
    while (ng - ok > 1) {
      int mid = ok + ng >> 1;
      (st.acc(i + 1, mid) <= x ? ok : ng) = mid;
    }
    return ok;
  };

  lint res = 0;
  for (int i = 1; i <= n; ++i) {
    lint l = fl(i, st[i]);
    lint r = fr(i, st[i]);
    if (l) {
      lint ll = fl(l, st[i]);
      res += (l - ll) * (r - i) * st[i];
    }
    if (r <= n) {
      lint rr = fr(r, st[i]);
      res += (i - l) * (rr - r) * st[i];
    }
  }
  cout << res << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
class XorShift {
public:
	unsigned int x, y, z, w;
	double nL[65536];

	XorShift()
	{
		init();
	}

	void init()
	{
		x = 314159265; y = 358979323; z = 846264338; w = 327950288;
		double n = 1 / (double)(2 * 65536);
		for (int i = 0; i < 65536; i++) {
			nL[i] = log(((double)i / 65536) + n);
		}
	}

	inline unsigned int next()
	{
		unsigned int t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8;
	}

	inline double nextLog() {
		return nL[next() & 0xFFFF];
	}

	inline int nextInt(int m)
	{
		return (int)(next() % m);
	}


	int nextInt(int min, int max)
	{
		return min + nextInt(max - min + 1);
	}


	double nextDouble()
	{
		return (double)next() / ((long long)1 << 32);
	}


};
int solve(int N, string S) {
	S += "00";
	vector<int> k;
	k.clear();
	int cnt = 0;
	int mn = 0;
	int res = 0;
	int st;
	vector<int> dp1(N);
	vector<int> dp2(N);
	vector<int> dp3(N);
	vector<int> dp4(N);
	for (int i = 0; i < N + 1; i++) {
		if (S[i] == '0' && S[i + 1] == '0') {
			k.push_back(cnt);

			if ((int)k.size() > 1) {
				//cerr << k.size() << endl;
				for (int j = 0; j < k.size(); j++) {
					//cerr << k[j] << " ";
					dp1[j] = 0;
					dp2[j] = 0;
					dp3[j] = 0;
					dp4[j] = 0;
				}
				//cerr << endl;
				//cerr << endl;
				for (int j = 1; j < k.size(); j++) {
					if (k[j - 1] > 1) {
						dp1[j] = max(max(dp4[j - 1] + 1, dp1[j - 1] + k[j - 1] - 1), dp3[j - 1] + k[j - 1]);
					}
					else {
						dp1[j] = dp3[j - 1] + k[j - 1];
					}
					if (k[j - 1] > 1) {
						dp2[j] = max(max(dp1[j - 1] + k[j], dp4[j - 1] + k[j]), dp3[j - 1] + k[j]);
					}
					else {
						dp2[j] = dp3[j - 1] + k[j];
					}
					if (k[j - 1] > 1) {
						dp4[j] = max(max(dp4[j-1]+k[j]-1,dp1[j - 1] + k[j] - 1), dp3[j - 1] + k[j] - 1);
					}
					else {
						dp4[j] = dp3[j - 1] + k[j] - 1;
					}

					dp3[j] = max(max(dp4[j - 1],dp1[j - 1]), max(dp2[j - 1], dp3[j - 1]));
				}
				res += max(max(dp4[k.size() - 1],dp3[k.size() - 1]), max(dp2[k.size() - 1], dp1[k.size() - 1]));
			}
			k.clear();
			cnt = 0;
		}
		else {
			if (S[i] == '0') {
				if (cnt > 0) {
					k.push_back(cnt);
				}
				cnt = 0;
			}
			else {
				cnt++;
			}
		}
	}

	return res;
}
XorShift rnd;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	cout << solve(N, S) << endl;
	/*N = 20;
	S.resize(20);
	int score = 0;
	for (int l = 0; l < 1000; l++) {
		for (int i = 0; i < N; i++) {
			S[i] = (char)(rnd.nextInt(2) + '0');
		}
		score = solve(N, S);
		reverse(S.begin(), S.end());
		if (score != solve(N, S)) {
			cerr << S << endl;
			break;
		}
		if (l % 10 == 0) {
			cerr << l << endl;
		}
	}*/
}

Measured memory_bytes: 17564
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int64_t a, b, ans = 0;
  cin >> a >> b;
  if (a % 2 == 1)
  {
    ans ^= a;
    ++ a;
  }
  switch ((b - a + 1) % 4)
  {
  case 3:
    ans ^= b - 2;
  case 2:
    ans ^= b - 1;
  case 1:
    ans ^= b;
  default:
    ;
  }
  cout << ans << endl;
}

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

int n, k, W[100000];

int calcAmount(int P) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        int s = 0;
        while (s + W[i] <= P) {
            s += W[i];
            i++;
            if (i == n) {
                return n;
            }
        }
    }
    return i;
}

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

    int left = 1;
    int right = 100000 * 10000;
    int mid;
    int v;
    while (right - left > 0) {
        mid = (left + right) / 2;
        v = calcAmount(mid);
        if (v >= n) {
            right = mid;
        }
        else {
            left = mid + 1;
        }
    }
    cout << left << endl;
}



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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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

    if( N > 999 ) cout << "ABD" << endl;
    else cout << "ABC" <<endl;

}


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

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

int main() {
  int n, k;
  int p[1000];

  cin >> n >> k;
  rep(i, n) cin >> p[i];
  sort(p, p + n);
  int ans = 0;
  rep(i, k) ans += p[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int items = Integer.parseInt(sc.nextLine());
		int k = Integer.parseInt(sc.nextLine());
		int[] balls = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();

		int a_let = 0;
		int b_let = 0;
		int ans = 0;

		for (int i = 0; i < items; i++) {
			a_let = Math.abs(0 - balls[i]) * 2;
			b_let = Math.abs(k - balls[i]) * 2;

			if (a_let <= b_let) {
				ans +=a_let;
			} else {
				ans +=b_let;
			}
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 36148
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

//dp[i][j][k] i桁目 0でない数がk個 k 0: 上位桁が一致 1: 小さい
ll dp[101][4][2];

int main() {
    string s;
    int k;
    cin >> s >> k;
    int len = s.size();

    dp[0][0][0] = 1;
    //dp[0][0][1] = 1;
    rep(i, len) {
        int digit = s.at(i) - '0';

        //0
        rep(j, 4) {
            if (digit == 0) {
                dp[i + 1][j][0] += dp[i][j][0];
                dp[i + 1][j][1] += dp[i][j][1];
            }
            else { //0 < digit
                dp[i + 1][j][1] += dp[i][j][0];
                dp[i + 1][j][1] += dp[i][j][1];
            }
        }

        repr(num, 1, 10) {
            if (num < digit) {
                rep(j, 3) {
                    dp[i + 1][j + 1][1] += dp[i][j][0];
                    dp[i + 1][j + 1][1] += dp[i][j][1];
                }
            }
            else if (num == digit) {
                rep (j, 3) {
                    dp[i + 1][j + 1][0] += dp[i][j][0];
                    dp[i + 1][j + 1][1] += dp[i][j][1];
                }
            }
            else { //num > digit
                rep(j, 3) {
                    dp[i + 1][j + 1][1] += dp[i][j][1];
                }
            }
        }
    }

    ll res = dp[len][k][0] + dp[len][k][1];
    cout << res << endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    ac = 0
    wa = 0
    tle = 0
    re = 0
    for _ in range(n):
        result = input()
        if result == "AC":
            ac += 1
        elif result == "WA":
            wa += 1
        elif result == "TLE":
            tle += 1
        elif result == "RE":
            re += 1
    
    print("AC x " + str(ac))
    print("WA x " + str(wa))
    print("TLE x " + str(tle))
    print("RE x " + str(re))

resolve()

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

int main(){
    int n;
    cin >> n;
    int a[n+1][4];
    for(int i=0;i<n;i++){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    long long dp[n+1][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<2;j++){
            dp[i][j]=0;
        }
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    for(int i=0;i<n;i++){
       for(int j=0;j<2;j++){
           dp[i+1][0]=max(dp[i][1],dp[i][2])+a[i+1][0];
           dp[i+1][1]=max(dp[i][0],dp[i][2])+a[i+1][1];
           dp[i+1][2]=max(dp[i][0],dp[i][1])+a[i+1][2];
       }
    }
    cout << max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]) << endl;
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
#include <functional>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
constexpr ll INF = 1LL << 60;


int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N;string S; cin >> N >> S;
  if(N&1){
    cout << "No" << endl;
  } else {
    for(int i = 0; i < N / 2; ++i) {
      if(S[i] != S[i + N / 2]) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String dow = sc.next();
        ArrayList<String> week = new ArrayList<>(Arrays.asList("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"));
        
        int result = 7 - week.indexOf(dow); 
        System.out.println(result);
    }
}


Measured memory_bytes: 35432
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<ll, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
P x[100010], y[100010];

class UnionFind {
private:
    static const int MAX = 100010;
    int par[MAX];
    int r[MAX];
public:
    UnionFind(int n = MAX) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            r[i] = 0;
        }
    }

    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (r[x] < r[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (r[x] == r[y]) r[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};
typedef pair<ll, P> PP;
ll solve() {
    sort(x, x+n);
    sort(y, y+n);

    vector<PP> vec;
    for (int i = 0; i < n-1; i++) {
        vec.push_back(PP(x[i+1].first - x[i].first, P(x[i+1].second, x[i].second)));
        vec.push_back(PP(y[i+1].first - y[i].first, P(y[i+1].second, y[i].second)));
    }

    sort(ALL(vec));
    UnionFind uf(n);
    ll res = 0;
    for (int i = 0; i < vec.size(); i++) {
        int a = vec[i].second.first;
        int b = vec[i].second.second;
        if (!uf.same(a, b)) {
            res += vec[i].first;
            uf.unite(a, b);
        }
    }
    return res;
}

void input() {
    cin >> n;
    int a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        x[i] = P(a, i);
        y[i] = P(b, i);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 11760
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define MOD 1000000007
typedef long long ll;
 
#include <stdlib.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
 
int main(){
	int n;
	scanf("%d", &n);
	int a[n];
	rep(i, n) scanf("%d", &a[i]);
	qsort(a, n, sizeof(int), compare_int);
    rep(i, n - 1){
    	if(a[i] == a[i + 1]){
    		printf("NO");
    		return 0;
    	}
    }
	printf("YES");
	return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int,int>
#define mii map<int,int>
#define mci map<char,int>
#define fir first
#define sec second
#define eline "\n"

bool f(string s) {
	int n = s.length();
	for(int i = 0; i < n / 2; ++i) 
		if(s[i] != s[n - i - 1]) return false;
	return true;
}

int main() {

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

	string s;
	cin >> s;
	
	if(!f(s)) cout << "No" << eline;
	else {
		int n = (s.length() - 1) / 2;
		if(!f(s.substr(0, n))) cout << "No" << eline;
		else {
			int j = (s.length() + 3) / 2;
			if(!f(s.substr(j - 1))) cout << "No" << eline;
			else cout << "Yes" << eline;
		}
	}
	
	return 0;
}


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

#define N 29
int c[ N ], v[ N ];
int main(){
    int n;
    cin >> n;

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

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

    int sum = 0;

    for( int i = 0; i < n; i++ ){
        if( v[ i ] - c[ i ] > 0 )
            sum += v[ i ] - c[ i ];
    }

    cout << sum << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> mini(n / 2), maxi(n / 2);
    for (int i = 0; i < n / 2; ++i) {
        mini[i] = a[i];
    }
    reverse(a.begin(), a.end());
    for (int i = 0; i < n / 2; ++i) {
        maxi[i] = a[i];
    }
    long long ans = maxi[0] - mini[0];
    for (int i = 1; i < n / 2; ++i) {
        ans += maxi[i - 1] - mini[i];
    }
    for (int i = 1; i < n / 2; ++i) {
        ans += maxi[i] - mini[i - 1];
    }
    if (n % 2 == 1) {
        ans += max(a[n / 2 - 1] - a[n / 2], a[n / 2] - a[n / 2 + 1]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
さっき割り当てた数字が残ってるのの下からj文字目
集めるdpにして、累積和で高速化する
*/

ll n,dp[3010],dp2[3010],mod=1e9+7,ans=0;
string s;

int main(void){
	cin>>n>>s;
	//
	rep(j,n)dp[j]=1;//最初の文字を1~nにする
	//
	rep(i,n-1){
		//通常の配るDP
		// rep(j,n)dp2[j]=0;
		// if(s[i]=='>'){
		// 	rep(j,n)reg(k,j+1,n-i-1)dp2[k-1]=(dp2[k-1]+dp[j])%mod;//詰める
		// }else{
		// 	rep(j,n)rep(k,j)dp2[k]=(dp2[k]+dp[j])%mod;
		// }
		// rep(j,n)dp[j]=dp2[j];
		//集めるDPにして累積和で計算量を縮めた
		dp2[0]=dp[0];
		reg(j,1,n-1)dp2[j]=(dp[j]+dp2[j-1])%mod;
		if(s[i]=='>'){
			rep(j,n){
				dp[j]=(dp2[n-1]-dp2[j]+mod)%mod;
			}
		}else{
			rep(j,n-1-i){//n-1-i文字残っている
				dp[j]=dp2[j];
			}
			reg(j,n-1-i,n-1){
				dp[j]=0;
			}
		}
	}
	rep(j,n)ans=(ans+dp[j])%mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

int c,n,m,s,d;

VV(pii) vv;


void mainmain(){
	while(cin>>c>>n>>m>>s>>d,c){
		vv=VV(pii)(n);
		s--;
		d--;
		rep(i,m){
			int a,b,t;
			cin>>a>>b>>t;
			a--;
			b--;
			vv[a].PB(pii(b,t));
			vv[b].PB(pii(a,t));
		}
		vvint dp;
		initvv(dp,n,c+1,-1);
		typedef pair<int,pii> P;
		priority_queue<P> pq;
		pq.push(mkp(0,pii(0,s)));
		while(pq.size()){
			P top=pq.top();
			pq.pop();
			if(dp[top.S.S][-top.S.F]>=0) continue;
			dp[top.S.S][-top.S.F]=-top.F;
			for(auto x:vv[top.S.S]){
				if(dp[x.F][-top.S.F+1]<0){
					pq.push(mkp(top.F-x.S/2,pii(top.S.F-1,x.F)));
				}
				if(dp[x.F][-top.S.F]<0){
					pq.push(mkp(top.F-x.S,pii(top.S.F,x.F)));
				}
			}
		}
		int ans=INF;
		rep(i,c+1){
			mins(ans,dp[d][i]);
		}
		cout<<ans<<endl;
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 1340
#define rep(i,n) for(int i=0;i<(n);++i)

#include<iostream>
#include<fstream>
#include<iomanip>

#include<vector>
#include<array>
#include<string>
#include<bitset>
#include<queue>
#include<list>

#include<utility>

#include<algorithm>
#include<cmath>
using ll = long long;
using namespace std;

int src(){
    string str;
    cin>>str;
    rep(i,str.size()){
        if(i%2==0){if(str[i]=='L'){cout<<"No";return 0;}}
        if(i%2==1){if(str[i]=='R'){cout<<"No";return 0;}}
    }
    cout<<"Yes";
    return 0;
}


int main(int argc,char* argv[]){
    //ifstream in( argv[1] );
    //cin.rdbuf(in.rdbuf());
    src();    
    return 0;
}

Measured memory_bytes: 256