akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

void solve(){
	int n, sum = 0, mx = 0;
	scanf("%d%d", &sum, &n);
	REP(i, 0, n){
		int v;
		scanf("%d", &v);
		mx = max(mx, v);
	}
	int ans = max(0, mx - (sum - mx) - 1);
	printf("%d\n", ans);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    int i;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    
    int ans=0;
    int renzoku=0;
    for(i=0;i<n-1;i++){
        if(a[i]==a[i+1])renzoku++;
        else{
            ans+=(renzoku+1)/2;
            renzoku=0;
        }
    }
    ans+=(renzoku+1)/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,b;
  bool z = true;
  cin >> N;
int a[N] = {};
  for(int i = 0;i < N;i++){
  cin >> b;
    if(b <= i + 1){
      for(int j = i; j > b - 1; j--){
      a[j] = a[j - 1];
      }      
    a[b-1] = b;
    }
    else{
    cout << -1 << endl;
      z = false;
    break;
    }
  }
  
  if(z){
  for(int i = 0;i < N; i++){
  cout << a[i] << endl;
  }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1),b(n);
  for(int i=0;i<n+1;i++)cin>>a[i];
  for(int i=0;i<n;i++)cin>>b[i];
  long long ans=0;
  for(int i=0;i<n;i++){
    int p=min(a[i],b[i]);
    ans+=p;
    a[i]-=p;
    b[i]-=p;
    int q=min(a[i+1],b[i]);
    ans+=q;
    a[i+1]-=q;
    b[i]-=q;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4028
n = int(input())
a = list(map(int,input().split()))

def counting_sort(A,k):
    B = []
    C = [0]*(k+1)

    for j in range(len(A)):
        C[A[j]] += 1

    for i in range(len(C)):
        while True:
            if C[i] != 0:
                B.append(i)
                C[i] -= 1
            else:
                break
    return B

result = counting_sort(a,max(a))
print(*result)

Measured memory_bytes: 220976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, K;
  cin >> A >> B >> K;
  
  int m=min(A, B);
  vector<int> yaku(m);
  
  for(int i=1; i <= m; i++){
    if(A%i==0 && B%i==0){
      yaku.at(i-1)=i;
    }
  }
  sort(yaku.begin(), yaku.end());
  reverse(yaku.begin(), yaku.end());
  cout << yaku.at(K-1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

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

#include <iostream>
#include <set>

using namespace std;

char c1[] = {'.', '.', '#', '#'};
char c2[] = {'.', '#', '.', '#'};

int main(){
  string s1;
  string s2;

  const int n = getInt();

  bool rev = false;

  while ((int)s1.size() < n){
    REP(j,4){
      string ss1;
      string ss2;

      if(!rev){
        ss1 = s1 + c1[j];
        ss2 = s2 + c2[j];
      }else{
        ss1 = c1[j] + s1;
        ss2 = c2[j] + s2;
      }

      printf("%s\n%s\n", ss1.c_str(), ss2.c_str());
      fflush (stdout);

      char buff[16];
      scanf("%s", buff);
      if(buff[0] == 'T'){
        s1 = ss1;
        s2 = ss2;
        goto ok;
      }
    }

    if(rev) break;
    rev = true;
  ok:;
  }

  return 0;
}


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

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            String n; 

            n = Console.ReadLine();

            if (n[0] == '9' || n[1] == '9')
                Console.WriteLine("Yes");

            else 
                Console.WriteLine("No");

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int k;
	cin >> k;
	string q = "abcdefghijklmnopqrstuvwxyz";
	//0 ~ 25
	string result = "";
	int shift[s.size()];
	int b;
	for (int i = 0; i < s.size(); ++i)
	{
		b = q.find(s[i]);
		if(26 - b <= k && b!=0){//aだったらそもそもシフトしなくていい。
			shift[i] = 0;
			k -= 26 - b;
		}else{
			shift[i] = b;
		}
	}
	shift[s.size()-1] = (shift[s.size()-1]+k)%26;
	for (int i = 0; i < s.size(); ++i)
	{
		result += q[shift[i]];
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <algorithm>

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

typedef long long ll;

using namespace std;
int main(){
    int A, B, C;
    string ans;
    cin >> A >> B >> C;
    if (C >= A && C <= B) ans = "Yes";
    else ans = "No";

    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];

		for (int i = 0; i < 3; i++) {
			a[i] = scan.nextInt();
		}

		Arrays.sort(a);
		String concat = Integer.toString(a[2]) + Integer.toString(a[1]);
		int result = Integer.parseInt(concat) + a[0];
		System.out.println(result);
	}

}

Measured memory_bytes: 23124
n = int(input())
S = [ord(t) - ord('a') for t in input()]
cnt = [0]*26
for s in S:
    cnt[s] += 1
ans = 1
mod = 10**9 + 7
for c in cnt:
    ans *= c+1
    ans %= mod
print((ans-1)%mod)


Measured memory_bytes: 9916
def roll(die, d):
    if d == "E":
        return [die[3], die[1], die[0], die[5], die[4], die[2]]
    if d == "N":
        return [die[1], die[5], die[2], die[3], die[0], die[4]]
    if d == "S":
        return [die[4], die[0], die[2], die[3], die[5], die[1]]
    if d == "W":
        return [die[2], die[1], die[5], die[0], die[4], die[3]]

die = list(map(int, input().split()))
queue = input()
for i in range(len(queue)):
    die = roll(die, queue[i])
print(die[0])

Measured memory_bytes: 7760
n=int(input())
p = list(map(int, input().split()))
check=0
for i in range(len(p)-2):
    if p[i+1]<p[i+2] and p[i+1]>p[i]:
        check+=1
    elif p[i+1]>p[i+2] and p[i+1]<p[i]:
        check+=1
print(check)

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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

A,B = inputIL()

if A<=8 and B<=8:
  print("Yay!")
else:
  print(":(")


Measured memory_bytes: 63980
while True:
    h, w = input().split()
    if h == "0" and w == "0":
        break
    for j in range(int(h)):
        for i in range(int(w)):
            if (i+j) % 2 == 0:
                s = "#"
            else:
                s = "."
            print(s, end="")
        print()
    print()

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  bool flag;
  for (int i=0; i<H; i++) {
    flag = false;
    for (int j=0; j<W; j++) {
      if (A.at(i).at(j) == '#')
        flag = true;
    }
    if (!flag) {
      for (int x=i; x<H-1; x++) {
        for (int y=0; y<W; y++) {
          A.at(x).at(y) = A.at(x+1).at(y);
        }
      }
      H--;
      i--;
    }
  }
  for (int i=0; i<W; i++) {
    flag = false;
    for (int j=0; j<H; j++) {
      if (A.at(j).at(i) == '#')
        flag = true;
    }
    if (!flag) {
      for (int x=0; x<H; x++) {
        for (int y=i; y<W-1; y++) {
          A.at(x).at(y) = A.at(x).at(y+1);
        }
      }
      W--;
      i--;
    }
  }
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cout << A.at(i).at(j);
      if (j == W-1)
        cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include <stdio.h>
#include<unordered_map>
#define Amr_Abdelazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vpll vector<pair<ll,ll> >
#define P complex<ld>
#define X real()
#define Y imag()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i,n)   for(int i=0;i<n;i++)
#define repp(i,s,n)   for(int i=s;i<=n;i++)
#define print(v) {for(auto i:v)cout<<i<<" ";cout<<"\n";}
#define mkp make_pair
#define clr(ar,v) memset(ar,v,sizeof(ar));
#define TC ll amr_abdelazim;cin>>amr_abdelazim;while(amr_abdelazim--)
#define popcnt(x) __builtin_popcount(x)
#define EPS 1e-9
#define INF 1000000000000000009
using namespace std;
//freopen("output.txt", "w", stdout);
//freopen("input.txt", "r", stdin);
const int mod = 1000000007;
const int N = 2 * 100000 + 9;
const double pi = acos(-1);
class cmp{
public:
	bool operator() (ll &A, ll &B){
		return A > B;
	}
};
bool by_sec(const pll &a, const pll &b){
	if ((abs(a.first) == abs(b.first)))
		return (abs(a.second) < abs(b.second));
	return (abs(a.first) < abs(b.first));
}
bool byth(const tuple<ll, ll, ld>& a, const tuple<ll, ll, ld>& b){
	return (get<2>(a) < get<2>(b));
}
ld dist(P a, P b){
	return (ld)abs(a - b);
}
ll fact[1000009], inv[1000009];
ll fp(ll a, ll b){
	if (b == 0)
		return 1;
	ll ans = fp(a, b / 2);
	ans = (ans * ans) % mod;
	if (b % 2 != 0)
		ans = (ans * (a % mod)) % mod;
	return ans;
}
void FacInv(ll n){
	fact[0] = inv[0] = 1;
	for (ll i = 1; i <= n; i++)
	{
		fact[i] = ((i%mod) * fact[i - 1] % mod) % mod;
		inv[i] = fp(fact[i], mod - 2);
	}
}
ll ncr(ll n, ll r){
	return (((fact[n] * inv[r]) % mod) * inv[n - r]) % mod;
}
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll max(ll a, ll b){
	if (a >= b)return a;
	else return b;
}
ll min(ll a, ll b){
	if (a <= b)return a;
	else return b;
}



int main()
{
	Amr_Abdelazim

		ll n,ans=0;
	cin >> n;
	vll a(n+1), b(n);
	rep(i, n+1)cin >> a[i];
	rep(i, n)cin >> b[i];
	rep(i, n){
		ll mn = min(a[i], b[i]);
		a[i] -= mn;
		b[i] -= mn;
		ans += mn;
		mn = min(b[i], a[i + 1]);
		a[i+1] -= mn;
		b[i] -= mn;
		ans += mn;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

const ll MAX = 10000001;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main(void){
    ll x,y;
    cin >> x >> y;

    COMinit();
    
    if(x/2 <= y && y <= 2*x){
        if((x+y) % 3 == 0){
            ll kk = (x+y)/3;
            ll jj = (x-kk);
            ll ans = COM(kk, jj);
            cout << ans << "\n";
        }
        else{
            cout << 0 << "\n";
        }
    }
    else{
        cout << 0 << "\n";
    }

    return 0;
}

Measured memory_bytes: 234752
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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





void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k,n; cin >> k >> n;
    vector<int> A(n+10);
    for(int i = 0; i < n; i ++){
        cin >> A[i];
    }
    int maxD = -1;
    for (int i = 1; i < n; i++) {
        maxD = max(maxD,A[i]-A[i-1]);
    }
    maxD = max(maxD,A[0]+k - A[n-1]);
    
    cout << k - maxD << endl;
        
    
    
    
    
    
}



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



Measured memory_bytes: 1024
MOD = 10**9+7
n = int(input())
s1 = input()
s2 = input()

i = 0
ans = 1
pre_state = None
while i < n:
    if s1[i] == s2[i]:
        if pre_state == 'same':
            ans = (ans*2)%MOD
        elif pre_state == 'diff':
            pass
        else:
            ans = 3
        pre_state = 'same'
        i += 1
    elif s1[i] != s2[i]:
        if pre_state == 'same':
            ans = (ans*2)%MOD
        elif pre_state == 'diff':
            ans = (ans*3)%MOD
        else:
            ans = 6
        pre_state = 'diff'
        i += 2

print(ans)


Measured memory_bytes: 3188
// abc149_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll A, B, K;
    cin >> A >> B >> K;

    if (K < A){
        print(A-K, B);
    } else if (K < A + B){
        print(0, B - (K - A));
    } else {
        print(0, 0);
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            Set<String> c = new HashSet<>();
            for (int i = 0; i < n; i++) {
                c.add(in.next());
            }

            if (c.size() == 3) {
                out.println("Three");
            } else {
                out.println("Four");
            }

        }

    }
}



Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int a, b, c; cin >> a >> b >> c;
    int mx = min(a - b, c);
    cout << c - mx << "\n";
}


