akhauriyash/Code-Regression huggingface dataset:
n, q = map(int, input().split())
s = input()
ans = [0] * (n + 1)
for i in range(n):
    ans[i + 1] = ans[i] + (1 if s[i:i+2] == "AC" else 0)
for j in range(q):
    l,r = map(int, input().split())
    res = ans[r-1] - ans[l-1]
    print(res)

Measured memory_bytes: 7748
#include <stdio.h>
#include <stdlib.h>

int main(){
    char n[3] = {0};
    scanf("%s",n);
    int i;
    for(i=0; i<3; i++){
        if(n[i] == '1'){
            n[i] = '9';
        }else{
            n[i] = '1';
        }
    }
    printf("%d\n",atoi(n));
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
    vint a(n);
  rep(i,n){
    cin>>a[i];
  }
  if(k>100){
    rep(i,n){
      cout<<n<<' ';
    }
  }
  else{
    rep(i,k){
      vector<int> imos(n);
      rep(i,n){
        if(i-a[i]<0){
          imos[0]++;
        }
        else{
          imos[i-a[i]]++;
        }
        if(i+a[i]+1>=n){
        }
        else{
          imos[i+a[i]+1]--;
        }
      }
      int count=0;
      rep(i,n){
        count+=imos[i];
        a[i]=count;
      }
    }
    rep(i,n){
      cout<<a[i]<<' ';
    }
  }
  return(0);
}


Measured memory_bytes: 4920
class Array
  # being_deleted must be sorted
  def delete_ats(being_deleted)
    tmp = []
    current = 0
    self.each_with_index do |a, i|
      if being_deleted[current] == i
        current += 1
      else
        tmp << a
      end
    end
    self.replace(tmp)
  end
end

s = gets.chomp.chars
(0..s.size).each do |from|
  (0..s.size - from).each do |length|
    copy = Marshal.load(Marshal.dump(s))
    copy.delete_ats((from...from + length).to_a)
    if copy.join == "keyence"
      puts "YES"
      exit
    end
  end
end
puts "NO"


Measured memory_bytes: 3836
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 50005;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = (int)s.size();
    if (n == 2)cout << s << endl;
    else {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: break
    sum_a = sum_b = 0
    for i in range(n):
        a, b = map(int, input().split())
        if a > b:sum_a = sum_a + a + b
        elif a < b:sum_b = sum_b + a + b
        else:
            sum_a = sum_a + a
            sum_b = sum_b + b
    print(sum_a,sum_b)



Measured memory_bytes: 5608
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k, x;
    cin >>k >>x;
    vector<int> ans;
    int low = x - 1;
    int high = x + 1;
    ans.push_back(x);
    int temp = k - 1;
    while(low >= -1000000 && temp--){
        ans.push_back(low);
        low--;
    }
    temp = k - 1;
    while(high <= 1000000 && temp--){
        ans.push_back(high);
        high++;
    }
    sort(ans.begin(), ans.end());
    for(auto ele : ans)
        cout <<ele <<" ";
    return 0;
}


Measured memory_bytes: 256
fn input_trio<T: std::str::FromStr + Copy> () -> (T, T, T) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let arr: Vec<_> = s.trim().split_whitespace().flat_map(str::parse).collect();
    (arr[0], arr[1], arr[2])
}

fn main() {
    let (a, b, c) = input_trio::<usize>();
    if a == b && b != c || a == c && c != b || b == c && c != a {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main(){
    
    ll N,x,total=1;
    cin >> N;
    vector<ll> vec(N,0);
    vector<ll> vec2;
    rep(i,N){
        cin >> x;
        if(i==0&&x!=0) total = 0;
        if(i!=0&&x==0) total = 0;
        vec[x]++;
    }
    
    for(ll i=1;i<N;i++){
        for(ll j=0;j<vec[i];j++){
            vec2.push_back(vec[i-1]);
        }
        if(vec[i-1]=0&&vec[i]!=0){
            total = 0;
            break;
        }
    }
    
    for(ll i=0;i<vec2.size();i++){
        total=total*vec2[i];
        total=total%998244353;
    }
    
    cout << total << endl;
    
   

    return 0;
}

Measured memory_bytes: 2168
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        UnionFindTree uft = new UnionFindTree(n);
        for (int i = 0; i < m; i++) {
            uft.unite(sc.nextInt() - 1, sc.nextInt() - 1);
            sc.nextInt();
        }
        System.out.println(uft.getCount());
    }
    
    static class UnionFindTree {
        int[] parents;
        
        public UnionFindTree(int size) {
            parents = new int[size];
            for (int i = 0; i < size; i++) {
                parents[i] = i;
            }
        }
        
        public int find(int x) {
            if (x == parents[x]) {
                return x;
            } else {
                return parents[x] = find(parents[x]);
            }
        }
        
        public boolean same(int x, int y) {
            return find(x) == find(y);
        }
        
        public void unite(int x, int y) {
            if (!same(x, y)) {
                parents[find(x)] = find(y);
            }
        }
        
        public int getCount() {
            HashSet<Integer> set = new HashSet<>();
            for (int x : parents) {
                set.add(find(x));
            }
            return set.size();
        }
    }
}

