akhauriyash/Code-Regression huggingface dataset:
#include<cassert>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<map>
#include<cmath>
//#include<>
using namespace std;

typedef long long ll;
#define rep(i,j) for(int i=0;i<j;i++)
#define rep_a_to(a,i,j) for(int i=a;i<=j;i++)
#define rev_rep(i,j) for(int i=j;i>=0;i--)

const int INF=1<<30;
//sumに区間部分加算総和、dataに区間全体各加算和を入れる
class Segment_Tree
{
public:
  int n;
  vector<int> data,sum;//data:区間の総和最小//sum:その対応区間全てに追加した和


  Segment_Tree(int n_)
  {
    n=1;
    while(n<n_)n*=2;
    data.resize(2*n-1,0);
    sum.resize(2*n-1,0);
  }

  //[a,b]にxを加算
  void add(int a,int b,int x)
  {
    add_getmin(a,b,x,0,0,n);
  }

  int get_min(int a,int b)
  {
    return get_min(a,b,0,0,n);
  }

private:
  //区間に追加してその区間の最小値を返す
  int add_getmin(int a,int b,int x,int k,int l,int r)
  {
    //目的範囲から完全に外れたら
    if(r<=a||b<=l)return data[k];
    //加算希望区間に収まっていたら
    if(a<=l && r<=b)
      {
	data[k]+=x;//区間全体に+xなので最小値はその区間最小値+x
	sum[k]+=x;
	return data[k];
      }
    //加算希望区間を含むなら
    else if(l<b && a<r)
      {
	//区間最小値は下の最小値にすでに足されていた値を足したもの
	return  data[k]=min(add_getmin(a,b,x,k*2+1,l,(l+r)/2),add_getmin(a,b,x,k*2+2,(l+r)/2,r))+sum[k];
      }
    assert(false);
  }
  //[a,b)の最小値,kは今の場所,[l,r)はkの守備範囲
  int get_min(int a,int b,int k,int l,int r)
  {
    //目的範囲から完全に外れたら
    if(r<=a||b<=l)return INF;
    //目的範囲より狭くなったら
    if(a<=l&&r<=b)return data[k];
    else {
      //左の子側の範囲
      int vl=get_min(a,b,k*2+1,l,(l+r)/2);
      //右の子側の範囲
      int vr=get_min(a,b,k*2+2,(l+r)/2,r);
      return min(vl,vr)+sum[k];
    }
  }

};

void debug_show(string str,Segment_Tree *ST,int n)
{

  cout<<str<<endl;
  cout<<"Sum ";
  rep(j,n)
    cout<<ST->get_min(j,j+1)<<" ";
  cout<<endl;
  cout<<"Min " ;
  rep(j,n)
    cout<<ST->get_min(j,n)<<" ";
  cout<<endl;
}

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

  //入力
  string str;cin>>str;

  Segment_Tree ST(n);
  
  rep(i,(int)str.size())
    {
      if(str[i]=='('){
	ST.add(i,n,1);
      }
      else
	ST.add(i,n,-1);
    }

  rep(i,q)
    {
      int flip;cin>>flip;
      flip--;
      if(str[flip]=='(')
	{
	  str[flip]=')';
	  int ans=str.find(')',0);
	  cout<<ans+1<<endl;
	  str[ans]='(';
	  ST.add(flip,n,-2);
	  ST.add(ans,n,+2);
	}
      else
	{
	  str[flip]='(';
	  ST.add(flip,n,+2);
	  /* 
	  int p=-1;
	  if(flip==n-1)p=flip;
	  else
	    do{p=str.find('(',p+1);}
	    while(ST.get_min(p,n)<2);
	  
	  */
	  //cout<<"bf "<<flip+1<<"changed"<<endl;
	  //debug_show(str,&ST,n);
	  
	  int p=0,e=n;
	  if(flip==n-1)p=flip;
	  else{
	    while(e>p+1){
	      if(ST.get_min((p+e)/2,n)<2)p=(p+e)/2;
	      else e=(p+e)/2;
	    }
	    p=str.find('(',p+1);
	  }
	  cout<<p+1<<endl;
	  str[p]=')';
	  ST.add(p,n,-2);
	  //puts("af");
	  //debug_show(str,&ST,n);

	}
    }


  return 0;
}

Measured memory_bytes: 9596
#include <iostream>
#include <string>

using namespace std;

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

	int q;
	cin >> q;

	string command;
	int a, b, p;
	for (int i = 0; i < q; i++){
		cin >> command >> a >> b;
		if (command == "print"){
			for (int i = a; i <= b; i++)
				cout << str[i];
			cout << endl;
		} else if (command == "reverse"){
			string cp = str;
			for (int i = 0; i <= b - a; i++){
				str[i + a] = cp[b - i];
			}
		} else if (command == "replace"){
			string p;
			cin >> p;
			for (int i = 0; i <= b - a; i++) {
				str[i + a] = p[i];
			}
		}
	}

	return 0;
}



