akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
    int key;
    struct node *prev,*next;
};
typedef struct node node;


node *head;

void init(){
head=(node *)malloc(sizeof(node));
head->prev=head;
head->next=head;
}

void insert(int y){
    node *x;
    x=(node *)malloc(sizeof(node));
    x->key=y;
    
    x->next=head->next;
    head->next->prev=x;
    head->next=x;
    x->prev=head;
}


node* listsearch(int num){
    node *cur = head->next;
while(cur!=head&&cur->key!=num){
    cur=cur->next;
    }   
return cur;
}


void delete(node *z){
    if(z==head)return;
    z->prev->next=z->next;
    z->next->prev=z->prev;
    free(z);
}

void deleteFirst(){
  delete(head->next);  
}

void deleteLast(){
    delete(head->prev);
}

void deletekey(int num){
   node *a;
   a=listsearch(num);
    delete(a);
}


int main(){
  int num,n,i,j=1;
  char sel[20];
  node *sel2;
  scanf("%d",&n);
  init();
  for (i=0;i<n;i++){
    scanf("%s",sel);

    if (sel[0]=='i') {
        scanf("%d",&num);
        insert(num); 
    }
    else if(sel[0]=='d') {
      if(strlen(sel)>6){
	    if (sel[6]=='F') deleteFirst();
	    else if(sel[6]=='L') deleteLast();
      }
      else {
        scanf("%d",&num);
        deletekey(num);
      } 
    }
  }
  sel2=head->next;
  while(1){
    if (sel2==head) break;
    if (j==0)printf(" ");
    printf("%d",sel2->key);
    sel2=sel2->next;
    j= 0;
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 32948
#include<bits/stdc++.h>
using namespace std;
string s;
int x=0x7fffff,y;
int main()
{
    cin>>s;
    for(int i = 0;i < s.size();i++)
    {
        if(s[i]=='C'){x=min(i+1,x);}
        if(s[i]=='F'){y=max(i+1,y);}
    }
    if((x)&&(y)&&(x<y))
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef double ld;
#define MAX (1LL << 63LL) - 1LL
#define MIN (-1LL) * (1LL << 63LL) + 1LL

ll n;
ll a[200010][10];
ll on = MIN, tw = MIN, th = MIN, fo = MIN;

int main(void)
{
	scanf("%lld", &n);
	
	for(ll i = 1 ; i <= n ; i++)
	{
		scanf("%lld %lld", &a[i][0], &a[i][1]);
		on = max(on, a[i][0] + a[i][1]);
		tw = max(tw, a[i][0] - a[i][1]);
		th = max(th, -a[i][0] - a[i][1]);
		fo = max(fo, -a[i][0] + a[i][1]);
	}
	
	printf("%lld", max(on + th, tw + fo));
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  int W[N];
  for(int i=0;i<N;i++){
    cin>>W[i];
  }
  int total=0;
  for(int i=0;i<N;i++){
    total=total+W[i];
  }
  int ans=10000;
  for(int i=1;i<N;i++){
    int temp=0;
    for(int j=0;j<i;j++){
      temp=temp+W[j];
    }
    ans=min(ans,abs((total-temp)-temp));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main (){
    FastIO
    lld dda[3][3];
    lld i,j,n,r,k;
    foi(i,3){
    	foi(j ,3){
    		cin >> dda[i][j];
    	}
    }
    cin >> n;
    foi(k,n){
    	cin >> r;
    	foi(i,3){
    		foi(j, 3){
    			if (dda[i][j] == r)
    				dda[i][j] = -1;
    		}
    	}
    }
    lld f;
    foi(i,3){
    	f=0;
    	foi(j,3){
    		if (dda[i][j] == -1){
    			f+=1;
    		}
    	}
    	if (f == 3){
    		break;
    	}
    }
    if (f == 3)
    			cout << "Yes" << "\n";
    else{
    	foi(j,3){
    		f=0;
    		foi(i,3){
    			if (dda[i][j] == -1){
    				f+=1;
    			}
    		}
    		if (f == 3){
    			break;
    		}
    	}
    	if (f == 3)
    				cout << "Yes" << "\n";
    	else{
    			if (dda[0][0] == -1 && dda[1][1] == -1 && dda[2][2] == -1)
    				cout << "Yes" << "\n";
    		else{
    			if (dda[0][2] == -1 && dda[1][1] == -1 && dda[2][0] == -1)
    				cout << "Yes" << "\n";
    			else
    				cout <<  "No" << "\n";
    		}
    	}
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int c[5000];
int d[5000];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",c+i);
	for(int i=0;i<b;i++)scanf("%d",d+i);
	int ret=0;
	for(int i=0;i<b;i++){
		int at=0;
		for(int j=i;j<b;j++){
			while(at<a&&c[at]!=d[j])at++;
			if(at>=a)break;
			at++;
			ret=max(ret,j-i+1);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 0
def insertionSort(A, n, g):
    cnt = 0
    for i in xrange(g, n, 1):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
    return cnt

def shellSort(A, n):
    cnt = 0
    G = [1]
    i = 0
    while G[i] * 3 + 1 <= n:
        G.append(G[i] * 3 + 1)
        i += 1
    G.reverse()
    m = len(G)
    print m
    print ' '.join(map(str, G))
    for x in G:
        cnt += insertionSort(A, n, x)
    return cnt

N = int(raw_input())
A = [int(raw_input()) for i in xrange(N)]
cnt = shellSort(A, N)
print cnt
for i in A:
    print i

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

using namespace std;
typedef long long ll;
    
int main()
{
    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	string s;
	cin>>s;
	int sum=0;
	forn(i,0,s.size()){
		sum+=s[i]-'0';
	}
	if (sum%9==0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3704
import math

n, k = map(int, input().split())

if n == 0:
    print(1)
    exit()

ans = math.log(n, k)
# ans = math.ceil(ans)
# print(ans)

# if isinstance(ans, int):
if ans.is_integer():
    print(int(ans+1))
else:
    print(math.ceil(ans))

Measured memory_bytes: 38512
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import deque
def main():
    X=input()
    stack=deque()
    for x in X:
        if x=='S' or (x=='T' and (not stack or stack[-1]=='T')):
            stack.append(x)
        elif stack and stack[-1]=='S':
            stack.pop()
    print(len(stack))
if __name__=='__main__':
    main()

Measured memory_bytes: 5092
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n;cin>>n;
  if(n%2)cout<<0<<endl;
  else{
    ll ans=0;
    while(n>0){
      ans+=(n/5)/2;
      n/=5;
    }
    cout<<ans<<endl;
  }
}



Measured memory_bytes: 3616
#include <iostream>
#include <vector>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    for(int i =0 ; i < N; i++){
        cin >> A[i];
        A[i]--;
    }
    long long ans = 0;
    while(K > 0){
        vector<long long> B(N);
        for(int i = 0; i < N; i++) B[i] = A[A[i]];
        if(K & (1 << 0)){
            ans = A[ans];
        }
        K >>= 1;
        A.swap(B);
    }
    cout << ans + 1 << endl;
}

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

//Max-Flow,?????§???
template<int V>
struct MaxFlow {
	using T = double;
	const T INF = 1<<28;

	struct Edge {
		int to,rev;
		T cap;
	};

	vector<Edge> g[V];
	int level[V];
	int iter[V];

	void add(int from, int to, T cap) {
		g[from].push_back(Edge{to, (int)g[to].size(), cap});
		g[to].push_back(Edge{from, (int)g[from].size()-1, 0});
	}
	void add_multi(int from, int to, T cap) {
		g[from].push_back(Edge{to, (int)g[to].size(), cap});
		g[to].push_back(Edge{from, (int)g[from].size()-1, cap});
	}

	void bfs(int s) {
		fill_n(level,V,-1);
		queue<int> que;
		level[s] = 0;
		que.push(s);
		while(!que.empty()) {
			int v = que.front();
			que.pop();
			for(Edge e: g[v]) {
				if(e.cap <= 0)continue;
				if(level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					que.push(e.to);
				}
			}
		}
	}

	T dfs(int v,int t,T f) {
		if(v == t)return f;
		for(int &i = iter[v]; i < g[v].size(); i++) {
			Edge &e = g[v][i];
			if(e.cap <= 0)continue;
			if(level[v] < level[e.to]) {
				T d = dfs(e.to,t,min(f,e.cap));
				if(d <= 0)continue;
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
		return 0;
	}
	T exec(int s,int t) {
		T flow = 0;
		while(true) {
			bfs(s);
			if(level[t] < 0)return flow;
			fill_n(iter,V,0);
			T f;
			while((f = dfs(s,t,INF)) > 0) {
				flow += f;
			}
		}
	}
};

bool solve(){
	int m,n;
	cin >> m >> n;
	if(m == 0 && n == 0)return false;

	vector<int> b(m),r(n);
	for(int i=0;i<m;i++)
		cin >> b[i];
	for(int i=0;i<n;i++)
		cin >> r[i];

	MaxFlow<1100> mf;
	for(int i=0;i<m;i++){
		mf.add(0,i+1,1);
	}
	for(int i=0;i<n;i++){
		mf.add(i+m+1,m+n+1,1);
	}

	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(__gcd(b[i],r[j]) > 1){
				mf.add(i+1,j+m+1,1);
				// cerr << b[i] << " " << r[j] << " " << __gcd(b[i],r[j]) << endl;
			}
		}
	}

	cout << mf.exec(0,m+n+1) << endl;

	return true;
}

int main(void){
	while(solve()){}
	return 0;
}

Measured memory_bytes: 8932
N,*P = `dd`.split.map &:to_i
Q = [N+1, *P, N+1]

def scan(ps, ref = nil)
  rs = []
  ps.each_with_index{ |q,i| # 6,7
    j = ref ? (ref[i] ? ref[i]-1 : nil) : i-1 # 2
    prev = j ? ps[j] : nil # 2
    if !prev
      rs << nil
    else
      while j do
        if ps[j] > q
          break
        end
        j = ref ? ref[j] : rs[j]
      end
      rs << j
    end
  }
  rs
end

L1 = scan(Q)
L2 = scan(Q, L1)
R1 = scan(Q.reverse)
R2 = scan(Q.reverse, R1)
L1.map!{ |i| i ? [i-1,-1].max : nil }
L2.map!{ |i| i ? [i-1,-1].max : nil }
R1.reverse!.map!{ |i| i ? [N-i,N].min : nil }
R2.reverse!.map!{ |i| i ? [N-i,N].min : nil }
#p Q[1...-1],L1[1...-1],L2[1...-1],R1[1...-1],R2[1...-1]

p (0...N).reduce(0){ |a,i|
  vl = (L1[i+1] - L2[i+1]) * (R1[i+1] - i)
  vr = (L1[i+1] - i) * (R1[i+1] - R2[i+1])
  #p [i,Q[i],vl,vr]
  a + P[i]*(vl+vr)
}

Measured memory_bytes: 17812
n = int(input())
ary = []
s = [0,0,0,0]

for i in range(n):
    ary.append(str(input()))

for j in ary:
    if j == "AC":
        s[0] += 1
    elif j == "WA":
        s[1] += 1
    elif j == "TLE":
        s[2] += 1
    elif j == "RE":
        s[3] += 1

print("AC x {}".format(s[0]))
print("WA x {}".format(s[1]))
print("TLE x {}".format(s[2]))
print("RE x {}".format(s[3]))


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

using namespace std;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;



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

    ll n, p, q;
    cin >> n >> p >> q;
    vll c(n);
    REP(i, n) cin >> c[i];

    REP(i, n) c[i] += p * i;

    sort(c.rbegin(), c.rend());

    vll sumc(n+1);
    REP(i, n) sumc[i+1] = sumc[i] + c[i];

    ll ans = -LINF;
    REP(k, n+1) {
        chmax(ans, sumc[k] + (n-k) * p * q + p * ((ll)k * k - (2*n-1) * k + n*(n-1)/2));
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 10748
h, w = map(int, input().split())
lsa = [list(map(int, input().split())) for i in range(h)]
lsb = [list(map(int, input().split())) for i in range(h)]
ls = [[abs(lsa[i][j] - lsb[i][j]) for j in range(w)] for i in range(h)]
bias = 80*80*80

dp = [[0 for _ in range(w)] for _ in range(h)]

dp[0][0] = 1 << ls[0][0]+bias

for i in range(h):
    for j in range(w):

        if j != 0:  
            dp[i][j] |= dp[i][j-1] << ls[i][j]
            dp[i][j] |= dp[i][j-1] >> ls[i][j]

        if i != 0:
            dp[i][j] |= dp[i-1][j] << ls[i][j]
            dp[i][j] |= dp[i-1][j] >> ls[i][j]

ans = dp[h-1][w-1] >> bias
idx = 0
while(1):
    if 1 << idx & ans:
        break
    idx += 1
print(idx)

Measured memory_bytes: 451336
#include <stdio.h>

int
main()
{
	int x, y;
	int v;

	int a[100][100] = {0};
	int b[100] = {0};
	int c[100] = {0};
	int n, m;

	scanf("%d %d", &n, &m);
	for (y = 0; y < n; y++)
	{
		for (x = 0; x < m; x++)
		{
			scanf("%d", &v);
			a[y][x] = v;
		}
	}
	for (x = 0; x < m; x++)
	{
		scanf("%d", &v);
		b[x] = v;
	}

	for (y = 0; y < n; y++)
	{
		for (x = 0; x < m; x++)
		{
			c[y] += a[y][x] * b[x];
		}
	}

	for (y = 0; y < n; y++)
	{
		printf("%d\n", c[y]);
	}

	return 0;
}

Measured memory_bytes: 648
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    vector<string> st(3);
    REP(i,3){
        cin >> st[i];
        reverse(all(st[i]));
    }
    vector<vector<int>> s(3);
    REP(i,3){
        REP(j,st[i].size()){
            s[i].push_back(st[i][j]-'a');
        }
    }
    int turn = 0;
    while(!s[turn].empty()){
        int temp = s[turn].back();
        s[turn].pop_back();
        turn = temp;
    }
    cout << (char)('A'+turn) << endl;
    return 0;
}


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

int main(){
	int n, oneStep, twoStep;
	scanf("%d", &n);
	int ans[n+1], weight[n+1];
	for(int i=0;i<n;i++)
		scanf("%d", &weight[i]);
	ans[0] = 0;
	ans[1] = abs(weight[1] - weight[0]);
	for(int i=2;i<n;i++){
		oneStep = abs(weight[i] - weight[i-1]) + ans[i-1];
		twoStep = abs(weight[i] - weight[i-2]) + ans[i-2];
		if(oneStep < twoStep) ans[i] = oneStep;
		else ans[i] = twoStep;
	}
	printf("%d\n", ans[n-1]);

}


Measured memory_bytes: 1024
$queen_poss = [nil] * 8

def valid?(new_i, new_j)

  if $queen_poss[new_i] != nil
    return false
  end

  # Check column
  $queen_poss.each{|j|
    if j == new_j
      return false
    end
  }

  i = new_i
  j = new_j
  while 0 <= i-1 && 0 <= j-1
    i -= 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while i+1 < 8 && j+1 < 8
    i += 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end

  i = new_i
  j = new_j
  while 0 <= i-1 && j+1 < 8
    i -= 1
    j += 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  i = new_i
  j = new_j
  while i+1 < 8 && 0 <= j-1
    i += 1
    j -= 1
    q_j = $queen_poss[i]
    if q_j == j
      return false
    end
  end


  return true
end

def print_queens()
  $queen_poss.each{|j|
    row = ['.'] * 8
    row[j] = 'Q'
    puts(row.join)
  }
end


$fixed_ijs = []

# Input values
_ = gets
while line = gets
  i, j = line.split(' ').map(&:to_i)
  $queen_poss[i] = j
  $fixed_ijs.push([i, j])
end


def solve(i)

  if i == 8
    print_queens()
    return true
  end

  (0...8).each{|j|
    if $fixed_ijs.include?([i,j])
      solve(i+1)
    end
    if valid?(i, j)
      $queen_poss[i] = j
      # p ['q:', $queen_poss]
      solve(i+1)
      $queen_poss[i] = nil
    end
  }

  return false
end


solve(0)


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

typedef long long ll; 

int main(){
    int n; cin>>n; 
    int b[n]; 
    int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; b[i]=a[i]; }
    sort(a,a+n); 
    for(int i=0;i<n;i++){
        int l=0,h=n-1;
        int m;
        int pos; 
        while((h-l)>1){
            m=(l+h)>>1; 
            if(a[m]>b[i]) h=m-1;
            else if(a[m]<b[i]) l=m+1; 
            else break; 
        }
        if(a[m]==b[i]) pos=m; 
        else if(a[l]==b[i]) pos=l; 
        else pos=h; 
        if(pos<n/2) { cout<<a[n/2]<<endl; }
        else { cout<<a[n/2-1]<<endl; }
    }

	return 0; 
}



Measured memory_bytes: 3712
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

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

void Main()
{
	vector<vll> c;
	c.push_back(vector<ll>());
	c.push_back(vector<ll>());
	c.push_back(vector<ll>());
		
	REP(i, 3)
	{
		inll c_;
		c[0].push_back(c_);
	}
	REP(i, 3)
	{
		inll c_;
		c[1].push_back(c_);
	}
	REP(i, 3)
	{
		inll c_;
		c[2].push_back(c_);
	}

	REP(i, 3)
	{
		REP(j, 3)
		{
			ll it = c[i][j];
			ll flip = c[j][i];
			ll ionly = c[i][i];
			ll jonly = c[j][j];
			if (it + flip != ionly + jonly)
				return OUT("No");
		}
	}

	return OUT("Yes");
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if(a > b){
        printf("a > b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 262145;

int n, N, R[MAXN], low[MAXN], hig[MAXN], val[MAXN];
priority_queue <pii, vector <pii>, greater <pii>> q;
vector <pii> eve[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), N = 1 << n;
	for (int i = 1; i < N; i ++)
		R[i] = (R[i >> 1] >> 1) | ((i & 1) << n - 1);
	for (int i = 0; i < N; i ++)
		val[i] = Read() - 1;
	for (int i = N - 1; ~i; i --)
	{
		hig[i] = N - 1;
		if (~val[i])
			hig[i] = val[i];
		for (int j = 0; j < n; j ++)
			if (!(i >> j & 1))
				hig[i] = min(hig[i], hig[i ^ 1 << j]);
	}
	for (int i = 0; i < N; i ++)
	{
		low[i] = 0;
		if (~val[i])
			low[i] = val[i];
		for (int j = 0; j < n; j ++)
			if (i >> j & 1)
				low[i] = max(low[i], low[i ^ 1 << j]);
	}
	for (int i = 0; i < N; i ++)
		if (low[i] > hig[i])
			return puts("NO"), 0;
		else
			eve[low[i]].pb(mp(hig[i], i));
	for (int i = 0; i < N; i ++)
	{
		for (auto e : eve[i])
			q.push(e);
		if (q.empty() || q.top().xx < i)
			return puts("NO"), 0;
		val[q.top().yy] = i, q.pop();
	}
	puts("YES");
	for (int i = 0; i < N; i ++)
		printf("%d%c", val[R[i]] + 1, i == N - 1 ? '\n' : ' ');
	return 0;
}


Measured memory_bytes: 20224
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;


int main()
{
	int N, M;
	cin >> N >> M;
	char A[50][50], B[50][50];
	for (int ay = 0; ay < N; ay++)
		for (int ax = 0; ax < N; ax++)
			cin >> A[ay][ax];
	for (int by = 0; by < M; by++)
		for (int bx = 0; bx < M; bx++)
			cin >> B[by][bx];
	
	for (int i = 0; i <= N - M; i++)
	{
		for (int j = 0; j <= N - M; j++)
		{
			int match = 1;
			for (int ai = 0; ai < M; ai++)
			{
				for (int aj = 0; aj < M; aj++)
				{
					if (B[ai][aj] != A[i + ai][j + aj])
					{
						match = 0;
						break;
					}
				}
				if (match == 0)
					break;
			}
			if (match)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
	
}	

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

#define printl(s) cout << s << endl;
#define printFix(n,i) cout << fixed << setprecision(i) << n << endl; return 0;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;

const ll modSeed = pow(10,9) + 7;
const int INF = 1'000'000'000;

template <typename T>
vector<T> getVector(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
ll N,M,ans;

int main(){
  ans = 0;
  cin >> N>>M;
  vector<int> pattern(N);
  rep(i,N){
    pattern[i] = i+1;
  }

  vector<set<int>> direc(N+1);
  for(int i=1;i<=M;i++){
    int a,b;
    cin >>a>>b;
    if(!direc[a].count(b)){
      direc[a].insert(b);
    }
    if(!direc[b].count(a)){
      direc[b].insert(a);
    }
  }

  do{
    if(pattern[0]!=1) continue;
    bool flg = true;
    for(int i=0;i<N-1;i++){
      if(!direc[pattern[i]].count(pattern[i+1])) {
        flg = false;
        break;
      }
    }
    if(flg) ans++;
  }while(next_permutation(pattern.begin(),pattern.end()));

  printl(ans);
}


Measured memory_bytes: 3644
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for (auto& g : grid) {
        cin >> g;
    }
    vector<int> cnt(26, 0);
    rep(i, 0, H) rep(j, 0, W) {
        ++cnt[grid[i][j] - 'a'];
    }
    rep(i, 0, H / 2) rep(j, 0, W / 2) {
        bool found = false;
        for (auto& c : cnt) {
            if (c >= 4) {
                found = true;
                c -= 4;
                break;
            }
        }
        if (!found) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (H & 1) {
        rep(i, 0, W / 2) {
            bool found = false;
            for (auto& c : cnt) {
                if (c >= 2) {
                    found = true;
                    c -= 2;
                    break;
                }
            }
            if (!found) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if (W & 1) {
        rep(i, 0, H / 2) {
            bool found = false;
            for (auto& c : cnt) {
                if (c >= 2) {
                    found = true;
                    c -= 2;
                    break;
                }
            }
            if (!found) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long ll;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

#define FOR(i, start, end) for(ll i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main(void) {
    int X, N;
    cin >> X >> N;
    vector<int> p(N);
    REP (i, N) {
        cin >> p[i];
    }
    int ans;

    REP (i, 51) {
        int lower = X - i;
        int upper = X + i;
        if (find(p.begin(), p.end(), lower) == p.end()) {
            ans = lower;
            break;
        }
        if (find(p.begin(), p.end(), upper) == p.end()) {
            ans = upper;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
long double EPS=1E-8;
////////////////////////////////////////



int main(){
    ll n;cin>>n;
    string s[3];rep(i,0,2)cin>>s[i];
    ll ans=0;
    rep(j,0,n-1){
        ll c=0;
        if(s[0][j]==s[1][j]){
            if(s[1][j]==s[2][j]){
                c=0;
            }else c=1;
        }else{
            if(s[2][j]==s[0][j]||s[2][j]==s[1][j]){
                c=1;
            }else{
                c=2;
            }
        }
        ans+=c;
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
	long long int a[101][21];
	int n, i, i2, b[101];
	cin >> n;

	for (i = 0; i < n; i++){
		cin >> b[i];
	}
	for (i = 0; i < n + 1; i++){
		for (i2 = 0; i2 <= 20; i2++){
			a[i][i2] = 0;
		}
	}
	a[0][b[0]] = 1;
	for (i = 0; i < n - 2; i++){
		for (i2 = 0; i2 <= 20; i2++){
			if (a[i][i2] != 0){
				if (b[i + 1] + i2 <= 20){
					a[i + 1][b[i + 1] + i2] += a[i][i2];
				}
				if (i2 - b[i + 1] >= 0){
					a[i + 1][i2 - b[i + 1]] += a[i][i2];
				}
			}
		}


	}
	printf("%lld\n", a[n - 2][b[n - 1]]);
	return 0;
}


Measured memory_bytes: 3228
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int N = reader.nextInt();
		int[] arr = new int[N];
		int[] ans = new int[N];
		ArrayList<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			arr[i] = reader.nextInt();
		}
		for (int i = 0; i < N/2*2; i+=2) {
			ans[N/2+i/2] = arr[i];
			ans[N/2-(i/2+1)] = arr[i+1];
		}
		if (N%2==1) {
			ans[N-1] = arr[N-1];
			for (int i = N-1; i >= 0; i--) {
				System.out.print(ans[i] + " ");
			}
		} else {
			for (int i = 0; i < N; i++) {
				System.out.print(ans[i] + " ");
			}
		}


		reader.close();
	}


}





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

int N,M,Q;
vector<int> a,b,c,d;

int ans=0;
void dfs(vector<int> s){
    if(s.size()==N+1) {
        int now=0;
        for(int i=0;i<Q;++i) if(s[b[i]]-s[a[i]]==c[i])now+=d[i];
        ans=max(ans,now);
        return;
    }
    
    s.push_back(s.back());
    while(s.back()<=M){
        dfs(s);
        s.back()++;
    }
}

int main(){
    cin>>N>>M>>Q;
    a=b=c=d=vector<int>(Q);
    
    for(int i=0;i<Q;++i)cin>>a[i]>>b[i]>>c[i]>>d[i];
    
    dfs(vector<int>(1,1));
    
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int w,h;
int tansaku[51][51];
int c[51][51];
int a[3]={1,-1,0};
void dfs(int x,int y){
  if(tansaku[x][y]||x<0||x>=h||y<0||y>=w||c[x][y]==0){return;}
  tansaku[x][y]=1;
  rep(i,3){
    rep(j,3){
          dfs(x+a[i],y+a[j]);
      }
    }
  }
signed main() {

while(true){
  cin>>w>>h;
  int ans=0;
if(w==0&&h==0){break;}
rep(i,51){
  rep(j,51){
    tansaku[i][j]=0;
  }
}
rep(i,h){rep(j,w)cin>>c[i][j];}
rep(j,h){
  rep(i,w){
    if((!tansaku[j][i])&&(c[j][i]==1)){dfs(j,i);ans++;}
  }
}
cout<<ans<<endl;
}
}



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

#define ll long long int
#define ull unsigned long long int
#define Max 1000005
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define pi acos(-1.0)
#define pb push_back
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define endl '\n'

#define sc(n) scanf("%d",&n)
#define scan(n) scanf("%lld",&n)
/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define fi first
#define se second

struct HASH{
size_t operator()(const pair<int,int>&x)const{
return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
}
};


//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;
typedef tuple<ll,ll,ll>tpl;
typedef unordered_map<pair<int,int>,int,HASH>u_map;

int main()
{
    // ll n,x,t;
    // cin>> n>> x>> t;
    // int d=n/x;
    // if(n%x!=0)d++;
    // cout<<d*t<<endl;
    string s;
    cin>> s;
    int ss=0;
    for(char c:s)ss+=(c-'0');
    cout<<(ss%9==0?"Yes":"No")<<endl;
}
/*
    remember:
    ll vs int
    array size
    case for 1 2 3 
*/



Measured memory_bytes: 3760
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n, x;
	vector<ll> v1, v2;
	ll ans = 0;

	cin >> n >> x;

	REP(i, n) {
		ll a;
		cin >> a;
		v1.push_back(a);
		v2.push_back(a);
		ans += a;
	}

	FOR(i, 1, n) {
		ll sum = x * i;
		REP(j, n) {
			if (j - i < 0) {
				v2[j] = min(v2[j], v1[(j - i) % n + n]);
			}
			else {
				v2[j] = min(v2[j], v1[(j - i) % n]);
			}
			sum += v2[j];
		}
		if (sum < ans) {
			ans = sum;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    int n, y;
    cin >> n >> y;
    for ( int i = 0; i <= n; ++i ) {
        for ( int j = 0; j <= n - i; ++j ) {
            int k = n - i - j;
            if ( i * 10000 + j * 5000 + k * 1000 == y ) {
                printf("%d %d %d", i, j, k);
                return 0;
            }
        }
    }
    printf("%d %d %d", -1, -1, -1);
}


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

int main() {
  int x;
  cin >> x;
  
  vector<long long int> vec(90);
  vec.at(0)=2;
  vec.at(1)=1;
  for(int i=2;i<90;i++){
    vec.at(i)=vec.at(i-1)+vec.at(i-2);
  }
  cout<<vec.at(x)<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    ll def = 0;
    for (ll i=0;i<n;i++){
        if(i){
            if(s[i-1] == s[i]){
                def++;
            }
        }
    }
    cout << min(n-1, def + 2*k) << endl;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int ac, wa, tle, re;
	ac = wa = tle = re = 0;
	for (int i = 0;i < n;i++) {
		string s;
		cin >> s;
		if (s == "AC")ac++;
		if (s == "WA")wa++;
		if (s == "TLE")tle++;
		if (s == "RE")re++;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    string s;
    cin >> N;
    cin >> s;
    string a = "";
    for(int i = 0; i < s.size(); i++){
        char c = s[i];
        c = (c + N - 'A')%('Z' - 'A'+1)+'A';
        a+=c;
    }
    cout << a << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009LL;

//===



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

	vector<Pll> td(N);
	for (int i = 0; i < N; ++i) {
		cin >> td[i].first >> td[i].second;
	}

	auto comp_g = [](Pll& lhs, Pll& rhs) {
		return lhs.second > rhs.second;
	};

	sort(td.begin(), td.end(), comp_g);

	Vi num(N + 1);
	ll r = 0, q = 0;
	for (int i = 0; i < K; ++i) {
		if (num[td[i].first]++ == 0) ++q;
		r += td[i].second;
	}

	ll ans = r + q * q;

	int eidx = K - 1, neidx = K;
	while (true) {
		for (; eidx >= 0; --eidx) {
			if (num[td[eidx].first] > 1) break;
		}
		if (eidx == -1) break;

		--num[td[eidx].first];
		r -= td[eidx].second;
		--eidx;

		for (; neidx < N; ++neidx) {
			if (num[td[neidx].first] == 0) break;
		}
		if (neidx == N) break;

		++num[td[neidx].first];
		r += td[neidx].second;
		++neidx;

		++q;
		ans = max(ans, r + q * q);
	}

	cout << ans << endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    string S;
    cin >> S;
    int N = S.size();
    for(int i=0; i<N; i++){
        if(i%2==0 && S[i] == 'L'){
            cout << "No" << endl;
            return 0;
        }
        if(i%2==1 && S[i] == 'R'){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define llong long long
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    int first = 0;
    int end = 0;
    int tmp=0;
    for(int i=0; i<n; i++){
        if(s[i] == '('){
            if(tmp>=0){
                tmp++;
            }else{
                first -= tmp;
                tmp = 1;
            }
        }else{
                tmp--;
        }
        if(i==n-1){
            if(tmp>0){
                end += tmp;
            }else{
                first-=tmp;
            }
        }
    }
    for(int i=0; i<first; i++){
        cout << "(" ;
    }
    cout << s;
    for(int i=0; i<end; i++){
        cout << ")";
    }
    cout << endl;


}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

struct MyStruct
{
	int list[13];
};


signed main() {
	int i, j, n;
	string s;


	getline(cin, s);


	for (i = 0; i < s.length(); i++) {
		if (s[i] >= 65 && s[i] <= 90) {
			s[i] += 32;
		}
		else if (s[i] >= 97 && s[i] <= 122) {
			s[i] -= 32;
		}
		cout << s[i];
	}
	cout << endl;
	











	getchar();
	getchar();
	return 0;
}


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

const int inf = -1000;

int main() {

    string s;
    cin>>s;
    sort(s.begin(),s.end());
    char x = s[0];
    char y = s[3];
    
    if(x!=y&&x==s[1]&&y==s[2]){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
    return 0;
      }


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


int main() {
  char a;
  cin >> a;
  
  if(isupper(a)){
      //大文字
    cout << "A" << endl;
  }else{
    cout << "a" << endl; 
  }
  
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(void)
{
    int n, k;
    cin >> n >> k;
    int cnt=0;
    for (int  i = 0; i < n; i++)
    {
        int h;
        cin >> h;
        if(h >= k)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const int N = 1e6 + 10;
int n;
int main() {
	scanf("%d", &n);
	if (n % 1000 == 0)puts("0");
	else printf("%d\n", 1000 - n % 1000);
	return 0;
}

Measured memory_bytes: 3812
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<array>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int ms[100][100],n,tt=0;
int color[101],nt[101];
int d[100],f[100];
int next(int v){
    for(int i=nt[v];i<n;i++){
        nt[v]=i+1;
        if(ms[v][i]==1)return i;
    }
    return -1;
}

void visit_dfs(int v){
    stack<int> s;
    s.push(v);
    d[v]=++tt;
    color[v]=1;
    while(!s.empty()){
        int u=s.top();
        int uu=next(u);
        if(uu!=-1){
            if(color[uu]==0){
            s.push(uu);
            d[uu]=++tt;
            color[uu]=1;
            }
        }else{
            s.pop();
            f[u]=++tt;
            color[u]=2;
        }
    }
    
    
}
void dfs(){
    for(int i=0;i<n;i++){
        color[i]=0;
        nt[i]=0;
    }
    for(int i=0;i<n;i++){
        if(color[i]==0){
            visit_dfs(i);
        }
    }
    for(int i=0;i<n;i++){
        cout<<i+1<<" "<<d[i]<<" "<<f[i]<<endl;
    }
}

int main(){
    
    cin>>n;
    rep(i,n){
        int a,b,c;
        cin>>a>>b;
        a--;
        rep(j,b){
            cin>>c;
            c--;
            ms[a][c]=1;
        }
    }
    
    dfs();
    return 0;

    
}



Measured memory_bytes: 3136
#include<iostream>
#include<vector>

int main(){
    int a,over;
    std::cin>>a;
    long double count;
    count=1;
    over=0;
    std::vector<long long int> b(a);
    for(int i=0;i<a;i++){
        std::cin>>b[i];
        if(b[i]==0){
            count=0;
        }
//        std::cout<<count<<std::endl;
    }
//    std::cout<<count<<std::endl;
    if(count==0){
        std::cout<<0<<std::endl;
    }else{
        for(int i=0;i<a;i++){
            if(count/1000000000*b[i]/1000000000>1){
                over=-1;
                break;
            }
            count=count*b[i];
//            std::cout<<count<<std::endl;
        }
//        std::cout<<count<<std::endl;
        long long int c;
        c=count;
        if(over==-1){
            std::cout<<-1<<std::endl;
        }else {
            std::cout<<c<<std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main() {
 // ifstream cin("in.txt");
  int n, q;
  cin >> n >> q;
  vector<stack<int>> S(n);
  while (q--) {
    int op, t;
    cin >> op >> t;
    if (op == 0) {
      int x;
      cin >> x;
      S[t].push(x);
    } else if (op == 1) {
      if (S[t].size()) cout << S[t].top() << endl;
    } else if (op == 2) {
      if (S[t].size()) S[t].pop();
    }
  }

  return 0;
}


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



int main() {

	int N, K;
	cin >> N >> K;

	int a = 1;
	for (int i = 0; i < N; i++) {
		if (a < K) a *= 2;
		else a += K;
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X, y, a,b;
  cin >> X;
  
  //500円玉の数
  y = X / 500;
  //500割ったあまり
  a = X % 500;
  b = a / 5;

  
    cout << y*1000 + b*5 << endl;
  
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> city(N);
  
  for (int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    city.at(a-1)++;
    city.at(b-1)++;
  }
  for (int i = 0; i < N; i++){
    cout << city.at(i) << endl;
  }

}


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

using namespace std;

int main() {
  int n, m, p;
  while(cin>>n>>m>>p && !(n==0 && m==0 && p==0)) {
    vector<int> personal;
    //double percentage = (double)p/100.0;
    int total = 0;
    for(int i=0; i<n; i++) {
      int tmp;
      cin>>tmp;
      personal.push_back(tmp);
      total += tmp;
    }
    //cout<<personal[m-1]<<"!";
    //double payBackD = total*(1.0-percentage);
    //int payBackI = (int)payBackD;
    if(personal[m-1] > 0) {
      cout<<(100-p)*total/personal[m-1]<<endl;
    }
    else {
      cout<<"0"<<endl;
    }
  }
}

Measured memory_bytes: 1220
{
  const main = (input: string) => {
    const r = reader(input)
    const n = r.n()
    const s = r.s()

    let prev = '-'
    let sum = 0

    s.split('').forEach(v => {
      if (v !== prev) {
        sum +=1
      }
      prev = v
    })

    console.log(sum)
  }

  const reader = (str: string) => {
    const lines = str.trim().split("\n")
    const s = () => lines.shift() || ""
    const n = () => Number(s())

    const ss = () => s().split(" ")
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require("fs").readFileSync("/dev/stdin", "utf8")

  main(getInput())
}


Measured memory_bytes: 8396