Measured memory_bytes: 63404
N = input()[::-1]
l = len(N)

n0 = int(N[0])
dp = [[0, 0] for i in range(l)]
dp[0] = [n0, 11-n0]

for i, n in enumerate(N[1:], 1):
  n = int(n)
  dp[i][0] = min(dp[i-1][0]+n, dp[i-1][1]+n)
  dp[i][1] = min(dp[i-1][0]+1+(10-n), dp[i-1][1]+(9-n))


print(min(dp[-1]))

Measured memory_bytes: 142364
import java.util.*;
public class Main {
  public static void main(String args[]) {
	Scanner scn = new Scanner(System.in);
    String result;
    
    
    if (scn.nextInt() % 2 == 0) {
    	result = "Even";
    } else {
        if (scn.nextInt() % 2 == 0) {
          result = "Even";
        } else {
          result = "Odd";
        }
    }
    
    System.out.println(result);
  }
}


Measured memory_bytes: 19796
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  int k;
  cin >> s >> k;
  int n = s.size();

  int c = 0, first = 0;
  ll one_cycle = 0, ans = 0;
  rep(i, 1, n) {
    if (s[i - 1] == s[i])
      c++;
    else {
      if (one_cycle == 0)
        first = c;
      one_cycle += (c + 1) / 2;
      c = 0;
    }
  }

  if (n & 1 && c == n - 1) {
    ll t = n / 2;
    ll eve = k / 2;
    ll odd = k - eve;
    ans = t * odd + (t + 1) * eve;
    cout << ans << endl;
    return 0;
  }

  one_cycle += (c + 1) / 2;
  ans = one_cycle * k;

  if (first != 0 && first % 2 == 0 && c % 2 == 0 && s[0] == s[n - 1])
    ans += k - 1;
  cout << ans << endl;
}


Measured memory_bytes: 3656
#include <stdio.h>
#include <string.h>
#define N 5000
#define M 500000
#define MAX(a, b) ((a)>(b)?(a):(b))

typedef struct tagBX {
    short b;
    short x;
    struct tagBX *next;
} BX;

BX bx[M], *abx[N + 1];

short work1[N+1];
short work2[N+1];

int main(void) {
    int m, n, a, i, j;
    int ans = 0;
    short *prev, *now, *tmp;
    scanf("%d %d", &n, &m);
    for (i = 0; i < m; i++) {
        scanf("%d %d %d", &a, &bx[i].b, &bx[i].x);
        bx[i].next = abx[a];
        bx[i].x += 1;
        abx[a] = bx + i;
    }
    prev = work1;
    now = work2;
    for (i = 1; i <= n; i++) {
        BX *p;
        memset(now, 0, sizeof(short)*i);
        for (p = abx[i]; p != NULL; p = p->next) {
            if (p->x > now[p->b]) now[p->b] = p->x;
        }
        for (j = 1; j <= i; j++) {
            now[j] = MAX(now[j], MAX(prev[j], prev[j-1])-1);
            ans += now[j] > 0;
        }
        tmp = prev;
        prev = now;
        now = tmp;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 8472
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	vs := make([][2]int, N)
	for i := 0; i < N; i++ {
		vs[i] = [2]int{ReadInt(), ReadInt()}
	}

	m := make(map[[2]int]int)
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if i == j {
				continue
			}
			p := vs[i][0] - vs[j][0]
			q := vs[i][1] - vs[j][1]
			m[[2]int{p, q}]++
		}
	}

	cnt := 0
	for _, c := range m {
		cnt = Max(cnt, c)
	}
	fmt.Println(N - cnt)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main(){
  int n,a,b,c,i;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> a >> b >> c;
    a*=a,b*=b,c*=c;
    if(a==b+c||b==a+c||c==a+b) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
import sys
def input():
  return sys.stdin.readline()[:-1]

from fractions import gcd
def lcm(x, y):
  return (x * y) // gcd(x, y)
  
def main():
  a, b = map(int, input().split())
  print(lcm(a,b))
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 64364
list =list(map(int,input().split()))

list.sort(reverse=True)

Even=['Odd','Odd','Odd']

m,n=0,0

for i in range(len(list)):
    if list[i]%2==0:
        Even[i]='Even'

if Even[0]==Even[1] and Even[0]==Even[2]:
    m=0
    n=(2*list[0]-list[1]-list[2])/2

elif Even[0]!=Even[1] and Even[0]!=Even[2]:
    m=list[0]-list[1]
    n=(list[1]-list[2])/2
else:
    m=1
    n=(2*list[0]-list[1]-list[2]+1)/2

print(int(m+n))

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n, k;
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		k = scan.nextInt();
		Double[] list = new Double[n];
		for(int i = 0; i < n; i++) {
			Integer p = scan.nextInt();
			list[i] = culcExpectedValue(p);
		}
		Double maxExpectedValue = 0.0;
		Double expected = 0.0;
		for(int i = 0;i < k; i++) {
			expected += list[i];
		}
		maxExpectedValue = expected;
		for(int i = k; i < n; i++) {
			expected = expected + list[i] - list[i-k];
			if(maxExpectedValue < expected) maxExpectedValue = expected;
		}

		System.out.println(String.format("%.12f", maxExpectedValue));
		scan.close();
	}

	public static Double culcExpectedValue(int p) {
		Double ret = 0.0;
		for(int i=1;i<=p;i++) {
			ret += ((double) i) / ((double) p);
		}
		return ret;
	}

}

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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
 for (int i = A; i <=B; i++) {
   int a = i/10000; // 10000
   int e = i%10; // 1
   int b = i/1000-i/10000*10; // 1000
   int d = i/10-i/100*10; // 10
   if((a == e) && (b == d)){
     count ++;
   }
 }
  cout << count << endl;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <vector>
