akhauriyash/Code-Regression huggingface dataset:
import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Stack;

public class Main {
	
	public static Stack<Entry<Integer, Integer>> simulate(String mount){
		Stack<Integer> patches = new Stack<Integer>();
		Stack<Entry<Integer, Integer>> results = new Stack<Entry<Integer, Integer>>();
		int total = 0;
		int i = 0;
		while(i < mount.length()) {
			// the negative slope
			if(mount.charAt(i) == '\\') {
				//push the index
				patches.push(i);
			}else if(mount.charAt(i) == '/') {
				if(!patches.isEmpty()) {
					int s = patches.pop();
					int sum = i - s;
					total += sum;
					while(!results.isEmpty() && results.peek().getKey() >= s) {
						sum += results.pop().getValue(); // include the area
					}
					
					results.push(new AbstractMap.SimpleEntry<Integer, Integer>(s, sum));
				}
			}
			
			
			i++;
		}
		
		results.push(new AbstractMap.SimpleEntry<Integer, Integer>(total, total));

		return results;
		
	}
	
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		String mount = cin.nextLine();
		Stack<Entry<Integer, Integer>> s = simulate(mount);
		
		System.out.println(s.pop().getValue());
		System.out.print(s.size());
		if(s.size() == 0) {
			System.out.print("\n");
		}else {
			System.out.print(" ");
		}
		
		Iterator<Entry<Integer, Integer>> iter = s.iterator(); 
		
		
		while(iter.hasNext()) {
			System.out.print(iter.next().getValue());
			if(iter.hasNext()) {
				System.out.print(" ");
			}else {
				System.out.println();
			}
			
		}
		
		
		cin.close();
		

	}
	
	

}

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

const int N = 1e6 + 100;

int Parity(vector<int> v) {
//    cout << "vector: ";
//    for(int x : v) {
//        cout << x << " ";
//    }
//    cout << endl;
    int n = v.size()-1;
    int ret = 0;
    for(int r = 0; r <= n; r++) {
        if(v[r]&1) {
            int nn = n, rr = r;
            int cont = 1;
            for(int k = 0; k <= 20; k++) {
                int nnn = nn&1, rrr = rr&1;
                nn /= 2;
                rr /= 2;
                if(nnn < rrr) {
                    cont = 0;
                    break;
                }
            }
            ret ^= cont;
        }
    }
    return ret;
}

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n == 2) {
        cout << abs(s[0]-s[1]) << endl;
        return 0;
    }
    vector<int> new_v;
    for(int i = 0; i+1 < n; i++) {
        int x = abs(s[i]-s[i+1]);
        new_v.push_back(x);
    }
    int p = Parity(new_v);
    if(p&1) {
        cout << 1 << endl;
        return 0;
    }
    for(int x : new_v) {
        if(x == 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < new_v.size(); i++) {
        new_v[i] /= 2;
    }
    if(Parity(new_v)) cout << 2 << endl;
    else cout << 0 << endl;
    return 0;
}



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

