akhauriyash/Code-Regression huggingface dataset:
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque


def main():
    num = int(input())
    data = list(map(int, input().split()))

    min_num = min(data)
    max_num = max(data)

    ans_list = []
    if max_num + min_num >= 0:
        idx = data.index(max_num)
        for i in range(num):
            if data[i] == max_num:
                continue
            ans_list.append([idx + 1, i + 1])
        for i in range(num - 1):
            ans_list.append([i + 1, i + 2])

    else:
        idx = data.index(min_num)
        for i in range(num):
            if data[i] == min_num:
                continue
            ans_list.append([idx + 1, i + 1])
        for i in range(num - 1)[::-1]:
            ans_list.append([i + 2, i + 1])

    print(len(ans_list))
    for i, j in ans_list:
        print(i, j)





if __name__ == '__main__':
    main()


Measured memory_bytes: 38636
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    int n;
    cin >> n;
    double ans = 0;
    double a[n]; rep(i, n){
        cin >> a[i];
        ans += 1/a[i];
    }
    cout << 1/ans << endl;
    
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    lint N, C;
    cin >> N >> C;
    
    if (N == 1) {
        cout << 0 << endl;
        return 0;
    }
    
    vector<vector<lint>> D(C + 1, vector<lint>(C + 1, 0));
    repeat_from_to (i, 1, C) {
        repeat_from_to (j, 1, C) {
            cin >> D[i][j];
        }
    }
    
    vector<vector<lint>> c(N + 1, vector<lint>(N + 1, 0));
    repeat_from_to (i, 1, N) {
        repeat_from_to (j, 1, N) {
            cin >> c[i][j];
        }
    }
    
    
    vector<vector<pair<lint, lint>>> series(3, vector<pair<lint, lint>>(C + 1, make_pair(0, 0)));
    
    repeat_from_to (newcolor, 1, C) {
        repeat_from_to (i, 1, N) {
            repeat_from_to (j, 1, N) {
                int oldcolor = c[i][j];
                int sidx = (i + j) % 3;
                series[sidx][newcolor].fst += D[oldcolor][newcolor];
                series[sidx][newcolor].snd = newcolor;
            }
        }
    }
    
    auto cmp = [](pair<lint, lint> &a, pair<lint, lint> &b) -> bool {
        return a.fst < b.fst;
    };
    
    repeat (i, 3) {
        sort(series[i].begin(), series[i].end(), cmp);
    }
    
    /*repeat (i, 3) {
        for (auto e: series[i]) {
            cout << "(" << e.fst << ":to color" << e.snd << ") ";
        }
        cout << endl;
    }*/
    
    lint ans = 1e18;
    repeat_from_to (i, 1, 3) {
        repeat_from_to (j, 1, 3) {
            repeat_from_to (k, 1, 3) {
                lint s0c = series[0][i].snd;
                lint s1c = series[1][j].snd;
                lint s2c = series[2][k].snd;
                if (s0c == s1c or s1c == s2c or s2c == s0c) continue;
                lint s0d = series[0][i].fst;
                lint s1d = series[1][j].fst;
                lint s2d = series[2][k].fst;
                ans = min(ans, s0d + s1d + s2d);
            }
        }
    }
    cout << ans << endl;
                
                
}

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

int main() {
  int n;
  cin >>n;
  vector<string>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  map<string,int>mp;
  for(string s:a){
    if(mp.count(s))mp.at(s)++;
    else mp[s]=1;
  }
  cout<<mp.size()<<endl;
  return 0;
}

Measured memory_bytes: 25084
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll mod = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 8000000000000000000LL;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct edge1 { ll from, to, cost; };
double pai = 3.141592653589793;
std::vector<edge>v[100000];

int main() {
	std::string s;
	std::cin >>s;
	for (int i = 0;i < s.size() - 1;i++) {
		if (s[i] == s[i + 1]) {
			std::cout << i + 1 << ' ' << i + 2 << std::endl;
			exit(0);
		}
		if (s[i] == s[i + 2]) {
			std::cout << i + 1 << ' ' << i + 3 << std::endl;
			exit(0);
		}
	}
	std::cout << -1 << ' ' << -1 << std::endl;
}

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

int main() {
    string ans = "Yes";
    string S;
    cin >> S;
    for(size_t i = 0; i < S.size(); i++) {
        if(i % 2 == 1 && S[i] == 'R')
            ans = "No";
        if(i % 2 == 0 && S[i] == 'L')
            ans = "No";
    }

    cout << ans << endl;
}

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

long long  my_abs(long long  x){
    if(x < 0){
        x *= -1;
    }
    return x;
}