using namespace std;

const bool CHECK_OVERFLOW64 = true;
const long long LL_INF =  2e18 + 5;

struct point {
    long long x, y;

    point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}

    point operator-(const point &other) const {
        return point(x - other.x, y - other.y);
    }
};

long long cross(const point &a, const point &b) {
    return a.x * b.y - b.x * a.y;
}

int cross_sign(const point &a, const point &b) {
    if (CHECK_OVERFLOW64) {
        double double_value = (double) a.x * b.y - (double) b.x * a.y;

        if (abs(double_value) > 1e18)
            return double_value > 0 ? +1 : -1;
    }

    uint64_t uint64_value = (uint64_t) a.x * b.y - (uint64_t) b.x * a.y;

    if (uint64_value == 0)
        return 0;

    return uint64_value < 9e18 ? +1 : -1;
}

bool left_turn(const point &a, const point &b, const point &c) {
    return cross_sign(b - a, c - b) > 0;
}


// monotonic_dp_hull enables you to do the following two operations in amortized O(1) time:
// 1. Insert a pair (a_i, b_i) into the structure. a_i must be non-decreasing.
// 2. For any value of x, query the maximum value of a_i * x + b_i. x must be non-decreasing.
// All values a_i, b_i, and x can be positive or negative.
struct monotonic_dp_hull {
    deque<point> points;

    void insert(const point &p) {
        assert(points.empty() || p.x >= points.back().x);

        if (!points.empty() && p.x == points.back().x) {
            if (p.y <= points.back().y)
                return;

            points.pop_back();
        }

        while (points.size() >= 2 && left_turn(points[points.size() - 2], points.back(), p))
            points.pop_back();

        points.push_back(p);
    }

    void insert(long long a, long long b) {
        insert(point(a, b));
    }

    // Queries the maximum value of ax + by.
    long long query(long long x, long long y = 1) {
        static long long prev_x = -LL_INF, prev_y = 1;
        assert(prev_x == -LL_INF || x * prev_y >= prev_x * y);
        prev_x = x; prev_y = y;

        while (points.size() >= 2 && x * (points[1].x - points[0].x) >= (points[0].y - points[1].y) * y)
            points.pop_front();

        return points[0].x * x + points[0].y * y;
    }
};


int main() {
    int N;
    long long C;
    scanf("%d %lld", &N, &C);
    monotonic_dp_hull hull;
    long long dp = -1;

    for (int i = 0; i < N; i++) {
        long long H;
        scanf("%lld", &H);
        dp = i == 0 ? 0 : -hull.query(2 * H) + H * H;
        hull.insert(H, -(H * H + C + dp));
    }

    printf("%lld\n", dp);
}