Measured memory_bytes: 3200
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
x=int(input())
ans=0
di=make_divisors(x)
for i in di:
    if i==1:
        continue
    p=x
    while p%i==0:
        p=p//i
    q=x//p
    if p%i==1 or p==1:
        ans+=1
d=make_divisors(x-1)
print(ans+len(d)-1)

Measured memory_bytes: 39792
#include <stdio.h>

int a[111111], dy[111111];

int main(void)
{
	int n, i;

	scanf("%d", &n);
	for (i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	for (i = n; i >= 1; i--)
		if (i % 2 == 0)
			dy[1] -= a[i];
		else
			dy[1] += a[i];

	for (i = 2; i <= n; i++)
		dy[i] = -(dy[i - 1] - a[i-1]) + a[i-1];
	
	for (i = 1; i <= n; i++)
		printf("%d ", dy[i]);
	return 0;
}

Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    int n, t[100001], x[100001], y[100001];
    int i, dt, dist,dx,dy,dz;
    scanf("%d", &n);
    t[0] = x[0] = y[0] = 0;
    for (i=1; i<n+1; i++)
    {
        scanf("%d %d %d", &t[i], &x[i], &y[i]);
    }
 
    for (i=1; i<n+1; i++)
    {
        dt = t[i] - t[i-1];
        dx = x[i] - x[i-1];
        dy = y[i] - y[i-1];

        dist = abs(dx) + abs(dy);
        
        if(dist > dt){
            printf("No");
            return 0;
        }
        
        if(dist % 2 != dt % 2){
            printf("No");
            return 0;
        }
    }
 
        printf("Yes\n");

    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dictionary<string, int> dic = new Dictionary<string, int>();
            for (int i = 0; i < n; i++) {
                string s = new string(Console.ReadLine().ToArray().OrderBy(p => p).ToArray());
                if (dic.ContainsKey(s)) {
                    dic[s]++;
                } else {
                    dic[s] = 1;
                }
            }

            ulong ans = 0;
            foreach (var i in dic.Values) {
                if (i >= 2) {
                    for (int j = 1; j < i; j++) {
                        ans += (ulong)j;
                    }
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 31116
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}

typedef struct ListKey {
    int num;
} ListKey;
bool listkey__equal(ListKey *a, ListKey *b) {
    return a->num == b->num;
}
typedef struct ListDat {
    ListKey key;
    struct ListDat *prev;
    struct ListDat *next;
} ListDat;
typedef struct List {
    size_t len;
    ListDat *hdr;
} List;
#define list_init(l) ((l) ? ((l)->len = 0, (l)->hdr = NULL) : 0)
#define list_len(l) ((l) ? (l)->len : 0)
#define list_delete_first(l) ((l)->len ? list__delete((l), (l)->hdr->next) : 0)
#define list_delete_last(l) ((l)->len ? list__delete((l), (l)->hdr->prev) : 0)
void list_insert(List *l, ListKey x) {
    ListDat *new_dat = malloc(sizeof(ListDat));
    if(l->len) {
        new_dat->next = l->hdr->next;
        l->hdr->next->prev = new_dat;
        l->hdr->next = new_dat;
    } else {
        l->hdr = malloc(sizeof(ListDat));
        l->hdr->prev = l->hdr->next = new_dat;
        new_dat->next = l->hdr;
    }
    new_dat->key = x;
    new_dat->prev = l->hdr;
    l->len++;
}
void list__delete(List *l, ListDat *a) {
    a->prev->next = a->next;
    a->next->prev = a->prev;
    free(a);
    l->len--;
}
void list_delete(List *l, ListKey x) {
    for(ListDat *it = l->hdr->next; it != l->hdr; it = it->next) {
        if(listkey__equal(&x, &it->key)) {
            list__delete(l, it);
            break;
        }
    }
}
void list_print(List *l) {
    for(ListDat *it = l->hdr->next; it != l->hdr->prev; it = it->next) {
        put_uint(it->key.num);
        putchar_unlocked(' ');
    }
    put_uint(l->hdr->prev->key.num);
    putchar_unlocked('\n');
}
int main(int argc, char **argv) {
    int n = get_uint();
    List l;
    list_init(&l);
    for(int i = 0; i < n; ++i) {
        char str[16];
        get_str(str);
        if(strlen(str) == 6 && strncmp(str, "insert", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_insert(&l, key);
        } else if(strlen(str) == 6 && strncmp(str, "delete", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_delete(&l, key);
        } else if(strlen(str) == 11 && strncmp(str, "deleteFirst", 11) == 0) {
            list_delete_first(&l);
        } else if(strlen(str) == 10 && strncmp(str, "deleteLast", 10) == 0) {
            list_delete_last(&l);
        }
    }
    list_print(&l);
    return 0;
}



Measured memory_bytes: 32852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll sc(ll nowx, ll nowy, ll nowz, ll x, ll y, ll z)
{
    return abs(nowx + x) + abs(nowy + y) + abs(nowz + z);
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> x(n);
    vector<ll> y(n);
    vector<ll> z(n);
    rep(i, n) cin >> x[i] >> y[i] >> z[i];

    ll ans = 0;
    rep(i, 8)
    {
        vector<ll> v(n);

        // cout << i << endl;
        // cout << ((i & 1) == 1) << (i & 2) << (i & 4) << endl;

        rep(j, n)
        {
            ll s = 0;
            if ((i & 4) == 4)
            {
                s += x[j];
            }
            else
            {

                s -= x[j];
            }
            if ((i & 2) == 2)
            {

                s += y[j];
            }
            else
            {

                s -= y[j];
            }
            if ((i & 1) == 1)
            {
                s += z[j];
            }
            else
            {
                s -= z[j];
            }
            v[j] = s;
        }

        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());

        ll sum = 0;
        rep(k, m)
        {
            sum += v[k];
        }
        chmax(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

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

long long gcd(long long a,long long b){
    if(a < b)swap(a,b);
    if(b == 0)return a;
    if(a%b==0)return b;
    else return gcd(b, a % b);
}

int pf(long long n) {
  map<long long,int>p;
  for (long long i = 2; i*i <= n; i++) {
    if (n%i !=0) continue;
    p[i]++;
    while (n%i == 0) {
      n = n / i;
      p[i]++;
    }
    //cout<<i<<endl;
  }
  if (n != 1) p[n]++;
  return p.size();
}

int main(){
  long long A,B,temp,ans;
  cin>>A>>B;
  ans=0;
  temp=gcd(A,B); //A,Bの最大公約数を計算 
  //cout<<"gcd"<<temp<<endl;
  auto f=pf(temp);
  ans=f+1;
  cout<<ans<<endl;
  //for(auto i=0;i<f.size();i++){
  //  cout<<f[i].first<<" "<<f[i].second<<endl;
  //}
      
  return 0;
}

  
  




 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#pragma warning(disable:4996)
int main() {
	long long n; cin >> n;
	for (long long i = 1; i <= 60000; i++) {
		long long P = i*(i + 1) / 2;
		if (P >= n) { cout << i << endl; break; }
	}
	return 0;
}

Measured memory_bytes: 256
# ABC098B - Cut and Count
import collections

n = int(input())
s = input().rstrip()
count = 0
answer = 0
lst = [i for i in s]

if collections.Counter(lst) == 1:
    print(1)
else:
    for i in range(1, n):
        count = 0
        lst_sub1 = lst[:i]
        lst_sub2 = lst[i:]

        set_sub1 = set(lst_sub1)
        set_sub2 = set(lst_sub2)

        for j in set_sub1:
            if j in set_sub2:
                count += 1
        answer = max(answer, count)

    print(answer)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
typedef long long ll; 

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> s(H);
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}

	vector<bool> r(H, false);
	vector<bool> c(H, false);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '#') {
				r[i] = true;
				c[j] = true;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		if (!r[i]) continue;

		for (int j = 0; j < W; j++) {
			if (!c[j]) continue;

			cout << s[i][j];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
x = list(map(int, input().split()))

dis = 300000000

for i in range(N-K+1):
    disl = abs(x[i]) + abs(x[i+K-1]-x[i])
    disr = abs(x[i+K-1]) + abs(x[i+K-1]-x[i])

    dis = min(dis, disl, disr)
#    if (y[0]*y[-1]<0):
#        disy = y[-1]-y[0]+min(abs(y[-1]), abs(y[0]))
#    else:
#        disy = max(abs(y[0]), abs(y[-1]))
#    dis = min(dis, disy)

print(dis)

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;
vector<long long> c, u;
vector<int> v[10010];

void dfs(int curr, int prev) {
    u.emplace_back(curr);
    for (auto x: v[curr]) {
        if (x == prev) continue;
        dfs(x, curr);
    }
    return;
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        v[a].emplace_back(b);
        v[b].emplace_back(a);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long d; cin >> d;
        c.emplace_back(d);
        ans += d;
    }
    sort(c.rbegin(), c.rend());
    ans -= c[0];
    vector<int> q(n);
    dfs(0, -1);
    for (int i = 0; i < n; i++) {
        q[u[i]] = c[i];
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << q[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define lp(i,n) for(int i=0;i<(n);i++)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define CTOI(x) (x - 'A') 
#define ctoi(x) (x - 'a')
#define BIT(x) (1 << (x))
#define int long long
using namespace std;

signed main(){
    string a;
    cin >> a;
    cout << (a[0]==a[2]?"Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

def bfs(colors, links):
    q = deque([(0, 0)])
    
    while q:
        v, current = q.popleft()

        for next_v, distance in links[v]:
            if colors[next_v] != -1: continue
        
            if (current+distance) % 2 == 0:
                colors[next_v] = 0
            else:
                colors[next_v] = 1

            q.append((next_v, current + distance))
        
def solve():
    N = int(input())
    A = [list(map(int, input().split())) for _ in range(N-1)]
    cs = [-1] * N
    cs[0] = 0

    links = [[] for _ in range(N)]
    for u, v, w in A:
        v -= 1
        u -= 1
        links[v].append((u, w))
        links[u].append((v, w))

    bfs(cs, links)

    print('\n'.join(map(str, cs)))

solve()

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int std_in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};
const int MOD = 1000000007;

signed main(){
    int A[3][3];
    REP(i, 3) REP(j, 3) cin >> A[i][j];
    int N, b;
    cin >> N;
    vector<int> B;
    REP(i, N){
        cin >> b;
        B.push_back(b);
    }
    REP(i, 3){
        REP(j, 3){
            for(int b : B){
                if(A[i][j] == b) A[i][j] = 0;
            }
        }
    }
    REP(i, 3){
        if(A[i][0] + A[i][1] + A[i][2] == 0){
            PRINT("Yes");
            return 0;
        }
    }
    REP(j, 3){
        if(A[0][j] + A[1][j] + A[2][j] == 0){
            PRINT("Yes");
            return 0;
        }
    }
    if(A[0][0] + A[1][1] + A[2][2] == 0 || A[0][2] + A[1][1] + A[2][0] == 0){
        PRINT("Yes");
        return 0;
    }
    PRINT("No");
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd(int a, int b)
{
    if(b == 0) {
        return a;
    }

    return gcd(b, a%b);
}

int main()
{
    int N;
    int A1;
    int A2;
    int i;

    scanf("%d", &N);
    scanf("%d", &A1);
    for(i = 1; i < N; i++) {
        scanf("%d", &A2);
        A1 = gcd(A1, A2);
    }

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

    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int K, N, ans=0;
	int A[200005];

	cin >> K >> N;
	rep(i,N) cin >> A[i];
	A[N] = A[0] + K;

	int mx = 0;
	rep(i,N) chmax(mx, A[i+1] - A[i]);

	ans = K - mx;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int K = sc.nextInt();

        int[] P = new int[N];
        for (int i = 0; i < N; i++) P[i] = sc.nextInt();

        int[] sortedFrom = new int[N];
        sortedFrom[0] = 0;

        for (int i = 1; i < N; i++) {
            if (P[i] < P[i - 1]) sortedFrom[i] = i;
            else sortedFrom[i] = sortedFrom[i - 1];
        }

        int[] min = new int[N];     // minimum of last k
        int[] max = new int[N];     // maximum of last k

        Deque<Integer> queue = new ArrayDeque<>();

        for (int i = 0; i < K; i++) {
            while (!queue.isEmpty() && P[i] > P[queue.peekLast()]) queue.pollLast();
            queue.addLast(i);
        }

        for (int i = K; i < N; i++) {
            max[i - 1] = P[queue.peekFirst()];
            while (!queue.isEmpty() && queue.peekFirst() <= i - K) queue.pollFirst();
            while (!queue.isEmpty() && P[i] > P[queue.peekLast()]) queue.pollLast();
            queue.addLast(i);
        }

        max[N - 1] = P[queue.peekFirst()];

        queue = new ArrayDeque<>();

        for (int i = 0; i < K; i++) {
            while (!queue.isEmpty() && P[i] < P[queue.peekLast()]) queue.pollLast();
            queue.addLast(i);
        }

        for (int i = K; i < N; i++) {
            min[i - 1] = P[queue.peekFirst()];
            while (!queue.isEmpty() && queue.peekFirst() <= i - K) queue.pollFirst();
            while (!queue.isEmpty() && P[i] < P[queue.peekLast()]) queue.pollLast();
            queue.addLast(i);
        }

        min[N - 1] = P[queue.peekFirst()];

        int sol = 0;
        for (int i = K - 1; i < N; i++) {
            if (i - sortedFrom[i] >= K - 1) {
                sol = 1;
                break;
            }
        }
        int i = 0;

        while (i + K - 1 < N) {
            if (sortedFrom[i + K - 1] <= i) {
                i++;
                continue;
            }
            if (P[i] != min[i + K - 1]) {
                sol++;
                i++;
                continue;
            }
            if (i + K >= N) {
                sol++;
                break;
            }
            if (P[i + K] != max[i + K]) {
                sol++;
                i++;
                continue;
            }
            i++;
        }

        System.out.println(sol);
    }
}


Measured memory_bytes: 88712
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val a = scn.nextInt()
	val b = scn.nextInt()
	val m = scn.nextInt()
	val fs = IntArray(a){scn.nextInt()}
	val ms = IntArray(b){scn.nextInt()}
	var min = fs.min()!! + ms.min()!!
	repeat(m){
		val fr = fs[scn.nextInt()-1]
		val mw = ms[scn.nextInt()-1]
		min = Math.min(min, fr+mw-scn.nextInt())
	}
	print(min)
}

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

int cmp(const void *a, const void *b){

    return strcmp(a, b);
}

int main(){

    int x, y;
    scanf("%d %d", &x, &y);
    char nome[x][y+1];
    for(int i = 0; i < x; ++i){
        scanf(" %s", nome[i]);
    }

    qsort(nome, x, sizeof(nome[0]), cmp);

    for(int i = 0; i < x; ++i){
        printf("%s", nome[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
struct dama
{
    /* data */
    double x;
    string kind;
};
#define oneBTC 380000.0

int main(void)
{
    int N;
    cin >> N;
    dama *data;
    data = new dama[N];
    urept(i, 0, N)
    {
        cin >> data[i].x >> data[i].kind;
    }
    double sum = 0.0;
    urept(i, 0, N)
    {
        if (data[i].kind == "JPY")
        {
            sum += data[i].x;
        }
        else
        {
            sum += data[i].x * oneBTC;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n, y;
int main(){
  cin >> n >> y;
  for(int i=0; i<=n; i++){
    for(int j=i; j<=n; j++){
        if(10000*i + 5000*(j-i) + 1000*(n-j) == y){
          cout << i << ' ' << j-i << ' ' << n-j << endl;
          return 0;
          }
      }
    }
  cout << "-1 -1 -1" << endl;
  return 0;
  }

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

int main(){
  
  int n;
  cin >> n;
  
  n%=10;
  
  if(n==0 ||n==1 || n==6 || n==8) cout << "pon" << endl;
  else if(n==3) cout << "bon" << endl;
  else cout << "hon" << endl;
  
  
}
  
  
  
  


Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

int N;
vector<int> p;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  p.resize(N);
  for (int i = 0; i < N; i++) {
    int pi;
    cin >> pi;
    pi--;
    p[i] = pi;
  }

  int ans = 0;
  int i = 0;
  while (i < N) {
    if (i != p[i]) {
      i++;
      continue;
    }

    int num = 0;
    while (i < N && i == p[i]) {
      i++;
      num++;
    }

    if (num % 2 == 0) {
      ans += (num / 2);
    } else {
      ans += (num / 2) + 1;
    }
  }

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

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>

using namespace std;

vector<int> ps;

int isprime(int n){
	vector<int>::iterator it;
	for(it=ps.begin();it!=ps.end();it++){
		if(n%(*it) == 0) return 0;
		if(n <= (*it)*(*it)) break;
	}
	ps.push_back(n);
	return 1;
}

int main(){
	int n;
	ps.push_back(2);
	while(scanf("%d", &n)!=EOF){

		int c=0;
		int last=2;
		for(vector<int>::iterator it=ps.begin();it!=ps.end();it++){
			if((last = *it) <= n) c++;
		}

		for(int i=last+1;i<=n;i++){
			if(i&1 && isprime(i)) c++;
		}

		printf("%d\n", c);
	}
}

Measured memory_bytes: 1236
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, D = get_ints

x = 2 * D + 1
waru = N / x
amari = N % x

puts waru + ((amari > 0) ? 1 : 0)


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

int main(){
  int a[10];
  int b = 0;
  for(int i = 0; i < 6; i++)cin>>a[i];

    for(int i = 0; i < 5; i++){
      for(int j = 0; j < 5; j++){
        b = max(b, abs(a[i]-a[j]));
        /*
        cout<<"b = "<<b<<endl;
        cout<<"a[6] = "<<a[5]<<endl;
        cout<<"abs = "<<abs(a[i]-a[j])<<endl;
        if(b <= a[5]){
          cout<<abs(a[i]-a[j])<<"Yay!"<<endl;
        }else{
          cout<<abs(a[i]-a[j])<<":("<<endl;
        }
        */
      }
    }


  if(b <= a[5]){
    cout<<"Yay!"<<endl;
  }else{
    cout<<":("<<endl;
  }
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

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

int sum[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, q;
	string s;
	cin >> n >> q >> s;
	sum[0] = 0;
	rep(i, n){
		sum[i + 1] = sum[i];
		if(i && s[i] == 'C' && s[i - 1] == 'A') sum[i + 1]++;
	}
	while(q--){
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l] << endl;
	}
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'

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

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

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;

ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
int main() {

    ull X=in<ull>();
    ull Y=in<ull>();
    //debug(double(Y)/X);
    ull temp;temp=Y/X;
    ull ans;
    while(temp>=2){
        ans++;
        temp/=2;
    }
    ans++;
    print(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

long long int maximum_path(std::vector<std::vector<long long int> > &G, std::vector<long long int> &dp_table, long long int start);

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

  std::vector<std::vector<long long int> > G(N);
  long long int tmp_f, tmp_t;
  
  for(int i = 0; i < M; i++){
    scanf("%lld%lld", &tmp_f, &tmp_t);
    G[tmp_f-1].push_back(tmp_t-1);
  }
  
  // solve problem
  std::vector<long long int> dp_table;
  for(long long int i = 0; i < N; i++){
    dp_table.push_back(-1);
  }
  
  long long int ans = 0;
  for(long long int i = 0; i < N; i++){
    ans = std::max(ans, maximum_path(G, dp_table, i));
  }
  
  std::cerr << "Answer: " << std::endl;
  std::cout << ans << std::endl;
  return 0;
}

long long int maximum_path(std::vector<std::vector<long long int> > &G, std::vector<long long int> &dp_table, long long int start){
  // if the point have been already tested
  if(dp_table[start] >= 0){
    return dp_table[start];
  }
  // if there is no path starting from start
  if(G[start].size() == 0){
    dp_table[start] = 0;
    return 0;
  }
  // if there are edges starting from start
  else{
    long long int tmp = 0;
    for(long long int i = 0; i < G[start].size(); i++){
      tmp = std::max(tmp, maximum_path(G, dp_table, G[start][i])+1);
    }
    dp_table[start] = tmp;
    return tmp;
  }
}


Measured memory_bytes: 9332
n = int(input())
s = list()
count = 0
oa = 0
bo = 0
ba = 0
for i in range(0,n):
    s.append(str(input()))
    count += s[i].count("AB")
    if s[i][0] == "B":
        if s[i][-1] == "A":
            ba += 1
        else:
            bo += 1
    elif s[i][-1] == "A":
        oa += 1

if ba > 0:
    count += ba-1
    if oa > 0:
        count += 1
        oa -=1
    if bo >0:
        count += 1
        bo -=1
    count += min(oa,bo)
elif ba == 0:
    count += min(oa,bo)
print(count)

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX 1000000000
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 10010010010001;
vector<vector<int>> graph;
vector<vector<bool>> reached;


int main(){
    int N,M;
    cin >> N >> M;
    cout << (1900*M+100*(N-M))*pow(2,M) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=1e9+5;
const int N=2e5+5;
const ll oo=1e18+5;
const ll mod=1e9+7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	double r;
	cin>>r;
	r=2*r*3.141592654;
	cout<<fixed<<setprecision(8)<<r;
	return 0;
}


Measured memory_bytes: 3764
#include<stdio.h>
int main()
{
    int a[5],max=0,i;
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }
    int t;
    for(i=0;i<5;i++)
    {
        if(max<(10-(a[i]%10))&&a[i]%10!=0)
        {
            max=10-(a[i]%10);
            t=i;
        }
    }
    int sum=0;
    for(i=0;i<5;i++)
    {
        if(i!=t)
        {
            if(a[i]%10!=0)
            {
                sum=sum+a[i]+(10-a[i]%10);
            }
            else
            {
                sum=sum+a[i];
            }
        }
        else
        {
            sum+=a[i];
        }
    }
    printf("%d",sum);
}


Measured memory_bytes: 1720
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1,n-1):
    if min(p[i-1:i+2]) != p[i] and max(p[i-1:i+2]) != p[i]:
        ans += 1

print(ans)




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

int main(){

    int n,m;
    cin >> n >> m;
    vector<int> a(n+1,0);
    int mod=1000000007;

    rep(i,m){
        int t;
        cin >> t;
        a[t]=-1;
    }
    a[0]=1;
    if(a[1]!=-1){
        a[1]=1;
    }

    for(int i=2;i<=n;i++){
        if(a[i]==-1)continue;
        if(a[i-2]!=-1){
            a[i]+=a[i-2];
        }
        if(a[i-1]!=-1){
            a[i]+=a[i-1];
        }
        a[i]%=mod;
    }

    cout << a.back() << endl;


    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int mx = 5500;
string str;
string num[mx*5];
bool cmp(string a,string b)
{
    int len=min(a.length(),b.length());
    for(int i=0;i<len;i++){
        if(a[i]!=b[i])
            a[i]<b[i];
    }
    if(a.length()<b.length())
        return a<b;
    else
        return a>b;
}
int main()
{
    int k;
    while(cin>>str){
        cin>>k;
        int len=str.length();
//        char sign='z';
//        for(int i=0;i<len;i++)
//            if(str[i]<sign)
//                sign=str[i];
        int cont=0;
        for(int i=0;i<len;i++){
            string s="";
            s=s+str[i];
            num[cont++]=s;
            for(int j=1;j<=4;j++){
                if(i+j<len){
                    s=s+str[i+j];
                    num[cont++]=s;
                }
            }
        }
//        cout<<cont<<endl;
        sort(num,num+cont);
//        for(int i=0;i<cont;i++)
//            cout<<num[i]<<endl;
        int tmp=unique(num,num+cont)-num;
//        for(int i=0;i<cont;i++)
//            cout<<"       "<<num[i]<<endl;
        cout<<num[k-1]<<endl;
    }
    return 0;
}


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

int main() {

    int N;
    cin>>N;
    vector <int> a(N);
    for(int i=0;i<N;i++) {
        cin >> a.at(i);
    }
    int sum=0;
    for(int i=0;i<N;i++){
        sum += (a.at(i)-1);
    }

    cout<<sum;




    return 0;
}



Measured memory_bytes: 256
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a_ls = list(map(int, input().split()))
a_csum = [0] * n
now = 0
for i in range(n):
    now += a_ls[i]
    a_csum[i] = now
a_csum.append(0)
a_csum.sort()
ans = 0
now = 0
for i in range(n):
    if a_csum[i] == a_csum[i+1]:
        now += 1
    else:
        if now > 0:
            ans += combinations_count(now+1,2)
        now = 0
if now > 0:
    ans += combinations_count(now+1,2)
print(ans)


Measured memory_bytes: 32796
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#define LL long long

using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}

inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

inline void read(LL &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}

 int n,a[100010];

int main()
{
	cin>>n;
    int x=0,y=0,ans=0;
    memset(a,0,sizeof(a));
    while(n--)
    {
        cin>>y;
        if(a[y]) x++;else a[y]++,ans++;
    }
    if(x%2) ans--;
    cout<<ans<<endl;
}

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

int A, B;

int main() {
    cin >> A >> B;
    if (A == 1) A += 13;
    if (B == 1) B += 13;

    string ans = "Draw";
    if (A > B) {
        ans = "Alice";
    } else if (B > A) {
        ans = "Bob";
    }

    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  N--;
  int B[N];
  int A = 0;
  
  for(int i = 0; i < N; ++i){
    cin >> B[i];
  }
  
  A += B[0] + B[N - 1];
  for(int i = 1; i < N; ++i){
    A += min(B[i - 1],B[i]);
  }
  cout << A << endl;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextLong() }.toLongArray()
   
  val mod = 1_000_000_000 + 7

  var sum = 0L
  for (ai in a) {
    sum += ai
    sum %= mod
  }

  var ans = 0L
  for (i in 0 until n) {
    sum -= a[i]
    if (sum < 0) sum += mod

    ans += a[i] * sum
    ans %= mod
  }

  println(ans)

}


Measured memory_bytes: 67244
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<list>
#include<deque>
#include<cmath>
#include<unordered_map>
#include<unordered_set>
#include<numeric>
using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<endl


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"


///////////////////////////////////////////////////////////////////////////

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

	ll N;
	cin >> N;

	ll ans = 1;
	for (ll i = 1; i <= N; ++i) {
		ans *= i;
		ans %= 1000000007;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

using ll = long long;

ll N;
ll A[100010], B[100010];
ll ans;

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

  rep( i, N )
    std::cin >> A[i] >> B[i];

  ll sum = 0;

  repd( i, N )
  {
    ll r = (A[i]+sum)%B[i];

    if( !r )
      continue;

    ll rest = B[i]-r;

    sum += rest;

    ans += rest;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 1792
main = getContents >>= putStr.unlines.(\xs -> [fst x | x<-xs, fst x /= ""]).(\(x:_:xs) -> (scanl (flip ($)) ("",x) $map (f.words) xs) ).lines
    where f ("print":a:b:_)     (_,s) = (between a b s, s)
          f ("reverse":a:b:_)   (_,s) = ("", g a b s $reverse (between a b s))
          f ("replace":a:b:p:_) (_,s) = ("", g a b s p)
          r = read
          g a b s t = take (r a) s ++ t ++ drop ((r b)+1) s
          between a b = (take $(r b)-(r a)+1).drop (r a)

Measured memory_bytes: 5520
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

using namespace std;

int main(void) {
	string s;
	cin >> s;
	int c = 0;
	for (int i = 2; i < s.size(); i += 2) {
		if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
			c = i;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	long long n,l;
	cin >> n;
	cin >> l;
	vector<string> s (n);
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		s[i].erase(l);
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++)
	{
		cout << s[i];
	}

	return 0;
}

Measured memory_bytes: 256
S = input()
L = []
R = []
rev = 0
for _ in range(int(input())):
    A = input().split()
    if A[0] == "1":
        rev ^= 1
    else:
        if (int(A[1]) ^ rev) & 1:
            L.append(A[2])
        else:
            R.append(A[2])

if rev:
    print("".join(R[::-1]) + S[::-1] + "".join(L))
else:
    print("".join(L[::-1]) + S + "".join(R))

Measured memory_bytes: 6268
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	string s;
	while (true) {
		cin >> s;
		if (s == "-") break;
		int n; cin >> n;
		int sum = 0;
		int len_s = len(s), t;
		rep(i, 0, n) {
			cin >> t;
			sum += t;
		}
		sum = sum % len_s;
		if (sum == 0) P(s);
		else {
			t = sum;
			P(s.substr(t) + s.substr(0, t));
		}
	}
	return 0;
}

Measured memory_bytes: 3180
import java.util.*;

public class Main {
	public  static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	double a = sc.nextInt();
	double b = 1/a;
	double c = Math.ceil(a/2);
	double d = b * c;

	System.out.println( d );
	}
}

Measured memory_bytes: 23764
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    w=[chomp(readline()) for i in 1:n]
    ans="Yes"
    for i in 2:n
        if w[i][1]!=w[i-1][end]
            ans="No"
        end
        for j in 1:i-1
            if w[i]==w[j]
                ans="No"
            end
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 111640
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    W, H, N = map(int, input().split())
    field = [[0] * W for _ in range(H)]
    for _ in range(N):
        x, y, a = map(int, input().split())
        min_y, max_y, min_x, max_x = 0, H, 0, W
        if a == 1:
            max_x = x
        elif a == 2:
            min_x = x
        elif a == 3:
            max_y = y
        elif a == 4:
            min_y = y

        for y in range(min_y, max_y):
            for x in range(min_x, max_x):
                field[y][x] = 1

    ans = 0
    for y in range(H):
        for x in range(W):
            ans += (field[y][x] == 0)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4072
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	string S;
	cin >> S;
	int G = 0;
	int P = 0;
	int answer = 0;
	for(int i = 0;i < S.size();i++) {
		if(S.at(i) == 'g') {
			if(G > P) {
				P++;
				answer++;
			}
			else {
				G++;
			}
		}
		if(S.at(i) == 'p') {
			if(G > P) {
				P++;
			}
			else {
				G++;
				answer--;
			}
		}
	}
	cout << answer << endl;
}

Measured memory_bytes: 512
M=1000003
f=[1]
for i in range(1,M):f.append(f[i-1]*i%M)
for _ in'_'*int(input()):
	x,d,n=map(int,input().split())
	t=x*pow(d,M-2,M)%M
	if d==0:
		print(pow(x,n,M))
	elif 0<t<=M-n:
		print(f[t+n-1]*pow(f[t-1],M-2,M)*pow(d,n,M)%M)
	else:
		print(0)


Measured memory_bytes: 45284
using System;
using System.Diagnostics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int K = cin.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = cin.nextInt();
            y[i] = cin.nextInt();
        }

        long ans = long.MaxValue;

        for (int xl = 0; xl < N; xl++)
        {
            for (int xr = 0; xr < N; xr++)
            {
                for (int yl = 0; yl < N; yl++)
                {
                    for (int yr = 0; yr < N; yr++)
                    {
                        long L = x[xl];
                        long R = x[xr];
                        long U = y[yl];
                        long D = y[yr];
                        int cnt = 0;
                        for (int i = 0; i < N; i++)
                        {
                            if (x[i] >= L && x[i] <= R && y[i] >= U && y[i] <= D) cnt++;
                        }
                        if(cnt >= K)
                        {
                            ans = Math.Min(ans, (D - U) * (R - L));
                        }
                    }
                }
            }
        }

        Console.WriteLine(ans);

    }
    
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}




Measured memory_bytes: 13140