Measured memory_bytes: 892
package main

import "fmt"

func main() {
	var x, a, b int
	fmt.Scan(&x, &a, &b)
	if -x > (a - b) {
		fmt.Println("dangerous")
		return
	}
	if 0 > (a - b) {
		fmt.Println("safe")
		return
	}
	fmt.Println("delicious")
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int acc[3][1000][1000];
int R, C;
int get(int buf[1000][1000], int r, int c) {
    if(r < 0 || r >= R || c < 0 || c >= C) return 0;
    return buf[r][c];
}

void calc_acc(const vector<string> &field, char ch, int buf[1000][1000]) {
    for(int r = 0; r < R; ++r) {
        for(int c = 0; c < C; ++c) {
            buf[r][c] = get(buf, r-1, c) + get(buf, r, c-1) - get(buf, r-1, c-1);
            if(field[r][c] == ch) ++buf[r][c] ;
        }
    }
}

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

    int K;
    cin >> R >> C >> K;
    vector<string> field(R);
    for(int i = 0; i < R; ++i) {
        cin >> field[i];
    }
    calc_acc(field, 'J', acc[0]);
    calc_acc(field, 'O', acc[1]);
    calc_acc(field, 'I', acc[2]);
    for(int i = 0; i < K; ++i) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        --a; --b; --c; --d;
        for(int j = 0; j < 3; ++j) {
            if(j > 0) cout << ' ';
            cout << get(acc[j], c, d) - get(acc[j], c, b-1) - get(acc[j], a-1, d) + get(acc[j], a-1, b-1);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int i,j;
    char a[100];
    scanf("%s",a);
    for (i=strlen(a)-1;i>=0;i--)
        if (a[i]=='F'||a[i]=='f')
           break;
    for (j=0;j<i;j++)
        cout <<  a[j] ;
    cout <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i] >>y[i];
typedef long long int ll;
using namespace std;

class UnionFind{
public:
	vector<ll> par,num;

	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	ll size(int v){
		return num[find(v)];
	}
};

int main(){
	ll n,m; cin >>n>>m;
	UnionFind Uf(n);
	vector<int> a(m),b(m);
	cinf(m,a,b);
	vector<ll> ans;
	ll cnt=n*(n-1)/2;
	ans.push_back(cnt);
	for(int i=m-1;i>=0;i--){
		if(!Uf.same(a[i]-1,b[i]-1)){
			cnt-=Uf.size(a[i]-1)*Uf.size(b[i]-1);
			Uf.unite(a[i]-1,b[i]-1);
		}
		ans.push_back(cnt);
	}
	reverse(ans.begin(),ans.end());
	for(int i=1;i<=m;i++){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4596
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,x,i;
    cin >> a;
    cin >> b;
    cin >> c;
    i=0;
    for(x=a;x<=b;x++)
    if((c%x)==0){
        i+=1;
    }else{
        i=i;
    }
    cout << i;
    cout << endl;
}



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

#define int long long 
signed main() {
    string t, p;
    cin >> t >> p;
    
    for(int i = 0; i < ((int)t.size()) - ((int)p.size()) + 1; i++) {
        if(t.substr(i, p.size()) == p) cout << i << endl;
    }
    return 0;
}


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

int main() {
	int a,b,c,d,e,f;
	cin >> a >> b >> c >> d;
	e = (c+b-1)/b;
	f = (a+d-1)/d;
	if(e>f){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}

}



Measured memory_bytes: 3596
#include<iostream>
using namespace std;
int dp[100000][3]={0};
 
int ans(int a[100000][3],int i,int j,int n)
{
	if(i==n)
		return 0;
 
	if(dp[i][j]!=0)
		return dp[i][j];
 
	int best=0;
	for(j;j<3;j++)
	{
		for(int k=0;k<3;k++) 
		{
			if(k==j)
				continue;
			best=max(best,a[i][j]+ans(a,i+1,k,n));
		}
		if(i!=0)
			break;
	}
	return dp[i][j]=best;
}
 
int main()
{
	ios_base::sync_with_stdio(0);           
	cin.tie(NULL);
	cout.tie(NULL);
	int n,a[100000][3];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	}
	cout<<ans(a,0,0,n);
    
    return 0;
}

Measured memory_bytes: 15320
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	var L = 1;
	var R = N;
	for(var i = 0; i < M; i++){
		var tmp = nextIntArray();
		L = Math.max(L, tmp[0]);
		R = Math.min(R, tmp[1]);
	}
	myout(Math.max(R - L + 1, 0));
}


