akhauriyash/Code-Regression huggingface dataset:
def GCD(x, y): 
    while(y): 
       x, y = y, x % y 
    return x

n = int( input() )
a = list( map( int, input().split() ) )
left = [0]*n
right = [0]*n

left[0] = a[0]
for i in range(1,n):
    left[i] = GCD(left[i-1], a[i])

right[-1] = a[-1]
for i in range(2,n+1):
    right[-i] = GCD(right[-i+1], a[-i])

max_gcd = 0
for i in range(n):
    if i == 0 and max_gcd < right[1]:
        max_gcd = right[1]
    elif i == n-1 and max_gcd < left[n-2]:
        max_gcd = left[n-2]
    if i >= 1 and i <= n-2 and max_gcd < GCD( left[i-1], right[i+1]):
        max_gcd = GCD( left[i-1], right[i+1])

print(max_gcd)    

Measured memory_bytes: 63856
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll power(ll a,ll b)
{
    ll res =1;
    while(b)
    {
        if(b&1) res = (res%mod*a%mod)%mod;
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return res;
}
ll sieve[1000005];
void pre()
{
    sieve[0]=1;
    sieve[1]=1;
    for(int i=2;i<1000005;i++)
    {
        if(sieve[i]==0)
        for(int j=2*i;j<1000005;j+=i)
        {
            sieve[j]=1;
        }
    }
}
ll ch(ll p)
{
    ll sum=0;
    while(p)
    {
        sum++;
        p/=10;
    }
    if(sum%2!=0)
    return 1;
    else
    return 0;
}
signed main()
{
    
    senky_bansal
    IIIT_ALLAHABAD
      
    ll n;
    cin>>n;
     ll a[n];
     ll f=0;
     for(int i=0;i<n;i++)
     cin>>a[i];
     for(int i=1;i<n;i++)
     {
         if(a[i]>a[i-1])
         a[i]-=1;
     }
     for(int i=1;i<n;i++)
     if(a[i]<a[i-1])
     f=1;
    
    if(!f)
    cout<<"Yes";
    else
    cout<<"No";
    
    
    
    
    
}








Measured memory_bytes: 1024
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	String s;

	void run() {
		s = sc.nextLine();
		solve();
	}

	void solve() {
		int n = s.length();
		int[] count = new int[2 * n + 1];
		int now = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == '(') {
				now++;
			} else {
				now--;
			}
			count[now + n]++;
		}
		// debug(count);
		now = 0;
		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == '(') {
				now++;
			} else {
				now--;
			}
			count[now + n]--;
			// debug(now, count[now + n]);
			ans += count[now + n];
		}
		println(ans + "");
	}

	void println(String s) {
		System.out.println(s);
	}

	void print(String s) {
		System.out.print(s);
	}

	void debug(Object... os) {
		System.err.println(deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <algorithm>
using namespace std;
int min(int a,int b){
    return a<b?a:b;
}
int main(void){
    int a,b;
    int ans = 0;
    cin >> a >> b;
    if(a > b){
        int tmp = a;
        a = b;
        b = tmp;
    }
    for(int i=1;i<=b;i++){
        ans = ans * 10 + a;
    }
    cout << ans ;
}


Measured memory_bytes: 3196
// AOJ 0574 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0574)
#include<cstdio>
#include<vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

const int MAX_N = 5000;

int N, M;
std::vector<std::vector<int> > S( MAX_N+2 );

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

	rep( i, N+2 )
		S[i].resize( i+2 );

	rep( i, M )
	{
		int A, B, X;
		scanf( "%d%d%d", &A, &B, &X );
		--A; --B;
		++S[A][B]; --S[A][B+1];
		--S[A+X+1][B]; ++S[A+X+1][B+X+2];
		++S[A+X+2][B+1]; --S[A+X+2][B+X+2];
	}

	rep( i, N+2 ) rep( j, i+1 )
		S[i][j+1] += S[i][j];
	rep( i, N+1 ) rep( j, i+2 )
		S[i+1][j] += S[i][j];
	rep( i, N+1 ) rep( j, i+1 )
		S[i+1][j+1] += S[i][j];

	int ans = 0;
	rep( i, N ) rep( j, i+1 ) if( S[i][j] )
		++ans;

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

	return 0;
}

Measured memory_bytes: 49848
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	cin >> s; int a = 0, b = 0;
	rep(i, 3)
	{
		if (s[i] == 'A')
			a++;
		else
			b++;
	}
	if (a > 0 && b > 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

using ll = long long;

#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (int)(a.size())
#define clr(a, b) memset(a, b, sizeof(a))
#define REP(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REPD(i, a, b) for(int i=(int)(a)-1; i>=(int)(b); --i)

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

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

int x[123456], y[123456];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    REP(i, 0, N) {
    	cin >> x[i] >> y[i];
    }
    int res = 0;
    REP(i, 0, N-2) {
    	if(x[i] == y[i] && x[i+1] == y[i+1] && x[i+2] == y[i+2]) ++res;
    }
    if(res)
    	cout << "Yes\n";
    else
    	cout << "No\n";
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int main(){
  int N;
  scanf("%d", &N);
  
  if(N<=111){
    printf("111");
    return 0;
  }
  if(N<=222){
    printf("222");
    return 0;
  }
  if(N<=333){
    printf("333");
    return 0;
  }
  if(N<=444){
    printf("444");
    return 0;
  }
  if(N<=555){
    printf("555");
    return 0;
  }
  if(N<=666){
    printf("666");
    return 0;
  }
  if(N<=777){
    printf("777");
    return 0;
  }
  if(N<=888){
    printf("888");
    return 0;
  }
  if(N<=999){
    printf("999");
    return 0;
  }
}


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

class Move
{
  public:
    int current;
    string plus;
    string minus;
    Move(int start, string p, string m)
    {
        current = start;
        plus = p;
        minus = m;
    }

    void move(int to)
    {
        for (int i = 0; i < abs(to - current); i++)
        {
            if (current < to)
            {
                cout << plus;
            }
            else
            {
                cout << minus;
            }
        }
        current = to;
    }
};

int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    Move x(sx, "R", "L");
    Move y(sy, "U", "D");

    x.move(tx);
    y.move(ty);
    x.move(sx);
    y.move(sy);

    if (sx < tx)
    {
        x.move(sx - 1);
    }
    else
    {
        x.move(sx + 1);
    }

    if (sy < ty)
    {
        y.move(ty + 1);
    }
    else
    {
        y.move(ty - 1);
    }

    x.move(tx);
    y.move(ty);

    if (sx < tx)
    {
        x.move(tx + 1);
    }
    else
    {
        x.move(tx - 1);
    }

    if (sy < ty)
    {
        y.move(sy - 1);
    }
    else
    {
        y.move(sy + 1);
    }

    x.move(sx);
    y.move(sy);

    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    //データ定義
    string s,p;
    
    //データ入力
    cin >> s >> p;
    
    //主処理
    s += s; /*つなげて輪のようにする*/
    //検索文字列が見つかったか判定
    if(s.find(p) != -1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}


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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	//A < Bに設定
	if (A > B) swap(A, B);

	int count = 0, ans;
	
	for (int i = A;i > 0;i--) {
		if (A % i == 0 && B % i == 0) { count++; }
		if (count == K) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")

#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n,t; cin >> n >> t;
  queue< pair<string, int> > q;
  int timeSum = 0;
  rep(i, n){
    string a; int b;
    cin >> a >> b;
    q.push(make_pair(a,b));
  }
  while(q.size() > 0){
    pair<string, int> tmp = q.front();
    q.pop();
    if(tmp.second <= t){
      cout << tmp.first <<" "<< tmp.second+timeSum <<"\n";
      timeSum += tmp.second;
    }else{
      timeSum += t;
      q.push(make_pair(tmp.first, tmp.second-t));
    }
  }
}


Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
	if(a % b == 0){
		return b;
	} else {
		return GCD(b, a % b);
	}
}

int main(){
	int N;
	scanf("%d", &N);
	vector<long long> A(N);
	vector<long long> gcd(N);
	vector<long long> memo(N, 0);//1 ~ i-1 番目までのGCD
	vector<long long> MEMO(N, 0);//i+1 ~ N番目までのGCD
	for(int i = 0; i < N; i++)cin >> A.at(i);
	memo[1] = A[0];
	MEMO[N - 2] = A[N - 1];
	
	for(int i = 2; i < N; i++){
		memo[i] = GCD(memo[i - 1], A[i - 1]);
		MEMO[N - 1 - i] = GCD(MEMO[N - i], A[N - i]);
	}
	
	long long ans = max(memo[N - 1], MEMO[0]);
	for(int i = 1; i < N - 1; i++){
		long long res = GCD(memo[i], MEMO[i]);
		if(ans < res)ans = res;
	}
  	
	printf("%d\n", ans);
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n,d;
    cin >> n >> d;
    int a,b;
    int cnt = 0;
    for (int i=0;i<n;i++) {
        double a,b;
        cin >> a>> b;
        double dd = sqrt((a*a) + (b*b));
        if (dd <= d) cnt++;
    }
    cout << cnt << "\n";

}


Measured memory_bytes: 3824
line = readlines
len = line.length
i = 0

while i < len
    line[i] = line[i].chomp
    i += 1
end

N = line[0].to_i
S = line[1]

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
ar = []
for i in 1..52 do
  ar.push(a[i-1])
end

answer = ""
for i in 1..S.length do
  num = ar.index(S[i-1])
  answer = answer + ar[num+N]
end

print answer

Measured memory_bytes: 18812
<?php

$n = trim(fgets(STDIN));
$nsize = strlen(floor(sqrt($n)));
$rslt = strlen($n);

for($i = 1; $i <= floor(sqrt($n));  $i++){
    if($n%$i == 0){
        $rslt = strlen($n/$i);
        if($rslt == $nsize) break;
    }
}

print $rslt;

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=INF,aa[220000],ans=0,t,a;
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n>>t>>a;
    rep(i,n){
        cin>>aa[i];
        if(abs(a*1000-t*1000+6*aa[i])<cnt){
            cnt=abs(a*1000-t*1000+6*aa[i]);
            ans=i+1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10508
n = int(input())
a_list = list(map(int,input().split()))

num_dict = {}

for i,a in enumerate(a_list):
    idx = a+i
    if idx > 0:
        if idx not in num_dict:
            num_dict[idx] = 1
        else:
            num_dict[idx] += 1

count = 0

for i,a in enumerate(a_list):
    target_idx = i-a
    if target_idx in num_dict:
        if target_idx != a-i:
            count += num_dict[target_idx]
        else:
            count += num_dict[target_idx]-1


print(count)

Measured memory_bytes: 40448
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Kenji
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC107B solver = new ABC107B();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC107B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            List<String> list = new ArrayList<>();
            for (int i = 0; i < H; i++) {
                list.add(in.next());
            }
            for (int i = 0; i < H; i++) {
                String s = list.get(i);
                if (s.indexOf("#") == -1) {
                    s = s.replaceAll(".", "!");
                    list.set(i, s);
                }
            }
            for (int i = 0; i < W; i++) {
                boolean f = true;
                for (int j = 0; j < H; j++) {
                    String s = list.get(j);
                    if (s.charAt(i) == '#') {
                        f = false;
                    }
                }
                if (f) {
                    for (int j = 0; j < H; j++) {
                        String s = list.get(j);
                        String s2 = s.substring(0, i) + "!" + s.substring(i + 1, s.length());
                        list.set(j, s2);
                    }
                }
            }
            for (int i = 0; i < H; i++) {
                String s = list.get(i);
                boolean f = false;
                for (int j = 0; j < s.length(); j++) {
                    if (s.charAt(j) != '!') {
                        out.append(s.charAt(j));
                        f = true;
                    }
                }
                if (f) {
                    out.println();
                }
            }
        }

    }
}



