akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

struct card{
	char suit;
	int num;
};
card A[100000];

int partition(int p, int r) {
	int x = A[r].num;
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].num <= x) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

void quicksort(int p, int r) {
	if (p < r) {
		int q = partition(p, r);
		quicksort(p, q - 1);
		quicksort(q + 1, r);
	}
}

int isStable(int n, card s[]) {
	for (int i = 0; i < n; i++) {
		int j = 0;
		while (1) {
			while (j < n && s[j].num != A[i].num)j++;
			if (j == n) break;
			if (s[j].suit != A[i].suit) return 0;
			if (A[i].num != A[i + 1].num) break;
			i++;
			j++;
		}
	}
	return 1;
}

int main(void) {
	int n;
	card s[100000];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i].suit >> A[i].num;
		s[i] = A[i];
	}
	quicksort(0, n - 1);
	if (isStable(n, s)) {
		cout << "Stable" << endl;
	} else {
		cout << "Not stable" << endl;
	}
	for (int i = 0; i < n; i++) {
		cout << A[i].suit << " " << A[i].num << endl;
	}
	return 0;
}

Measured memory_bytes: 2720
N = int(input())
S = []
M_num = 0
A_num = 0
R_num = 0
C_num = 0
H_num = 0
ans = 0
for i in range(N):
    S.append(input())
# print(S)

for i in range(N):
    temp = str(S[i])
    if temp[0] == "M":
        M_num += 1
    elif temp[0] == "A":
        A_num += 1
    elif temp[0] == "R":
        R_num += 1
    elif temp[0] == "C":
        C_num += 1
    elif temp[0] == "H":
        H_num += 1
ans += M_num*A_num*R_num
ans += M_num*A_num*C_num
ans += M_num*A_num*H_num

ans += A_num*R_num*C_num
ans += A_num*R_num*H_num

ans += R_num*C_num*H_num
ans += M_num *C_num*H_num
ans += M_num*R_num*C_num

ans += A_num * C_num * H_num
ans += M_num * R_num * H_num
print(ans)

Measured memory_bytes: 9772
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, n);
	VEC(int, a, n);
	int pos = 0, neg = 0;
	int pos_sm = 0, neg_sm = 0;
	REP(i, n) {
		pos_sm += a[i];
		neg_sm += a[i];
		if (i & 1) {
			if (pos_sm >= 0) {
				pos += abs(pos_sm) + 1;
				pos_sm = -1;
			}
			if (neg_sm <= 0) {
				neg += abs(neg_sm) + 1;
				neg_sm = 1;
			}
		} else {
			if (pos_sm <= 0) {
				pos += abs(pos_sm) + 1;
				pos_sm = 1;
			}
			if (neg_sm >= 0) {
				neg += abs(neg_sm) + 1;
				neg_sm = -1;
			}
		}
		debug(neg);
		debug(pos);
	}
	int ans = min(neg, pos);
	OUT(ans)BR;

  
  return 0;
}


Measured memory_bytes: 1280
K = int(input())

#偶数、5の倍数はありえない
if(K % 2 == 0):
    print(-1)
    exit()

if(K % 5 == 0):
    print(-1)
    exit()

ans = 1
tmp = 7
for i in range(1*10**6):
    if tmp % K == 0:
        print(ans)
        exit()
    
    hoge = tmp % K
    ans += 1
    tmp = hoge * 10 + 7
#    print(ans, tmp)

print(-1)


Measured memory_bytes: 9164
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;

using namespace std;

mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

typedef pair < int , int > pii ;
#define y1 sfasfd
const int N = 3e5 + 123;
string s;
int pr[32][N];
set < pii > st[32];
int main(){        
	cin >> s;
	//p[i] - p[j - 1] > (i - j + 1) / 2
	//2 * (p[i] - p[j - 1]) > i - j + 1
	//2 * p[i] - i > 2 * p[j - 1] - j + 1
	for(int i = 1 ; i <= sz(s) ; i++){
		pr[s[i - 1] - 'a'][i]++;
		for(int j = 0 ;j < 26 ; j++)
			pr[j][i] += pr[j][i - 1];
		if(i >= 2)
		for(int j = 0 ; j < 26 ; j++){
			st[j].insert({2 * pr[j][i - 3+1] - i + 2-1 + 1, i - 2+1});
			auto x = *st[j].begin();	
			if(x.fi < 2 * pr[j][i] - i){
				cout << x.se << ' ' << i ;return 0;
			}
		}

	}
	cout << "-1 -1";
}