Measured memory_bytes: 54304
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
 
const int mxN = 1e5 + 1;
ll n, mod;
vt<ll> adj[mxN], child[mxN];
vt<ll> dp1(mxN, 1);
vt<ll> dp2(mxN, 1);
vt<vt<ll>> pref(mxN);
vt<vt<ll>> suf(mxN);
ll node;

void dfs1(int u, int p)
{
    for(int v: adj[u])
    {
        if(v == p) continue;
        child[u].pb(v);
        dfs1(v, u);
        dp1[u] *= 1 + dp1[v];
        dp1[u] %= mod;
    }
}

void dfs2(int u, int p = -1)
{
    int sz = (int) child[u].size();
    for(int i = 0; i < sz; i++)
    {
        int v = child[u][i];
        ll mul = 1;
        mul = mul * dp2[u] % mod;
        if(i > 0)
            mul = mul * pref[u][i-1] % mod;
        if(i != sz-1)
            mul = mul * suf[u][i+1] % mod;
        dp2[v] = dp2[v] * (1 + mul) % mod;
        dfs2(v, u);
    }
}
 
 
int main()
{
FIO
 
    cin >> n >> mod;
    ll u, v;
    For(n-1)
    {
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    dfs1(1, -1);

    FOR(n)
    {
        int sz = (int) child[i].size();
        pref[i].resize(sz, 1);
        suf[i].resize(sz, 1);
        for(int j = 0; j < sz; j++)
        {
            pref[i][j] = (1 + dp1[child[i][j]]) * (j == 0 ? 1: pref[i][j-1]);
            pref[i][j] %= mod;
        }
        for(int j = sz - 1; j >= 0; j--)
        {
            suf[i][j] = (1 + dp1[child[i][j]]) * (j == sz - 1 ? 1: suf[i][j+1]);
            suf[i][j] %= mod;
        }
    }

    dfs2(1, -1);

    FOR(n)
    {
        cout << (dp1[i] * dp2[i]) % mod << endl;
    }
}

Measured memory_bytes: 33368
from collections import Counter as C
n = int(input())
a = list(map(int,input().split()))
c1 = C(a[::2])
c2 = C(a[1::2])
mc1 = c1.most_common(2)
mc2 = c2.most_common(2)
if mc1[0][0] != mc2[0][0]:
  ans = n - mc1[0][1] - mc2[0][1]
else:
  if len(mc1) + len(mc2) == 2:
    ans = n // 2
  elif len(mc1) == 1:
    ans = n - mc1[0][1] - mc2[1][1]
  elif len(mc2) == 1:
    ans = n - mc1[1][1] - mc2[0][1]
  else:
    if mc1[1][1] >= mc2[1][1]:
      ans = n - mc1[1][1] - mc2[0][1]
    else:
      ans = n - mc1[0][1] - mc2[1][1]
print(ans)

Measured memory_bytes: 18656
#include<iostream>
using namespace std;
int ans(int n, int m, int x);
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    cout <<ans(n,m,0)<<endl;
  }
  return 0;
}
int ans(int n, int m, int x){
  int a=0;
  if(n == 0 && m == 0) return 1;
  if(n>0) for(int i=x; i<10; i++) if(m-i>=0) a+=ans(n-1,m-i,i+1);
  return a;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int a,b;
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	
	cin>>a>>b;
	int tmp = b,note=0;
	while(tmp){
		tmp/=10;
		note++;
	}
	
	int ans = a*(int)pow(10,note)+b;
	
	if((int)sqrt(ans)*(int)sqrt(ans)==ans)
		cout<<"Yes"<<endl;
	else 
		cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 11872
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<pair<int, int>> v;
    int n, l, ans = 0;
    cin >> n >> l;
    for(int i = 0; i < n; ++i) {
        v.push_back(make_pair(abs(l+i), l+i));
    }
    sort(v.begin(), v.end());
    for(int i = 1; i < n; ++i) {
        ans += v[i].second;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_must_use)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i64,
        a: [i64; n]
    }

    println!("{:?}", a.iter().sum::<i64>() - n);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main() {
    ll a,b,c,d; cin >> a >> b >> c >> d;

    cout << max(max(a*c,a*d),max(b*c,b*d));

}