Measured memory_bytes: 2432
#include <stdio.h>
int main(void){
    int k, n;
    int a[200000+5];
    scanf("%d %d", &k, &n);
    for(int i=0; i<n; i++)scanf("%d",&a[i]);
    
    long long int ans=a[0]+k-a[n-1];    // またぐデータ
    long long max=a[0]+k-a[n-1];
    for(int i=1; i<n; i++){
        ans+=a[i]-a[i-1];
        if(a[i]-a[i-1]>max)max=a[i]-a[i-1];
    }
    
    printf("%lld\n", ans-max);
}


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

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	a.push_back(k + a[0]);
	int length = 0;
	for (int i = 0; i < n; i++) {
		length = max(length, a[i + 1] - a[i]);
	}
	cout << k - length << endl;
}

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

int main()
{    
  long long int sum=0;
  long long int i,j,k,l;
  long long int N,Q;  
  scanf("%lld",&N);
  long long int count[100001];
  for(i=0;i<100001;i++){
    count[i] = 0;
  }
  for(i=0;i<N;i++){
    scanf("%lld",&j);
    sum += j;
    count[j]++;
  }
  scanf("%lld",&Q);
  for(i=0;i<Q;i++){
    scanf("%lld %lld",&j,&k);
    sum += (k-j)*count[j];
    count[k] += count[j];
    count[j] = 0;
    printf("%lld\n",sum);
  }
  
  return 0; 
}

Measured memory_bytes: 2484
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
template <class T, class U>
void chmin(T& t, const U& u) {
  if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
  if (t < u) t = u;
}