Measured memory_bytes: 151680
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int s = scanner.nextInt();
		
		int h = s / 3600;
		int m = s / 60 % 60;
		s %= 60;
		System.out.println(h + ":" + m + ":" + s);
	}

}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  int GCD=A.at(0);
  for(int i=0; i<N-1; i++){
    int B=max(GCD,A.at(i+1));
    int C=min(GCD,A.at(i+1));
    int r=B%C;
    while(r!=0){
      B=C;
      C=r;
      r=B%C;
    }
    GCD=C;
  }
  cout << GCD << endl;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<ll, int> ll_i;
struct edge { int v, w; };
const ll INF = LLONG_MAX / 3;
const int MOD = 1e9 + 114514;

pair<vector<ll>, vector<int>> dijkstra(int N, vector<vector<edge>>& G, int s) {
	vector<ll> d(N, INF); d[s] = 0;
	vector<int> way(N); way[s] = 1;
	priority_queue<ll_i, vector<ll_i>, greater<ll_i>> pq;
	pq.push(ll_i(0, s));
	while (pq.size()) {
		ll_i p = pq.top(); pq.pop();
		int u = p.second;
		if (p.first > d[u]) continue;
		for (edge e: G[u]) {
			if (d[e.v] > d[u] + e.w) {
				d[e.v] = d[u] + e.w;
				way[e.v] = 0;
				pq.push(ll_i(d[e.v], e.v));
			}
			if (d[e.v] == d[u] + e.w)
				way[e.v] = (way[e.v] + way[u]) % MOD;
		}
	}
	return {d, way};
}

int main() {
	int N, M; cin >> N >> M;
	vector<int> a(M), b(M), c(M);
	rep(i, M) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--;
	vector<vector<edge>> G(N), _G(N);
	rep(i, M) G[a[i]].pb({b[i], c[i]}), _G[b[i]].pb({a[i], c[i]});
	auto z = dijkstra(N, G, 0), _z = dijkstra(N, _G, 1);
	vector<ll> d = z.first, _d = _z.first;
	vector<int> way = z.second, _way = _z.second;
	ll D = d[1]; int WAY = way[1];
	rep(i, M) {
		int u = a[i], v = b[i];
		if (d[u] + c[i] + _d[v] == D && (ll)way[u] * _way[v] % MOD == WAY)
			printf("SAD\n");
		else if (d[v] + c[i] + _d[u] < D)
			printf("HAPPY\n");
		else
			printf("SOSO\n");
	}
}

Measured memory_bytes: 19692
import sys

sys.setrecursionlimit(6500)

def find(n):
    if d[n]<0:
        return n
    else:
        d[n]=find(d[n])
        return d[n]

def union(a,b):
    a=find(a)
    b=find(b)
    if a==b:return False
    if d[a]<=d[b]:
        d[a]+=d[b]
        d[b]=a
    else:
        d[b]+=d[a]
        d[a]=b
    return True

def members(n):
    p=find(n)
    ans=[]
    for i in range(N):
        if find(i)==p:
            ans.append(i)
    return ans

def same(a,b):
    if find(a)==find(b):return True
    else:return False

N,M=map(int,input().split())
p=list(map(int,input().split()))

d=[-1]*N

for i in range(M):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    union(x,y)

ans=0
for i in range(N):
    if same(i,p[i]-1):
        ans+=1
print(ans)

Measured memory_bytes: 20400
from itertools import accumulate

input()

top = tuple(map(int, input().split(' ')))
bottom = tuple(map(int, input().split(' ')))

top_candies = tuple(accumulate(top))
bottom_candies = tuple(reversed(tuple(accumulate(reversed(bottom)))))