Measured memory_bytes: 3620
raw = gets.split(" ")
n=raw[0].to_i
x=raw[1].to_i
datas = gets.split(" ").map{|ye|ye.to_i}
ans = 1
last = 0
len = 0
while last < n
  len += datas[last]
  last += 1
  break if len > x
  ans += 1
end
puts ans.to_s

Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, int> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-4;
const LL INF = 1e7 - 1;
const LL mod = 1000000007;
const LL LINF = 1e18 + 10;
const int MAXN = 100001;
const int MAXK = 101;

int n;
VLL a;
VLL SS;
VLL max_in;
VVI g;
int root;

void dfs(int v, int p = -1)
{
	if (SZ(g[v]) == 1)
	{
		max_in[p] = max(max_in[p], a[v]);
		a[p] -= a[v];
		if (a[p] < 0)
		{
			cout << "NO";
			exit(0);
		}

		a[v] = 0;
		return;
	}

	for (auto i : g[v])
		if (i != p)
			dfs(i, v);

	if (a[v] && p == -1)
	{
		cout << "NO";
		exit(0);
	}

	if (a[v])
	{
		max_in[p] = max(max_in[p], a[v]);
		max_in[v] = max(max_in[v], a[v]);
		a[p] -= a[v];
		a[v] = 0;
		if (a[p] < 0)
		{
			cout << "NO";
			exit(0);
		}
	}
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);

	cin >> n;
	g.resize(n);
	a.resize(n);
	max_in.assign(n, 0);
	FOR(i, 0, n)
		cin >> a[i];

	SS = a;
	FOR(i, 0, n - 1)
	{
		int u, v;
		cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	if (n == 2)
	{
		if (a[0] == a[1])
			cout << "YES";
		else
			cout << "NO";
		return 0;
	}

	FOR(i, 0, n)
		if (SZ(g[i]) > 1)
		{
			root = i;
			break;
		}

	FOR(i, 0, n)
		if (SZ(g[i]) > 1)
			a[i] *= 2LL;

	dfs(root);
	FOR(i, 0, n)
		if (a[i] || (max_in[i] > SS[i]))
		{
			cout << "NO";
			return 0;
		}

	cout << "YES";
	cin >> n;
	return 0;
}