int main(void) {
  int H, W, M;
  cin >> H >> W >> M;
  set<pair<int, int>> st;
  rep(i, M) {
    int tmpa, tmpb;
    cin >> tmpa >> tmpb;
    st.insert({tmpa, tmpb});
  }
  int hmax = 0, wmax = 0;
  map<int, int> hmp, wmp;
  for (auto tmp : st) {
    chmax(hmax, ++hmp[tmp.first]);
    chmax(wmax, ++wmp[tmp.second]);
  }
  vector<int> hmaxpos, wmaxpos;
  for (auto tmp : hmp) {
    if (hmax == tmp.second) hmaxpos.push_back(tmp.first);
  }
  for (auto tmp : wmp) {
    if (wmax == tmp.second) wmaxpos.push_back(tmp.first);
  }
  int ans = hmax + wmax - 1;
  for (auto h : hmaxpos) {
    if (ans >= hmax + wmax) break;
    for (auto w : wmaxpos) {
      if (st.find({h, w}) == st.end()) {
        ans = hmax + wmax;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int W,H,N;
  cin >>W>>H>>N;
  int data[N][3];
  for(int i=0;i<N;i++){
    cin>>data[i][0]>>data[i][1]>>data[i][2];
  }
  vector<int> x(W);
  vector<int> y(H);
  for(int i=0;i<N;i++){
    if(data[i][2]==1){
      for(int j=0;j<data[i][0];j++){
        x[j]=1;
      }
    }
    if(data[i][2]==2){
      for(int j=data[i][0];j<W;j++){
        x[j]=1;
      }
    }
    if(data[i][2]==3){
      for(int j=0;j<data[i][1];j++){
        y[j]=1;
      }
    }
    if(data[i][2]==4){
      for(int j=data[i][1];j<H;j++){
        y[j]=1;
      }
    }
  }
  int sum_x=0;
  int sum_y=0;
  for(int a:x){
    if(a==0)sum_x++;
  }
  for(int a:y){
    if(a==0)sum_y++;
  }
  cout << sum_x*sum_y<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long LL;
typedef pair<int,int> PII;


int main(){
       int a; cin >> a;
       string s; cin >> s;
       if(a < 3200) cout << "red" << endl;
       else cout << s << endl;
    return 0;
}

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

// Sparse Table
template<class Monoid> struct SparseTable {
    vector<vector<Monoid> > data;
    vector<int> height;
    
    SparseTable() {}
    SparseTable(const vector<Monoid> &vec) { init(vec); }
    void init(const vector<Monoid> &vec) {
        int n = (int)vec.size();
        int h = 0; while ((1<<h) < n) h++;

        height.assign(n+1, 0);
        rep(i,n+1) if(i >= 2) height[i] = height[i>>1]+1;

        data.assign(h, vector<Monoid>(n));
        rep(i,n) data[0][i] = vec[i];
        rep(i,h) if(i) rep(j,n) data[i][j] = min(data[i-1][j], data[i-1][min(j+(1<<(i-1)),n-1)]);
    }
    
    Monoid get(int a, int b) {
        int k = height[b-a];
        return min(data[k][a], data[k][b-(1<<k)]);
    } // [a,b) 0-indexed
};

// Suffix Array
struct SuffixArray {
    string str;
    int n;
    vector<int> sa; // the starting index of the i-th smallest suffix (i = 0 ~ n)
    vector<int> lcp; // the lcp(longest common prefix array) of sa[i] and sa[i+1] (i = 0 ~ n-1)
    
    SuffixArray() {}
    SuffixArray(const string &str_) { str = str_; n = (int)str.length(); buildSA(); calcLCP(); }
    void init(const string &str_) { str = str_; n = (int)str.length(); buildSA(); calcLCP(); }
    
    // build suffix array
    vector<int> rank, tmp_rank;
    void buildSA() {
        sa.resize(n+1), rank.resize(n+1), tmp_rank.resize(n+1);

        rep(i,n) sa[i] = i, rank[i] = str[i] - 'a';
        sa[n] = n, rank[n] = -1;

        int k = 1;
        while (k <= n) {
            auto comp = [&](int i, int j) {
                if (rank[i] != rank[j]) return rank[i] < rank[j];
                return (i+k <= n ? rank[i+k] : -1) < (j+k <= n ? rank[j+k] : -1);
            };
            sort(sa.begin(), sa.end(), comp);
            tmp_rank[sa[0]] = 0;
            rep(i,n+1) if(i) {
                tmp_rank[sa[i]] = tmp_rank[sa[i-1]];
                if (comp(sa[i-1], sa[i])) tmp_rank[sa[i]]++;
            }
            rank = tmp_rank;
            k <<= 1;
        }
    }

    // calculate lcp
    vector<int> rsa;
    SparseTable<int> st;
    void calcLCP() {
        lcp.resize(n), rsa.resize(n+1);
        rep(i,n+1) rsa[sa[i]] = i;

        int count = 0;
        rep(i,n) {
            int pi = sa[rsa[i] - 1];
            if (count > 0) count--;
            while(i + count < n && pi + count < n){
                if (str[pi + count] != str[i + count]) break;
                count++;
            }
            lcp[rsa[i] - 1] = count;
        }
        st.init(lcp);
    }
    
    int getLCP(int a, int b) {
        a = rsa[a]; b = rsa[b]; if(a > b) swap(a,b);
        return st.get(a,b);
    } // s[a:] と s[b:] のlcp
};

int main() {
    int n; string s; cin >> n >> s;
    SuffixArray SA(s);
  
    int ans = 0;  
    rep(i,n) rep(j,n) if(i < j) ans = max(ans,min(SA.getLCP(i,j),j-i));
    cout << ans << endl;
    return 0;
}

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

int main(){
	int sum = 0, n = 0;
	string s, ans;

	while( getline(cin,s) ){
		ans = "";
		for(int i=0 ; i<s.size() ; i++){
			if(s[i]=='@'){
				for(int j=0 ; j<(s[i+1]-'0') ; j++){
					ans += s[i+2];
				}
				i += 2;
			}else{
				ans += s[i];
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
use proconio::input;

fn main() {
    input! {
        a:usize,
        b:usize,
        c:usize,
        x:usize
    }
    let mut e = 0;
    for i in 0..=a {
        for j in 0..=b {
            for k in 0..=c {
                if i * 10 + j * 2 + k == x / 50 {
                    e += 1
                }
            }
        }
    }
    println!("{}", e);
}


Measured memory_bytes: 2140
#include <stdio.h>
#include <limits.h>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

void prim(void);

int color[MAX],M[MAX][MAX],d[MAX],p[MAX];
int n;

int main(){
  int i,j;
  int sum = 0;
  
  scanf("%d",&n);

  for (i = 0;i < n;i++)
    for (j = 0;j < n;j++){
      scanf("%d",&M[i][j]);
    }

  prim();

  for (i = 0;i < n;i++){
    sum += d[i];
  }

  printf("%d\n",sum);
  
  return 0;
}

void prim(){
  int i;
  int u,mincost;

  for (i = 0;i < n;i++){
    color[i] = WHITE;
    d[i] = INT_MAX;
  }

  d[0] = 0;
  p[0] = -1;

  while (1){
    mincost = INT_MAX;

    for (i = 0;i < n;i++)
      if (color[i] != BLACK && d[i] < mincost){
	mincost = d[i];
	u = i;
      }

    if (mincost == INT_MAX)
      break;

    color[u] = BLACK;

    for (i = 0;i < n;i++)
      if (color[i] != BLACK && M[u][i] != -1)
	if (M[u][i] < d[i]){
	  d[i] = M[u][i];
	  p[i] = u;
	  color[i] = GRAY;
	}
    
  }
  
}



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

const int N = 1e6 + 10;
int prime[N];
int cnt[N];

void sieve(){
    prime[1] = 1;
    for( int i = 2 ; i < N ; ++i ){
        if( prime[i] == 0 ){
            for( int j = i ; j < N ; j += i ){
                prime[j] = i;
            }
        }
    }
}

int main(){
   sieve();
    int n;
    cin >> n;
    int GCD = 0;
    for( int i = 0 ; i < n ; ++i ){
        int x;
        cin >> x;
        GCD = __gcd( GCD , x );
        while( x > 1 ){
            int pri = prime[x];
            ++cnt[pri];
            while( x % pri == 0 ) x /= pri;
        }
    }
    bool arePrimes = true;
    for( int i = 2 ; i < N ; ++i ) arePrimes &= ( cnt[i] < 2 );
    if( arePrimes ) cout << "pairwise coprime";
    else if( GCD == 1 ) cout << "setwise coprime";
    else cout << "not coprime";

    return 0;
}

Measured memory_bytes: 11448
#pragma warning disable
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System;
class E { static void Main() { new J(); } }
class J
{
	int F() { return int.Parse(Console.ReadLine()); }
	int[] G() { return Console.ReadLine().Split().Select(_ => int.Parse(_)).ToArray(); }
	public J()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
		while (true)
		{
			var N = F();
			if (N == 0) break;
			var dict = new Dictionary<char, char>();
			for (var i = 0; i < N; i++)
			{
				var I = Console.ReadLine().Split();
				dict[I[0][0]] = I[1][0];
			}
			var M = F();
			for (var i = 0; i < M; i++)
			{
				var c = Console.ReadLine()[0];
				if (dict.ContainsKey(c)) Console.Write(dict[c]);
				else Console.Write(c);
			}
			Console.WriteLine();
		}
		Console.Out.Flush();
	}
}

Measured memory_bytes: 9752
#include<stdio.h>
 
int main(void){
  int i,n;
  long data,min=1000000,max=-1000000,sum=0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&data);
    if(data<min)min=data;
    if(data>max)max=data;
    sum+=data;
  }
  printf("%ld %ld %ld\n",min,max,sum);
}

Measured memory_bytes: 1028
from collections import deque
n,m=map(int,input().split())

r=[[] for _ in range(n)]
d=deque()
b=[n+1]*n
for _ in range(m):
    a,z=map(int,input().split())
    r[a-1].append(z-1)
    r[z-1].append(a-1)

o=0
f=1
b[o]=0
for _ in range(n):
    for i in r[o]:
        if(b[i]==n+1):
            b[i]=o
            d.append(i)
    if(d):
        o=d.popleft()
        f+=1
    else:
        break

if (f==n):
    print("Yes")
    for i in b[1:]:
        print(i+1)
else:
    print("No")

Measured memory_bytes: 94868
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
SS ss;
#define debug ss
#endif

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int mem[40][40][4],m[40][40];

int turn(int d,int ord){
	switch(ord){
	case 0: return d;
	case 1: return (d+3)%4;
	case 2: return d^2;
	case 3: return (d+1)%4;
	}
	assert(0);
}

int main() {
	int w,h,cost[4];
	IL{
		cin>>w>>h;
		if(w==0&&h==0)break;
		rep(i,h)rep(j,w)rep(k,4)mem[i][j][k]=INF;
		rep(i,h)rep(j,w)cin>>m[i][j];
		rep(i,4)cin>>cost[i];
		priority_queue<pair<int,pair<pint,int> >,vector<pair<int,pair<pint,int> > >,greater<pair<int,pair<pint,int> > > > que;
		que.push(MP(0,MP(MP(0,0),0)));
		while(!que.empty()){
			pair<int,pair<pint,int> > now=que.top();
			que.pop();
			int c=now.first,x=now.second.first.X,y=now.second.first.Y,d=now.second.second;
//debug<<x<<" "<<y<<" "<<c<< " "<<d<<endl;
			if(x<0||w<=x||y<0||h<=y)continue;
			if(mem[y][x][d]<=c)continue;
			mem[y][x][d]=c;
			rep(ord,4){
				int nd=turn(d,ord);
				que.push(MP(c+(ord!=m[y][x]?cost[ord]:0),MP(MP(y+dy[nd],x+dx[nd]),nd)));
			}
		}
		int res=INF;
		rep(i,4)chmin(res,mem[h-1][w-1][i]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define elif(a) else if(a)
#define INF INT_MAX
#define F first
#define S second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int n,k,d[100005];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  FOR(i,n) cin>>d[i];
  sort(d,d+n);
  int mim=INF;
  FOR(i,n-k+1){
    mim=min(mim,d[i+k-1]-d[i]);
  }
  cout<<mim<<endl;
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}


Measured memory_bytes: 3556
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<math.h>
#include<vector>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c)                                             
        cout<<"Yes"<<"\n";
    else
        cout<<"No"<<"\n";
    return 0;        

}

Measured memory_bytes: 764
//template---{{{
#include <bits/stdc++.h>

using namespace std;

//DEFINE---{{{
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b); i > (a); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
//end.DEFINE---}}}

//end.template ---}}}

int main() {
  int A, B;

  cin >> A >> B;

  if (A > 8 || B > 8) cout << ":(" << endl;
  else cout << "Yay!" << endl;

  return (0);
}


Measured memory_bytes: 256
N = int(input())
S = input()

loop_flg = True
while loop_flg:
    s_length = len(S)
    next_s = [s for i, s in enumerate(S) if S[i+1:i+2] != s]
    if s_length == len(next_s):
        loop_flg = False
    else:
        S = next_s

print(len(S))


Measured memory_bytes: 4064
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner teclado = new Scanner(System.in);
		int r = teclado.nextInt();
		int A = 3 * (r * r);
		
		System.out.println(A);
		
		teclado.close();
		
	 }
}

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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

vector < vector < ll > > adj(MAXN, vector < ll > ());
vector < bool > used(MAXN, false);
vector < ll > v;

void dfs(ll u){
  used[u] = true;
  for(auto to : adj[u]){
    if(!used[to]) dfs(to);
  }
  v.push_back(u);
}

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

  ll n, m;
  cin >> n >> m;
  vector < ll > in_deg(n + 1, 0);
  for(int i = 0; i < m; i++){
    ll u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    in_deg[v]++;
  }

  vector < ll > d(n + 1, LLONG_MIN);
  for(int i = 1; i <= n; i++){
    if(in_deg[i] == 0) d[i] = 0;
  }

  ll mx = LLONG_MIN;
  for(int i = 1; i <= n; i++){
    if(!used[i]) dfs(i);
  }
  reverse(v.begin(), v.end());

  for(auto u : v){
    for(auto to : adj[u]){
      d[to] = max(d[to], d[u] + 1);
      mx = max(mx, d[to]);
    }
  }

  cout << mx << '\n';
}


Measured memory_bytes: 10488
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [a, b, c, k] = input[0].split(" ").map((x: string): number => +x);

console.log(a + b >= k ? Math.min(a, k) : a - (k - a - b));


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

struct edge {
    int from, to;
    ll cost;
};

class BellmanFord {
    int V;
    int E;
    vector<edge> edges;
    vector<ll> dist;
    vector<bool> negative;

public:
    BellmanFord(int v, int e) : V(v), E(e), negative(v) {
        dist.resize(V, INF);
    }

    void add_edge(int from, int to, ll cost) {
        edges.push_back({from, to, cost});
    }

    ll get_total_cost(int v) {
        return dist[v];
    }

    // v に到達するまでに負ループがあるかを検出する
    bool is_negative(int v) {
        return negative[v];
    }

    // ベルマンフォード法の実行・全辺の負閉路を検出 trueを返す時に負閉路を含む
    bool exec() {
        bool updated = false;
        dist[0] = 0;
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < E; ++j) {
                edge edge = edges[j];
                if (dist[edge.from] != INF && dist[edge.to] > dist[edge.from] + edge.cost) {
                    dist[edge.to] = dist[edge.from] + edge.cost;
                    if (i == V - 1) updated = true;
                }
            }
        }

        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < E; ++j) {
                edge edge = edges[j];
                if (dist[edge.from] != INF && dist[edge.to] > dist[edge.from] + edge.cost) {
                    negative[edge.to] = true;
                }
                if (negative[edge.from]) {
                    negative[edge.to] = true;
                }
            }
        }
        return updated;
    }
};