print(max([t + b for t, b in zip(top_candies, bottom_candies)]))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define F(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define f(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define file(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

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

inline int read() {
 int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}
double d,x,n;
double ans;
int main () {
    n=read();
	d=read();
	x=read();
    for(int i=n;i;i--){
      double sum=(d*2.0*n+n*(n+n-1)*x);
        ans+=sum/2.0/n;
        double dd=(d*(n+n-2)+d+2.0*x+3.0*d+3.0*x)/2.0/n;
        sum-=(4.0*d+4.0*n*x-2.0*x)/2.0/n;--n;
        d=dd;x=(sum-2.0*n*d)/n/(n+n-1);	   
	}
	printf("%.10lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
//
// Created by 吉川純平 on 2019-12-01.
//

#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
//using ull = unsigned long long;
#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll maxi = 10001;
void countingSort(vector<ll> &vec,ll n){
  vector<ll> count_vec(maxi,0);
  rep(i,n){
    count_vec[vec[i]]++;
  }
  ll piv = 0;
  ll cou = 0;
  while(1){
    if(cou == n){
      break;
    }
    if(count_vec[piv]){
      count_vec[piv]--;
      cout << piv;
      cou++;
      if(cou != n){
        cout << " ";
      }
    }else{
      piv++;
    }
  }
  cout << endl;
}
int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i,n){
    cin >> vec[i];
  }
  countingSort(vec,n);
}



Measured memory_bytes: 18368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
 
typedef long long int ll;
 
#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)
 
const ll MOD = 1000000007;
 
using namespace std;
 
int main()
{
	int D, N;
	cin >> D >> N;
 
	int k = pow(100, D);
	int n = 0;
 
	REP(i, N)
	{
		n += k;
	}
	if (N == 100)
	{
		n += k;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstring>
#include <iostream>

int main(){
    std::string str;
    std::cin >> str;
    long long t1 = 0;
    for(int i = 0; i <= 3; ++i) t1 = t1 * 10 + (str[i] - '0');
    if (t1 < 2019) return !(std::cout << "Heisei");
    else if (t1 > 2019) return !(std::cout << "TBD");
    else {
        t1 = 0;
        for(int i = 5; i <= 6; ++i) {
            t1 = t1 * 10 + (str[i] - '0');
        }
        if (t1 > 4) return !(std::cout << "TBD");
        else if (t1 < 4) return !(std::cout << "Heisei");
        else {
            t1 = 0;
            for(int i = 8; i <= 9; ++i ) t1 = t1 * 10 + (str[i] - '0');
            if (t1 > 30 ) return !(std::cout << "TBD");
            else return !(std::cout << "Heisei");
        }
    }
}

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

divisors=make_divisors(N)
l=[]
for i in divisors:
    tmp=N//i
    l.append(i-1+tmp-1)

print(min(l))

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

signed main(){
	int k,n;
	cin>>k>>n;
    
   int ar[n];

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

	int x = ar[n-1] - ar[0];

	if( x == k or n == 2){
		cout<<x<<"\n";
		return 0;
	}
    
    int acw = k -x,w = (int) 1e9;

    for(int i=0;i<n-1;i++){
    	w = min(w,acw + (ar[i] -ar[0]) + (ar[n-1] - ar[i+1]) );
    }
 
   cout<<min(w,x)<<"\n";

	return 0;
}


//-5 0 10

Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] x=new long[n];
        long[] y=new long[m];
        for(int i=0;i<n;i++){
            x[i]=sc.nextLong();
        }
        for(int i=0;i<m;i++){
            y[i]=sc.nextLong();
        }
        long xSum=0;
        n--;
        m--;
        for(int i=0;i<n/2.0;i++){
            xSum+=(x[n-i]-x[i])*(long)(n-2*i);
            xSum=xSum%1000000007l;
        }
        long ySum=0;
        for(int i=0;i<m/2.0;i++){
            ySum+=(y[m-i]-y[i])*(long)(m-2*i);
            ySum=ySum%1000000007l;
        }
        long result=0;
        result=xSum%1000000007l;
        result=(result*ySum)%1000000007l;
        System.out.println(result);

    }
}

Measured memory_bytes: 65900
//https://beta.atcoder.jp/contests/dwacon5th-prelims/tasks/dwacon5th_prelims_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int N,K;
LL a[1123];
LL as[1123];
LL b[1123456];
int M=0;
int f(LL bit){
    int ret=0;
    for(int i:range(M)){
        if((b[i]&bit)==bit)ret++;
    }
    return ret;
}
int main(){
    cin>>N>>K;
    for(int i:range(N)){
        cin>>a[i];
        as[i+1]=a[i]+as[i];
    }
    for(int i:range(N)){
        for(int j:range(i+1,N+1)){
            b[M++]=as[j]-as[i];
            //cout<<b[M-1]<<endl;
        }
    }
    LL ret=0;
    for(int i=60;i>=0;i--){
        LL tes=(1ll<<i);
        if(f(ret|tes)>=K)ret|=tes;
    }
    cout<<ret<<endl;
    return 0;
}

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

int main() {
  int N, K, a = 1;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
	if (a + K < a*2) {
      a += K;
    } else {
      a *= 2;
    }
  }
  
  cout << a << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
  int n;
  cin >> n;
  vector<int> data(n);
  rep(i,0,n){
      cin >> data.at(i);
  }
  int ans=0;
  int m=data.at(0);
  rep(i,0,n){
      m=min(m,data.at(i));
      if(m==data.at(i)){
          ans++;
      }
  }
  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 1024
from collections import Counter
from functools import reduce
# import statistics
import bisect
import copy
import fractions
import math
import random
import pprint
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)


# nは頂点の数
n, m = MI()
ans = 0
sides = [LI() for _ in range(m)]
# 隣接行列を用いてグラフの管理をする
# graph = [[False] * n for _ in range(n)]

# もしグラフ全体が連結ならばuf[i]=iとなる頂点がただ1つだけある
# Union-Find
for i in range(m):

    # 最初各ノードの根は自分自身
    node = [k for k in range(n)]
    
    for j, side in enumerate(sides):
        
        # 連結しない
        if i == j:
            continue

        unite(side[0]-1, side[1]-1)

    # 根が自分自身であるものが2つ以上存在する場合、グラフは非連結である
    # 1である場合連結なのでのぞいた辺は橋「ではない」
    if sum(node[num] == num for num in range(len(node))) != 1:
        ans += 1

print(ans)


Measured memory_bytes: 6208
/*input
100000
*/
#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;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k; cin >> k;
    deque<pair<ll, int>> bfs;
    for(int i = 1; i <= 9; i++)
    {
    	bfs.push_back(make_pair(i, i));
    	if(i == k)
    	{
    		cout << bfs.back().first;
    		return 0;
    	}
    }
    int i = 9;
    while(1)
    {
    	ll n = bfs.front().first;
    	int c = bfs.front().second;
    	bfs.pop_front();
    	if(n % 10 - 1 > -1) bfs.push_back(make_pair(10 * n + (n % 10 - 1), i++));
    	if(i == k)
    	{
    		cout << bfs.back().first;
    		return 0;
    	}
    	bfs.push_back(make_pair(10 * n + (n % 10), i++));
    	if(i == k)
    	{
    		cout << bfs.back().first;
    		return 0;
    	}
    	if(n % 10 + 1 < 10) bfs.push_back(make_pair(10 * n + (n % 10 + 1), i++));
    	if(i == k)
    	{
    		cout << bfs.back().first;
    		return 0;
    	}
    }

    return 0;
}