Measured memory_bytes: 12032
#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;

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

    vector<int64_t> a(87);
    a.at(0) = 2;
    a.at(1) = 1;
    for (int i = 2; i <= 86; i++)
        a.at(i) = a.at(i - 2) + a.at(i - 1);

    cout << a.at(N) << endl;
}

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

# dp[i] := i円引き出すのに必要な最小操作回数
dp = [float('inf')] * (N + 1)
dp[0] = 0
operates = sorted([1, 6, 36, 216, 1296, 7776, 46656, 9, 81, 729, 6561, 59049])
for i in range(N):
    for ope in operates:
        if i + ope > N:
            break
        dp[i + ope] = min(dp[i + ope], dp[i] + 1)

print(dp[N])


Measured memory_bytes: 9520
N,M,Q=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(Q)]

def nextlist(A):
    for i in range(A[-1],M+1):
        yield A+[i]

X=[[1]]
for rep in range(N-1):
    NX=[]
    for x in X:
        NX.extend(nextlist(x))
    X=NX

ANS=0
for x in X:
    score=0
    for a,b,c,d in SC:
        if x[b-1]-x[a-1]==c:
            score+=d
    ANS=max(ANS,score)

print(ANS)
    


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

using namespace std;

const int MOD = 1000000007;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<bool> f(n+1, true);
    vector<int> dp(n+1, 0);

    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        f[a] = false;
    }

    dp[0] = 1;
    if (f[1]) dp[1] = 1;
    for (int i = 2; i <= n; ++i) {
        if (f[i-1]) dp[i] += dp[i-1];
        if (f[i-2]) dp[i] += dp[i-2];
        dp[i] %= MOD;
    }

    cout << dp[n] << endl;

    return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int a = B / A;
  if(a >= C) a = C;

  cout << a << endl;

  return 0;  

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    while(true){
        int a,b; cin >> a >> b;
        if(a == 0 && b == 0) break;
        if(a < b){
            cout << a << ' ' << b << endl;
        }else{
            cout << b << ' ' << a << endl;
        }
    }
}