int main() {

    int n;

    cin >> n;

    long long  a[n];

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

    long long  dis[n+1];
    long long  all_dis = 0;

    dis[0] = my_abs(a[0]);
    all_dis += dis[0];

    for(int i=0; i<n-1; i++){
        dis[i+1] = my_abs(a[i+1]-a[i]);
        all_dis += dis[i+1];
    }

    dis[n] = my_abs(a[n-1]-0);
    all_dis += dis[n];

    if(n == 2){

        cout << my_abs(a[1]*2) << endl;
        cout << my_abs(a[0]*2) << endl;

    }
    else{

        cout << all_dis - dis[0] - dis[1] + my_abs(a[1]) << endl;

        for(int i=1; i<n-1; i++){
            cout << all_dis - dis[i] - dis[i+1] + my_abs(a[i+1]-a[i-1]) << endl;
        }
        
        cout << all_dis - dis[n-1] - dis[n] + my_abs(a[n-2] - 0) << endl;

    }

    return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int n; cin >>n;
  cout <<"Christmas "; n++;
  if(n<26) cout <<"Eve "; n++;
  if(n<26) cout <<"Eve "; n++;
  if(n<26) cout <<"Eve ";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAXN = 100000;
struct edge {ll to, cost;};
int n;
vector<edge> G[MAXN];
ll dist[MAXN];

void dijkstra(int s) {
    priority_queue<P, vector<P>, greater<P>> que;
    fill(dist, dist + n, LINF);
    dist[s] = 0;
    que.push(P(dist[s], s));

    while(!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];
            if (dist[e.to] > dist[v] + e.cost) {
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to], e.to));
            };
        }
    }
    for (int i = 0; i < n; i++) {
        if (dist[i] % 2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        edge e;
        e.to = v, e.cost = w;
        G[u].push_back(e);
        e.to = u;
        G[v].push_back(e);
    }

    dijkstra(0);

    return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<pi>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int n;
ll cst[1 << 16];
ll A[16][16];
ll dp[1 << 16];

int main(){
    cin >> n;
    rep(i, n) rep(j, n) cin >> A[i][j];
    rep(msk, 1 << n) rep(i, n) REP(j, i + 1, n) if (msk >> i & 1 && msk >> j & 1) cst[msk] += A[i][j];
    rep(msk, 1 << n) {
        for (int msk2 = msk; msk2 > 0; msk2 = msk2 - 1 & msk) {
            dp[msk] = max(dp[msk], dp[msk - msk2] + cst[msk2]);
        }
    }
    co(dp[(1 << n) - 1]);
}


Measured memory_bytes: 4692
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<ll> V;
    rep (i, N - 1) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            V.pb(i);
        }
    }
    rep (i, Q) {
        ll l, r;
        cin >> l >> r;
        --l;
        --r;
        auto lit = lower_bound(all(V), l);
        auto rit = lower_bound(all(V), r) - 1;
        if (lit != V.end()) {
            cout << (rit - lit) + 1 << endl;
        } else {
            cout << 0 << endl;
        }
    }
}


Measured memory_bytes: 1464
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[21];
	int i;
	int len;
	
	scanf("%s", str);
	
	len = strlen(str);
	
	for (i = 1; str[i-1] != '\0'; i++){
		printf("%c", str[len-i]);
	}
	printf("\n");
	
	return (0);
}

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

int a[100001], lis[100001];

