akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  map<int, int> mp;
  ll ans = 0;
  rep(i,n){
    int aj = i - A[i];
    ans += mp[aj];
    int ai = A[i] + i;
    mp[ai]++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 21136
/*
题意：

平面上有$n$个点，每个点都有一个位置$x_i$，和向右的速度$v_i$

现在要求你对其中的一些点进行染色，当一个点被染色后，在无限距离内与它相遇的点也会被染色

问在可能的$2^n$种染色方案中，有多少种染色方案可以使得最后的点全部被染色

Sol

非常好的dp题。

首先考虑若点$i$被染色后，哪些点会被染色

最显然的两种情况

1. $x_j < x_i$且$v_j > v_i$
2. $x_j > x_i$且$v_j < v_i$

当然还有其他的情况，因为题目中的“染色”是一个连锁反应，也就是说$a$被染色，$a$又遇到了$b$，那么$b$也会被染色

实际上，当我们把所有点按速度从大到小排序。

对于$x_i$，向左找到第一个$x_l < x_i$的最小的$l$(此时同时保证了$v_l$最大)
		   向右找到第一个$x_r > x_i$的最大的$r$(同理保证了$v_r$最小)

那么区间$[l, r]$内所有的点都会被染色

现在问题转化成了，每个点能覆盖一段区间$[l, r]$，问把区间$[l, N]$覆盖的方案数

预处理出每个点能覆盖的区间$[l, r]$，前缀和优化dp即可

*/
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define fi first
#define se second
#define MP(x, y) make_pair(x, y)
#define LL long long 
#define int long long 
using namespace std;
const int MAXN = 1e6 + 10, mod = 1e9 + 7;
inline int read() {
	char c = getchar(); int x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N, date[MAXN], L[MAXN], R[MAXN], f[MAXN];
struct Node {
	int x, v, id, l, r;
	bool operator < (const Node &rhs) const {
		return v > rhs.v;
	}
}a[MAXN];
int comp(const Node &a, const Node &b) {
	return a.r == b.r ? a.l < b.l : a.r < b.r;
}
void GetL(int *op) {
	vector<Pair> q; 
	for(int i = 1; i <= N; i++) q.push_back(MP(a[i].x, a[i].id));
	sort(q.begin(), q.end());
	for(int i = 1; i <= N; i++) {
	//	if(op[i]) continue;
	//	op[i] = i;
		while(!q.empty()) {
			if(a[i].x <= q.back().fi) op[q.back().se] = i, q.pop_back();
			else break;
		}
	}
}
void GetR(int *op) {
	vector<Pair> q; 
	for(int i = 1; i <= N; i++) q.push_back(MP(a[i].x, a[i].id));
	sort(q.begin(), q.end());
	reverse(q.begin(), q.end());
	for(int i = N; i >= 1; i--) {
//		if(op[i]) continue;
//		op[i] = i;
		while(!q.empty()) {
			if(a[i].x >= q.back().fi) op[q.back().se] = i, q.pop_back();
			else break;
		}
	}
}
int dp() {
	for(int i = 1; i <= N; i++) a[i].r = N - L[i] + 1, a[i].l = N - R[i] + 1;
	sort(a + 1, a + N + 1, comp);
	//for(int i = 1; i <= N; i++) printf("%d %d\n", a[i].l, a[i].r);
	static int s[MAXN], f[MAXN];//f[i]：前i只猫覆盖所有区间的方案
	int ans = 0;
	for(int i = 1, j = 1; i <= N; i++) {
		while(a[j].r < a[i].l - 1) j++;
		f[i] = (s[i - 1] + mod - s[j - 1] ) % mod;
		if(a[i].l == 1) f[i]++;
		if(a[i].r == N) (ans += f[i]) %= mod;
		s[i] = (s[i - 1] + f[i]) % mod;
	}
	return ans % mod;	
}
main() {
	N = read();
	for(int i = 1; i <= N; i++) a[i].x = read(), a[i].v = read(), a[i].id = i, date[i] = a[i].v;
	sort(date + 1, date + N + 1);
	int num = unique(date + 1, date + N + 1) - date - 1;
	for(int i = 1; i <= N; i++) a[i].v = lower_bound(date + 1, date + num + 1, a[i].v) - date;
	sort(a + 1, a + N + 1);
	GetL(L); GetR(R);
	//for(int i = 1; i <= N; i++) printf("%d %d\n", L[i], R[i]);
	printf("%d", dp() % mod);

}
/*

*/


Measured memory_bytes: 30984
#include <iostream>
#include <array>
#include <algorithm>
#include <cmath>

int main() {
    std::array<long long int, 3> arr;;
    int n;
    
    std::cin >> n;

    while (n--) {
        std::cin >> arr[0] >> arr[1] >> arr[2];
        std::sort(arr.begin(), arr.end());
        std::cout << (std::pow(arr[0], 2) + std::pow(arr[1], 2)
                      == std::pow(arr[2], 2) ? "YES" : "NO")
                  << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1172
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    s = input()
    ans = 0
    for i in range(n-1):
        if s[i] == s[i+1]:
            ans += 1
    print(min(ans+2*k,n-1))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 40048
//20-27行描述了填色标准，算法核心
//为什么这么移动？
//走S形
//在奇数行时，向右移动；在偶数行时，向左移动
//奇数行末尾，列数达到最大，向下移动；偶数行末尾，列数为1，向下移动
//用代码描述一下就是这样
//理论上还可以选择另一种S形状，即“竖过来”
#include <bits/stdc++.h>
using namespace std;
int r,c;//行数、列数
int n;//颜色总数
int x,y;//当前待着色点坐标
int ans[200][200];//答案记录表

int main()
{
    cin>>r>>c>>n;//分别输入行数、列数、颜色总数
    x=1,y=1;//初始坐标设置为（1，1）
    for(int i=1; i<=n; i++)
    {
        int cnt;//“当前颜色剩余着色块数”计数器
        cin>>cnt;
        while(cnt--)//对当前颜色一块一块着色
        {
            ans[x][y]=i;//着色
            if(y==c&&x%2==1)//如果该点在右边缘 且 在奇数行上
                y=c,x++;//下移一行，列数不变
            else if(y==1&&x%2==0)//如果该点在第一列上，且在偶数行上
                y=1,x++;//列数不变，下移一行
            else if(x&1)//如果在奇数行上
                y++;//右移一列
            else//否则左移一列
                y--;
        }
    }
    for(int i=1; i<=r; i++)
        for(int j=1; j<=c; j++)
            printf("%d%c",ans[i][j],j==c?'\n':' ');//在到达当前行最后一列前，每次空一格；到达后，换行；
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;

///////////////////////////////////////////////
// for template
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 main() {
    int N; cin >> N;
    bool ans = false;
    int count = 0;
    REP(i,N){
        int d1,d2;
        cin >> d1 >> d2;
        if (d1 == d2) count++;
        else count = 0;
        if (count >= 3) ans = true;
    }

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,l,r) for (ll i = (ll)l; i < (ll)(r); i++)
typedef vector<vector<ll> > Graph;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

ll N,M,K;

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

    Graph F(N+1),B(N+1);
    UnionFind Friends(N);
    rep(i,0,M){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        F[a].push_back(b); F[b].push_back(a);
        Friends.unite(a,b);
    }
    rep(i,0,K){
        ll c,d;
        cin >> c >> d;
        c--; d--;
        if(Friends.find(c) == Friends.find(d)) {
            F[c].push_back(d); B[d].push_back(c);
        }
    }

    rep(i,0,N){
        cout << Friends.size(i) - F[i].size() - B[i].size() - 1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 14776
#include<stdio.h>
int main(){
  int a,b,c,tmp;
	
	scanf("%d %d %d",&a,&b,&c);
	
	if(a > b) 
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	if(a > c)
	{
		tmp = a;
		a = c;
		c = tmp;
	}
	if(b > c)
	{
		tmp = b;
		b = c;
		c = tmp;
	}
	
	printf("%d %d %d\n",a,b,c);
	
	return 0;


}

Measured memory_bytes: 596
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



int main() {

	char S[12];
	scanf("%s", S);
	//printf("%d", (S[0]-'0'));

	int tmp, min = 1000;
	int ans;
	for (int i = 0; i < strlen(S) - 2; i++) {
		tmp = 0;
		tmp += (S[i + 0] - '0') * 100;
		tmp += (S[i + 1] - '0') * 10;
		tmp += (S[i + 2] - '0') * 1;
		min = Min(abs(753 - tmp),min);
	}
	ans = min;
	printf("%d\n", ans);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;


class C {
	int n;
public:
	void solve()
	{
		int v;
		vector<int> odd(100001, 0);
		vector<int> even(100001, 0);

		for (int i{ 0 }; i < n; i++)
		{
			cin >> v;
			if (i & 1)
				++odd[v];
			else
				++even[v];
		}

		int max_odd{ 0 }, max_even{ 0 };
		int second_odd{ 0 }, second_even{ 0 };
		int ans;
		
		for (int i{ 0 }; i <= 100001; i++)
		{
			if (odd[max_odd] < odd[i])
			{
				second_odd = max_odd;
				max_odd = i;
			}
			else if (odd[second_odd] < odd[i])
			{
				second_odd = i;
			}
			if (even[max_even] < even[i])
			{
				second_even = max_even;
				max_even = i;
			}
			else if (even[second_even] < even[i])
			{
				second_even = i;
			}
		}
		
		if (max_odd != max_even)
		{
			ans = accumulate(odd.begin(), odd.end(), 0) - odd[max_odd];
			ans += accumulate(even.begin(), even.end(), 0) - even[max_even];
		}

		else
		{
			int tmpans;
			tmpans = accumulate(odd.begin(), odd.end(), 0) - odd[max_odd];
			tmpans += accumulate(even.begin(), even.end(), 0) - even[second_even];

			ans = accumulate(odd.begin(), odd.end(), 0) - odd[second_odd];
			ans += accumulate(even.begin(), even.end(), 0) - even[max_even];

			if (tmpans < ans) ans = tmpans;
		}

		cout << ans << endl;
	}
	
	C()
	{
		cin >> n;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    set<unsigned long> s;
    copy_n(istream_iterator<unsigned long>(cin), N, inserter(s, end(s)));
    puts(s.size() == N ? "YES" : "NO");
    return 0;
}

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

using namespace std;

typedef long long ll;

string s;

void solve()
{
  int p = s.rfind("FESTIVAL");
  s = s.substr(0, p);
  cout << s << endl;
}

int main()
{
#ifdef linjia
freopen("C:\\Users\\linjian\\Documents\\in.txt", "r", stdin);
#endif
  cin >>s;
  solve();
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

# 標準入力を取得
A, B, C, X, Y = list(map(int, input().split()))

# 求解処理
ans = sys.maxsize
max_c = 2 * max(X, Y)
for c in range(0, max_c + 1, 2):
    a = max(X - c // 2, 0)
    b = max(Y - c // 2, 0)
    price = a * A + b * B + c * C
    ans = min(ans, price)

# 結果出力
print(ans)


Measured memory_bytes: 9144
#include<iostream>
using namespace std;
int front,end;
string a;
int main(){
	cin>>a;
	int hugcnt=0;
	int leng=a.length();
	for(int i=0;i<leng/2;i++){
		if(a[i]!=a[leng-i-1]){
			hugcnt++;
		}
	}
	cout<<hugcnt<<endl;
	return 0;
}



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


void solve(long long K, std::string S){
    if(S.size() <= K){
        cout<<S<<endl;
    }else{
        cout<<S.substr(0, K)<<"..."<<endl;;
    }
}

int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3696
#include <cstdio>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
const int maxn=200000+5;
int pd[maxn];
int color[maxn];//记录各个结点的颜色
ll sum[maxn];//精髓所在
ll sizes[maxn];//记录各个结点以下的结点数
vector<int> tree[maxn];//记录树
set<int> col;
ll ans[maxn];
void find_size(int fa,int gfa){//找出各点的 sizes[i]
    sizes[fa]=1;
    for(int i=0;i<tree[fa].size();i++){
        if(tree[fa][i]==gfa)    continue;
        find_size(tree[fa][i],fa);
        sizes[fa]+=sizes[tree[fa][i]];
    }
}
void find_ans(int fa,int gfa){
    ll tmp=0;
    if(sum[color[fa]]!=0){
//此处 sum[color[fa]] 记录的是目前已知的从各个分枝的第一个颜色为 color[fa] 的点到叶子的结点数，那么当最后求出这个值以后，上文提及的第一类路径的结点数即为 n-sum[i]
        tmp=sum[color[fa]];
        sum[color[fa]]=0;
/*      *****************       */
    }
    for(int i=0;i<tree[fa].size();i++){
        if(tree[fa][i]==gfa)    continue;
        find_ans(tree[fa][i],fa);
//此处sum[color[fa]]用于求从 tree[fa][i] 这个结点出发到下一个颜色为 color[fa] 或者叶子的联通块的结点数
//请注意上下两处划线处的代码
        ans[color[fa]]-=(sizes[tree[fa][i]]-sum[color[fa]])*(sizes[tree[fa][i]]-sum[color[fa]]-1)/2;
        sum[color[fa]]=0;
/*      *****************       */
    }sum[color[fa]]=sizes[fa]+tmp;
}
int main(){
    int n,a,b;
    scanf("%d",&n);
        col.clear();
        for(int i=1;i<=n;i++){
            sum[i]=0;
            tree[i].clear();
        }
        for(int i=1;i<=n;i++){
            scanf("%d",&color[i]);
            pd[color[i]]++;
            col.insert(color[i]);
        }
        for(int i=1;i<=n;i++)if(pd[i])
        ans[i]=1ll*n*(n-1)/2;
        for(int i=1;i<n;i++){
            scanf("%d%d",&a,&b);
            tree[a].push_back(b);
            tree[b].push_back(a);
        }find_size(1,0);
        find_ans(1,0);
        set<int>::iterator pt=col.begin();
        for(;pt!=col.end();pt++){
            int cl=*pt;
            ans[cl]-=(n-sum[cl])*(n-sum[cl]-1)/2;
        }
        for(int i=1;i<=n;i++)
        {
            ans[i]+=pd[i];
        }
        for(int i=1;i<=n;i++)
        {
            printf("%lld\n",ans[i]);
        }
    return 0;
}


Measured memory_bytes: 41984
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
	int n;
	scanf("%d", &n);
	vector<int> l(n * 2);
	for(int i = 0; i < 2 * n; i++){
		scanf("%d", &l[i]);
	}
	sort(l.begin(), l.end());
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans += l[2 * i];
	}
	printf("%d\n", ans);
	return 0;
}

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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize,
        s: String
    }
    let (t1,t2) = s.split_at(n/2);
    if t1 == t2 {
        println!("Yes");
    } else {
        println!("No");
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
using namespace std;
int main(void){
	char ti[10000];
	int ho[10000];
	while(1){
		int n,win[10000]={},lose[100000]={},blow[100000]={};
	
		cin >> n;
		if(n == 0) break;
		for(int i=0;i < n;i++){
			cin >> ti[i];
			for(int j=0;j<n-1;j++){
				cin >> ho[j];
				if(ho[j] == 0) win[i]+=1;
				if(ho[j] == 1) lose[i]+=1;
			}
		}for(int i=0;i<n;i++){
			for(int j=0;j+1<n;j++){
				if(win[j] < win[j+1] || (win[j]==win[j+1] && lose[j] > lose[j+1]) ){
					swap(lose[j],lose[j+1]);	
					swap(win[j],win[j+1]);	
					swap(ti[j],ti[j+1]);
				}
			}
		}for(int i=0;i<n;i++){
		 cout << ti[i] << endl;	
		}
	}
}

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

const int MAX_N = 8;
const int MAX_M = 28;

int main() {
    // input
    int N, M, a[MAX_M], b[MAX_M];
    cin >> N >> M;
    for (int i = 0; i < M; i++) cin >> a[i] >> b[i];

    // initialize path
    int path[MAX_N + 1][MAX_N + 1];
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) path[i][j] = 0;
    }
    for (int i = 0; i < M; i++) {
        path[a[i]][b[i]] = 1;
        path[b[i]][a[i]] = 1;
    }

    // initialize permutation
    int perm[MAX_N];
    for (int i = 0; i < N; i++) perm[i] = i + 1;

    int count_path = 0;
    do {
        bool exist_path = true;
        for (int i = 1; i < N; i++) {
            if (path[perm[i-1]][perm[i]] == 0) exist_path = false;  
        }
        if (exist_path) count_path++;
    } while (next_permutation(perm + 1, perm + N));

    cout << count_path << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

void primeFactor(ll val, map<ll,ll> &primeList){
  if(val<1){
    return;
  }
  for(int i=2;i*i<val;i++){
    while(val%i==0){
      primeList[i]++;
      val/=i;
    }
  }
  if(val!=1){
    primeList[val]=1;
  }
  return;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  int n;cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    ll N=n/i;
    ans+=ll(i)*N*(N+1)/2;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k,x;
  cin>>k>>x;
  for(int i=0;i<(2*k-1);i++)
  {
  cout<<x-(k-1)+i;
   if(i<(2*k-2)) cout<<" ";
  }
}

Measured memory_bytes: 256
from itertools import combinations
N,K=map(int, input().split())
M=(N-1)*(N-2)//2
if K>M:
    print(-1)
else:
    E=[]
    for i in range(2,N+1):
        E.append((1,i))
    E+=list(combinations(range(2,N+1), 2))[:M-K]
    print(len(E))
    for e in E:
        print(*e)

Measured memory_bytes: 3992
package main

import (
	"fmt"
	"regexp"
	"strconv"
	"strings"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	hate_nums := make([]string, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&hate_nums[i])
	}
	hate_num_joins := strings.Join(hate_nums, "|")
	re := regexp.MustCompile("(" + hate_num_joins + ")")
	answer := n
	for {
		if re.MatchString(strconv.Itoa(answer)) {
			answer += 1
		} else {
			break
		}
	}
	fmt.Print(answer)
}


Measured memory_bytes: 2480
//#pragma GCC optimize("03", "unroll-loops")
//#pragma GCC target("avx2")

#include <bits/stdc++.h>

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define FOR(i,n) for(i=0;i<n;i++)
#define FORn(i,j,n) for(i=j;i<n;i++)
#define pb push_back
#define unique_sort(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define vli vector<lli>
#define vi vector<int>
#define vs vector<string>
#define vprint(v) for(auto t:v)cout<<t<<" "
#define endl "\n"

typedef long long int lli;
typedef long int li;

const lli mod=1000000007;
const lli limit=1000000;

using namespace std;

void fc(lli &x)
    {
        bool neg=false;
        register char c;
        x =0;
        c=getchar();
        if(c=='-')
        {
            neg = true;
            c=getchar();
        }
        for(;(c>47 && c<58);c=getchar())
            x = (x<<1) + (x<<3) +c -48;
        if(neg)
            x *=-1;
    }

int main() {

    fast()
    lli n,q,t;
    lli temp,temp1,temp2,temp3;
    lli i,j,k;
    cin>>n>>k;
    temp=n/k;
    temp1=n-k*temp;
    temp2=k*(temp+1)-n;
    temp=min(temp1,temp2);
    cout<<temp<<endl;

 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

void solve() 
{
    int n,m;cin>>n>>m;
    if(n<m){
        REP(i,m)cout<<n;
    }else{
        REP(i,n)cout<<m;
    }cout<<endl;

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


Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <vector>
#include <cstdio>
#include <cstring>
#include <utility>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>

#define i64 long long
#define ui64 unsigned long long
#define REP(i,n) for(int (i)=0;(i)<(n);i++)
#define REP2(i,k,n) for(int (i)=(k);(i)<(n);i++)
#define MDIST(a,b) abs(a-b)
#define DIST(a,b) sqrt((a)*(a)+(b)*(b))
#define ATCODER 1000000007
using namespace std;
 
////////////////////////

class BIT{
  int size;
  vector<i64> tree;
 
public:
  BIT():size(0),tree(0){};
  BIT(int n):size(n),tree(n+1,0){};
  void add(i64 x,int n){
    for(int i=n;i<=size;i+=i&-i){
      tree[i]+=x;
    }
  }
  i64 sum(int s,int t){
    if(s>t)return 0;
    i64 res=0;
    for(int i=t;i>0;i-=i&-i){
      res += tree[i];
    }
    for(int i=s-1;i>0;i-=i&-i){
      res -= tree[i];
    }
    return res;
  }
  i64 get(int n){
    return tree[n];
  }
};

int main(){
  int n,q;
  cin >> n >> q;
  BIT d(n);
  int com,x,y;
  for(int i=0;i<q;i++){
    cin >> com >> x >> y;
    if(com)cout << d.sum(x,y) << endl;
    else d.add(y,x);
    // for(int i=1;i<=n;i++){
    //   cout << d.get(i) << " ";
    // }cout << endl;
  }
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>A(N);
    int count=0;
    bool zero=false;
    ll sum=0;
    int m=1000000000;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]<0){count++;}
        if(A[i]==0){zero=true;}
        sum+=abs(A[i]);
        m=min(m,abs(A[i]));
    }
    if(zero==true){cout<<sum<<endl;}
    else if(count%2==0){cout<<sum<<endl;}
    else{cout<<sum-(2*m)<<endl;}
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
ll x[MAXN],dif[MAXN],tdif[MAXN],dp[MAXN][60],ind[MAXN],tind[MAXN],n,m,k;
int main(){
    scanf("%lld",&n);
    for(int i=1;i<=n;++i) scanf("%lld",&x[i]);
    scanf("%lld %lld",&m,&k);
    for(int i=1;i<=n;++i) dp[i][0]=i;
    for(int i=1;i<=m;++i){
        ll t;scanf("%lld",&t);
        swap(dp[t][0],dp[t+1][0]);
    }
    for(int j=1;((ll)1<<j)<=k;++j){
        for(int i=1;i<=n;++i){
            dp[i][j]=dp[dp[i][j-1]][j-1];
        }
    }
    for(int i=1;i<=n;++i) ind[i]=i;
    for(int j=59;k;--j){
        if(((ll)1<<j)>k) continue;
        k-=(ll)1<<j;
        for(int i=1;i<=n;++i) tind[i]=dp[ind[i]][j];
        for(int i=1;i<=n;++i) ind[i]=tind[i];
    }
    dif[1]=x[1];
    for(int i=2;i<=n;++i) dif[i]=x[i]-x[i-1];
    for(int i=1;i<=n;++i) tdif[i]=dif[ind[i]];
    for(int i=2;i<=n;++i) tdif[i]+=tdif[i-1];
    for(int i=1;i<=n;++i) printf("%lld\n",tdif[i]);
    return 0;
}

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

typedef long long ll;
const int MAX_N = 130;    // Change as necessary
const ll  MODD = 1000000009; //



int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  string s;
  cin >> s;
  
  ll ans = 0, val = 0;
  for(int i=0;i<s.length();i++){
    val = 0;
    for(int j=i;j<s.length();j++){
      val = val*10 + s[j]-'0';
      int p = s.length()-1;
      if(i != 0) p--;
      if(j != s.length()-1) p--;
      p -= (j-i);
      ans += val * (1ll << p);
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int h, w, k;    cin >> h >> w >> k;
    vector<string>c(h);
    rep(i, h)   cin >> c[i];
    int ans = 0;
    rep(row, 1 << h)    rep(col, 1 << w){
        int black = 0;
        rep(i, h)   rep(j, w){
            if(row>>i&1)    continue;
            if(col>>j&1)    continue;
            if(c[i][j] == '#')  black++;
        }
        if(black == k)  ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <utility>
#include <algorithm>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstring>
typedef long long ll;


using namespace std;




int main()
{
   //IOS;
	int n;
	cin >> n;
	ll a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
		if(a[n-1]!=2)
	{
		cout << "-1";
		return 0;
	}
	ll range1=a[n-1];
		ll range2=(2LL*a[n-1])-1;
		int i=n-1;
	while(1)
	{
		//cout << range1 <<" "<<range2<<"\n";
		if(i==0)
			break;
		if(i>=1)
		{
			ll div1=(range1/a[i-1]);
			ll ream1=(range1%a[i-1]);
			ll div2=(range2/a[i-1]);
			ll ream2=(range2%a[i-1]);
			if(div2-div1>=1 || ream1==0 || ream2==0)
			{
				//if(div2-div1>=1)
				//{
					if(ream1!=0)
					range1=(div1+1)*a[i-1];
				  else
				  	range1=(div1)*a[i-1];
				range2=(div2*a[i-1]+(a[i-1]-1));
				//}
				/*else if(ream1==0)
				{
					range1=(a[i-1]);
					range2=(2LL*a[i-1])-1;
				}*/
			}
			else
			{
				range1=-1;
				range2=-1;
			}
		}
		if(range2==-1 || range1==-1)
			break;
		i--;

	}
	if(range1==-1 || range2==-1)
	{
		cout << "-1";
		return 0;
	}
	cout << range1<<" "<<range2;
    
}

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

int main(void){
    
    int i;
    char a[110],b[110];
    
    scanf( "%s", a);
    scanf( "%s", b);
    
    int length_a = strlen(a);
    int length_b = strlen(b);
    
    if( length_a > length_b ){
        printf( "GREATER" );
    }
    else if( length_a < length_b ){
        printf( "LESS" );
    }
    else{
        for( i = 0; i < length_a; i++ ){
            if( a[i] > b[i] ){
                printf( "GREATER" );
                break;
            }
            else if( a[i] < b[i] ){
                printf( "LESS" );
                break;
            }
        }
    
        if( i == length_a ){
            printf( "EQUAL" );
        }
    }
    
    
    return 0;
}

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

int main() {
	int n;
	cin>>n;
	int a[n],i;
	for(i=0;i<n;i++)
	cin>>a[i];
	
    int ans[n];
    for(i=0;i<n;i++)
    ans[i]=INT_MAX;
    ans[0]=0;
    for(i=0;i<n-1;i++)
    {
        int i1=i+1,i2=i+2;
        int z2,z1=ans[i]+abs(a[i]-a[i+1]);
        if(i2<n)
        {
            z2=ans[i]+abs(a[i]-a[i+2]);
        }
        ans[i1]=min(ans[i1],z1);
        if(i2<n)
        ans[i2]=min(ans[i2],z2);
    }
	 cout<<ans[n-1];   
	
	
	return 0;
}

Measured memory_bytes: 4388
#include <stdio.h>
#include <stdlib.h>
int compar(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}

int main () {
	int N, K;
	scanf("%d", &N);
	scanf("%d", &K);
	int *p = malloc(N * sizeof(int));

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &p[i]);
	}
	qsort(p, N, sizeof(int), compar);
	int sum = 0;
	for (int i = 0; i < K; i++)
	{
		sum += p[i];
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 1680
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K;
    cin >> N >> K;
    int ret = (N + K + K) / (2 * K + 1);
    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 256
import kotlin.math.max

fun main() {
    val n = readInt()
    val a = readInts()
    var currMax = 0
    var ans = 0L
    for (i in 0 until n) {
        currMax = max(currMax, a[i])
        ans += currMax - a[i]
    }
    println(ans)
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    rep(i, K) cin >> D[i];

    vector<int> ok;
    rep(i, 10) {
        bool flg = true;
        rep(j, K) {
            if (D[j] == i) flg = false;
        }
        if (flg) ok.push_back(i);
    }

    int n = N;
    int keta = 0;
    while (n > 0) {
        n /= 10;
        keta++;
    }

    vector<int> x(4, 0);
    rep(i, keta) x[i] = 1;

    int ans = INF;
    for (int a : ok) {
        for (int b : ok) {
            for (int c : ok) {
                for (int d : ok) {
                    int n = N;
                    while (n > 0) {
                        n /= 10;
                    }
                    int res = a * 1000 * x[3] + b * 100 *x[2] + c * 10 * x[1] + d * x[0];
                    if (N <= res) ans = min(ans, res);
                }
            }
        }
    }

    if (ans == INF) {
        if (ok.front() != 0) cout << ok.front();
        else cout << ok[1];
        rep(i, keta) cout << ok.front();
        cout << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
 
int main()
{
	string S;
	int fd = 0;
	cin >> S;
	for (unsigned i = 0; i < S.length(); i++)
		if (S.at(i) == 'x')
			fd++;
	if (fd > 7)
		printf("NO");
	else
		printf("YES");
	return 0;
}

Measured memory_bytes: 256
#方針ーできるだけ計算を省きながら全探索する。n=10^9までなので、頑張れば行ける
# 一桁目が3,5,7以外　＝＞ 即死
# 0,2,4,6,8は偶数で切れる(前回取得していた場合は必ず偶数になる)
# 100の位が1 => 100ならば200までは候補ならない＝＞飛ばす
n = gets.to_i
ans = 0
last_time_get = false
dev10 = 0
able_get = false
next_count = 0
count = 0
numc = 0
while(numc <= n)
  num = numc
  #ぶっ飛ばししょり
  dev100000000 = num % 100000000
  if dev100000000 == 0
    case (num / 100000000)%10
    when 1,2,4,6,8,9
    next_count = 100000000
    end
  end
  #ぶっ飛ばししょり
  dev10000000 = num % 10000000
  if dev10000000 == 0
    case (num/10000000)%10
    when 1,2,4,6,8,9
    next_count = 10000000
    end
  end
  #ぶっ飛ばししょり
  dev1000000 = num % 1000000
  if dev1000000 == 0
    case (num/1000000)%10
    when 1,2,4,6,8,9
    next_count = 1000000
    end
  end
  #ぶっ飛ばししょり
  dev100000 = num % 100000
  if dev100000 == 0
    case (num/100000)%10
    when 1,2,4,6,8,9
    next_count = 100000
    end
  end
  #ぶっ飛ばししょり
  dev10000 = num % 10000
  if dev10000 == 0
    case (num/10000)%10
    when 1,2,4,6,8,9
    next_count = 10000
    end
  end
  #ぶっ飛ばししょり
  dev1000 = num % 1000
  if dev1000 == 0
    case (num/1000)%10
    when 1,2,4,6,8,9
    next_count = 1000
    end
  end
  #ぶっ飛ばししょり
  dev100 = num % 100
  if dev100 == 0
    case (num/100)%10
    when 1,2,4,6,8,9
    next_count = 100
    end
  end
  #ぶっ飛ばししょり
  dev = num % 10
  if dev == 0
    case (num/10)%10
    when 1,2,4,6,8,9
    next_count = 10
    end
  end
  if next_count > 0
    numc += next_count
    next_count = 0
    next
  end

    count += 1

  if last_time_get
    last_time_get = false
    numc += 1
    next
  end
  if num % 2 == 0
    numc += 1
    next
  end
  if num == 1
    numc += 1
    next
  end
  able_get = true
  is3 = false
  is5 = false
  is7 = false
  while num != 0
    dev10 = num % 10
    if dev10 == 1 or dev10 == 9 or dev10 == 0 or dev10 == 2 or dev10 == 4 or dev10 == 6 or dev10 == 8
      able_get = false
      break
    end
    is3 = true if dev10 == 3
    is5 = true if dev10 == 5
    is7 = true if dev10 == 7
    num -= dev10
    num /= 10
  end
  if able_get && is7 && is5 && is3
    ans += 1
    last_time_get = true
  end

  numc += 1
end

puts ans.to_s

Measured memory_bytes: 1916
#include <iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>
using namespace std;

int main()
{
    int  a=0,b=0,i=0,j=0;
    string s1,s2;
    cin >> s1 >> s2;
    for(i=0;i<s1.size();i++){
        for(j=0;j<s2.size();j++){
            if(s1[i+j]!=s2[j]){break;}
            if(j==s2.size()-1){
                cout << i << endl;
            }
        }
    }
}

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

#define N (2019)

int main(void) {
	int x, y, c;
	int a[N], b[N];

	c = 0;
	memset(a, 0, N);
	while ((x = getchar() - '0') > 0) {
		a[0] += 1;
  	memset(b, 0, N * sizeof(int));
		for (y = 0; y < N; y++) {
			b[(y * 10 + x) % N] = a[y];
		}
		memcpy(a, b, N * sizeof(int));
		c += a[0];
	}

	printf("%d\n", c);
}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Query {
    ll a, b, c, d;
};

std::istream &operator>>(std::istream &in, Query &o) {
    cin >> o.a >> o.b >> o.c >> o.d;
    o.a--;
    o.b--;
    return in;
}

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

    vector<int> prev(2019, 0);
    ll ans = 0;
    rep(i, n) {
        vector<int> next(2019, 0);

        char c = s[i];
        int j = c - '0';
        next[j]++;
        rep(k, 2019) {
            next[(k * 10 + j) % 2019] += prev[k];
        }
        ll now = next[0];
        ans += now;
        prev = next;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// random {{{ 1
ll rnd(){
    static ll x = time(0);
    x = x ^ (x << 13); x = x ^ (x >> 7);
    return x = x ^ (x << 17);
}
// }}}
// }}} 0

int main() {

    int N;
    Scd(N);

    bool a = false;
    Rep(i,10)Rep(j,10) a = a||(N==i*j);
    YesNo(a);

    return 0;
}




Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>
#include <set>
#include <string>

using namespace std;


string s,t;

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

    int cnt = 0;
    for(int i=0;i<s.size();i++) {
        if(s[i]!=t[i]) {
            cnt++;
        }
    }

    cout<<cnt<<endl;
    
    return 0;
}

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

 int main (){
     int a,b;
     char o;
     while(1){
     cin >> a >> o >> b;
        if (o == '?'){
            return 0;
        }else {
            switch(o){
                case '+':
                    cout << a + b << endl;
                    break;
                case '-':
                    cout << a - b << endl;
                    break;
                case '/':
                    cout << a / b << endl;
                    break;
                case '*':
                    cout << a * b << endl;
                    break;
            }
        }
    }
 }


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define all(x) x.begin(), x.end()
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

typedef long long ll;

int main(void){
    ll n, k, s;
    cin >> n >> k >> s;
    
    for (int i = 0; i < n; i++) {
        if (i < k)
            cout << s;
        else if (s != 1)
            cout << s-1;
        else
            cout << s+1;
        if (i != n-1)
            cout << " ";
    }
    cout << endl;
}

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

int main()
{
	int n,p;
	string s;
	cin >> n;
	while(n--)
	{
		if(cin.peek()=='\n') cin.ignore();
		getline(cin,s);
		while(p=s.find("Hoshino"), p!=-1)
		{
			s.replace(p,7,"Hoshina");
		}
		cout << s << endl;
	}
}

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

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

	int maxh = 0;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (maxh <= h[i]) {
			ans++;
			maxh = h[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut a = String::new();
    std::io::stdin().read_line(&mut a).unwrap();
    let a = a.trim();
    let mut b = String::new();
    std::io::stdin().read_line(&mut b).unwrap();
    let b = b.trim();
    let mut c = String::new();
    std::io::stdin().read_line(&mut c).unwrap();
    let c = c.trim();

    let mut card = 'a';
    let mut x = 0;
    let mut y = 0;
    let mut z = 0;

    loop {
        let fin = match card {
            'a' => 
                if x < a.len() {
                    card = a.chars().nth(x).unwrap();
                    x += 1;
                    false
                }
                else {true},
            'b' => 
                if y < b.len() {
                    card = b.chars().nth(y).unwrap();
                    y += 1;
                    false
                }
                else {true},
            'c' =>
                if z < c.len() {
                    card = c.chars().nth(z).unwrap();
                    z += 1;
                    false
                }
                else {true},
            _ => true
        };
        if fin {break;}
    }

    println!("{}", if card == 'a' {'A'} else if card == 'b' {'B'} else {'C'});
}



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

vector<int> data;

bool che(int x){
	
	for(int i=0;i<data.size();i++){
		if(data[i]%x!=0)return false;
	}
	return true;
}

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		data.push_back(a);
	}
	
	for(int i=1;i<156345758;i++){
		if(che(i))cout<<i<<endl;
	}
	
	
	
}

Measured memory_bytes: 1212
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

int N, A[int(1e5)], B[int(1e5)], C[int(1e5)];
ll CountB[int(1e5 + 5)];

int main(){
  scanf("%d", &N);
  for (int i = 0; i < N; i++) scanf("%d", A + i);
  for (int i = 0; i < N; i++) scanf("%d", B + i);
  sort(B, B + N);
  for (int i = 0; i < N; i++) scanf("%d", C + i);
  sort(C, C + N);

  for (int i = 0; i < N; i++){
    if (B[i] < C[0]){
      CountB[i] = N; continue;
    }
    int L = 0, R = N;
    while (R - L > 1){
      int now = (L + R) / 2;
      if (C[now] <= B[i]) L = now;
      else R = now;
    }
    CountB[i] = N - R;
  }

  for (int i = N - 1; i >= 0; i--){
    CountB[i] += CountB[i + 1];
  }

  ll ans = 0;
  for (int i = 0; i < N; i++){
    if (A[i] < B[0]){
      ans += CountB[0]; continue;
    }
    int L = 0, R = N;
    while (R - L > 1){
      int now = (L + R) / 2;
      if (B[now] <= A[i]) L = now;
      else R = now;
    }
    ans += CountB[R];
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
typedef long long ll;
int main(void){
    ll n,a,b;
    cin>>n>>a>>b;
    if(b<a||(n==1&&a!=b)){
        cout<<0<<endl;
        return 0;
    }else if(n<=2){
        cout<<1<<endl;
        return 0;
    }
    n-=2;
    b-=a;
    cout<<b*n+1<<endl;
}


Measured memory_bytes: 256
package main

import(
  
  "fmt"
  
)

func main() {
  var s string
  var count int
  fmt.Scan(&s)
  
  for i := 0; i <= 2; i++ {
    for e := i + 1; e <= 3; e++ {
      if s[i] == s[e] {
        count++
      }
    }
  }
  
  if count == 2 {
    fmt.Println("Yes")
  }else {
    fmt.Println("No")
  }
  
  
  
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{const int size=2e+5;
int a[size],b[size];
int n;
cin>>n;

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

for(int i=n-1,j=0,k=n-1;i>-1;i--)
{
	
	
	b[j++]=a[i--];
	
	if(i<0)
	break;
	
	b[k--]=a[i];

}


for(int i=0;i<n;i++)
{cout<<b[i]<<" ";
}
return 0;
 } 

Measured memory_bytes: 3712
//https://atcoder.jp/contests/abc143/tasks/abc143_b

#include<iostream>
#include<vector>
using namespace std;

int func(int n, vector<int> dn){
    
    if(n == 0) {
        return 0;
    }else if(n==1){
        return 0;
    }

    int sum = 0;

    for(int i = 0 ; i < n - 1; i++){
        sum += dn[n - 1]  * dn[n - 2 - i];
    }

    return sum + func(n - 1 , dn);
}

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

    vector<int> dn(n);

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

    cout << func(n, dn) << endl;
    
    return 0;

}

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

int main() {
  int N;
  cin >> N;
  bool flag = false;

  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (N == (i * j)) {
        flag = true;
      }
    }
  }
  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3620