Measured memory_bytes: 2976
N = int(input())
h = list(map(int, input().split()))
# N = 6
# h = [30, 10, 60, 10, 60, 50]
dp = [0]*(N)
# print("ini dp", dp)
for i in range(1, N):
    if i == 1:
        dp[1] = abs(h[1]-h[0])
        # print("ini dp 1", dp)

    else:
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
        # print("ini dp 2", dp)

print(dp[-1])

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

oS = S
S = list(S)

cnt = 0
while True:
    p_cnt = cnt
    for i in range(len(S) - 1):
        if S[i] == "(" and S[i + 1] == ")":
            S.pop(i + 1)
            S.pop(i)
            cnt += 1
            break

    if cnt == p_cnt:
        break

cnt_open = 0
cnt_close = 0

for s in S:
    if s == "(":
        cnt_open += 1
    else:
        cnt_close += 1

ans = ("(" * cnt_close) + oS + (")" * cnt_open)
print(ans)


Measured memory_bytes: 9196
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
const long double pi = 3.14159265358979323846264338327950288;
bool a[1000001];
int main() {
	string s, t;
	int n;
	cin >> n >> s >> t;
	for (int i = n; i <= 2 * n; i++) {
		bool l = true;
		for (int j = 0; j < 2 * n - i; j++) {
			if (t[j] != s[n-(2 * n - i) + j])
				l = 0;
		}
		if (l) {
			cout << i << endl;
			break;
		}
	}
	cin >> n;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()
#define fst first
#define sec	second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<long,long> P;

const int mod = 1e9 + 7;


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

	int n;
	cin >> n;

	vi a(n);
	vi b(n);
	vi c(n);
	rep(i, n){
		cin >> a[i];
	}
	rep(i, n){
		cin >> b[i];
	}
	rep(i, n-1){
		cin >> c[i];
	}

	int ans = 0;
	rep(i, n){
		ans += b[i];
		if(a[i]+1 == a[i+1] && i < n){
			ans += c[a[i]-1];
		}
	}

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



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

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

  string a;
  cin >> a;

  for(auto& c: a){
    c -= 1;
  }

  bool has_1 = any_of(a.begin(), a.end(),
                      [](char c){return c == '1'; });
  vector<int> two_cnt(N);
  two_cnt[0] = 0;
  for(int k = 1; k <= N - 1; k++){
    int two_cnt_diff = 0;
    int up = N - 1 - k + 1;
    while(up % 2 == 0){
      up /= 2;
      two_cnt_diff++;
    }
    int down = k;
    while(down % 2 == 0){
      down /= 2;
      two_cnt_diff--;
    }
    two_cnt[k] = two_cnt[k - 1] + two_cnt_diff;
  }
  if(has_1){ // 0 or 1
    for(auto& c: a){
      if(c == '2'){
        c = '0';
      }
    }
  }else{ // 0 or 2
    for(auto& c: a){
      if(c == '2'){
        c = '1';
      }
    }
  }
  bool one = false;
  for(int i = 0; i < N; i++){
    if(a[i] == '1' && two_cnt[i] == 0){
      one = !one;
    }
  }
  if(has_1 && one){
    cout << 1 << endl;
  }else if(one){
    cout << 2 << endl;
  }else{
    cout << 0 << endl;
  }

}


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