Measured memory_bytes: 32084
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	long x = s.nextLong();
    	long y = s.nextLong();
    	long z = s.nextLong();
    	System.out.print(z+" "+x+" "+y);
    	
    }	
}





        
    

      
 

Measured memory_bytes: 37544
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

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

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
	string s;
	cin >> s;
	int n;
	n = s.size();

	int i = 1 << (n-1);
	ll res = 0;
	while(!(i & (1 << n))){
		ll tmp = 0;
		rep(j, n){
			tmp += s[j] - '0';
			if(i & (1 << j)){
				res += tmp;
				tmp = 0;
			}else{
				tmp *= 10;
			}
		}
		i++;
	}

	cout << res << endl;
}

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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,x,*l=map(int,open(0).read().split());print(sum(x>=sum(l[:i+1])for i in range(n))+1)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 7100
n,q=map(int,input().split())
stx=[list(map(int,input().split())) for _ in range(n)]
d=[int(input()) for _ in range(q)]
inf=float('inf')

import heapq
class pqheap:
  def __init__(self,key=None):
    self.p = list()
    self.q = list()

  def insert(self,x):
    heapq.heappush(self.p, x)
    return

  def erase(self,x):
    heapq.heappush(self.q, x)
    return

  def minimum(self):
    while self.q and self.p[0] == self.q[0]:
      heapq.heappop(self.p)
      heapq.heappop(self.q)
    return self.p[0] if len(self.p)>0 else -1