Measured memory_bytes: 1280
s=int(input())
if s%(10**9)==0:
  print(0,end=" ")
  print(0,end=" ")
  print(10**9,end=" ")
  print(0,end=" ")
  print(0,end=" ")
  print(s//(10**9))
else:
  print(0,end=" ")
  print(0,end=" ")
  print(10**9,end=" ")
  print(1,end=" ")
  print(10**9-s%(10**9),end=" ")
  print(s//(10**9)+1)

Measured memory_bytes: 3064
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=200005;
int a[M],b[M];
 main()

{
    fast
    int n;
    cin>>n;
    f(i,0,n-1)cin>>a[i];
    f(i,0,n-1)cin>>b[i];
    f(i,0,n-1)
    {
        if(b[i]<a[i])
        {
            cout<<"-1"<<endl;return 0;
        }
    }
    priority_queue<pi>pq;
    f(i,0,n-1)
    {
        if(a[i]!=b[i])pq.push(mp(b[i],i));
    }
    int ses=0;
    while(!pq.empty())
    {
        int y=pq.top().si;
        int x=(y-1+n)%n;
        int z=(y+1)%n;
        pq.pop();
        int cost=0;
        if(b[y]!=a[y] && b[y]>b[x] && b[y]>b[z])
        {
            cost=(b[y]-a[y])/(b[x]+b[z]);
            b[y]-=(cost*(b[x]+b[z]));
        }
        ses+=cost;
        if(b[y]!=a[y] && cost==0)
        {
            cout<<"-1"<<endl;
            return 0;
        }
        if(b[y]!=a[y])
        {
            pq.push(mp(b[y],y));
        }

    }
    f(i,0,n-1)
    {
        if(a[i]!=b[i])
        {
            cout<<"-1"<<endl;return 0;
        }
    }
    cout<<ses<<endl;
    return 0;

}





































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

using namespace std;

const int INF = 1000000009;

int main(){
  int n; cin >> n;
  vector<int> coin;
  coin.push_back(1);
  int a = 6, b = 9;
  while (a <= n) { coin.push_back(a); a *= 6; }
  while (b <= n) { coin.push_back(b); b *= 9; }

  vector<int> dp(n+1, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < coin.size(); j++) {
      if (i + coin[j] > n) { continue; }
      dp[i+coin[j]] = min(dp[i+coin[j]], dp[i] + 1);
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var ST = Read().Split(' ');
            var AB = ReadArrayInt();
            var U = Read();
            if (ST[0] == U) AB[0]--;
            else AB[1]--;

            Console.WriteLine(AB[0] + " " + AB[1]);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;}


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

int N, M; cin >> N >> M;
VI A(N); invec(A);

int all = accumulate(ALL(A), (i64)0);
int cnt = 0;
for(int a: A){
    if (a * 4 * M >= all) ++cnt;
}

cout << (cnt >= M ? "Yes" : "No") << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 問題文から考える。自分ができることから考える。
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:268435456")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;




int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	int n = sz(s);
	const int m = 2019;
	
	vi dp(m + 1);
	dp[s[0] - '0'] = 1;
	int res = 0;
	for (int i = 1; i < n; i++)
	{
		vi ndp(m + 1);
		int cd = s[i] - '0';
		for (int j = 0; j < m; j++)
		{
			
			ndp[(j * 10 + cd) % m] += dp[j];
		}
		ndp[cd] += 1;
		res += ndp[0];
		dp = ndp;
	}

	cout << res;
	return 0;
}

Measured memory_bytes: 3760
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int k = sc.nextInt();
        int n = sc.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int d = k - a[n-1] + a[0];
        int max = d;
        for (int i = 1; i < n; i++) {
            d = a[i] - a[i-1];
            max = Math.max(d, max);
        }

        System.out.println(k - max);
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 46420
#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 vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int h,w;
    cin >> h >> w;
    vector<vi> c(10,vi(10));
    rep(i,10) rep(j,10) cin >> c[i][j];
    vi a(10);
    rep(i,h) rep(j,w){
        int b;
        cin >> b;
        if(b==-1) continue;
        a[b]++;
    }
    rep(k,10) rep(i,10) rep(j,10){
        if(c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k] + c[k][j];
    }
    ll ans = 0;
    rep(i,10) ans += c[i][1]*a[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define alll(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define endl '\n'

int par[100005];
int find(int x) {return x==par[x]?x:par[x]=find(par[x]);}
int a[100005];
map<int,int> mp[100005];
int main()
{
    int n,m;
    cin>>n>>m;
    ii cin>>a[i];
    ii par[i]=i;
    for(int i=1;i<=m;++i)
    {
        int u,v;
        cin>>u>>v;
        par[find(u)]=find(v);
    }
    ii mp[find(i)][a[i]]++;
    int ans=0;
    ii ans+=mp[find(i)][i];
    cout<<ans<<endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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 (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int A, B;
	cin >> A >> B;
	A--;
	B--;
	if (A == 0)A = 13;
	if (B == 0)B = 13;
	if (A > B)
	{
		cout << "Alice" << endl;
	}
	else if (A < B)
	{
		cout << "Bob" << endl;
	}
	else
	{
		cout << "Draw" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readLine().toInt
    val a = io.StdIn.readLine().split(' ').map(_.toInt)

    val b = for (i <- 1 to n) yield {
      if (a(i - 1) <= i) false
      else if (a(a(i - 1) - 1) == i) true
      else false
    }

    println(b.filter(_ == true).length)
  }
}


Measured memory_bytes: 35568
#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;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}

Measured memory_bytes: 256
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

//
// solution 
//
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input!{
        H: usize,
        W: usize,
        K: usize,
    }

    if W == 1 {
        println!("1");
        return;
    }

    const MOD: usize = 1_000_000_007;
    let mut count = vec![0; W];
    count[0] = 1;
    count[1] = 2; // '0' or '1'
    if W > 2 {
        for w in 2..W {
            count[w] 
                = count[w-1]  // '0' + 'ind-1 bits' 
                + count[w-2]; // '1' + '0' + 'ind-2 bits'
        }
    }

    let mut dp = vec![vec![0; W+2]; H+1];
    dp[0][1] = 1;
    for h in 0..H {
        for w in 1..W+1 {
            dp[h+1][w] = 
                dp[h][w-1] * count[w.saturating_sub(3)] * count[(W-w).saturating_sub(1)] +
                dp[h][w]   * count[w.saturating_sub(2)] * count[(W-w).saturating_sub(1)] +
                dp[h][w+1] * count[w.saturating_sub(2)] * count[(W-w).saturating_sub(2)];
            dp[h+1][w] %= MOD;
        }
    }

    println!("{}", dp[H][K]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = n - 1; i >= 0; i--){
        cout << a[i];
        if (i != 0) {
            cout << " ";
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" "<<x<<"\n";
#define lli long long int
long long int mod= 1000000007,modd=998244353;
int32_t main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);  cout.tie(0);
   lli n,i;
   bool fl=false;
   cin>>n;
   lli a[n+1];
   lli b[n+1];
   for(i=1;i<=n;i++)
   { cin>>a[i]>>b[i];
   }
   for(i=1;i<=n-2;i++)
   { if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
       {
         fl=true;
         break;
       }
   }
   if(fl==false)
   { cout<<"No"<<"\n";
   }
   else
   { cout<<"Yes"<<"\n";
   }
   return 0;
}//main


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define int long long
const int INF=1e18;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s,t,ans;
    int n,m;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    int dp[n+1][m+1];
    rep(i,0,n+1){
        rep(j,0,m+1){
            dp[i][j]=0;
        }
    }
    rep(i,1,n+1){
        rep(j,1,m+1){
            if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    while(n>0&&m>0){
        if(dp[n][m]==dp[n-1][m]){n--;}
        else if(dp[n][m]==dp[n][m-1]){m--;}
        else{n--;m--;ans.push_back(s[n]);}
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}

Measured memory_bytes: 70656
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

bool check(string S, string s){
  int SL = S.length(), sl = s.length();
  REP(i, sl){
    string a = s.substr(i, SL);
    if((int)(a.length()) < SL) a += s.substr(0, SL - (int)(a.length()));
    if(a == S) return true;
  }
  return false;
}

int main() {
  string S; cin >>S;
  int ans = 0, N; cin >>N;
  REP(n, N){
    string s; cin >>s;
    if(check(S, s)) ++ans;
  }
  cout <<ans <<endl;
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    char s[3];
    cin>>s[0]>>s[1]>>s[2];
    if(s[0]=='S'&&s[1]=='S'&&s[2]=='S'){
        cout<<0<<endl;
        return 0;
    }else if(s[0]=='R'&&s[1]=='R'&&s[2]=='R'){
        cout<<3<<endl;
        return 0;
    }else if(s[0]=='R'&&s[1]=='S'&&s[2]=='R'){
        cout<<1<<endl;
        return 0;
    }else if(s[0]=='R'&&s[1]=='S'&&s[2]=='S'){
        cout<<1<<endl;
        return 0;
    }else if(s[0]=='S'&&s[1]=='R'&&s[2]=='S'){
        cout<<1<<endl;
        return 0;
    }else if(s[0]=='S'&&s[1]=='S'&&s[2]=='R'){
        cout<<1<<endl;
        return 0;
    }else{
        cout<<2<<endl;
        return 0;
    }

}



Measured memory_bytes: 3632
#include<iostream>
#include<queue>
using namespace std;
int main(){
    string s;
    int x,y,i,j,r=0,cnt;
    cin>>s>>x>>y;
    queue<int>v,h;
    for(i=0;i<s.size()&&s[i]!='T';i++)r++;
    while(i<s.size()){
        for(cnt=0,i++;i<s.size()&&s[i]!='T';i++,cnt++);
        v.push(cnt);
        for(cnt=0,i++;i<s.size()&&s[i]!='T';i++,cnt++);
        h.push(cnt);
    }
    int vs=v.size(),hs=h.size();
    bool dpv[vs+1][16001]={},dph[hs+1][16001]={};
    dpv[0][8000]=true;
    for(i=0;i<vs;i++){
        cnt=v.front();v.pop();
        for(j=0;j<=16000;j++)if(dpv[i][j])dpv[i+1][j+cnt]=dpv[i+1][j-cnt]=true;
    }
    dph[0][8000+r]=true;
    for(i=0;i<hs;i++){
        cnt=h.front();h.pop();
        for(j=0;j<=16000;j++)if(dph[i][j])dph[i+1][j+cnt]=dph[i+1][j-cnt]=true;
    }
    cout<<(dph[hs][x+8000]&&dpv[vs][y+8000]?"Yes":"No")<<endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N; cin >> N;

    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }
    sort(vec.begin(), vec.end());

    ll ans = 0;

    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            //a + b以上になる位置を検索
            ll t = vec[i] + vec[j];
            ll posi = lower_bound(vec.begin(), vec.end(), t) - vec.begin(); 
            //マイナス防止
            ans += max(posi - (j + 1), ll(0));
        }
    }

    
    cout << ans << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int n, m;
	cin >> n >> m;
	int i, j;
	int cnt = 0;
	for (i = 1; i < n; i++)
	{
		for (j = i + 1; j <= n; j++)
		{
			cnt++;
		}
	}
	for (i = 1; i < m; i++)
	{
		for (j = i + 1; j <= m; j++)
		{
			cnt++;
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,ans=0;
  string s,t;
  cin>>s;
  cin>>N;
  for(int i=0;i<N;++i){
    cin>>t;
    t+=t;

    if(t.find(s)!=std::string::npos) ans++;;
    
    
    /* int cnt=0;
    int j=0,k=0;
    while(j+1!=t.size()){
      if(cnt==s.size()){
        ans++;
        break;
      }
      if(t[j]==s[k]){
        cnt++;
        j++;
        k++;
        continue;
      }else{
        cnt=0;
        j++;
      }
      }*/
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T="keyence";cin>>S;
  int i;
  for(i=0;i<8;i++){
    if(S.substr(0,i)==T.substr(0,i)&&S.substr(S.size()+i-7,7-i)==T.substr(i,7-i))break;
  }
  if(i==8)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

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

typedef long long LL;
typedef pair <int,int> pii;

#define pb push_back
#define fi first
#define sc second
#define mp make_pair

int main()
{
	#ifdef local
		freopen("read.txt","r",stdin);
	#endif
	char s[105];
	int n;
	scanf("%d%s",&n,s);
	int c0=0,c1=0;
	for (int i=0;i<n;i++)
		if (s[i]=='R')
			c0++;
		else
			c1++;
	printf(c0>c1?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define se second
#define fi first
#define rep(i, l, r) for (ll i = (ll)(l); i < (ll)(r); i++)
#define print(v) for (const auto itr : v){cout << itr << ' ';} cout << endl;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
#define inf 1e18
using namespace std;
const ll INF = 1e18L + 5;
const ll maxn = 1e5+5, maxn1=202;
ll ceel(ll a, ll b)
{
   if (a % b == 0)
       return a / b;
   return a / b + 1;
}
ll modneg(ll a,ll m)
{
    a = a % m;
    if(a<0)
        a=a+m;
    return a;
}
ll powermod(ll x, unsigned ll y, ll p){ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); };
ll csb(ll n){ ll count = 0;while (n){ count += n & 1; n >>= 1; } return count;}

int main()
{

// ll t,i,j,k,n,m,a,b,x,y,u,temp;
ll t,a,b;
cin>>t;
a=100;
b=0;
while(a*1.0<t*1.0)
{
    a+=a*1.0/100*1.0;
    // cout<<a<<endl;
    b++;
}
cout<<b<<endl;
}

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

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

    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;

    vector<ll> p(A);
    rep(i,A) cin >> p[i];
    sort(p.begin(), p.end(), greater<ll>());

    vector<ll> q(B);
    rep(i,B) cin >> q[i];
    sort(q.begin(), q.end(), greater<ll>());

    vector<ll> r(C);
    rep(i,C) cin >> r[i];
    sort(r.begin(), r.end(), greater<ll>());

    vector<ll> pick;
    pick.insert(pick.end(), p.begin(), p.begin() + X);
    pick.insert(pick.end(), q.begin(), q.begin() + Y);
    pick.insert(pick.end(), r.begin(), r.end());
    sort(pick.begin(), pick.end(), greater<ll>());

    ll sum = accumulate(pick.begin(), pick.begin() + X + Y, 0LL);

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 6208
import heapq

H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
	for i in range(10):
		for j in range(10):
			C[i][j] = min(C[i][j], C[i][k]+C[k][j])

cost = 0
for i in range(H):
	for j in range(W):
		num = A[i][j]
		if num == -1:
			continue
		else:
			cost += C[num][1]

print(cost)

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#define INF 1 << 29
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>T;
	vector<int>A;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		T.push_back(a);
	}
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	vector<int>upper(N, -1);
	vector<int>lower(N, INF);
	int prevT = 0;
	for (int i = 0; i < N; i++) {
		if (T[i] != prevT) {
			upper[i] = T[i];
			lower[i] = T[i];
		}
		else {
			upper[i] = T[i];
			lower[i] = 1;
		}
		prevT = T[i];
	}
	bool out = false;
	int prevA = 0;
	for (int i = N-1; i > -1; i--) {
		if (A[i] != prevA) {
			if (upper[i] >= A[i] && A[i] >= lower[i]) {
				upper[i] = A[i];
				lower[i] = A[i];
			}
			else {
				out = true;
				break;
			}
		}
		else {
			if (upper[i] >= A[i]) {
				upper[i] = A[i];
			}
		}
		prevA = A[i];
	}
	if (out) {
		cout << 0 << endl;
	}
	else {
		unsigned long long answer = 1;
		for (int i = 0; i < N; i++) {
			if(upper[i] != lower[i])
				answer = (answer * (upper[i] - lower[i] + 1)) % (10*10*10*10*10*10*10*10*10 + 7);
		}
		cout << answer << endl;
	}
}

Measured memory_bytes: 2040
#include<cstdio>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
#define max(a,b) ((a)>(b)?(a):(b))
#define reg register
typedef long long ll;
int n,k,cnt,fac[2005];
ll f[2005],ans;
const int mod=1e9+7;
inline ll qpow(ll a,ll b){
	reg ll res=1;
	while(b){
		if(b&1)res=res*a%mod;
		a=a*a%mod;b>>=1;
	}
	return res;
}
int main(){
	scanf("%d%d",&n,&k);
	for(reg int i=1;i<=sqrt(n);i++)
		if(!(n%i)){
			fac[++cnt]=i;
			if(i!=(n/i))fac[++cnt]=n/i;
		}
	std::sort(fac+1,fac+1+cnt);
	for(reg int i=1;i<=cnt;i++){
		f[i]=qpow(k,(fac[i]+1)/2);
		for(reg int j=1;j<i;j++)
			if(!(fac[i]%fac[j]))
				f[i]=(f[i]-f[j]+mod)%mod;
		if(fac[i]&1)ans=(ans+f[i]*fac[i]%mod)%mod;
		else ans=(ans+(f[i]*fac[i]>>1)%mod)%mod;
	}
	printf("%lld\n",ans);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll a, b, k;
  cin >> a >> b >> k;
  ll takahashi = max(0ll, a-k);
  ll aoki = max(0ll, b-max(0ll, k-a));
  cout << takahashi << " " << aoki << endl;
}

Measured memory_bytes: 256