using namespace std;

int const N = 2e5 + 100;
int n, a[N];

int main(){
    scanf("%d", &n);
    for(int i = 0;i < n;++i) scanf("%d", &a[i]);
    
    int mn = 1e9;
    long long ans = 0;
    for(int i = n - 1;i >= 0;--i){
        if(i - a[i] < 0){puts("-1"); return 0;}
        
        if(i != n - 1 && a[i + 1] == a[i] + 1) continue;
        mn = min(mn, i - a[i]);
        if(i - a[i] == mn) ans += a[i];
        else {puts("-1"); return 0;}
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct UnionFind {
    vector<ll> data;
    UnionFind(int size) : data(size,-1) { }

    int root(int x){
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
    }

    ll size(int x){
        return -data[root(x)];
    }

    bool isConnect(int x,int y){
        return root(x) == root(y);
    }

    bool connect(int x , int y){
        x = root(x);
	    y = root(y);
	
        if(x==y) return false;
        
        if(data[x] > data[y]){
            x ^= y;
            y ^= x;
            x ^= y;
        }
        
        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};

UnionFind U(100002);

int main(){
    ll N,M;
    cin >> N >> M;
    ll C = (N * (N-1)) / 2;
    vector<PII> AB;
    REP(i,M){
        int a,b;
        cin >> a >> b;
        AB.PB(MP(a,b));
    }

    vector<ll> ans;

    reverse(ALL(AB));
    ll nans = 0;

    REP(i,M){
        ll a,b;
        ans.PB(nans);
        a = AB[i].fst;
        b = AB[i].snd;
        if (!U.isConnect(a,b)){
             nans += U.size(a) * U.size(b);
        }
        U.connect(a,b);
    }

    reverse(ALL(ans));
    REP(i,M){
        cout << C - ans[i] << "\n";
    }

}


Measured memory_bytes: 3828
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = -1;
        int ans = 1;
        for (int i = 0; i < n; i++) {
            int l = 0, r = n;
            while(l + 1 < r){
                int m = (l+r) / 2;
                if(dp[m] < a[i]) l = m;
                else r = m;
            }
            dp[l+1] = a[i];
            if(ans < l+1) ans = l+1;
        }
        System.out.println(ans);
        sc.close();

    }

}



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

int main()
{
	int64_t N = 0;
	cin >> N;

	vector<int64_t> L(N+1);
	L.at(0) = 2;
	L.at(1) = 1;
	for (int i = 1; i <= N; i++)
	{
		if (i == 0 || i == 1)
		{
			continue;
		}
		L.at(i) = L.at(i - 1) + L.at(i - 2);
	}
	cout << L.at(N) << endl;
}

Measured memory_bytes: 256
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();
        int d = m / n;
        while (true) {
            if (m % d == 0) {
                System.out.println(d);
                return;
            }
            d--;
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    string a;
    long long int b[5]={0};
    cin>>N;
    while(N--)
    {
        cin>>a;
        if(a[0]=='M')
            b[0]++;
        else if(a[0]=='A')
            b[1]++;
        else if(a[0]=='R')
            b[2]++;
        else if(a[0]=='C')
            b[3]++;
        else if(a[0]=='H')
            b[4]++;
    }
    int flag=0;
    long long int s;
    for(int i=0; i<5; i++)
        if(b[i])
            flag++;
    if(flag<3)
        printf("0\n");
    else if(flag==3)
    {
        s=1;
        for(int i=0; i<5; i++)
            if(b[i])
                s*=b[i];
        cout<<s<<endl;
    }
    else if(flag>=4)
    {
        s=0;
        int x,y,z;
        for(x=0; x<3; x++)
            for(y=x+1; y<4; y++)
                for(z=y+1; z<5; z++)
                    if(b[x]&&b[y]&&b[z])
                        s+=b[x]*b[y]*b[z];
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math

S = int(input())


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p


p = 10 ** 9 + 7
N = 10 ** 6  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

c=1

if S==1 or S==2:
    print(0)
elif S==3:
    print(1)
elif S==4 or S==5:
    print(1)
else:
    for i in range(2, S // 3 + 1):
        c += cmb(S - 3 * i + i - 1, i - 1, p)

    print(int(c)%(10**9+7))




Measured memory_bytes: 167920