void bsearch(int n,int len)
{
    int left=1;
    int right=len;
    while(left<=right)
    {
        int med=(left+right)/2;
        if(lis[med]>=n)  right=med-1;
        else left=med+1;
    }
    lis[left]=n;
}
int main()
{
    int N;
    cin >> N;
    for(int i=0;i<N;i++)
       cin >> a[i];
    int len=1;
    lis[len]=a[0];
    for(int i=1;i<N;i++)
    {
        if(lis[len]<a[i])
        {
            len++;
            lis[len]=a[i];
        }
        else
           bsearch(a[i],len);
    }
    cout << len << endl;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n;
    cin >> n;
    mint cnt=1;
    for(int i = 1; i < n+1; i++){
        cnt *= i;        
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
  N = int(input())
  items = [int(input()) for _ in range(N)] 
  items.sort() # 最も定価が高いものを半額で変える
  items[-1] = items[-1] // 2

  result = 0
  for n in items:
    result += n
  print(result)

main()

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a < b && b < c) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 26236
#include <bits/stdc++.h>
const int INF=1e9;
const int MOD=1e9+7;
//const int MOD=998244353;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<"No"<<endl;return 0;}
//template
//main
signed main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<max(c+b-a,0LL)<<endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func r() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func gcd(a, b int) int {
	for b != 0 {
		c := a % b
		a, b = b, c
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	n := r()

	var x int
	y := r()
	for i := 1; i < n; i++ {
		x = r()
		y = gcd(x, y)
	}

	fmt.Println(y)
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;

const int max_num_teams = 50;
const int max_num_probs = 10;

// time, num_errors
pair<int, int> probrems[max_num_teams + 1][max_num_probs + 1];
// num_corrects, time
struct team {
    int team_id;
    int num_corrects;
    int time;
};

bool operator<(const team& l, const team& r) {
    if (l.num_corrects == r.num_corrects) {
        if (l.time == r.time) {
            return l.team_id > r.team_id;
        }
        return l.time < r.time;
    }
    return l.num_corrects > r.num_corrects;
}

bool same_place(const team& l, const team& r) {
    return l.num_corrects == r.num_corrects && l.time == r.time;
}

team teams[max_num_teams];

int main() {
    for (;;) {
        int M, T, P, R;
        scanf("%d%d%d%d", &M, &T, &P, &R);

        if (!M && !T && !P && !R) { break; }

        for (int i = 1; i <= max_num_teams; i++) {
            for (int j = 1; j <= max_num_probs; j++) {
                probrems[i][j] = make_pair(-1, 0);
            }
            teams[i].team_id = i;
            teams[i].num_corrects = 0;
            teams[i].time = 0;
        }

        for (int i = 0; i < R; i++) {
            int m, t, p, j;
            scanf("%d%d%d%d", &m, &t, &p, &j);
            if (j == 0) { // Correct answer
                probrems[t][p].first = m;
            } else { // Wrong answer
                probrems[t][p].second++;
            }
        }

        for (int i = 1; i <= T; i++) {
            for (int j = 1; j <= P; j++) {
                if (probrems[i][j].first != -1) {
                    teams[i].num_corrects++;
                    teams[i].time += probrems[i][j].first;
                    teams[i].time += probrems[i][j].second * 20;
                }
            }
        }

        sort(&teams[1], &teams[T + 1]);

        for (int i = 1; i <= T - 1; i++) {
            printf("%d", teams[i].team_id);
            if (same_place(teams[i], teams[i + 1])) {
                printf("=");
            } else {
                printf(",");
            }
        }
        printf("%d\n", teams[T].team_id);
    }
    return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n, k;
	cin >> n >> k;
	ll arr[n];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	ll food[n];
	for (int i = 0; i < n; i++)
		cin >> food[i];
	sort(arr, arr + n);
	sort(food, food + n);
	ll l = 0 ; ll r = 1e13; ll mid; mid = l + r; mid /= 2;
	int f = 1; ll ans = -1; int u = 0;
	while (f == 1)
	{
		u++;
		if (u > 100)
			break;
		if (l == r)
		{

			mid = l + r;
			mid /= 2;
			ll cnt = 0; int flag1 = 1;
			for (int i = 0; i < n; i++)
			{
				ll a = mid / food[n - 1 - i];
				if (arr[i] > a)
					cnt += arr[i] - a;
				if (cnt > k)
				{flag1 = 0; break;}
			}
			cnt = 0; mid++; int flag2 = 1;
			for (int i = 0; i < n; i++)
			{
				ll a = mid / food[n - 1 - i];
				if (arr[i] > a)
					cnt += arr[i] - a;
				if (cnt > k)
				{flag2 = 0; break;}
			} mid--;
			//cout << l << " " << mid << " " << r << " " << flag1 << " " << flag2 << endl;
			if (flag1 == 0 && flag2 == 0)
			{
				ans = mid;
			}
			else if (flag1 == 0 && flag2 == 1)
			{
				ans = mid + 1; break;
			}
			else
			{
				ans = mid;
			}
			break;
		}
		else
		{
			mid = l + r;
			mid /= 2;
			ll cnt = 0; int flag1 = 1;
			for (int i = 0; i < n; i++)
			{
				ll a = mid / food[n - 1 - i];
				if (arr[i] > a)
					cnt += arr[i] - a;
				if (cnt > k)
				{flag1 = 0; break;}
			}
			cnt = 0; mid++; int flag2 = 1;
			for (int i = 0; i < n; i++)
			{
				ll a = mid / food[n - 1 - i];
				if (arr[i] > a)
					cnt += arr[i] - a;
				if (cnt > k)
				{flag2 = 0; break;}
			} mid--;
			//cout << l << " " << mid << " " << r << " " << flag1 << " " << flag2 << endl;
			if (flag1 == 0 && flag2 == 0)
			{
				l = mid + 1;
			}
			else if (flag1 == 0 && flag2 == 1)
			{
				ans = mid + 1; break;
			}
			else
			{
				r = mid - 1;
			}
			//cout << l << " " << mid << " " << r << " " << flag1 << " " << flag2 << endl;
		}
	}
	cout << ans;
	return 0;
}

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

long long n;

int main()
{
	cin>>n;
	int a[n+1],b[n+1];
	
	for(int i=1;i<=n;i++) b[i]=0;
	 
	for(int i=2;i<=n;i++)   //1 1 2 2
	{
		cin>>a[i];
		b[a[i]]+=1;
	}
	
	for(int i=1;i<=n;i++)
	 cout<<b[i]<<endl;
	
	return 0;
}
 


Measured memory_bytes: 5180
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#define ALL(p) (p).rbegin(),(p).rend()
using namespace std;
typedef long long ll;
int main(){
  ll i,j,n,x,y,result;
  ll a;
  map<ll,ll> dp[2010];
  //dp[i][j]: i人を配置し、うち左にj人、右にi-j人いるときのmax
  cin >> n;
  vector<pair<ll,ll> > p(n+1);
  for(i=0;i<n;i++){
    cin >> p[i].first;
    p[i].second = i;
  }
  sort(ALL(p));
  
  for(i=0;i<n;i++){
    a = p[i].first;
    j = p[i].second;
    for(x=0;x<=i;x++){
      if(dp[i][x]>=0){
        dp[i+1][x+1] = max(dp[i+1][x+1],dp[i][x]+a*abs(j-x));
        dp[i+1][x] = max(dp[i+1][x],dp[i][x]+a*abs(n-1-(i-x)-j));
      }
    }
  }
  result=dp[n][0];
  for(i=1;i<=n;i++) result = max(result,dp[n][i]);
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 128896
import sys
N=int(input())
H=list(map(int,input().split()))
tmp=0
for i in range(N-1):
  tmp=max(tmp,H[i])
  if H[i]<=H[i+1]:
    pass
  elif H[i]-H[i+1]==1:
    H[i]-=1
    if tmp-H[i]>=2:
      print('No')
      sys.exit()
    else:
      pass
  else:
    print('No')
    sys.exit()
print('Yes')

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

#define N 200005

vector<long long int> a, b;

int check(long long int max_time, long long int k, int n) {
	long long int sum = 0;
	for(int i=0; i<n; i++) {
		if(a[i] * b[i] <= max_time) 
			continue;
		sum += abs(a[i] - max_time/b[i]);
	}
	if(sum <= k)
		return 1;
	return 0;
}

int main() {
	int n;
	long long int k;
	
	scanf("%d", &n);
	scanf("%lld", &k);
	for(int i=0; i<n; i++) {
		long long int temp;
		scanf("%lld",&temp);
		a.push_back(temp);
	}
	for(int i=0; i<n; i++) {
		long long int temp;
		scanf("%lld" ,&temp);
		b.push_back(temp);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());

	long long int max_time = a[0] * b[0];
	for(int i=1; i<n; i++) {
		max_time = max(max_time, a[i]*b[i]);
	}

	long long int left = 0, right = max_time;
	while(left != right) {
		if(left + 1 == right) {
			if(check(left, k, n)) {
				right = left;
			}
			else {
				left = right;
			}
			continue;
		}
		long long int mid = (left + right)/2;
		if(check(mid, k, n)) {
			right = mid ; 
		}
		else {
			left = mid + 1;
		}
	}
	printf("%lld\n", left);


	return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;
int main() {
	int n, k, m = 0, a = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> k;
		if (m < k)
		{
			a += m;
			m = k;
		}
		else
		{
			a += k;
		}
	}

	if (m < a)cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll s[200];
int main(){
  ll n,ans=0,tmp=0;
  cin>>n;
  rep(i,0,n){cin>>s[i];ans+=s[i];}
  sort(s,s+n);
  rep(i,0,n) if(s[i]%10!=0){tmp=s[i];break;}
  if(ans%10!=0)cout<<ans;
  else if(tmp==0)cout<<"0";
  else cout<<ans-tmp;
  
}



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

using namespace std;

static const int MAX_N = 2e5;

int main()
{
	int n;
	cin >> n;
	vector<pair<int64_t, int64_t>> points(n);
	for (int i = 0; i < n; ++i)
	{
		int64_t first, second;
		cin >> second >> first;
		points[i].first = first;
		points[i].second = second;
	}

	sort(points.begin(), points.end());
	int64_t now = 0;
	for (int i = 0; i < n; ++i)
	{
		points[i].first -= now;
		now += points[i].first;
	}
	bool ans = true;
	int64_t lefttime = 0;
	for (int i = 0; i < n; ++i)
	{
		lefttime += points[i].first;
		lefttime -= points[i].second;
		if (lefttime < 0)
		{
			ans = false;
			break;
		}
	}
	if (ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> pii;

#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define MOD 1000000007LL

int main(){
    ll N, X, D;
    cin >> N >> X >> D;

    if(D == 0){
        if(X == 0){
            cout << 1 << endl;
        }else{
            cout << N+1 << endl;
        }
        return 0;
    }
    if(D < 0){
        X = -X;
        D = -D;
    }
    map<ll,vector<pii>> m;
    REP(k,0,N+1){
        ll l = k*(k-1)/2*D + k*X;
        ll r = (N*(N-1)/2 - (N-k)*(N-k-1)/2)*D + k*X;
        ll d = (k*X)%D;
        m[d].push_back(make_pair(l,r));
    }
    
    ll ret = 0;
    for(auto n : m){
        vector<pii> v = n.second;
        sort(v.begin(), v.end());
        ll l=v[0].first;
        ll r=v[0].second;
        ll last=-1;
        REP(j,1,v.size()){
            if(r<v[j].first){
                ret+=(r-l)/D+1;
                last=j;
                l=v[j].first;
                r=v[j].second;
            }else{
                r=max(r,v[j].second);
            }
        }
        ret+=(r-l)/D+1;
    }
    cout<<ret<<endl;

    return 0;
}

Measured memory_bytes: 22144
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n,w;
    cin >> n >> w;
    int s,v;
    int m=w;
    
    vector<pair<int, int>> vc;
    pair<int, int> p;
    
    for(int i=0;i<n;i++){
        cin >> s >> v;
        vc.push_back(pair<int, int>(s,v));
    }
    
    long long dp[n+1][w+1];
    
    for(int i=0;i<n+1;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<w+1;i++){
        dp[0][i]=0;
    }  
    
    for(int i=1;i<n+1;i++){
        s = vc[i-1].first;
        v = vc[i-1].second;
        for(int j=1; j<m+1; j++){
            if(j>=s){
                dp[i][j]=max(dp[i-1][j], dp[i-1][j-s]+v);
            }else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
        
    
    std::cout << dp[n][m] << std::endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int edge1 = X;
    int edge2 = Y;
    rep(0, i, N)
    {
        int x;
        cin >> x;
        edge1 = max(edge1, x);
    }
    rep(0, i, M)
    {
        int y;
        cin >> y;
        edge2 = min(edge2, y);
    }
    if (edge1 < edge2)
    {
        cout << "No War" << endl;
    }
    else
    {
        cout << "War" << endl;
    }
}

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

long long comb[51][51];

int main() {
  {
    comb[0][0] = 1;
    for (int i = 1; i < 51; ++i) {
      for (int j = 0; j <= i; ++j) {
	comb[i][j] = comb[i-1][j] + (j > 0 ? comb[i-1][j-1] : 0);
      }
    }
  }
  
  int N, P;
  std::cin >> N >> P;
  std::vector<int> A(N);
  int even = 0, odd = 0;
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i];
    A[i] %= 2;
    if (A[i] == 1) ++odd;
    else ++even;
  }
  long long ans = 0;
  for (int i = P; i <= odd; i += 2) {
    ans += comb[odd][i] * (1LL << even);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main(){
  int a,b,t;
  cin >> a >> b >> t;
  int time=0;
  int ans=0;
  
  while(time<=t){
    ans+=b;
    time+=a;
  }
  ans-=b;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define endl "\n"
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
#define mod             1000000007
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll power(ll a, ll b, ll m = mod) { ll ans = 1; a = a % m;  while (b > 0) {  if (b & 1)  ans = (1ll * a * ans) % m; b >>= 1; a = (1ll * a * a) % m;} return ans;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll lcm( ll x, ll y) { return (x * y) / gcd(x, y);}
bool isprime(ll n) {if (n < 2) return 0; ll i = 2; while (i * i <= n) {if (n % i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x & (x - 1)));
}
void offset(vector<int>&a, int x) {
  for (int i = 0; i < sz(a); i++) {
    a[i] = x;
  }
}
struct cmp {
  bool operator() (const pair<int, int>& lhs, const pair<int, int>& rhs) const {
    return lhs.ff * rhs.ss < lhs.ss * rhs.ff;
  }
//for map<pii,int>
};


// auto cmp = [](pair<int,int>a,pair<int,int>b) {if(a.first==b.first)return a.second>b.second;
//      else return a.first > b.first;
//  };
//  multiset<pair<int,int>,decltype(cmp)>fc(cmp);
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
  return sqrt(1. * pow(x - z, 2) + 1. * pow(y - w, 2));
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
  //unordered_map<long long, int, custom_hash> safe_map;
};

const int MAXN = 2e5 + 10;

#define int long long
bool cmps(pair<int, int>p1, pair<int, int>p2) {
  return p1.ss > p2.ss;
}
int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("inp.txt", "r", stdin);
  freopen("op.txt", "w", stdout);
#endif
  fio
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b)cout << c;
  else if (a == c)cout << b;
  else if (b == c)cout << a;

  cerr << endl << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;


}






Measured memory_bytes: 3872
#include<cstdio>
#include<vector>
std::vector<int> g[1000005];
std::vector<int> vis[1000005];
std::vector<int> dis[1000005];
char s[1000005];
struct Element{
	int x,y;
	Element(int x=0,int y=0):x(x),y(y){}
};
Element queue[1000005];

int main(){
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	int x1,y1,x2,y2;
	scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
	for(int i = 1; i <= n; i++){
		scanf("%s",s+1);
		g[i].push_back(-1);
		vis[i].push_back(0);
		dis[i].push_back(0);
		for(int j = 1; j <= m; j++){
			if(s[j]=='.') g[i].push_back(0);
			else g[i].push_back(1);
			vis[i].push_back(0);
			dis[i].push_back(0);
		}
	}
	int h = 0, t = -1;
	queue[++t] = Element(x1,y1);
	vis[x1][y1] = 1; dis[x1][y1] = 0;
	while(h<=t){
		Element u = queue[h++];
		int x = u.x, y = u.y;
		for(int i = 1; i<=k && x+i<=n; i++){
			if((vis[x+i][y] && dis[x+i][y]<=dis[x][y]) || g[x+i][y]){
				break;
			}
			else if(vis[x+i][y]==0){
				vis[x+i][y] = 1;
				dis[x+i][y] = dis[x][y]+1;
				queue[++t] = Element(x+i,y);
			}
		}
		for(int i = 1; i<=k && x-i>=1; i++){
			if((vis[x-i][y] && dis[x-i][y]<=dis[x][y]) || g[x-i][y]) break;
			else if(vis[x-i][y]==0){
				vis[x-i][y] = 1;
				dis[x-i][y] = dis[x][y]+1;
				queue[++t] = Element(x-i,y);
			}
		}
		for(int i = 1; i<=k && y+i<=m; i++){
			if((vis[x][y+i] && dis[x][y+i]<=dis[x][y]) || g[x][y+i]) break;
			else if(vis[x][y+i]==0){
				vis[x][y+i] = 1;
				dis[x][y+i]  =dis[x][y]+1;
				queue[++t] = Element(x,y+i);
			}
		}
		for(int i = 1; i<=k && y-i>=1; i++){
			if((vis[x][y-i] && dis[x][y-i]<=dis[x][y]) || g[x][y-i]) break;
			else if(vis[x][y-i]==0){
				vis[x][y-i] = 1;
				dis[x][y-i] =dis[x][y]+1;
				queue[++t] = Element(x,y-i);
			}
		}
	}
	if(!vis[x2][y2]) printf("-1\n");
	else printf("%d\n",dis[x2][y2]);
	return 0;
}


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

using namespace std;

const int md = 1e9 + 7;

int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  return x;
}

int main() {
#ifdef wxh010910
  freopen("input.txt", "r", stdin);
#endif
  string s;
  cin >> s;
  int n = s.length();
  bool flag = true;
  for (int i = 1; i < n; ++i) {
    flag &= s[i] != s[i - 1];
  }
  if (flag) {
    puts("1");
    return 0;
  }
  vector<int> sum(n + 1);
  for (int i = 0; i < n; ++i) {
    sum[i + 1] = (sum[i] + (s[i] == 'a') + 1) % 3;
  }
  vector<vector<int>> next(n + 1, vector<int> (3, n + 1));
  for (int i = n - 1; ~i; --i) {
    for (int j = 0; j < 3; ++j) {
      next[i][j] = next[i + 1][j];
    }
    next[i][sum[i + 1]] = i + 1;
  }
  vector<int> f(n + 1);
  int answer = 0;
  f[0] = 1;
  for (int i = 0; i <= n; ++i) {
    for (int j = 1; j <= 2; ++j) {
      if (next[i][(sum[i] + j) % 3] <= n) {
        f[next[i][(sum[i] + j) % 3]] = add(f[next[i][(sum[i] + j) % 3]], f[i]);
      }
    }
    if (i && sum[i] == sum[n]) {
      answer = add(answer, f[i]);
    }
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string ss;
    cin >> ss;
    int n=0,j=0;
    vector <char> str;
    int a[100]={0};
    int i;
    for(i=0;i<ss.size();i++)
    {
        str.push_back(ss[i]);
    }
    sort(str.begin(),str.end());
    for(i=0;i<ss.size();i++)
    {
        if(str[i]==str[i+1])
        {
            n++;
        }
        else
        {
            a[j]=n+1;
            j++;
            n=0;
        }
        
    }
    for(i=0;i<j;i++)
    {
        if(a[i]%2!=0)
        {
            cout << "No\n" ;
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 3644
import Control.Applicative

power :: Integral a => (t -> t -> t) -> t -> t -> a -> t
power _ e _ 0 = e
power f e a n = power f (if odd n then f a e else e) (f a a) (div n 2)

-- a^n (mod m)
powerMod :: (Integral a, Integral t) => t -> a -> t -> t
powerMod a n m = power (\x y -> mod (x * y) m) 1 a n

main :: IO ()
main = do
  [m, n] <- map read . words <$> getLine
  print $ powerMod m n 1000000007



Measured memory_bytes: 3688
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>
typedef long long LL;

using namespace std;



int main(void) {
	int n, m;
	cin >> n >> m;
	vector<string>A(n), B(m);
	int k;
	for (int i = 0; i < n; i++)cin >> A[i];
	for (int i = 0; i < m; i++)cin >> B[i];
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			for (k = 0; k < m; k++) {
				if (A[i + k].substr(j,m) != B[k]) {
					break;
				}
			}
			if (k == m) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  if(S[K-1] == 'A') S[K-1] = 'a';
  if(S[K-1] == 'B') S[K-1] = 'b';
  if(S[K-1] == 'C') S[K-1] = 'c';

  cout << S << endl;
  return 0;
}



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

int main()
{
  string S;
  cin >> S;
  if(S=="Sunny") cout << "Cloudy" << endl;
  else if(S=="Cloudy") cout << "Rainy" << endl;
  else if(S=="Rainy") cout << "Sunny" << endl;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
 
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)
 
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;

//const int mod= 998244353; 

signed main() {
 
	fastio();
//	#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif	
	string s;
	cin>>s;

	int dp[s.length()+2][14];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='?')
		{
			for(int j=0;j<13;j++)
			{
				for(int k=0;k<=9;k++)
				{
					dp[i+1][(j*10+k)%13]+=dp[i][(j)];
					dp[i+1][(j*10+k)%13]%=MOD;
				}
			}
		}else{
			int res=s[i]-'0';
			for(int j=0;j<13;j++)
			{
				dp[i+1][(j*10+res)%13]+=dp[i][j];
				dp[i+1][(j*10+res)%13]%=MOD;
			}
		}
	}
	cout<<dp[s.length()][5];
	return 0;
}

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

bool checked[100001] = {false};
int height[100001] = {0};

static bool higher(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second > b.second) return true;
  return false;
}

static bool is_good_tower(
  const int tower_no, 
  const vector <vector <int>> &road) {

    if (checked[tower_no]) return false;

    checked[tower_no] = true;

    const int this_height = height[tower_no];
    for (int i = 0; i < road[tower_no].size(); i++) {
      int to_tower_no = road[tower_no][i];
      if (this_height <= height[to_tower_no]) {
        return false;
      } else {
        checked[to_tower_no] = false;
      }
    }
    return true;
}

int main(void) {
  int N, M;
  cin >> N >> M;
  vector <pair <int, int> > tower(N+1);
  for (int i = 1; i <= N; i++) {
    int H;
    cin >> H;
    tower[i].first = i;
    tower[i].second = height[i] = H;
    
  }
  tower[0].first = 0;
  tower[0].second = 0;

  vector <vector <int>> road(N+1);
  for (int i = 1; i <= M; i++) {
    int A, B;
    cin >> A >> B;
    road[A].push_back(B);
    road[B].push_back(A);
  }

  sort(tower.begin(), tower.end(), higher);
  for (int i = 1; i <= N; i++) checked[i] = false;

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (is_good_tower(tower[i].first, road)) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n, y;
	cin >> n >> y;
	for(int i=0; 10000*i<=y; ++i){
		for(int j=0; 10000*i+5000*j<=y; ++j){
			if( 10000*i+5000*j+1000*(n-i-j) == y ){
				cout << i << " " << j << " " << n-i-j << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

Measured memory_bytes: 256
//written by NewbieChd
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxN = 100003;
int dis[maxN];
long double pow2[maxN];

int main() {
    int n = read(), k = read(), i;
    long double p, ans = 0;
    if (n >= k)
        ans = 1. * (n - k + 1) / n;
    p = 1. / n, n = min(n, k - 1), pow2[0] = 1;
    for (i = 1; i <= k; ++i)
        pow2[i] = pow2[i - 1] / 2;
    for (i = k - 1; i; --i)
        if (i << 1 >= k)
            dis[i] = 1;
        else
            dis[i] = dis[i << 1] + 1;
    for (i = 1; i <= n; ++i)
        ans += p * pow2[dis[i]];
    //cout << fixed << setprecision(10) << ans << '\n';
    printf("%.10Lf\n", ans);
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

const int MAX_N=10005;
unordered_map<int,int> mp;
int w[MAX_N], v[MAX_N];

int solve(int H, int n) {
    if(H<=0) return 0; 
    if(mp.count(H)) return mp[H];
    int res = 1e9;
    REP(i, n) {
        res = min(res, solve(H-w[i], n)+v[i]);
    }
    mp[H] = res;
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int H, n;
    cin >> H >> n;
    
    REP(i,n) {
        cin >> w[i] >> v[i];
    }
    
    cout << solve(H, n) << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    ll l, r;
    cin >> l >> r;
    if(r -l +1 >= 2019) cout << 0 << endl;
    else {
        ll minmod = 2020;
        for(ll i = l; i < r; i++) {
            for(ll j = i + 1; j <= r; j++) {
                minmod = min(minmod, i*j%2019);          
            }
        }
        cout << minmod << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
int len[100001];

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> a;
  for(int i = 0; i < n; i++){
    ll x;
    cin >> x;
    a.pb(x);
  }
  int r = 1;
  for(int i = 0; i < n; i++){
    if(r == i)r++;
    while(r < n){
      if(a[r - 1] <= a[r])r++;
      else break;
    }
    len[i] = max(len[i], r - i);
  }
  r = 1;
  for(int i = 0; i < n; i++){
    if(r == i)r++;
    while(r < n){
      if(a[r - 1] >= a[r])r++;
      else break;
    }
    len[i] = max(len[i], r - i);
  }
  int curr = 0;
  int res = 0;
  while(curr < n){
    int tmp = len[curr];
    curr = curr + tmp;
    res++;
  }
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 1524
n,l = map(int,input().split())
arr = list(map(int,input().split()))

key = 0
flag = False
for i in range(n-1):
    if arr[i] + arr[i+1] >= l:
        key = [i,i+1]
        flag = True
        break

# print(key)
if flag:
    print("Possible")
    for i in range(key[0]):
        print(i+1)
    temp = []
    for i in range(key[1]+1,n):
        temp.append(i)
    temp.reverse()
    for t in temp:
        print(t)
    print(key[1])

else:
    print("Impossible")




Measured memory_bytes: 14180
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

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

	public static void main(String[] args) {
		//??\???????´???¨TreeMap??????
		Map<Integer, Integer> numCount = new HashMap<Integer, Integer>();
		Integer num; //??\?????§???????????£?????°???
		Integer numPlus = 0;

		while(sc.hasNext()) { //??\?????¶?????°?????????
			num = sc.nextInt();

			if(numCount.containsKey(num)) {
				numPlus = numCount.get(num) + 1;
			} else {
				numPlus = 1;
			}

			numCount.put(num, numPlus);
		}

		List<Map.Entry<Integer, Integer>> entries
		= new ArrayList<Map.Entry<Integer, Integer>>(numCount.entrySet());

		//???????????\??????????????????????????????????????????
		Collections.sort(entries
				, new Comparator<Map.Entry<Integer, Integer>>() {

			@Override
			public int compare(
            		Entry<Integer, Integer> entry1
            		, Entry<Integer, Integer> entry2) {
                // 4. ??????
                return entry2.getValue().compareTo(entry1.getValue());
            }
        });

		int counter = 0;
		for(int $ = 0; $ < entries.size(); $++) {
			if(entries.get($).getValue() >= counter) {
				System.out.println(entries.get($).getKey());
				counter = entries.get($).getValue();
			}
		}

	}

}

Measured memory_bytes: 25640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;
using ll = long long;
#define REP(i, n) for(int i = 0; i < n; ++i)
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;
constexpr int MAX = 3030;


ll n, k, a[MAX], b[MAX];
ll c[MAX][MAX];

ll rec(bool turn, int l, int r) {
	if (c[l][r] != INF) return c[l][r];
	if (turn) {
		if (l == r) return a[l];
		// taro
		ll res = -INF;
		res = max(res, rec(0, l + 1, r) + a[l]);
		res = max(res, rec(0, l, r - 1) + a[r]);
		return c[l][r] = res;
	}
	else {
		if (l == r) return -a[l];
		// jiro
		ll res = INF;
		res = min(res, rec(1, l + 1, r) - a[l]);
		res = min(res, rec(1, l, r - 1) - a[r]);
		return c[l][r] = res;
	}
}

int main() {
	cin >> n;
	REP(i, n) cin >> a[i];
	REP(i, MAX) REP(j, MAX) c[i][j] = INF;
	cout << rec(1, 0, n - 1);
}

Measured memory_bytes: 72192