void Main() {
    ll N, M, P;
    cin >> N >> M >> P;
    BellmanFord bellmanFord(N, M);
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        bellmanFord.add_edge(a, b, P - c);
    }
    bellmanFord.exec();
    if (bellmanFord.is_negative(N - 1)) {
        cout << -1 << '\n';
    } else {
        cout << max(0LL, -bellmanFord.get_total_cost(N - 1)) << '\n';
    }
}

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


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();


		boolean f = true;
		if(a > b) {
			for(int i = b; i <= a; i++) {
				if(i == c) {
					f = false;
					break;
				}
			}
		}else {
			for(int i = a; i <= b; i++) {
				if(i == c) {
					f = false;
					break;
				}
			}
		}


		if(!f) {
			System.out.println("Yes");
		}else if(f){
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
    string s;
    cin >> s;
    int l = 1;
    vector<string> vec;
    vec.push_back(s.substr(0,1));
    for (int i = 1; i < s.size();) {
        if (s.substr(i,1)==vec[vec.size()-1]) {
            if (i==s.size()-1) break;
            vec.push_back(s.substr(i,2));
            i += 2;
        }
        else {
            vec.push_back(s.substr(i,1));
            i++;
        }
    }
    cout << vec.size() << endl;
    return 0;
}

Measured memory_bytes: 10996
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