int main(){
    int a, b;
    const int tax8=8/100, tax10=10/100;
    cin >> a >> b;
    rep(1,1001){
        if((i*8/100)==a && (i*10/100)==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static int N;
    private static int M;
    private static int[] X;

    static {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        M = Integer.parseInt(sc.next());
        X = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = Integer.parseInt(sc.next());
        }
    }

    public static void main(String[] args) {
        Arrays.sort(X);

        int[] l = new int[M - 1];
        for (int i = 0; i < M - 1; i++) {
            l[i] = X[i + 1] - X[i];
        }
        Arrays.sort(l);

        int sum = 0;
        for (int i = 0; i < M - N; i++) {
            sum += l[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 46968
n=list(input())
lis=[]
for k in range(len(n)):
  lis.append(int(n[len(n)-1-k]))
             
t=0

for k in range(len(lis)):
  if lis[k]==10:
    if k==len(lis)-1:
      t+=1
      break
    else:
      lis[k]=0
      lis[k+1]+=1
  if lis[k]<5:
    t+=lis[k]
  elif lis[k]>5:
    t=t+10-lis[k]
    if k==len(lis)-1:
        t+=1
        break
    else:
        
      lis[k+1]+=1
  elif lis[k]==5:
    if k==len(lis)-1:
      t+=5
    else:
      t+=5
      if lis[k+1]<5:
        pass
      else:
        lis[k+1]+=1
print(t)

Measured memory_bytes: 21348
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		ArrayList<Integer> list = new ArrayList<Integer>();
		int count = 0;
		for(int i = 0; i < s.length() - t.length() + 1; i++) {
			String temp = s.substring(i, i + t.length());
			for(int j = 0; j < t.length(); j++) {
				if(temp.charAt(j) != t.charAt(j)) {
					count++;
				}
			}
			list.add(count);
			count = 0;
		}
		Collections.sort(list);
		System.out.println(list.get(0));
	}

}


Measured memory_bytes: 36948
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
using namespace std;

void insertionSort(vector<int> &A, int n, int g, int &cnt) {
    for (int i=g; i<n; ++i) {
        int v = A[i];
        int j = i - g;
        while (j >= 0 && A[j] > v) {
            A[j+g] = A[j];
            j = j - g;
            cnt ++;
        }
        A[j+g] = v;
    }
}

void shellSort(vector<int> &A, int n) {
    int cnt = 0;
    vector<int> G;

    G.push_back(1);
    for (int h=4; h<=n; h=h*3+1) {
        G.push_back(h);
    }
    int m = G.size();

    cout << m << endl;

    for (int i=m-1; i>=0; --i) {
        cout << (i==m-1 ? "" : " ") << G[i];
        insertionSort(A, n, G[i], cnt);
    }
    cout << endl;

    cout << cnt << endl;

    for (int i=0; i<n; ++i) {
        cout << A[i] << endl;
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i=0; i<n; ++i) {
        cin >> A[i];
    }
    shellSort(A, n);
    return 0;
}

Measured memory_bytes: 4896
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner s = new Scanner(System.in)) {
			final String S = s.next();

			BitSet bs = new BitSet(100000);
			BitSet bs1 = new BitSet(100000);
			BitSet bs0 = new BitSet(100000);
			for (int i = 0; i < S.length(); i++) {
				if (i % 2 == 0) {
					bs1.set(i);
				} else {
					bs0.set(i);
				}
				if (S.charAt(i) == '1')
					bs.set(i);
			}

			bs1.xor(bs);
			bs0.xor(bs);

			System.out.println(Math.min(bs1.cardinality(), bs0.cardinality()));
		}
	}
}


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

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

    int ans = 0;

    for(int x = 0;x<=K;x++){
        for(int y = 0;y<=K;y++){
            int z = S - x - y;
            if(z >= 0 && z <=K){
                ans++;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()
rs = "".join(reversed(s))
n = len(s)

res = 0
i = 0
j = 0
while i+j<n:
    if s[i]==rs[j]:
        i += 1
        j += 1
    elif s[i]=="x":
        res += 1
        i += 1
    elif rs[j]=="x":
        res += 1
        j += 1
    else:
        print(-1)
        exit()

print(res)


Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define DEBUG if(0)
bool check_palim(int b, int e, string s) {
	while(b < e) {
		DEBUG cout << s[b] << " " << s[e] << endl;
		if(s[b] != s[e]) {
			return false;
		}
		b++;
		e--;
	}
	return true;
}
int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
	string s;
	while(cin >> s) {
		int len = s.size();
		string ans = "No";
		DEBUG printf("%d %d\n", (len - 1) / 2, (len + 3) / 2);
		if(check_palim(0, len - 1, s) && check_palim(0, ((len - 1) / 2) - 1, s) && check_palim(((len + 3) / 2) - 1, len - 1, s)) ans = "Yes";
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())

lisA = [["."] * 100 for i in range(50)]
lisB = [["#"] * 100 for i in range(50)]

nx = 0
ny = 0

for i in range(B-1):

    lisA[ny][nx] = "#"

    nx += 2

    if nx >= 100:
        nx = 0
        ny += 2

nx = 0
ny = 1
for i in range(A-1):

    lisB[ny][nx] = "."

    nx += 2

    if nx >= 100:
        nx = 0
        ny += 2

print (100,100)

for i in lisA:
    print ("".join(i))

for i in lisB:
    print ("".join(i))


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

def calc_costs(l, r):
    axl = abs(x[l])
    axr = abs(x[r])
    if 0 <= x[l] and 0 <= x[r]:
        return x[r]
    elif x[l] <= 0 and x[r] <= 0:
        return abs(x[l])
    elif axl < axr:
        return axl * 2 + axr
    else:
        return axl + axr * 2

l = 0
r = K-1
min_costs = calc_costs(l, r)
for i in range(1, N-K+1):
    l += 1
    r += 1
    costs = calc_costs(l, r)
    if costs < min_costs:
        min_costs = costs
print(min_costs)


Measured memory_bytes: 14792
#include <iostream>
#include <bits/stdc++.h>
#include <vector>

using namespace std;

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  vector<vector<long long> > v1(100, vector<long long>(100));
  vector<vector<long long> > v2(100, vector<long long>(100));
  vector<vector<long long> > v3(100, vector<long long>(100));
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      int a;
      cin >> a;
      v1.at(i).at(j) = a;
    }
  }
  for(int i = 0; i < m; i++){
    for(int j = 0; j < l; j++){
      int a;
      cin >> a;
      v2.at(i).at(j) = a;
    }
  }
  
  for(int i = 0; i < n; i++){
    for(int j = 0; j < l; j++){
      long long sum = 0;
      for(int k = 0; k < m; k++){
        sum += v1.at(i).at(k) * v2.at(k).at(j);
      }
      v3.at(i).at(j) = sum;
      cout << v3.at(i).at(j);
      if( j != l-1){
        cout << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
const int N=1e5+5;
int a[N][3];
int dp[N][3];
int main(){
	AC
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
		for(int j=0;j<3;j++){
			dp[i][j]=max(a[i][j]+dp[i-1][(j+1)%3],max(a[i][j]+dp[i-1][(j+2)%3],dp[i-1][j]));
		}
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}


Measured memory_bytes: 6000
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n").map(Number);

let sumP = 0;

for(let i=0;i<Arr.length;i++){
    if(pNum(Arr[i]))sumP++;
}

console.log(sumP);

function pNum(x){
    
    if(x === 2){
        return true;
    }
    
    if( (x < 2) || ( (x % 2) === 0) ){
        return false;
    }
    
    let j = 3;
    
    while(j <= Math.sqrt(x)){
        if( (x % j) === 0){
            return false;
        }
        
        j += 2;
    }
    
    return true;
}



Measured memory_bytes: 20248
@n = gets.chomp.to_i

@nodes = Array.new(@n+1){Array.new()}

(@n - 1).times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  @nodes[a] << b
  @nodes[b] << a
end

def dfs(start)
  que = [start]
  visited = Array.new(@n+1, false)
  dist = Array.new(@n+1, 0)
  while !que.empty?
    node = que.shift
    visited[node] = true
    @nodes[node].each do |i|
      if visited[i] then
        next
      else
        que << i
        dist[i] = dist[node] + 1
      end
    end
  end
  return dist
end

dist1 = dfs(1)
dist2 = dfs(@n)

# p dist1
# p dist2

fennec = 0
snuke = 0
(1..@n).each do |i|
  if dist1[i] <= dist2[i] then
    fennec += 1
  else
    snuke += 1
  end
end

if fennec > snuke then
  puts "Fennec"
else
  puts "Snuke"
end


Measured memory_bytes: 16816
#include <bits/stdc++.h>
 size_t strlen(const char *s);
#define rep(i,n) for(long long int i=0;i<n;i++)
#define sz(x) ((int)(x).size())

using namespace std;
std::vector<int> graph[10050];//graph頂点数のsize
const int N=200010;
const int P=1000000007;
using ll = long long;
vector<ll> prime;

//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
//小さい方
long long int min(long long int a,long long int b){
	if(a>b){
		return b;
	}else{
		return a;
	}
}
//大きい方
long long int max(long long int a,long long int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}
// a^n mod 
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod 
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ

/*
	memset(b, '\0', sizeof(b));
初期化*/


/*
	string s;
	s.size()
*/

/*
	char s[N];
	strlen(s)
*/
/*
	if(  <  )puts("Yes");
	else puts("No");
*/

/*文字列比較
if(strcmp(name[i],s)==0)
*/

/*
	graph[a].push_back(b);//graph[a][i番目に入れた]==b
	graph[j].size()	//forで回すときとか

*/


int main(){
  string s;
  ll p=2019;
  vector<ll> mod(2019);
  cin>>s;
  ll now=0;
  mod.at(0)++;
  ll tenk=1;
  rep(i, sz(s)){
    ll j=sz(s)-1-i;
    if(s.at(j)=='1'){
      now=(now+   1*tenk)%p;
    }
    if(s.at(j)=='2'){
      now=(now+   2*tenk)%p;
    }
    if(s.at(j)=='3'){
      now=(now+   3*tenk)%p;
    }
    if(s.at(j)=='4'){
      now=(now+   4*tenk)%p;
    }
    if(s.at(j)=='5'){
      now=(now+   5*tenk)%p;
    }
    if(s.at(j)=='6'){
      now=(now+   6*tenk)%p;
    }
    if(s.at(j)=='7'){
      now=(now+   7*tenk)%p;
    }
    if(s.at(j)=='8'){
      now=(now+   8*tenk)%p;
    }
    if(s.at(j)=='9'){
      now=(now+   9*tenk)%p;
    }
  tenk=(tenk*10)%p;
  mod.at(now)++;
  }
  
  
  ll ans=0;
  rep(i, p){
  ans+=mod.at(i)*(mod.at(i)-1)/2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 4004
# prim factorization
def prfct(n):
    l=[]
    if n%2==0:
        m=0
        while n%2==0:
            n//=2
            m+=1
        l.append((2,m))
    p=3
    while p**2<=n:
        if n%p==0:
            m=0
            while n%p==0:
                n//=p
                m+=1
            l.append((p,m))
        p+=2
    if n>1:
        l.append((n,1))
    return l

# modulo:mod

# inverse x^(-1)
def inv(x):
    global mod
    return pow(x,mod-2,mod)

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int,input().split()))

mp = {}

pfs = []
for Ai in A:
    pf = prfct(Ai)
    for pr, pw in pf:
        if pr not in mp:
            mp[pr] = pw
        else:
            mp[pr] = max(mp[pr], pw)
    pfs.append(pf)
# print(pfs)
# print(mp)

l = 1
for pr in mp:
    pw = mp[pr]
    l *= pow(pr, pw, mod)
# print(l)

ans = 0

for pf in pfs:
    temp = 1
    for prw in pf:
        pr, pw = prw
        temp = temp * pow(pr, pw, mod) % mod
    temp2 = l * inv(temp) % mod
    ans = (ans + temp2) % mod

print(ans)

Measured memory_bytes: 49372
n, m = map(int,input().split())
graph = {i:[] for i in range(n)}
H = list(map(int,input().split()))
for _ in range(m):
  a,b = map(int,input().split())
  a, b = a-1, b-1
  
  if H[a]<H[b]:
    graph[a].append(b)
  elif H[a]>H[b]:
    graph[b].append(a)
  else:
    graph[a].append(b)
    graph[b].append(a)
ans = 0

for i in range(n):
  if len(graph[i]) ==0:
    ans += 1
print(ans)

Measured memory_bytes: 90456
n,m,l=map(int,input().split())
A = [tuple(map(int,input().split())) for _ in range(n)]
B = [tuple(map(int,input().split())) for _ in range(m)]
for nnum in range(n):
    temp=[]
    for lnum in range(l):
        ret = 0
        for mnum in range(m):
            ret +=(A[nnum][mnum]*B[mnum][lnum])
        temp.append(ret)
    print(*temp)

Measured memory_bytes: 8672
// g++ -std=gnu++1y -O2 xxx.cpp
// (241) AtCoder Beginner Contest 154 - YouTube https://www.youtube.com/watch?v=JQmQjJd-sLA

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

int dp[105][4][2];

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int K;
    cin >> K;

    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2) {
        int nd = s[i]-'0';
        rep(d,10) {
            int ni = i+1, nj = j, nk = k;
            if (d != 0) nj++;
            if (nj > K) continue;
            if (k == 0) {
                if (d > nd) continue;
                if (d < nd) nk = 1;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque

S = input()
lenS = len(S)
pops = 0
ans = lenS
stack = deque()
for i in range(lenS):
    if stack and S[i] == "T":
        a = stack.pop()
        if a == "S":
            ans -= 2
    else:
        stack.append(S[i])
print(str(ans))

Measured memory_bytes: 47200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;
vector<ll>ans;

ll add(ll a, ll b)  {return ( (a%mod) + (b%mod) )%mod;}

ll multiply(ll a, ll b) {return ((a%mod) * (b%mod))%mod;}

ll power(ll a, ll b)
{
    if(b==0) return 1;
    ll temp=power(a,b/2);
    if(b%2==1) return multiply(temp,multiply(temp,a));
    else return multiply(temp,temp);
}

int main()
{
  ll x,y;
  cin>>x>>y;
  if(y%2==1 || ( y< 2*x) || ( y >4*x)) cout<<"No\n";
  else cout<<"Yes\n";
  
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		System.out.println(n*n*n);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}
std::vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend
#define all(x) (x).begin(),(x).end()
#define size_t ll
const int mod = 1000000007;
const ll ex = -100000;
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/

ll n,k,s;
std::vector<ll> ans;
int main(){
  cin >> n >> k >> s;
  ans.resize(n);
  for (size_t i = 0; i < k; i++) {
    ans[i] = s;
  }
  for (size_t i = k; i < n; i++) {
    ans[i] = (s != 1000000000 ? s+1 : 1);
  }
  for (size_t i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <math.h>
#include <tuple>
#include <queue>
#include <set>

using namespace std;

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

    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    vector<int> num_subgroup;

    bool is_before_0 = true;

    num_subgroup.push_back(0);

    int N_group = 0;
    for(int i = 0; i < N; i++){
        if(is_before_0 && S[i] == '1'){
            num_subgroup.push_back(N_group);
            N_group = 1;
        }
        else if(!is_before_0 && S[i] == '0'){
            num_subgroup.push_back(N_group);
            N_group = 1;
        }
        else{
            N_group++;
        }

        if(i == N-1){
            num_subgroup.push_back(N_group);
        }

        if(S[i] == '1') is_before_0 = false;
        if(S[i] == '0') is_before_0 = true;

    }

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

    ans[0] = accumulate(num_subgroup.begin(), num_subgroup.begin()+min(2*K+1, (int)(num_subgroup.size())), 0);
    for(int i = 1; i < num_subgroup.size(); i++){
        
        if(2*(i+K)-1 < num_subgroup.size())
        {
            if(2*(i+K) < num_subgroup.size())
            {
                ans[i] = ans[i-1] + (num_subgroup[2*(i+K)-1] + num_subgroup[2*(i+K)])-(num_subgroup[2*i-1] + num_subgroup[2*i-2]);
            }
            else
            {
                ans[i] = ans[i-1] +  (num_subgroup[2*(i+K)-1])-(num_subgroup[2*i-1] + num_subgroup[2*i-2]);
            }
        }
        else
        {
            break;
        }
    }

    cout << *max_element(ans.begin(), ans.end()) << endl;

    return 0;
}


Measured memory_bytes: 1272
def solve():
  X,Y=input(),input()
  lx,ly=len(X),len(Y)
  dp=[0 for _ in range(ly+1)]
  
  for i in range(lx):
    tmp=dp+[]
    x=X[i]
    for j in range(ly):
      if x == Y[j]:
        dp[j+1]=tmp[j]+1
      elif dp[j] > dp[j+1]:
        dp[j+1]=dp[j]
  return dp[-1]

n=int(input())
for _ in range(n):
  print(solve())


Measured memory_bytes: 5632
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }





int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll xor_sum = 0;
    REP(i, n){
        cin >> a[i];
        xor_sum ^= a[i];
    }
    sort(a.begin(), a.end(), greater<ll>());
    ll cnt = 0;
    for(ll i = 30; i >= 0; i--){
        if(xor_sum & (1 << i)){
            REP(j, n){
                if((a[j] ^ (a[j] - 1)) == (1 << (i + 1)) - 1){
                    cnt++;
                    xor_sum ^= a[j] ^ (a[j] - 1);
                    break;
                }
            }
        }
    }
    if(xor_sum == 0){
        cout << cnt << endl;
    }
    else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 1024
a, b, m = map(int, input().split())
a_price = list(map(int, input().split()))
b_price = list(map(int, input().split()))
m_prices = []
for i in range(m):
  m_prices.append(list(map(int, input().split())))

#check min price
ref = min(a_price)
mi = min(b_price)
total_min = ref + mi

#check discount ticket
discount_prices_from_tickets = []
dis_price_temp = 0
for i in range(m):
  discount_prices_from_tickets.append(a_price[m_prices[i][0] - 1] + b_price[m_prices[i][1] - 1] - m_prices[i][2]) 
bigest_discount = min(discount_prices_from_tickets)

print(min(total_min,bigest_discount))



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

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

using namespace std;

const int maxn = 2e6 + 10;

int n, m, k, bal;
char in[maxn << 1], out[maxn << 1], a[maxn], b[maxn], *pnt, *S, *T;
set<int> s;

void read(int &n) {
	while(*pnt < '0') {
		++pnt;
	}
	while(*pnt >= '0') {
		n = n * 10 + *pnt++ - '0';
	}
	return;
}

struct Info {
	int l, r, a, b, c;

	Info() {}
	Info(int l, int r, int a, int b, int c): l(l), r(r), a(a), b(b), c(c) {}
};

vector<Info> f, nf;

void pb(int l, int r, int x, int y, int z) {
	if(!z || !x && !y) {
		return;
	}
	if(!nf.size()) {
		nf.push_back(Info(l, r, x, y, z));
		return;
	}
	auto &t = nf.back();
	int a = t.a, b = t.b, c = t.c;
	if(a == b) {
		if(x == y) {
			t = Info(t.l, r, a, b, c + z);
		}
		else {
			nf.push_back(Info(l, r, x, y, z));
		}
	}
	else {
		if(!(c & 1)) {
			a ^= 1;
			b ^= 1;
		}
		if(x != a && y != b) {
			t = Info(t.l, r, t.a, t.b, c + z);
		}
		else {
			nf.push_back(Info(l, r, x, y, z));
		}
	}
	return;
}

inline void ins(int i) {
	s.insert(i - bal);
	return;
}

inline void del(int i) {
	s.erase(i - bal);
	return;
}

inline int fnd_pre(int i) {
	auto it = s.lower_bound(i - bal);
	if(it == s.begin()) {
		return 0;
	}
	--it;
	return *it + bal;
}

inline int fnd_nxt(int i) {
	auto it = s.lower_bound(i - bal);
	if(it == s.end()) {
		return maxn;
	}
	return *it + bal;
}

void work(int &i, int &x, int &y, int l, int r, int a, int b, int c) {
	if(a && b && x == y) {
		if(x && y) {
			ins(i);
			pb(i + 1, i + 1, 1, 1, 1);
		}
		del(r);
		if(c > 1) {
			pb(l + 1, fnd_pre(r) + 1, 1, 1, c - 1);
		}
		i = r;
		x = y = 1;
		return;
	}
	for(;;) {
		int j = fnd_nxt(i + 1);
		if(j > r) {
			return;
		}
		del(j);
		if(x && y) {
			pb(i + 1, i + 1, 1, 1, 1);
			ins(i);
			x = a;
			y = b;
			i = j;
		}
		else {
			if(x + a > 1 || y + b > 1) {
				pb(j, j, x + a > 1, y + b > 1, 1);
				ins(j - 1);
			}
			x ^= a;
			y ^= b;
			i = j;
		}
		if(a != b) {
			a ^= 1;
			b ^= 1;
		}
	}
}

void Out(char *s) {
	int i = maxn - 1;
	while(!s[i]) {
		--i;
	}
	while(s[i] == '0') {
		--i;
	}
	while(i >= 0) {
		*pnt++ = s[i--];
	}
	*pnt++ = '\n';
	return;
}

int main() {
	fread(in, 1, sizeof in, stdin);
	pnt = in;
	read(n);
	read(m);
	read(k);
	while(*pnt < '0') {
		++pnt;
	}
	S = pnt + n - 1;
	pnt = S + 1;
	while(*pnt < '0') {
		++pnt;
	}
	T = pnt + m - 1;
	for (int i = 0; i < maxn; ++i) {
		if(i >= n && i >= m && !f.size()) {
			break;
		}
		int x = i < n ? S[-i] - '0' : 0, y = i < m ? T[-i] - '0' : 0, I = 0, z = fnd_pre(maxn);
		nf.clear();
		for (auto t: f) {
			work(I, x, y, t.l, t.r, t.a, t.b, t.c);
		}
		if(x && y) {
			if(z < k) {
				pb(z + 1, z + 1, 1, 1, 1);
				ins(z);
				x = y = 0;
			}
		}
		f = nf;
		++bal;
		a[i] = x + '0';
		b[i] = y + '0';
	}
	pnt = out;
	Out(a);
	Out(b);
	fwrite(out, 1, pnt - out, stdout);
	return 0;
}


Measured memory_bytes: 14336
#include<stdio.h>
int search(int A[],int n,int key){
int i=0;
A[n]=key;
while(A[i]!=key)i++;
return i!=n;
}
int main(){
int i,n,A[10000+1],q,key,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&A[i]);
}
scanf("%d",&q);
for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)) sum++;
}
printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 2716
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
coo=[a,b,c,d,e]
flag=0
for i in range(len(coo)):
  for j in range(i+1,len(coo)):
    if abs(coo[i]-coo[j])>k:
      flag=1
      break
    if flag==1:
      break
if flag==1:  
  print(":(")
else:
  print("Yay!")
      
  

Measured memory_bytes: 3064
<?php
  $stdin = fopen('php://stdin', "r");

  fscanf($stdin, "%d %d %d %d %d", $a, $b, $c, $x, $y);

  # それぞれ個別に買うケース
  $p1 = $a*$x + $b*$y;

  # 少ない方分買って足りない分を買うケース
  $p2 = 0;
  if ($x<$y) { // Xの方が少ない
    $p2  = $x*$c*2;
    $sub = $y-$x;
    $p2 += $sub*$b;
  } else { // yの方が少ない
    $p2  = $y*$c*2;
    $sub = $x-$y;
    $p2 += $sub*$a;
  }

  # 多い方分買って余らせるケース
  $max = max($x, $y);
  $p3 = $max*$c*2;

  echo min($p1, $p2, $p3).PHP_EOL;


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

using namespace std;
int vis[10];
int main()
{
    string s;cin>>s;
    for(int i=0;i<3;i++)
    {
        vis[s[i]-'a']=1;
    }

    for(int i=0;i<3;i++)
    {
        if(vis[i]==0)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m){
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main(){
    int q, M, i;
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        scanf("%d", &M);
        if(solve(0, M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<long long> B(N + 1, 0); 
    int mod = 1000000007;
 
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        B[i + 1] = B[i] + A[i];
    }
 
    long ans = 0;
 
    for (int i = 0; i < N; i++)
    {
        long long sum = (B[N] - B[i + 1]) % mod;
        ans += A[i] * sum;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5636
n = int(input())
a = [int(i) for i in input().split()]

b = []
for i in range(len(a)):
    b.append(a[i] - (i+1))

p_num = []
n_num = []
z_num = []

for i in range(len(b)):
    if b[i] > 0:
        p_num.append(b[i])
    elif b[i] < 0:
        n_num.append(b[i])
    else:
        z_num.append(b[i])

p_num.sort()
n_num.sort()
n_num.reverse()

if len(p_num) > len(n_num) + len(z_num):
    count_n = len(n_num) + len(z_num)
    count_p = len(p_num)
    index = -1
    while  count_p > count_n:
        count_p -= 1
        count_n += 1
        index += 1
    for i in range(len(b)):
        b[i] = b[i] - p_num[index]

elif len(n_num) > len(p_num) + len(z_num):
    count_n = len(n_num)
    count_p = len(p_num) + len(z_num)
    index = -1
    while  count_n > count_p:
        count_n -= 1
        count_p += 1
        index += 1
    for i in range(len(b)):
        b[i] = b[i] - n_num[index]

ans = 0
for i in range(len(b)):
    ans += abs(b[i])

print(ans)


Measured memory_bytes: 27844
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007
#define MOD2 1000000014000000049LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, int M>
struct ModFact {
    int inv[N+1];
    int fact[N+1];
    int ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        ll f = 1;
        fact[0] = f;
        for (int i = 0; i < N; i++) {
            f = f*(i+1)%M;
            fact[i+1] = f;
        }
        f = power(f, M-2);
        ifact[N] = f;
        for (int i = N-1; i >= 0; i--) {
            f = f*(i+1)%M;
            ifact[i] = f;
        }
        for (int i = 0; i < N; i++) {
            f = ll(fact[i])*ll(ifact[i+1])%M;
            inv[i] = f;
        }
    }
    constexpr ll power(ll a, ll b) {
        ll r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
	int operator[](int n) {
		return inv[n];
	}
};

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}

inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ModFact<100000, MOD> fact;

int main() {
    ll ans = 0, d;
    int a, N, prev, now;
    N = getint();
    prev = getint();
    REP(i, N-1) {
        now = getint();
        d = now - prev;
        prev = now;
        a = (a + fact[i]) % MOD;
        ans += a * d % MOD;
        // a += fact.inv[i+1];
        // if(a > MOD) a -= MOD;
        // ans += a * d;
        // if(ans > MOD2) ans -= MOD2;
    }
    printf("%lld\n", ((ans%MOD)*fact.fact[N-1])%MOD);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int K, X;
    cin >> K >> X;
    int last = min((int)1e6, X + K - 1);
    for(int i = max((int)-1e6, X - K + 1); i <= last; i++){
        cout << i;
        if(i == last){
            cout << endl;
        }
        else{
            cout << " ";
        }
    }

    return 0;
}

Measured memory_bytes: 256
N = gets.chomp.to_i
# N, K = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

A = gets.chomp.split.map(&:to_i)
A_with_index = A.map.with_index { |a, i| [a, i] }

sorted = A_with_index.sort_by { |(a, i)| a }

# p N
# p A
# p sorted

print sorted.map { |(order, i)| i + 1 }.join(" ") + "\n"

Measured memory_bytes: 21080
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right().to_owned()
    }};
}

fn main() {
    let m = 1_000_000_007u64;
    read_line!();
    let s = read_line!();
    let mut ab = vec![0u64; 26];
    for c in s.bytes() {
        ab[(c - 'a' as u8) as usize] += 1;
    }
    let mut ans = 1u64;
    for c in 0..26 {
        ans = (ans * (ab[c] + 1)) % m;
    }
    ans = (ans + m - 1) % m;
    println!("{}", ans);
}

Measured memory_bytes: 4352
/**
 *      ABC 84 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-02 04:08:15
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int M; cin >> M;
    cout << 48 - M << endl;
    return 0;
}


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

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

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, ) = input!(usize);
    let a = invec!(u32);
    let mut current = std::u32::MAX - 1;

    for &h in a.iter().rev() {
        if h == current + 1 {
            // println!("OK: {}", h);
            current = h - 1;
        } else if h > current + 1 {
            println!("No");
            return;
        } else {
            current = h;
        }

    }

    println!("Yes");
}

fn main() {
    solve();
}


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

int execute(string s, char c) {
    string str = "";
    bool ok = true;

    for(auto p : s)
        if(p != c + 'a') {
            ok = false;
        }

    if(ok) {
        return 0;
    }

    for(int i = 0; i < int(s.size()) - 1; ++i) {
        if(s[i] == c + 'a' or s[i + 1] == c + 'a') {
            str += c + 'a';
        } else {
            str += s[i];
        }
    }

    return 1 + execute(str, c);
}

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

    int ans = 1e9;

    for(int c = 0; c < 26; ++c) {
        ans = min(ans, execute(s, c));
    }

    cout << ans << "\n";
}

Measured memory_bytes: 256
package main

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

type operation struct {
	a, b int
}

type byA []operation

func (a byA) Len() int           { return len(a) }
func (a byA) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byA) Less(i, j int) bool { return a[i].a < a[j].a }

func main() {
	n := getInt()
	k := getInt()

	os := make([]operation, n)
	for i := range os {
		os[i].a = getInt()
		os[i].b = getInt()
	}

	sort.Sort(byA(os))

	for i, count := 0, 0; ; {
		count += os[i].b
		switch {
		case count < k:
			i++
		default:
			fmt.Println(os[i].a)
			return
		}
	}
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)
	{
		if(b==c)
		cout<<"No\n";
		else cout<<"Yes\n";
	}
	else if(a==c)
	{
		if(b==c)
		cout<<"No\n";
		else cout<<"Yes\n";
	}
	else if(b==c)
	{
		if(a==b)
		cout<<"No\n";
		else cout<<"Yes\n";
	}
	else cout<<"No\n";
}

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

int main(){
  int n;
  string s;
  int x=0;
  int amax=0;
  cin >> n >> s;
  int count=0;
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x++;
    }else if(s[i]=='D'){
      x--;
    }
    amax=max(amax,x);
  }
  cout << amax << endl;
}

Measured memory_bytes: 256
n=int(input())
ls=list(map(int,input().split()))

print(*ls)
for i in range(1,n):
    v=ls[i]
    j=i-1
    while j>=0 and ls[j]>v:
        ls[j+1]=ls[j]
        j-=1
    ls[j+1]=v
    print(*ls)



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

string d[4] = {"dreamer", "dream", "eraser", "erase"};

int main(){
  string s;
  cin >> s;
  int en = s.size();
  while(en != 0) {
    for (int i = 0; i < 4; i++) {
      int t = d[i].size();
      if (en-t >= 0) {
        if (s.compare(en-t, t, d[i]) == 0) {
          en -= t;
          break;
        }
      }
      if (i == 3) {
        cout << "NO" << endl;
        return 0;
      }
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

S = input()

C = Counter(S)
ans = (C['g'] - C['p']) // 2
print(ans)


Measured memory_bytes: 3564
#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#include<vector>
#define mp make_pair
#define endl "\n"
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lb lower_bound
#define forn(i,n) for(ll i=0 ; i<n ; i++)
#define arr(a,n) for(ll i=0;i<n;i++){ cin>>a[i]; }
#define ub upper_bound
#define pb push_back
#define mod 1000000007
using namespace std;

ll ipow(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    } 
    return result; 
} 

int main(){
	fio
	string a,b;
	cin>>a>>b;
	int n,m;
	cin>>n>>m;
	string u;
	cin>>u;
	if(u==b){
		cout<<n<<" "<<m-1<<endl;
	}
	else if (u==a)
	cout<<n-1<<" "<<m<<endl;
	
return 0;
}

Measured memory_bytes: 256
def bfs(q_list):
    cnt = -1
    while q_list:
        cnt += 1
        new_q_list = []
        for h, w in q_list:
            if not m_list[h][w+1]:
                m_list[h][w+1] = True
                new_q_list.append((h, w+1))
            if not m_list[h+1][w]:
                m_list[h+1][w] = True
                new_q_list.append((h+1, w))
            if not m_list[h][w-1]:
                m_list[h][w-1] = True
                new_q_list.append((h, w-1))
            if not m_list[h-1][w]:
                m_list[h-1][w] = True
                new_q_list.append((h-1, w))
        q_list = new_q_list
    print(cnt)


if __name__ == "__main__":
    h_len, w_len = map(int, input().split())
    m_list = [[True for _ in range(w_len+2)]]
    for _ in range(h_len):
        m_list.append([True] + [s=='#' for s in input()] + [True])
    m_list.append([True for _ in range(w_len+2)])
    q_list = []
    for h in range(1, h_len+1):
        for w in range(1, w_len+1):
            if m_list[h][w]:
                q_list.append((h, w))
    bfs(q_list)
	

Measured memory_bytes: 105976
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define INF 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

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

	ll A,V,B,W,T;
	cin >> A >> V >> B >> W >> T;
	if(V>W){
		if(abs(B-A) > (V-W)*T){
			cout << "NO" << endl;
		}
		else{
			cout << "YES" <<endl;
		}
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3612
package main

import (
  
	"fmt"
)

func main() {

	var n int

	fmt.Scan(&n)

	p := make([]int,n)

	for i:=0;i<n;i++{

		fmt.Scan(&p[i])
	}

	cnt :=0

	for i:= 1; i< n-1 ;i++{

		if p[i-1] < p[i] && p[i]<p[i+1]{

			cnt++

		}else if p[i+1] < p[i] && p[i] < p[i-1]{

			cnt++
		}

	}

	fmt.Println(cnt)

	
}

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

using namespace std;
using ll = long long;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;

    ll output = N / (A + B) * A;
    if (A >= N % (A + B))
        output += N % (A + B);
    else
        output += A;

    cout << output << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A = 0;
  int B = 0;
  int C = 0;
  int N;
  cin >> N;

  for(int i = 0; i < N; i++){
  	string S;
  	cin >> S;
    if(A >= 1 && B >= 1 && C >= 1){
    if(S == "Y"){
     cout << "Four" << endl;
     break;
    
   }
    else if(i >= N -1 && S !="Y"){
     cout << "Three" << endl;
    break;
    }
    }
   else if(S == "W"){
      A++; 
  }
    else if( S == "P"){
      B++;
  }
    else if( S == "G"){
      C++;
  }
          
       }
    }
  


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

typedef long long ll;

ll N;
vector<ll> A;
typedef pair<ll, vector<ll>> Result;

Result solve(ll start) {
  ll value = 0;
  vector<bool> use;
  pair<ll, ll> max = make_pair(-(1ll << 60), -1);
  vector<ll> picks;
  use.resize(N);
  for (ll i = start; i < N; i += 2) {
    if (max.first < A[i]) max = make_pair(A[i], i);
    if (A[i] > 0) {
      value += A[i];
      use[i] = true;
    }
  }
  ll imax = max.second;
  if (!use[imax]) {
    value += A[imax];
    use[imax] = true;
  }
  while (!use.front()) {
    picks.push_back(0);
    use.erase(use.begin());
  }
  while (!use.back()) {
    picks.push_back(use.size() - 1);
    use.erase(use.end() - 1);
  }
  assert(use.front() && use.back());
  while (use.size() > 1) {
    assert(use.front() && use.back());
    assert(use.size() % 2 == 1);
    if (use[2]) {
      picks.push_back(1);
      use.erase(use.begin() + 1);
      use.erase(use.begin() + 1);
    } else {
      picks.push_back(2);
      use.erase(use.begin() + 2);
      use.erase(use.begin() + 2);
    }
  }
  return make_pair(value, picks);
}
int main() {
  cin >> N;
  A.resize(N);
  for (ll i = 0; i < N; ++i) cin >> A[i];
  Result res = max(solve(0), solve(1));
  cout << res.first << endl;
  cout << res.second.size() << endl;
  for (ll pick : res.second) cout << pick + 1 << endl;
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
	ull n,t;
	cin >> n >> t;
	ull sum  = 0,st = 0,memo = 0,a = 0;
	
	
	rep(i,0,n){
		cin >> a;
		if(memo < a){
			sum += memo-st;
			st = a;
		}
		
		memo = max(memo,a+t);
		
	}
	
	sum += memo - st;
	
	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc179/tasks/abc179_d

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

int main()
{
    const long MOD = 998244353;

    long n, k;
    cin >> n >> k;

    vector<long> L(k), R(k);
    for (long i = 0; i < k; i++)
        cin >> L[i] >> R[i];

    vector<long> dp(n + 1, 0), acc(n + 1, 0);
    dp[1] = 1;
    acc[1] = 1;

    for (long i = 2; i <= n; i++)
    {
        for (long j = 0; j < k; j++)
        {
            long lj = i - R[j];
            long rj = i - L[j];
            if (rj < 1)
                continue;
            lj = max(1L, lj); // 1未満(範囲外)は-acc[]で0を引くようにする
            dp[i] = (dp[i] + acc[rj] - acc[lj - 1]) % MOD;
        }
        acc[i] = (acc[i - 1] + dp[i]) % MOD;
    }
    if (dp[n] < 0)
    {
        dp[n] += MOD;
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

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

	vi b(N,0);
	int count=0;
	int sum;
	for(int i=N; i>0; i--){
		sum=0;
		for(int j=i+i; j<=N; j+=i){
			sum+=b[j-1];
		}
		if(sum%2==a[i-1]){
			b[i-1]=0;
		}else{
			b[i-1]=1;
			count++;
		}
	}

	cout << count << endl;
	for(int i=0; i<N; i++){
		if(b[i]==1){
			cout << i+1 << " ";
		}
	}
	cout << endl;

	return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  string S;
  cin >> S;
  
  for(int i=0; i<S.size(); i++){
    if(i!=A){
      if(S.at(i) >= '0' && S.at(i) <= '9'){
        //nanimosinai
      }else{
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(S.at(i) != '-'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

int main() {
  string S; cin>>S;
  int cnt=0;
  rep(i, S.size()/2) {
    if (S[i]!=S[S.size()-1-i]) cnt++;
  }
  cout<<cnt<<endl;
}

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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"NO\n";
#define CY cout<<"YES\n";

using namespace std;
using ll = long long;

void solve()
{
    ll n; cin>>n;
    vector<ll>v(n);
    rep(i,n) cin>>v[i];
    sort(v.begin(), v.end());
    ll c=n-2;
    ll ans=0;
    ll i=n-2;
    ll f=0;
    while(c>0)
    {
        if(c==1)
        {
            f=1;
            ans*=2;
            ans+=v[i];break;
            
        }
        ans+=v[i];
        c-=2;
        i--;
    }
    if(!f) ans*=2;
    cout<<ans+v[n-1];
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
    //cin>>t;
    while(t--)
        {solve();}
    return 0;
}


Measured memory_bytes: 4784