memopush={}
memopop={}
from bisect import bisect_left,bisect_right
for s,t,x in stx:
  l,r=max(0,s-x),max(0,t-x)
  # 出発時刻が[l,r)の人の進む距離がxで抑えられる
  if l in memopush:
    memopush[l].append(x)
  else:
    memopush[l]=[x]
  if r in memopop:
    memopop[r].append(x)
  else:
    memopop[r]=[x]
keys=list(set(memopush.keys()).union(set(memopop.keys())))
keys.sort()
pq=pqheap()
dct=[[-1,-1]]
for k in keys:
  if k in memopush:
    for v in memopush[k]:
      pq.insert(v)
  if k in memopop:
    for v in memopop[k]:
      pq.erase(v)
  dct.append([k,pq.minimum()])
i=0
for x in d:
  while i+1<len(dct) and dct[i+1][0]<=x:
    i+=1
  if i>=len(dct):
    print(-1)
  else:
    print(dct[i][1])

#print(dct)

Measured memory_bytes: 234436
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int MAX_N=1e5+5;
const ll inf=1e18;
inline int qi(){
    int f=0,fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
inline ll ql(){
	ll f=0;int fu=1; char c=getchar();
    while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
    while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
    return f*fu;
}
ll c[MAX_N],p[MAX_N];
bool vis[MAX_N];
ll b[MAX_N],sum[MAX_N];
int q[MAX_N],st,ed;
ll cal(vector<ll> a,ll k)
{
 
	b[0]=sum[0]=0;
	for(auto x:a) b[++b[0]]=c[x];
	
	repi(i,1,b[0]) b[b[0]+i]=b[2*b[0]+i]=b[i];
	repi(i,1,3*b[0]) sum[i]=sum[i-1]+b[i];
	ll res=0,tk=k,tmp=-inf;
	if(sum[b[0]]>0&&(tk/b[0])>2) res+=sum[b[0]]*((tk/b[0])-1),tk-=b[0]*((tk/b[0])-1);
	else if(sum[b[0]]<0) tk=min(tk,b[0]-1);
	st=1,q[ed=1]=0;
	repi(i,1,3*b[0]){
		while(st<ed&&(i-q[st])>tk) st++;
		tmp=max(tmp,sum[i]-sum[q[st]]);
		while(st<=ed&&sum[i]<sum[q[ed]]) ed--;
		q[++ed]=i;
	}
	repi(i,1,tk)repi(j,1,b[0]) tmp=max(tmp,sum[j+i-1]-sum[j-1]);
	return res+tmp;
}
int main()
{
	ll n=ql(),k=ql();
	repi(i,1,n) p[i]=ql();
	repi(i,1,n) c[i]=ql();
	ll ans=-inf;
	repi(i,1,n)if(!vis[i]){
		ll now=i;
        vector<ll> tmp;
        while(p[now]!=i) tmp.pb(now),vis[now]=true,now=p[now]; vis[now]=true,tmp.pb(now);
    	ans=max(ans,cal(tmp,k));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4176
n, q = gets.chomp.split.map(&:to_i)
str = gets.chomp

ruisekiwa = []
flag = false
for i in 0...n
  if flag
    if str[i] == "C"
      ruisekiwa[i] = ruisekiwa[i-1] + 1
      flag = false
    else
      ruisekiwa[i] = ruisekiwa[i-1]
      flag = false if str[i] != "A"
    end
  else
    if str[i] == "A"
      flag = true
    end
    if i == 0
      ruisekiwa[i] = 0
    else
      ruisekiwa[i] = ruisekiwa[i-1]
    end
  end
end
ary = []
q.times do
  ary << gets.chomp.split.map(&:to_i)
end

ary.each do |item|
  ans = ruisekiwa[item[1]-1] - ruisekiwa[item[0]-1]
  puts ans
end




Measured memory_bytes: 11132
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, M, X[100001];
	scanf("%lld %lld", &N, &M);
	for (i = 0; i < M; i++) scanf("%d", &(X[i]));
	
	if (N >= M) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	
	int dif[100000] = {}, sum;
	merge_sort(X, M);
	sum = X[M-1] - X[0];
	for (i = 0; i < M - 1; i++) dif[i] = X[i+1] - X[i];
	merge_sort(dif, M - 1);
	for (i = 0; i < N - 1; i++) sum -= dif[M-2-i];
	
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w;
    cin >> h >> w;
    int a[500][500];
    rep(i, h) rep(ii, w) cin >> a[i][ii];
    vector<vector<int>> log;
    
    rep(i, h - 1) {
        rep(ii, w) {
            if (a[i][ii] % 2 == 1) {
                a[i][ii]--;
                a[i + 1][ii]++;
                vector<int> v;
                v.push_back(i);
                v.push_back(ii);
                v.push_back(i + 1);
                v.push_back(ii);
                log.push_back(v);
            }
        }
    }
    
    rep(i, w - 1) {
        if (a[h - 1][i] % 2 == 1) {
            a[h - 1][i]--;
            a[h - 1][i + 1]++;
            vector<int> v;
            v.push_back(h - 1);
            v.push_back(i);
            v.push_back(h - 1);
            v.push_back(i + 1);
            log.push_back(v);
        }
    }
    
    printf("%d\n", sz(log));
    
    rep(i, sz(log)) {
        printf("%d %d %d %d\n", log[i][0] + 1, log[i][1] + 1, log[i][2] + 1, log[i][3] + 1);
    }
    
    return 0;
}

Measured memory_bytes: 9904
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc  = new Scanner(System.in);
		int[] ans = new int[10];
		int len = ans.length;
		for(int i = 0; i < len; i++) {
			ans[i] = sc.nextInt();
		}
		Arrays.sort(ans);
		len--;
		for(int i = len; i > len - 3; i--) {
			System.out.println(ans[i]);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using  namespace  std;
using ll=long long;
int main(){
  vector<string> s(3);
  for(int i=0;i<3;i++)cin>>s.at(i);
  for(int i=0;i<3;i++)cout<<s.at(i).at(i);
  cout<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int f=0;
    int n;
    cin >> n;
    pair<int,int> ar[n+3];
    for(int i=1;i<=n;i++)
        cin >> ar[i].f >> ar[i].ss;

    for(int i=3;i<=n;i++)
    {
        if(ar[i].f==ar[i].ss && ar[i-1].f==ar[i-1].ss && ar[i-2].f==ar[i-2].ss)
        {
            f=1;
            break;
        }
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;cin>>s;
    int len=s.length(),count=0,res=0;
    for(int i=0;i<len;i++){
       if(s[i]=='A' or s[i]=='G' or s[i]=='C' or s[i]=='T') {
           count++;
           (res<count)? res=count:1;
       }
       else count=0;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 1000000007;


int main() {
  int X,t;
  cin >> X >> t;
  cout << max(0,X - t) << endl;
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
src = list(map(int,input().split()))
ctr = Counter(src)

l = None
for k,v in sorted(ctr.items(),reverse=True):
    if l:
        if v >= 2:
            print(l*k)
            exit()
    else:
        if v >= 4:
            print(k*k)
            exit()
        elif v >= 2:
            l = k
print(0)

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

int main(){
	string w;
	cin >> w;
	
	map<char, int> mp;
	for(int i = 0; i < w.length(); i++){
		mp[w[i]]++;
	}
	
	bool ok = true;
	for(auto a : mp){
		if(a.second % 2 != 0)ok = false;
	}
	
	if(ok == true){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	int sum = a + b + c;
	int x = max(max(a, b), c);
	sum -= x;
	for (int i = 0; i < k; i++) {
		x *= 2;
	}
	sum += x;
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int n, k;
    double p[200000+5];
    scanf("%d %d", &n, &k);
    for(int i=0; i<n; i++)scanf("%lf", &p[i]);
    for(int i=0; i<n; i++)p[i]=(double)(p[i]+1)/2;
    
    double s[200000+5];    // 累積和
    s[0]=p[0];
    for(int i=1; i<n; i++)s[i]=s[i-1]+p[i];
    
    float ans=s[k-1];
    for(int i=k; i<n; i++){
        if(ans<s[i]-s[i-k]){
            ans=s[i]-s[i-k];
        }
    }
    
    printf("%f\n", ans);
    return 0;
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

mint multichoose(int n,int k,int type=0){
	return choose(n+k-1,k,type);
}

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

	mint ans=0;
	rep(i,min(n,k)+1) ans+=choose(n,i)*multichoose(n-i,i);
	cout<<ans<<'\n';

	return 0;
}


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

const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main() {
  int h, w;
  cin >> h >> w;
  int si,sj;
  si = 0;
  sj = 0;
  int fi,fj;
  fi = h-1;
  fj = w-1;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> dist(h, vector<int>(w, INF));
  queue<P> q;
  auto update = [&](int i, int j, int x) {
    if (dist[i][j] != INF) return;
    dist[i][j] = x;
    q.push(P(i,j)); // .emplace(i,j)
  };
  update(si,sj,0);
  while (!q.empty()) {
    int i = q.front().first;
    int j = q.front().second; q.pop();
    rep(dir,4) {
      int ni = i+di[dir], nj = j+dj[dir];
      if (ni<0||ni>=h||nj<0||nj>=w) continue;
      if (s[ni][nj] == '#') continue;
      update(ni, nj, dist[i][j]+1);
    }
  }
  int c=0;
  rep(i,h)rep(j,w){
    if(s[i][j]=='#')c++;
  }
  if(dist[fi][fj]==INF)cout << -1 << endl;
  else cout << h*w - dist[fi][fj] - c - 1 << endl;
  return 0;
}


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

int main(){
  int N;
  string S,T,ans;
  cin>>N;
  cin>>S;
  cin>>T;
  for(int i=0;i<N;i++){
    ans.push_back(S.at(i));
    ans.push_back(T.at(i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	#define hell                         1000000007 
	#define M                            1000000007
	#define Maxi                      10000000000000000
	#define lcm(a,b)                     (a*b)/__gcd(a,b)
	#define ll                           long long
 
	#define vll                          vector<ll>
	#define vi                           vector<long long>
	#define pll                          vector< pair<ll,ll> >
	#define pb                           push_back
	//#define mp                           make_pair
	#define all(v)                       v.begin(),v.end()
	#define lbnd                         lower_bound
	#define ubnd                         upper_bound
	#define bs                           binary_search
	#define F                            first
	#define S                            second
	#define rep(i,a,b)                   for(i=a;i<b;i++)
	#define parr(a,n)                    for(i=0;i<n;i++) cout<<a[i]<<" ";cout<<endl;
	#define pcont(a)                     for(auto i:a) cout<<i<<" ";cout<<endl;
	#define ret(x)                       return cout<<x,0;
	#define dbg(x)                       cout << #x << " is " << x << endl;
	//#define endl                           '\n'
 
 
	// Debug //
 
	#define trace(x)                 cerr << #x << ": " << x << endl;
	#define trace1(x)                cerr << #x << ": " << x << endl;
	#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
	#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
	#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
	#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
	#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
 
	using namespace std;
 	
	int main()
	{
 
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);cout.tie(NULL);
		

	 	ll n;
	 	cin>>n;
	 	cout<<n*n*n<<endl;
 
		return 0;
		}
	 	


Measured memory_bytes: 256
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 228228
#define MOD 1000000007
ll n, x, k, z, m, a[200500], b[200500], ra[200500], rb[200500], pa, pb;
vector<vector<ll>> f;
vector<ll> g;
int main() {
    cin >> n >> m;
    ll p = 1;
    while (p < m) {
        p += n - 1;
        k++;
    }
    cout << k << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    int n;
    IN n;
    vector<ll> a;
    
    rep(i,0,n){
        ll b;
        IN b;
        if(b%2 == 0)a.pb(b);
    }
    
    if(sz(a) <= 0){
        P(0);
        ret 0;
    }
    ll ans = 0;
   
    for(auto ite: a){
        while(!(ite&1)){
            ans++;
            ite /= 2;
        }
    }
    P(ans);
	return  0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

long long N;
long long M;
std::vector<long long > A(100000);
std::vector<long long > kumisuu(200000, 0); // A_i>=x を満たすiの数
std::vector<long long > souwa(200000, 0); // A_i>=x を満たすiについてA_iの総和

long long get_possible_count(int value){ // 値がvalue以上となる組み合わせ総数を求める
  long long count = 0;
  for (int i=0; i<N; i++){
    count += kumisuu[std::max(value-A[i], (long long)0)];
  }
  return count;
}

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

  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    kumisuu[A[i]]++;
  }
  sort(A.begin(), A.end(), std::greater<long long>());

  for (int i=0; i<N; i++){
    souwa[i+1] = souwa[i] + A[i];
  }

  /*  累積和を求める */
  for (int i=200000; i>0; i--){
    kumisuu[i-1] += kumisuu[i];
  }

  int left = 0;
  int right = 200001;
  int mid;
  long long ans = 0;
  std::map<long long, long long> mp;
  while(right-left>1){
    mid = (left+right)/2;
    ans=0;
    for (int i=0; i<N; i++){
      ans += souwa[kumisuu[std::max(mid-A[i],(long long)0)]];
      ans += A[i]*kumisuu[std::max(mid-A[i],(long long)0)];
    }
    if (get_possible_count(mid)>=M){ // 
      left = mid;
    } else {
      right = mid;
    }
    mp[mid] = get_possible_count(mid);
  }
  if (left == mid){
    std::cout << ans-abs(M-mp[left])*left << std::endl;
  } else if (right==mid){
    std::cout << ans+abs(M-mp[right])*left << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>

int main() {
    int a, h, n;
    int ans;
    scanf("%d%d", &h, &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &a);
        h -= a;
    }
    if (h <= 0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 128
class Facts

  def initialize(mod=10**9+7, n_max=1)
    @mod = mod
    @n_max = n_max
    @fact = [1, 1]
    @inv = [0,1]
    @factinv = [1, 1]
    setup_table(n_max) if 1 < @n_max
  end

  def cmb(n,r)
    return 0 if r < 0 || n < r
    setup_table(n) if @n_max < n
    @fact[n] * (@factinv[r] * @factinv[n-r] % @mod) % @mod
  end

  def factorial(n)
    setup_table(n) if @n_max < n
    @fact[n]
  end

  def prm(n,k)
    setup_table(n) if @n_max < n
    @fact[n] * @factinv[n-k] % @mod
  end

  private
    # O(t)
    def setup_table(t)
      (@n_max+1).upto(t) do |i|
        @fact.push( @fact[-1] * i % @mod )
        @inv.push( -@inv[@mod % i] * (@mod / i) % @mod )
        @factinv.push( @factinv[-1] * @inv[-1] % @mod )
      end
      @n_max = t
    end
end

mod = 998244353

n, m, k = gets.to_s.split.map{|e|e.to_i}

b = Array.new(k+1)
b[-1] = m * (m-1).pow(n-1-k, mod)

k.times do |i|
  b[-2-i] = b[-1-i] * (m-1) % mod
end

ans = 0

f = Facts.new(mod)

(k+1).times do |i|
  ans += f.cmb(n-1, i) * b[i] % mod
end

puts ans % mod

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

int main()
{
    int h, w;
    cin >> h >> w;
    rep(i, w + 2)
    {
        cout << '#';
    }
    cout << endl;
    rep(i, h)
    {
        string in;
        cin >> in;
        cout << '#' << in << '#' << endl;
    }
    rep(i, w + 2)
    {
        cout << '#';
    }
    cout << endl;
    return 0;
}

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

struct Node {
    Node *parent;
    Node *left;
    Node *right;
    int key;
};

Node *NIL, *root;

void init() {
    root = NIL;
}

void insert(int key) {
    Node *y = NIL;
    Node *x = root;
    while (x != NIL) {
        y = x;
        if (key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    Node *node = (Node *)malloc(sizeof(Node));
    node->parent = y;
    node->key = key;
    node->left = NIL;
    node->right = NIL;
    if (y == NIL) {
        root = node;
    } else if (key < y->key) {
        y->left = node;
    } else {
        y->right = node;
    }
}

Node* find(int key) {
    Node *x = root;
    while (x != NIL && x->key != key) {
        if (key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    return x;
}

void deleteNode(int key) {

}

void printByPreorder(Node *node) {
    if (node == NIL) {
        return;
    }

    cout << " "<< node->key;
    printByPreorder(node->left);
    printByPreorder(node->right);
}

void printByInorder(Node *node) {
    if (node == NIL) {
        return;
    }

    printByInorder(node->left);
    cout << " "<< node->key;
    printByInorder(node->right);
}

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

    string command;
    int key;
    for (int i = 0; i < n; i++) {
        cin >> command;
        if (command == "insert") {
            cin >> key;
            insert(key);
        } else if (command == "find") {
            cin >> key;
            Node *node = find(key);
            if (node != NIL) cout << "yes" << endl;
            else cout << "no" << endl;
        } else if (command == "delete") {
            cin >> key;
            deleteNode(key);
        } else {
            printByInorder(root);
            cout << endl;
            printByPreorder(root);
            cout << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 21856
#include<iostream>
#include<cmath>
#include<cstdio>
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}

  double abs(){return sqrt(norm());}

  double norm(){return (x*x+y*y);}
};
typedef Point Vector;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){return (a.x*b.y-a.y*b.x);}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

bool isOrthogonal(Vector a,Vector b){
  return equals(dot(a,b),0.0);
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-eps)return CLOCKWISE;
  if(dot(a,b)<-eps)return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;
  return ON_SEGMENT;
}

int main()
{
  Point A,B,C,D;
  int q;

  cin>>A.x>>A.y>>B.x>>B.y;
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>C.x>>C.y;
    int ans=ccw(A,B,C);
    if(ans==1)cout<<"COUNTER_CLOCKWISE"<<endl;
    if(ans==-1)cout<<"CLOCKWISE"<<endl;
    if(ans==2)cout<<"ONLINE_BACK"<<endl;
    if(ans==-2)cout<<"ONLINE_FRONT"<<endl;
    if(ans==0)cout<<"ON_SEGMENT"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1232
n, m, c = map(int, input().split())

a=[]
b=[]
b = list(map(int, input().split()))

for _ in range(n):
    a.append(list(map(int, input().split())))
    
ans=0
for i in range(n):
    s=0
    for j, k in zip(a[i],b):
        s += j*k
    if s + c > 0:
        ans+=1

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 12 20:58:46 2020

@author: Kanaru Sato
"""

import math

k = int(input())

sum1 = 0
for i in range(1,k+1):
    sum1 += i

sum2 = 0
for i in range(1,k):
    for j in range(i+1,k+1):
        sum2 += math.gcd(i,j)
sum2 = 6*sum2

sum3 = 0
for i in range(1,k-1):
    for j in range(i+1,k):
        for k in range(j+1,k+1):
            sum3 += math.gcd(math.gcd(i,j),k)
sum3 = 6*sum3

ans = sum1 + sum2 + sum3

print(ans)

Measured memory_bytes: 9212
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: String = sc.read();
    let n = to_chars(n);
    let mut ans = 0;
    for i in 0..3 {
        if n[i] == '1' {
            ans += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = input()

while True:
    if s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    elif s[-5:] == 'dream' or s[-5:] == 'erase':
        s = s[:-5]
    elif len(s) == 0:
        print('YES')
        break
    else:
        print("NO")
        break

Measured memory_bytes: 3188
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    d,n = LI()
    if n < 100:
        return 100**d*n
    return 100**d*(n+1)


print(main())



Measured memory_bytes: 7752
import numpy as np

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
table = np.zeros(w+1, dtype=np.int64)

for i in range(n):
    l = table[:-wv[i][0]]
    r = table[wv[i][0]:]
    np.maximum(l + wv[i][1], r, out = r)

print(table[w])

Measured memory_bytes: 14604
#include <iostream>
#include <vector>
#include <math.h>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
	int N;
	int tmp;
	vector<int> v;
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> tmp;
		v.push_back(tmp);
	}

	int w1 = 0;
	int w2 = 0;

	int left_index = 0;
	int right_index = N-1;
	int counter = 0;
	
	while(counter != N){
		if (w1 > w2){
			w2 += v[right_index];
			right_index -= 1;
		}
		else if(w1 <= w2){
			w1 += v[left_index];
			left_index += 1;
		}
		counter++;
	}
	cout << abs(w1-w2) << endl;
}

Measured memory_bytes: 256