akhauriyash/Code-Regression huggingface dataset:
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m1, d1, m2, d2; cin >> m1 >> d1 >> m2 >> d2;
    if (m1 + 1 == m2) cout << 1 << '\n';
    else cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 256
def A():
    n, x, t = map(int, input().split())
    print(t * ((n+x-1)//x))

def B():
    n = list(input())
    s = 0
    for e in n:
        s += int(e)
    print("Yes" if s % 9 == 0 else "No")

def C():
    int(input())
    a = list(map(int, input().split()))
    l = 0
    ans = 0
    for e in a:
        if e < l: ans += l - e
        l = max(l, e)
    print(ans)

B()


Measured memory_bytes: 82744
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    valind=A.index(val)
    minabs=10**18
    for i in range(n):
        if i==valind: continue
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()

Measured memory_bytes: 62704
from itertools import product


def solve(string):
    l = len(string)
    *ns, = map(int, string)
    n = int(string)
    c = [0] + [10**i for i in range(6)]
    t = sum(c[:l - 1])
    t = [[t] * 10 for _ in range(10)]
    if l > 1:
        for i in range(10):
            t[i][i] += 1
    for i in range(1, ns[0]):
        for j in range(1, 10):
            t[i][j] += c[l - 1]
    for i in range(ns[0] * 10**(l - 1), n + 1):
        i = str(i)
        t[int(i[0])][int(i[-1])] += 1
    return str(sum(t[i][j] * t[j][i] for i, j in product(range(1, 10), repeat=2)))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long dp[307][307],c[307][307],s[307][307];
int main(){
	long long n,k,m,i,j,p;
	cin>>n>>k>>m;
	c[0][0]=1;
	for (i=1;i<=300;i++){
		c[i][0]=1;
		for (j=1;j<=i;j++){
			(c[i][j]=c[i-1][j]+c[i-1][j-1])%=m;
		}
	}
	for (i=k;i>-1;i--){
		dp[1][i]=1;
		s[1][i]=s[1][i+1]+1;
	}
	for (i=2;i<=n+1;i++){
		for (j=0;j<=k;j++){
			for (p=1;p<i;p++){
				(dp[i][j]+=dp[i-p][j]*c[i-2][p-1]%m*s[p][j+1])%=m;
			}
		}
		for (j=k;j;j--){
			(s[i][j]=s[i][j+1]+dp[i][j])%=m;
		}
	}
	cout<<dp[n+1][0]<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	n = n * (n - 1) / 2;
	m = m * (m - 1) / 2;
	cout << n + m << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO() \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool rev = false;
    string beg = "";
    while (q--) {
        int f;
        cin >> f;
        if (f == 1) {
            rev ^= 1;
            continue;
        }
        char c;
        cin >> f >> c;
        if (!rev) {
            if (f == 1) beg += c;
            else s += c;
        }
        else {
            if (f == 2) beg += c;
            else s += c;
        }
    }
    reverse(beg.begin(), beg.end());
    s = beg + s;
    if (rev)    reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 1116
#include <stdio.h>
int main(void){
    int H,W,N,i,j,k,x,y,a;
    scanf("%d%d%d",&H,&W,&N);
    int field[W][H];
    for(i=0;i<W;i++){
        for(j=0;j<H;j++){
            field[i][j]=0;
        }
    }
    for(i=0;i<N;i++){
        scanf("%d%d%d",&x,&y,&a);
        if(a==1){
            for(j=0;j<W;j++){
                for(k=0;k<x;k++){
                    field[j][k]=1;
                }
            }
        }
        if(a==2){
            for(j=0;j<W;j++){
                for(k=x;k<H;k++){
                    field[j][k]=1;
                }
            }
        }
        if(a==3){
            for(j=W-y;j<W;j++){
                for(k=0;k<H;k++){
                    field[j][k]=1;
                }
            }
        }
        if(a==4){
            for(j=0;j<W-y;j++){
                for(k=0;k<H;k++){
                    field[j][k]=1;
                }
            }
        }
    }
    int cnt=0;
    for(i=0;i<W;i++){
        for(j=0;j<H;j++)
            if(field[i][j]==0) cnt++;
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 256
while 1:
    m=int(raw_input())
    if m==0:break
    st=[map(int,raw_input().split()) for _ in xrange(m)]
    n=int(raw_input())
    pi=[map(int,raw_input().split()) for _ in xrange(n)]
    d=[[st[i][0]-st[0][0],st[i][1]-st[0][1]] for i in xrange(1,m)]
    for i in xrange(n):
        mo=[[pi[j][0]-pi[i][0],pi[j][1]-pi[i][1]] for j in xrange(n)]
        cnt=0
        cnt1=0
        for k in xrange(m-1):
            if not d[k] in mo:break
            else:cnt+=1
        if cnt==m-1:
            print pi[i][0]-st[0][0],pi[i][1]-st[0][1]
            break

Measured memory_bytes: 6572
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		if(a.equals(b)){
			System.out.print("H");
		}else{
			System.out.print("D");
		}
		sc.close();
	}
}

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

int main(){
  int n;
  cin >> n;
  int d = (n+999)/1000;
  cout << 1000*d - n << endl;
  return 0;
}


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

int main(){
	int N,M;
	scanf("%d %d",&N,&M);
	int a[N];
	int b[N];
	int c[M];
	int d[M];

	int min[N];
	int num[N];

	for(int i = 0; i < N; i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(int i = 0; i < M; i++){
		scanf("%d %d",&c[i],&d[i]);
	}

	for(int i = 0; i < N; i++){
		min[i] = abs(a[i] - c[0]) + abs(b[i] - d[0]);
		num[i] = 1;
		for(int j = 1; j < M; j++){
			if(min[i] > abs(a[i] - c[j]) + abs(b[i] - d[j])){
				min[i] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				num[i] = j + 1;
			}
		}
	}

	for (int i = 0; i < N; i++){
		printf("%d\n",num[i]);
	}
	return 0;
}

Measured memory_bytes: 128
import numpy as np
import sys
N, M = map(int,input().split())
X = list(map(int,input().split()))
X.sort()

X_list = list(np.diff(X))

if M-N < 1:
    print(0)
    sys.exit()

X_list.sort(reverse=True)
print(sum(X_list[N-1:]))

Measured memory_bytes: 23044
#include <bits/stdc++.h>
//Fast io
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//Class shorthands
#define ll long long
#define db long double
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
//Function Shorthands
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define po pop_back
#define eb emplace_back
//Code Shorthands
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
//Constants
#define hell 1000000007
#define PI acos(-1.0)
using namespace std;
ll binexpo(ll a, ll b, ll c){
    //if(b<0) return 0;
    if(!b) return 1;
    if(b&1) return (binexpo((a*a)%c, b>>1,c)*a)%c;
    return binexpo((a*a)%c, b>>1,c)%c;
}
void solve(){
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    ll s = 0;
    for(auto i: a) s+=i;
    s%=hell;
    ll ans = 0;
    for(int i=0;i<n;i++){
        ll cur = (s-a[i]+hell)%hell;
        ans += (cur*a[i])%hell;
        ans%=hell;
    }
    ans = (ans*binexpo(2, hell-2, hell))%hell;
    cout<<ans<<endl;
}

int main(){
    io;
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 5180
package main

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

func main() {
	sc := NewScanner()

	//	n := sc.NextString()
	n := sc.NextLine()

	if n[0] != n[2] {
		fmt.Printf("No\n")
		return
	}
	fmt.Printf("Yes\n")

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


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


int main() {
  int x;
  cin >> x;
  if(x < 1200) cout << "ABC" << endl;
  else cout << "ARC" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb emplace_back
#define F first
#define S second
#define rep(i, st, ed) for(ll i=st; i<ed; ++i)
#define repn(i, st, ed) for(ll i=st; i<=ed; ++i)
#define repb(i, ed, st) for(ll i=ed; i>=st; --i)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define PI acosl(-1.0)
#define mp(a, b) make_pair(a, b)
#define eps 1e-9
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int M = 1e9 + 7;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;
ll iv[N];
ll powM(ll a, ll b, ll M = M){ll res = 1;for(;b;a=a*a%M,b/=2) if(b&1) res=res*a%M;return res;}
ll nckbig(int n, int k){ll ans = 1;for(int i=1; i<=k; ++i){ans = ans*(n-i+1)%M*iv[i]%M;}return ans;}
ll caliv(){iv[1] = 1;for(int i=2; i<N; i++){iv[i] = M-M/i*iv[M%i]%M;}}
ll f1[N], f2[N];
ll calf(){f1[0] = f2[0] = 1;for(int i=2; i <N; ++i){f1[i] = f1[i-1]*i%M;f2[i] = f2[i-i]*iv[i]%M;}}
ll nck(int n, int k){return f1[n]*f2[n-k]%M*f2[k]%M;}
ll npk(int n, int k){return f1[n]*f2[n-k]%M;}
ll Rnck(int big){if(big){caliv();}else{calf();}}

void solve()
{
  int n;
  cin>>n;
  int ans = n / 2 + (n%2);
  cout<<ans<<endl;
}


int main()
{
    FAST
    ll Tests = 1;
    //cin>>Tests;
    while(Tests--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (long long)1e17
using namespace std;

struct e {
  long long to, c, t, r;
};

struct data {
  long long s, n, c, t;
  bool operator<(const data &r) const { return c > r.c; }
};

long long n, m, h, k, s, t, p;
vector<long long> v;
vector<vector<long long>> dp;
vector<vector<e>> edge;
priority_queue<data> pq;

long long solve();

int main() {
  while(1) {
    cin >> n >> m >> h >> k;
    if(n + m + h + k == 0) break;
    edge.assign(n, vector<e>(0));
    for(int i = 0; i < m; ++i) {
      long long a, b, c, x, r;
      cin >> a >> b >> c >> x >> r;
      --a, --b, --r;
      edge[a].push_back({b, c, x, r});
      edge[b].push_back({a, c, x, r});
    }
    cin >> s >> t >> p;
    --s, --t;
    v.assign(1LL << k, inf);
    v[0] = 0;
    for(int i = 0; i < p; ++i) {
      long long l, d, now = 0;
      cin >> l >> d;
      for(int i = 0; i < l; ++i) {
        int x;
        cin >> x;
        --x;
        now += 1LL << x;
      }
      v[now] = min(v[now], d);
    }
    for(int i = 0; i < (1LL << k); ++i)
      for(int j = 0; j < i; ++j)
        v[i | j] = min(v[i | j], v[i] + v[j]);

    cout << solve() << endl;
  }
  return 0;
}

long long solve() {
  long long res = inf;
  for(int x = 0; x < (1LL << k); ++x)
    if(v[x] != inf) {
      pq.push({x, s, v[x], 0});
      dp.assign(n, vector<long long>(h + 1, inf));
      dp[s][0] = v[x];
      while(pq.size()) {
        data now = pq.top();
        pq.pop();
        if(dp[now.n][now.t] != now.c) continue;
        for(auto nowe : edge[now.n]) {
          data nextp = now;
          nextp.n = nowe.to;
          nextp.t += nowe.t;
          if(nextp.t > h) continue;
          if(!(nextp.s >> nowe.r & 1)) nextp.c += nowe.c;
          if(dp[nextp.n][nextp.t] > nextp.c) {
            dp[nextp.n][nextp.t] = nextp.c;
            pq.push(nextp);
          }
        }
      }
      for(int i = 0; i <= h; ++i) res = min(res, dp[t][i]);
    }
  if(res == inf) return -1;
  return res;
}


Measured memory_bytes: 3280
N = gets.to_i
w0 = gets.chomp
ans = true
h = {}
h[w0] = true
(N - 1).times do
  w1 = gets.chomp

  if w0[-1] != w1[0] || h[w1]
    ans = false
  end

  h[w1] = true
  w0 = w1
end
puts ans ? 'Yes' : 'No'

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <functional>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

#define rep(i, begin, end) for(int64_t i = (begin); i <= (end); i++)
#define rev(i, begin, end) for(int64_t i = (begin); (end) <= i; i--)

void printvec(const std::vector<int>& vec) {
    for (int i = 0; i < vec.size(); i++) { std::cout << vec[i] << " "; } std::cout << std::endl;
}

const int MAX_N = 2e5 + 10;
int N;
int A[MAX_N];

int main(int argc, char **argv) {
    std::vector<int> vec;
    std::cin >> N;
    rep (i, 1, N) {
        std::cin >> A[i];
        vec.push_back(A[i]);
    }

    std::sort(vec.begin(), vec.end());
    
    rep (i, 1, N) {
        if (A[i] != vec.back()) {
            std::cout << vec.back() << std::endl;
        } else {
            std::cout << vec[vec.size()-2] << std::endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<string> s(n);
   rep(i, n) { cin >> s[i]; }
   map<string, int> t;
   rep(i, n) { t[s[i]]++; }
   int m = 0;
   for (auto t1 = t.begin(); t1 != t.end(); t1++) {
      m = max(m, t1->second);
   }
   for (auto t1 = t.begin(); t1 != t.end(); t1++) {
      if (m == t1->second)
         cout << t1->first << endl;
   }
   return 0;
}

Measured memory_bytes: 26752
import math

def count(target, digits, previous, candidates=[3,5,7]):
    if digits==0:
        nstr="{}".format(previous)
        chars=[int(c) for c in nstr]
        chars=set(chars)
        #print("#debug candidate={}".format(previous))
        for c in candidates:
            if not c in chars:
                #print("#debug {} not in {}".format(c,chars))
                return 0
#        print("#debug ok {}".format(previous))
        return 1
    #print("#debug {} {} {}".format(target,digits,previous))
    base = 10**(digits-1)
    ncases = 0
    for c in candidates:
        candidate = base*c + previous
        if candidate>target:
            continue
        ncases = ncases + count(target, digits-1, candidate) 
    return ncases
        
n=input()
ni=int(n)
ndigits=len(n)

ncases=0
#ndigits-1桁の場合3,5,7を自由においてもnを超えることはない
#3,5,7をつかってできる3桁以上ndigits-1桁以下の整数の個数を数える
#多項式の係数と同じ形式
#9!=362880なのでintに収まる
for p in range(3,ndigits):
    for i in range(1,p-1):
        for j in range(1,p-i):
#            print("{}, {}".format(i,j))
            ncases=ncases+int(math.factorial(p)/math.factorial(i)/math.factorial(j)/math.factorial(p-i-j))

#print("#debug reduced {}".format(ncases))
ncases=ncases+count(ni,ndigits,0)
print(ncases)

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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> x(N);
  for(int i=0;i<N;i++) cin >> x[i];
  vector<int> a = x;
  sort(a.begin(), a.end());
  int midleft = a[N/2 - 1];
  int midright = a[N/2];
  for(int i=0;i<N;i++){
    if(x[i] <= midleft) cout << midright << endl;
    else cout << midleft << endl;
  }
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


set<int> st[26];

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<int> ans;

    rep(i, 26) st[i].insert(INF);
    rep(i, n) st[s[i]-'a'].insert(i);

    rep(i, q){
        int k;
        cin >> k;
        if (k == 1){
            int j;
            char c;
            cin >> j >> c;
            j--;
            st[s[j]-'a'].erase(j);
            st[c-'a'].insert(j);
            s[j] = c;
        }
        else {
            int l, r;
            cin >> l >> r;
            l--;
            int cnt = 0;
            rep(i, 26){
                if(st[i].empty()) continue;
                int idl = *st[i].lower_bound(l);
                int idr = *st[i].lower_bound(r);
                if (idl < idr) cnt++;
            }
            ans.push_back(cnt);
        }
    }

    rep(i, ans.size()) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 27388
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#define int long long
using namespace std;
const int N = 1e5+4;

int last[N][26];
int mk1[26];
int32_t main(){

    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

    string s,t;

    cin>>s>>t;
    int n = s.length();
    
    for(auto c:s){

        mk1[c-'a'] = 1;
    }
    for(auto c:t){
        if(!mk1[c-'a']) {
            cout<<-1<<endl;
            return 0;
        }
    }
    memset(last,-1,sizeof last);
    for(int o=0;o<26;o++){
        for(int i=n-1;~i;i--){
            if(s[i]-'a'==o) last[i][o]=i;
            else last[i][o] = last[i+1][o];
        }
    }



    int now = 0;
    int b = 0;

    for(auto ch:t){
        now = last[now][ch-'a'];
        if(~now){
            now++;
            if(now==n) {
                now = 0;
                b++;
            }
            continue;
        }
        else{
            now=0;
            b++;
            now = last[now][ch-'a'];
            now++;
            if(now==n) {
                now=0;
                b++;
            }
        }
    }

    cout<<b*n+now<<endl;
    return 0;
}

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

using namespace std;
using   ll=long long;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define pll				pair<int , int>
#define int             long long int
#define endl            "\n"

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(int a , int m)
{
	return mod_pow(a , m - 2 , m);
}

const int maxn = 5e5 + 5;

void solve() {
	
	int n , x , m;
	
	cin >> n >> x >> m;
	
	map< int , int> f;
	
	int dp[maxn] {};
	int tot = 0;
	int pre = 1;
	
	for(int i = 1; i <= n; ++i) {
		if(i != 1) {
			pre = (pre * pre) % m;
		}
		else {
			pre = x % m;
		}
		
		if(f.find(pre) != f.end()) {
			int rem = n - i + 1;
			
			int p = i - f[pre];
			int tm = rem / p;
			int u = rem % p;
			
			for(int j = f[pre]; j < i; ++j) {
				tot += tm*dp[j];
			}
			
			for(int j = f[pre]; j < i; ++j) {
				if(u > 0) {
					tot += dp[j];
					u--;
				}
				else {
					break;
				}
			}
			
			break;
		}
		else {
			f[pre] = i;
			tot += pre;
			dp[i] = pre;
		}
	}
	
	cout << tot;
}

signed main() {
	fast;
   
    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


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

int N, M, r, q;
int t[1024], n[1024], m[1024], s[1024];

vector<pair<pair<int, int>, int> > query;
bool pc_status[10010];

bool input() {
	cin >> N >> M;
	if(N == 0 && M == 0)
		return false;
	cin >> r;
	for(int i = 0; i < r; i++) {
		cin >> t[i] >> n[i] >> m[i] >> s[i];
	}
	cin >> q;
	for(int i = 0; i < q; i++) {
		int tmp_ts, tmp_te, tmp_m;
		cin >> tmp_ts >> tmp_te >> tmp_m;
		query.push_back( pair<pair<int,int> ,int>(pair<int,int>(tmp_ts, tmp_te), tmp_m) );
	}

	return true;
}

void init() {
	query.clear();
	for(int i = 0; i < 10010; i++)
		pc_status[i] = false;
}

int solve(pair<pair<int,int>,int> que) {
	int use = 0;
	int ret = 0;
	int start = -1, end = -1;
	for(int i = 0; i < r; i++) {
		if(m[i] == que.second) {
			if(s[i] == 1) {
				if(use == 0)
					start = t[i];
				use++;
			}

			else {
				use--;
				if(use == 0)
					end = t[i];
			}

			if(use == 0) {
				if(start < que.first.second && end > que.first.first) {
					ret += min(end, que.first.second) - max(start, que.first.first);
				}
			}
		}
	}

	return ret;
}

int main(void) {
	while(init(), input()) {
		for(int i = 0; i < q; i++) {
			cout << solve(query[i]) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int n; ll a[55], b[55], ans = 9e18;
bool poss(ll x) {
    ll val = 0;
    FOR0(i, n) {
        b[i] = a[i] + x;
        if(b[i] > n-1) val += (b[i] - (n-1) - 1) / (n + 1) + 1;
    }
    return (val <= x);
}
bool solve(ll x) {
    FOR0(i, n+2) if(poss(x + i)) {ans = x+i; return true;}
    return false;
}
int main() {
    SYNC
    
    cin >> n;
    FOR0(i, n) cin >> a[i];
    ll l = 0, r = 2e18;
    while(l <= r) {
        ll mid = (l + r) >> 1;
        if(solve(mid)) {
            r = mid - 1;
        } else l = mid + 1;
    }
    cout << ans;
}

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

using namespace std;

#define int long long
#define double long double
#define mod 1000000007ll
#define INF 1000000000000000000ll

int dp[1000010];
int tab[1000010];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    int pop = -1;
    vector<int> v;
    v.push_back(0);
    for (int a, i=0; i<n; i++) {
        cin >> a;
        if (a != pop) {
            v.push_back(a);
            pop = a;
        }
    }
    dp[0] = 1;
    for (int i=1; i<v.size(); i++) {
        dp[i] = dp[i-1];
        if (tab[v[i]] != 0) {
            dp[i] += dp[tab[v[i]]];
        }
        tab[v[i]] = i;
        dp[i] %= mod;
    }
    cout << dp[v.size()-1];
    return 0;
}/*

*/


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

typedef pair<long long int,long long int>pa;
#define pb push_back 

long long int MAX= 200005;
long long int MOD=1e9+7;
long long int INF=1e18;


    
int main()
{
       ios_base::sync_with_stdio(false); 
       cin.tie(NULL);
       cout.tie(NULL);
     
       long long int i,j,k=0,l=0,r=0,m=0,n,p=0,cnt=0,cnt1=0,x=0,y,z,low,mid,high,ans=0,maxi=0,mini=INF,t;
      string s,s1;
    cin>>n>>m;
    long long int A[n+1];
    long long int B[n+1];
 pa C[m];
    long long int D[m];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    sort(A,A+n);
   
    for(i=0;i<m;i++)
    {
        cin>>C[i].second;
        cin>>C[i].first;
    }
    sort(C,C+m);
    l=-1;
    int prev=-1;
    for(i=m-1;i>=0;i--)
    {
        low=min(l+1,n-1);
        high=min(n-1,l+C[i].second);
        while(low<=high)
        {
            mid=(low+high)/2;
            if(A[mid]<=C[i].first)
            {
                low=mid+1;
                l=max(l,mid);
            }
            else
            {
                high=mid-1;
            }
            
        }
        ans=ans+((l-prev)*(C[i].first));
         prev=l;
    }
    for(i=l+1;i<n;i++)
        ans=(ans+A[i]);
    cout<<ans<<endl;
}

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

typedef long long LL;
const int N = 110;
int a[N];

void solve() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    LL res = 1000;
    for(int i = 2; i <= n; i++) {
        if(a[i] > a[i - 1]) {
            res += res / a[i - 1] * (a[i] - a[i - 1]);
        }
    }
    printf("%lld\n", res);
}

int main() {
//    freopen("in.txt", "r", stdin);
//    int t; cin >> t; while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3812
#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;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int a = 0, b = 0;
    for(int i = 0; i < 4; i++){
        int k;
        cin >> k;
        a += k;
    }
    for(int i = 0; i < 4; i++){
        int k;
        cin >> k;
        b += k;
    }
    cout << max(a,b) << endl;
}


Measured memory_bytes: 3092
// Written by newbiechd
#include <cstdio>
using namespace std;

const int maxN = 100003;

int main() {
  int k, n, i, j, c;
  scanf("%d", &k);
  if (k == 1) {
    printf("1\n1\n");
    return 0;
  }
  
  printf("%d\n", n = (k + 3) / 4 * 2);
  for (i = 0; i < n; ++i) {
    for (j = 0; j < n; ++j) {
      c = (i + j) % n;
      if (i & 1 && c + n < k)
        c += n;
      printf("%d ", c + 1);
    }
    putchar('\n');
  }
  return 0;
}


Measured memory_bytes: 1152
n,m = gets.split.map(&:to_i)
a = []
ans = []
m.times do |i|
    p,y = gets.split.map(&:to_i)
    a << [p,y,i]
end
a = a.sort_by{|i,j,k|j}
b = Hash.new(0)
a.each do |i,j,k|
    b[i] += 1
    ans << [("00000"+i.to_s)[-6..-1]+("00000"+b[i].to_s)[-6..-1],k]
end
ans.sort_by{|i,j|j}.each{|i,j|puts i}

Measured memory_bytes: 36808
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
	public static void Main()
	{
		int[] num = new int[10];
		for(int i = 0; i < 4; i++)
			num[GetInt()]++;
		bool ans = (num[1] == 1) && (num[9] == 1) && (num[7] == 1) && (num[4] == 1);
		Console.WriteLine(ans ? "YES" : "NO");
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
         int a,b,c;
  cin>>a>>b>>c;
  int k;
  cin>>k;
 
  for(int i=1;i<=k;i++){
  if(a>=b){b =b*2;}
    else if(b>=c){c *=2;}
  }
  if(a<b && b<c)cout <<"Yes";
  else  cout << "No";
}



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

int main() {
  string n;
  cin >> n;
  
  bool answer = false;
  for(int i = 0; i < 3; i++) {
    if(n.at(i) == '7') {
      answer = true;
      break;
    }
  }
  if(answer) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include<stdio.h>

int main(void)
{
  int a,b,c,d,f,g;
  scanf("%d %d %d",&a,&b,&c);
  
  d=a*c;
  
  for(g=1;g<=10;g++){
    f=d-b;
    printf("%d\n",f);
    d=a*f;
  }
  
  return 0;
}


Measured memory_bytes: 128
259
N,K=map(int,input().split())
A=[0]+list(map(int,input().split()))
m=1
towns=[1]
flg=[0]*(N+1)
flg[1]=1
while 1:
    m=A[m]
    towns.append(m)
    if flg[m]==1:
        l=len(towns)-towns.index(m)-1
        break
    flg[m]=1
pl=towns.index(m)
if K<=pl:
    print(towns[K])
else:
    print(towns[(K-pl)%l+pl])

Measured memory_bytes: 103980
/* Atcoder abc152b
 * See tasks at: https://atcoder.jp/contests/abc152/tasks/abc152_b
 */
#include <iostream>
#include <vector>
#include <algorithm>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    int a, b;
    cin >> a >> b;

    string as, bs;

    until(i, b) as += to_string(a);
    until(i, a) bs += to_string(b);
    
    if (as < bs)
        cout << as;
    else
        cout << bs;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
int n,k,x,y,ans=0,i;
scanf("%d%d%d%d",&n,&k,&x,&y);
for(i=1;i<=n;i++){
if(i<=k)ans+=x;
else ans+=y;
}
printf("%d\n",ans);
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }








int n, m;
const int N = 5003, M = 5003;
int dp[N][M];
pii pre[N][M];
string s, t;

void lcs() {
    rep(i, sz(s) + 1) rep(j, sz(t) + 1) {
        if (chmax(dp[i + 1][j], dp[i][j])) { pre[i + 1][j] = pii(i, j); }
        if (chmax(dp[i][j + 1], dp[i][j])) { pre[i][j + 1] = pii(i, j); }
        if (chmax(dp[i + 1][j + 1], dp[i][j] + (s[i] == t[j]))) { pre[i + 1][j + 1] = pii(i, j); }
    }
    // cout << dp[sz(s)][sz(t)] + 1 << endl;
}

string restore() {
    string ret;
    pii now = pii(n, m);
    while (now.F > 0 && now.S > 0) {
        pii nxt = pre[now.F][now.S];
        if (dp[now.F][now.S] == dp[nxt.F][nxt.S] + 1) ret += s[now.F - 1];
        now = nxt;
        // cout << now.F << " " << now.S << endl;
    }
    reverse(all(ret));
    return ret;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    cin >> s >> t;
    n = sz(s); m = sz(t);
    lcs();
    // rep(i, sz(s) + 1) { rep(j, sz(t) + 1) cout << dp[i][j] << " "; cout << endl; }
    
    cout << restore() << endl;
}


Measured memory_bytes: 179840
#include <bits/stdc++.h>
#define mod 1000000007
#define int long long
using namespace std;

vector<int> adj[200002];

signed main(){
    int n; cin>>n;
    
    int arr[n];
    
    for(int i=1; i<n; i++){
        int a; cin>>a;
        adj[a].push_back(i+1);
    }
    
    for(int i=1; i<=n; i++){
        cout<<adj[i].size()<<"\n";
    }
    
    return 0; 
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B){
    if(A == B) {
        cout << A + B << endl;
    } else if (A < B) {
        cout << B * 2 - 1 << endl;
    } else {
        cout << A * 2 - 1 << endl;
    }
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;

void Main() {
    string S;
    cin >> S;
    int ans = 700;
    for (int i = 0; i < 3; ++i) {
        if (S[i] == 'o') {
            ans += 100;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>

using namespace std;

int main() {
  int x, y;

  cin >> x >> y; 

  if(x<=y){
    if(x>=0 || y<=0){
      cout << y-x << endl;
      return 0;
    }else if(-x>y){
      cout << -y-x+1 << endl;
      return 0;
    }else{
      cout << y+x+1 << endl;
      return 0;
    }
  }else if(x==0){
    cout << x-y+1 << endl;
  }else if(y>0 || x<0){
    cout << x-y+2 << endl;
  }else if(x>-y){
    cout << y+x+1 << endl;
  }else if(x<=-y){
    cout << -y-x+1 << endl;
  }
  return 0;  
}
	
  


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

#define REP(i,init, n) for(int i=init;i<n;i++)
#define REPE(i,init, n) for(int i=init;i<=n;i++)
typedef long long int lli;
typedef pair<int, int> P;

int main() {
    priority_queue<lli, vector<lli>, greater<lli> > que;
    lli ans = 0;
    lli n, m;
    cin >> n >> m;
    REP(i, 0, n) {
        lli a;
        cin >> a;
        que.push(a);
        ans += a;
    }
    //lli ans = 0;
    //lli n, m;
    //cin >> n >> m;
    //vector<lli> v;
    //REP(i, 0, n) {
    //    lli a;
    //    cin >> a;
    //    v.push_back(a);
    //    ans += a;
    //}
    //sort(v.begin(), v.end());
    //priority_queue<lli, vector<lli>, greater<lli> > que(v.begin(), v.end());



    //lli b[m], c[m];
    //REP(i, 0, m) {
    //    cin >> b[i] >> c[i];
    //    REP(j, 0, b[i]) {
    //        lli num = que.top();
    //        if (num >= c[i])
    //            break;
    //        que.pop();
    //        que.push(c[i]);
    //        ans = ans - num + c[i];
    //    }
    //}
    vector<P> cb;
    REP(i, 0, m) {
        lli b, c;
        cin >> b >> c;
        cb.push_back(P(c, b));
    }
    sort(cb.rbegin(), cb.rend());
    REP(i, 0, cb.size()) {
        if (que.top() >= cb[i].first)
            break;
        REP(j, 0, cb[i].second) {
            lli num = que.top();
            if (num >= cb[i].first)
                break;
            que.pop();
            que.push(cb[i].first);
            ans = ans - num + cb[i].first;
        }
    }
    //while (!que.empty()) {
    //    cout << que.top() << endl;
    //    que.pop();
    //}

    cout << ans << endl;
}


Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	long long q1,b,c1,c2,q2;
	while(cin >> q1 , q1){
		cin >> b >> c1 >> c2 >> q2;
		long long now = q2 * c1;
		while(now>b){
			now -= c1;
			q2--;
		}
		while(q2+(b-now)/c2 < q1 && q2 > 0){
			now -= c1;
			q2--;
		}
		if(q2>0){
			cout << q2 << " " << (b-now)/c2 << endl;
		}else{
			cout << "NA" << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>

using namespace std;

int main(){
     string s;
     cin >> s;
     bool c = false;
     for(int i = 0; i < s.size(); i++){
         if(s[i] == 'C') c = true;
         if(c == true && s[i] == 'F'){
             printf("Yes\n");
             return 0;
         }
     }
     printf("No\n");
     return 0;
 }

Measured memory_bytes: 256
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")


#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(x,n)           for(int i=0;i<n;i++)  cin>>x[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll long long
#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	ll a[n + 1];
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
	}

	sort(a + 1, a + n + 1);

	ll ans = 0;
	if (n == 1) {
		ans = 0;
	} else if (n == 2) {
		ans = a[2];
	} else {
		ll k = n;
		ans += a[k--];
		for (ll i = 3; i <= n; i++) {
			ans += a[k];
			//watch(a[k]);
			if (i % 2 == 0) {
				k--;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>//万能文件头
using namespace std;
int main(){
    int n;
    int l,r,ans;//按照题定义
    cin>>n;//输入
    for(int i=1;i<=n;i++){
        cin>>l>>r;//输入公式里两个数
        ans+=r-l+1;//套公式环节
    }
    cout<<ans<<endl;//输出结果
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    vector<ll> L(2*N);
    rep (i, 2*N) {
        cin >> L[i];
    }

    sort(L.begin(), L.end());

    ll ans = 0;
    rep (i, 2*N) {
        ans += L[2*i];
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mp make_pair
 #define pb push_back
 const int N =(1e5) + 1;

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

int arr[n+1];

for (int i = 1; i <= n; ++i)
{
  cin>>arr[i];
}

int dp[n+1] = {};

dp[1] =0;

dp[2] = dp[0] +  abs(arr[1]-arr[2]); 

for (int i = 3; i <=n; ++i)
{
  dp[i] = min(dp[i-2] + abs(arr[i-2] - arr[i]) , dp[i-1] + abs(arr[i-1] - arr[i]));
}

/*for (int i = 1; i <= n; ++i)
{
  cout<<dp[i]<<" ";
}*/
cout<<dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if(d <= t * s) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    int h[n+1];
    for(int i=1;i<=n;i++) cin >> h[i];
    vector<int> adj[n+1];
    for(int i=0;i<m;i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int res = 0;
    for(int i=1;i<=n;i++) {
        if(adj[i].size() == 0) res++;
        else {
            bool good = true;
            for(auto next : adj[i]) {
                if(h[i] <= h[next]) {
                    good = false;
                    break;
                }
            }
            if(good) res++;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 9140
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();
    if(a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) {
		System.out.println("YES");
	}else {
		System.out.println("NO");
	}
  }
}


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	int N;
	string S;
	
	cin >> N;
	cin >> S;

	int W[300000+2] = {0}; //W[i] = 1 .. i-1で西を向いている人の数
	int E[300000+2] = {0}; //E[i] = i+1, ... ,Nの中で東を向いている人の数


	W[0] = 0, W[1] = 0;
	for(int i=0; i<S.size(); i++){
		if(S[i] == 'W'){
			W[i+2] = W[i+1] + 1;
		}
		else{
			W[i+2] = W[i+1];
		}
	}

	E[N] = 0, E[N+1] = 0;
	for(int i=S.size()-1; i>=0; i--){
		if(S[i] == 'E'){
			E[i] = E[i+1] + 1;
		}
		else{
			E[i] = E[i+1];
		}
	}

	int ans = 1<<30;
	for(int i=1; i<=N; i++){
		int v = W[i] + E[i];
		if( ans > v ){
			ans = v;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2948
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int main(){
  int a,b,n;
  scanf("%d %d %d",&a,&b,&n);
  a=MAX(a,b);
  printf("%d\n",(n-1)/a+1);
  return 0;
}


Measured memory_bytes: 128
package main
import (
  "fmt"
)
func main() {
  var n int
  fmt.Scan(&n)
  var result int
  if n < 105 {
    result = 0
  } else {
    result = 1
    for i := 106; i <= n; i++ {
      if i%2 == 0 {
        continue
      }
      num := 0
      for j := 1; j <= i; j++ {
        if i%j == 0 {
          num++
        }
      }
      if num == 8 {
        result++
      }
    }
  }
  fmt.Println(result)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A,B;
  cin >> A >> B;
  int ans = -1;
  for (int i = 1; i < 100000; i++) {
    if ((i * 8) / 100 == A && (i * 10) / 100 == B) {
      ans = i; break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>12)
        printf("%d",b);
    else if(a<13 && a>5)
        printf("%d",b/2);
    else if(a<6)
        printf("0\n");


    return 0;
}


Measured memory_bytes: 128
n = int(input())
for i in range(n):
    Max_num = ""
    Min_num = ""
    n = str(input())
    Lis = list(map(str,n))
    Min_num_lis = sorted(Lis)
    Max_num_lis = sorted(Lis)[::-1]
    for j in range(8):
        Max_num = Max_num + Max_num_lis[j]
        Min_num = Min_num + Min_num_lis[j]
    sa = int(Max_num) - int(Min_num)
    print(sa)
                  

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

for i in range(len(a)):
	if a[i] % 2 == 0:
		ans.append(a[i])


for i in ans:
	if not(i % 3 == 0 or i % 5 == 0):
		print("DENIED")
		exit()

print("APPROVED")




Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
  int n,m,k;std::cin>>n>>m>>k;
  std::vector<long long> a(n+2),b(m+1);
  for(int i=1;i<=n;i++){
    std::cin>>a[i];
  }
  a[n+1]=100000000000;
  for(int i=1;i<=m;i++){
    std::cin>>b[i];
  }
  for(int i=1;i<=n+1;i++){
    a[i]+=a[i-1];
  }
  
  int ans=0;
  long long sum_b=0;
  for(int i=0;i<=m;i++){
    sum_b+=b[i];
    long long amarizikan=k-sum_b;
    if(k-sum_b<0){
      continue;
    }
    int res=upper_bound(a.begin(),a.end(),amarizikan)-a.begin();
    ans=std::max(ans,i+res-1);
  }
  std::cout<<ans<<std::endl;
  
  return 0;
}
  


Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    string A[50], B[50];
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    int num = N-M+1;
    bool f = false;
    for(int i = 0; i < num; i++){
        for(int j = 0; j < num; j++){

            f = false;
            for(int a = 0; a < M; a++){
                for(int b = 0; b < M; b++){
                    if(A[a+i][b+j] == B[a][b]) f= true;
                    else {f = false; break;}
                }
                if(!f) break;
            }
            
            if(f) break;
        }
        if(f) break;
    }
    cout << (f ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256