#define _deb(x) cout<<x;
void _print() {cerr << "]\n";} template <typename T, typename... V>void _print(T t, V... v) {_deb(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
template <class T, class U> void print_m(const map<T,U> &m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}
template<class T, class U>void debp(const pair<T, U> &pr, bool end_line=1){cout<<"{"<<pr.first<<" "<<pr.second<<"}"; cout<<(end_line ? "\n" : ", ");}
template <class T> void print_vp(const T &vp, int sep_line=0){if(vp.empty()){cout<<"Empty"<<endl; return;}if(!sep_line) cout<<"{ ";for(auto x: vp) debp(x,sep_line);if(!sep_line) cout<<"}\n";cout<<endl;}
template <typename T>void print(const T &v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<sz(v); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<endl;}
template <typename T>void print_vv(const T &vv){if(sz(vv)==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<sz(*vv.begin()); j++)cout<<setw(w)<<j<<" ";cout<<endl;int i = 0;for(auto &v: vv){cout<<i++<<" {";for(auto &el: v) cout<<setw(w)<<el<<" ";cout<<"},\n";}cout<<endl;}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    while(cin>>n){
        bool zero = false;
        vl a(n); forn(i,n){
            cin>>a[i];
            if(!a[i])
                zero = true;
        }
        if(zero){
            cout<<0<<endl;
            continue;
        }

        ll ans = 1;
        bool done = false;
        for(auto x: a){
            if(ans>1e18L/x){
                cout<<-1<<endl;
                done = true;
                break;
            }
            ans*=x;
        }

        if(!done){
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3992
A = [ [ ] for i in range(11)]
A[1].append('a')
n = 1
for i in range(1,10):
    B = A[i]
    for b in B:
        x = 0
        for k in range(i):
            c = b[k]
            x = max(ord(c),x)
        for j in range(97,x+2):
            d = b + chr(j)
            A[i+1].append(d)
N = int(input())
for a in A[N]:
    print(a)

Measured memory_bytes: 14548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


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

	int N;
	cin >> N;
	vll a(N+1);
	a[0] = 2;
	a[1] = 1;
	repr(i,2, N+1) {
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[N] << endl;

	return 0;
}

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

int main()
{
    string s;

    cin>>s;
    int n = s.size();
    vector<int> dp(n + 1, 0);
    dp[0] = 0;
    dp[1] = 1;

    if(n >= 2){
        dp[2] = (s[0] != s[1]) ? 2 : 1;
        for(int i = 2; i < n ; i++){
            if(s[i] != s[i - 1]){
                dp[i + 1] = dp[i] + 1;
            }
            else{
                dp[i + 1] = dp[i - 2] + 2;
            }
        }
    }

    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    deque<ll> deq;

    rep(i, N) deq.push_back(A[i]);

    sort(all(deq));

    while (1) {
        ll k = deq.size();
        rep(i, k - 1) {
            if (deq[1] % deq[0] == 0) {
                deq.erase(deq.begin()+1);
            }
            else {
                deq.push_back(deq[1] % deq[0]);
                deq.erase(deq.begin() + 1);
            }
        }
        if (deq.size() == 1) { break; }
        sort(all(deq));
    }
    cout << deq[0] << endl;
}

Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define ll long long

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

	vec<ll> A(n + 1, 0);
	rep(i, n) {
		ll a;
		cin >> a;
		A[i + 1] = A[i] + a;
	}

	sort(A.begin(), A.end());
	ll ret = 0;
	ll cur = A[0];
	ll count = 1;
	rep(i, n) {
		if (A[i + 1] != cur) {
			ret += (count - 1) * count / 2;
			count = 1;
			cur = A[i + 1];
		} else {
			count++;
		}
	}
	ret += (count - 1) * count / 2;

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 1792
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextLine()
	arr := strings.Split(n, "")
	result := arr[len(arr)-1]
	if result == "3" {
		fmt.Println("bon")
	} else if result == "0" || result == "1" || result == "6" || result == "8" {
		fmt.Println("pon")
	} else {
		fmt.Println("hon")
	}
}


Measured memory_bytes: 1772
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;


class DMegalomania {
public:
    int N;
    vector<pair<ll, ll>> P;

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        REP(i, N) {
            ll a, b;
            in >> a >> b;
            P.push_back(make_pair(b, a));
        }
        sort(ALL(P));
        ll sum = 0;
        REP(i, N) {
            sum += P[i].second;
            if (sum > P[i].first) { COUT("No"); return; }
        }
        COUT("Yes");
    }
};


int main() {
    DMegalomania solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 6256