akhauriyash/Code-Regression huggingface dataset:
#include<map>
#include<set>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int n,k,a[5010],dp[17][5010],ans;

void solve(int l,int r,int dep)
{
	if(l==r)
	{
		int tmp=0;
		for (int i=max(0,k-a[l]); i<k; ++i)
		{
			tmp|=dp[dep][i];
		}
		ans+=1-tmp;
		return;
	}
	int mid=(l+r)>>1;
	for(int i=0; i<k; ++i)
	{
		dp[dep+1][i]=dp[dep][i];
	}
	for(int i=l; i<=mid; ++i)
	{
		for (int j=k-1; j>=a[i]; --j)
		{
			dp[dep+1][j]|=dp[dep+1][j-a[i]];
		}
	}
	solve(mid+1,r,dep+1);
	for(int i=0; i<k; ++i)
	{
		dp[dep+1][i] = dp[dep][i];
	}
	for(int i=mid+1; i<=r; ++i)
	{
		for(int j=k-1; j>=a[i]; --j)
		{
			dp[dep+1][j]|=dp[dep+1][j-a[i]];
		}
	}

	solve(l,mid,dep+1);
}

int main()
{
	scanf("%d%d",&n,&k);
	for (int i = 1 ; i <= n ; ++ i)
	{
		scanf("%d",&a[i]);
	}
	dp[1][0] = 1;
	solve(1,n,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func solve(sc *scanner, wr *bufio.Writer) int {
	a := sc.i()
	b := sc.i()

	if a <= b {
		for i := 0; i < b; i++ {
			fmt.Print(a)
		}
	} else {
		for i := 0; i < a; i++ {
			fmt.Print(b)
		}
	}
	fmt.Println()
	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		int max = h;
		if(max<w) {
			max = w;
		}
		if(n%max==0) {
			System.out.println(n/max);
		}else {
			System.out.println(n/max+1);
		}
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n,a,b; cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main(){
	int n, m; scanf("%d %d", &n, &m);
	ll x[100000], y[100000];
	for(int i = 0; i < n; i++) scanf("%lld", &x[i]);
	for(int i = 0; i < m; i++) scanf("%lld", &y[i]);
	ll s = 0, t = 0;
	for(int i = 1; i <= n; i++) s += (2 * i - n - 1) * x[i - 1];
	for(int i = 1; i <= m; i++) t += (2 * i - m - 1) * y[i - 1];
	s %= MOD; t %= MOD;
	ll res = s * t % MOD;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
using namespace std;
const long long MAXN = 6e5+5;
long long l[64][MAXN];
long long arr[MAXN];
long long c[MAXN];
vector<long long> S;
long long p[64][MAXN];
long long n,k;
int main(){
    ios::sync_with_stdio(false);
	cin.tie(NULL);
    cin>>n>>k;
    for(long long i=0;i<n;i++){
        cin>>arr[i];
        arr[i+n] = arr[i];
    }
    for(long long i=n+n-1;i>=0;i--){
        if(i<n){
            l[0][i] = c[arr[i]]-i+1;
            p[0][i] = (c[arr[i]]+1)%n;
        }
        c[arr[i]] = i;
    }
    for(long long i=1;i<60;i++){
        for(long long j=0;j<n;j++){
            l[i][j] = min((long long)1e18,l[i-1][j]+l[i-1][p[i-1][j]]);
            p[i][j] = p[i-1][p[i-1][j]];
        }
    }
    for(long long x=0,y=0;x<n*k;){
        for(long long i=59;i>=0 && x<n*k;i--){
            if(x+l[i][y]<=n*k){
                x+=l[i][y];
                y=p[i][y];
            }
        }
        if(x==n*k){
            break;
        }
        S.push_back(arr[y]);
        x++;
        y = (y+1)%n;
    }
    for(long long x:S){
        cout<<x<<" ";
    }
}

Measured memory_bytes: 442992
(ns Atcoder.ABC049-C)
(require '[clojure.string :as str])
(def S (apply str (vec (reverse (read-line)))))
(def div '("maerd" "remaerd" "esare" "resare"))
(def l (count S))

(def ans (loop [cnt 0 pos 0 flg 0]
           (if (and (< cnt 4) (< pos l))
             (if (>= l (+ (count (nth div cnt)) pos))
               (if (= (subs S pos (+ (count (nth div cnt)) pos)) (nth div cnt))
                 (recur 0 (+ pos (count (nth div cnt))) 1)  ; cnt = 0, pos = pos + div, flg = 1
                 (recur (inc cnt) pos 0))
               (if (= (subs S pos) (nth div cnt))
                 (recur 0 (+ pos (count (nth div cnt))) 1)
                 (recur (inc cnt) pos 0)))
             (if (= flg 1) "YES" "NO"))))

(println ans)

Measured memory_bytes: 88132
#include<stdio.h>
int main()
{
	long int a,b,c,d,sum1,sum2;
	while(scanf("%ld%ld%ld%ld",&a,&b,&c,&d)!=EOF)
	{
		sum1=a*b;
		sum2=c*d;
		if(sum1>=sum2)
			printf("%ld\n",sum1);
		else
			printf("%ld\n",sum2);	
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#define che
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define MK make_pair
#define PB push_back
#define fi first
#define se second

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

int main(){
	#ifdef che
	freopen("input.txt","rt",stdin);
	freopen("output.txt","wt",stdout);
	#endif
	LL n, p; cin>>n>>p;
	LL k = LL (sqrt(p+0.5)), ans=1;
	for (LL i=2; i<=k; ++i) if ( p%i==0){
		int pw=0;
		for(; p%i==0; p/=i)++pw;
		pw/=n;
		for (int j=0; j<pw; ++j) ans*=i;
	}
	if ( p>1 && n==1) ans *= p;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
	int x,y;
	int a;
	char s;

	while (1){
		scanf("%d %c %d", &x, &s, &y);
		if (s == '?') break;

		if (s == '+')a = x + y;
		else if (s == '-')a = x - y;
		else if (s == '*')a = x*y;
		else a = x / y;

		printf("%d\n",a);

	}
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 9223372036854775807
#define MOD 1000000007


    int main(void){

        int n;
        cin >> n;

        vector<int> boss(n,0);

        rep(i, n-1){
            int data;
            cin >> data;
            boss.at(data - 1)++;
        }
        rep(i,n){
            cout << boss.at(i) << endl;
        }

        return 0;
}


Measured memory_bytes: 4048
import * as fs from 'fs';
// main
function main(input: string[]) {
    // param
    let n;
    let r;
    let ans;
    // init
    // <example>
    [n, r] = input.shift().split(" ").map(x => Number(x));
    // solve
    if (10 <= n) {
        ans = r;
    } else {
        ans = r + 100 * (10 - n);
    }
    // answer
    console.log(ans);
}
// entrypoint
function entrypoint() {
    try {
        // linux
        let input = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        console.debug = function () { };
        main(input);
    }
    catch (ex) {
        // windows
        const lines: string[] = [];
        // @ts-ignore
        const reader = require('readline').createInterface({
            // @ts-ignore
            input: process.stdin,
            // @ts-ignore
            output: process.stdout
        });
        reader.on('line', function (line: string) {
            lines.push(line);
        });
        reader.on('close', function () {
            let input = lines;
            main(input);
        });
    }
}
entrypoint();


Measured memory_bytes: 29616
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int a;
    int b;
    int c;
    int d;
    int turn=0;
    cin >> a >> b >> c >> d;
    while(a>0 && c>0){
        if(turn%2==0){
            c-=b;
        }else{
            a-=d;
        }
        turn++;
    }

    if(a>0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<long> VL;

struct Node {
  int p;
  int left;
  int right;
};
vector<Node> l(30);

void preParse(int i) {
  if (i == -1) return;
  cout << " " << i;
  preParse(l.at(i).left);
  preParse(l.at(i).right);
}

void InParse(int i) {
  if (i == -1) return;
  InParse(l.at(i).left);
  cout << " " << i;
  InParse(l.at(i).right);
}

void PostParse(int i) {
  if (i == -1) return;
  PostParse(l.at(i).left);
  PostParse(l.at(i).right);
  cout << " " << i;
}

int main() {
  int n; cin >> n;
  int top;
  rep(i, n) {
    l.at(i).p = -1;
  }

  rep(i, n) {
    int id; cin >> id;
    int l_tmp; cin >> l_tmp;
    int r_tmp; cin >> r_tmp;
    if (l_tmp != -1) l.at(l_tmp).p = id;
    if (r_tmp != -1) l.at(r_tmp).p = id;
    l.at(id).left = l_tmp;
    l.at(id).right = r_tmp;
  }

  rep(i, n) {
    if (l.at(i).p == -1) top = i;
  }
  cout << "Preorder" << endl;
  preParse(top);
  cout << endl;

  cout << "Inorder" << endl;
  InParse(top);
  cout << endl;

  cout << "Postorder" << endl;
  PostParse(top);
  cout << endl;
}



Measured memory_bytes: 3088
#include"bits/stdc++.h"
using namespace std;
int main(){

    string a,b;
    cin>>a>>b;
    for(int i=0;i<a.size();i++){
           rotate(a.begin(), a.begin()+1, a.end());
           if(a==b){
                cout<<"Yes";
                return 0;
           }
    }
     cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    int P[200000];
    for(int i=0;i<N;i++)
        cin >> P[i];
    
    int num, dp[200001] = {}, max = 0;
    for(int i=0;i<N;i++){
        num = P[i];
        dp[num] = dp[num - 1] + 1;
        if(dp[num] > max)
            max = dp[num];        
    }
    
    cout << N - max << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>

int main()
{
     int a,b,c,aux;

    scanf("%i",&a);
    scanf("%i",&b);
    scanf("%i",&c);
    if(a>b)
    {
        aux=a;
        a=b;
        b=aux;
    }
    if(a>c)
    {
        aux=a;
        a=c;
        c=aux;
    }
    if(b>c)
    {
        aux=b;
        b=c;
        c=aux;
    }
    printf("%i %i %i",a,b,c);
    printf("\n");
}


Measured memory_bytes: 2120
using System;

namespace A___ringring
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = new int[3];
            a[0] = int.Parse(input[0]);
            a[1] = int.Parse(input[1]);
            a[2] = int.Parse(input[2]);
            Array.Sort(a);
            Console.WriteLine(a[0] + a[1]);
        }
    }
}

Measured memory_bytes: 11092
import java.io.*;

class Main {
    public static void main(String[] args) throws IOException{
	BufferedReader br =
	    new BufferedReader(new InputStreamReader(System.in));

	String str = br.readLine();
	String[] str1 = str.split(" ",0);
	
	int[] str2 = new int[str1.length];
	for (int i = 0; i < str1.length ; i++) {
	    str2[i] = Integer.parseInt(str1[i]);
	}
	int res1 = str2[0] * str2[1];
	int res2 = (str2[0]+str2[1]) * 2;
	System.out.println(res1 +" "+ res2);

    }
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	ll x , y ; 
	cin >> x >> y ; 
	int ans = 0 ;
	while(x <= y) {
		ans ++ ; 
		x *= 2 ;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import collections
from collections import defaultdict

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    A = [[int(x) for x in input().split()] for _ in range(N)]

    q = [collections.deque() for j in range(N)]

    for i, a in enumerate(A):
        for aa in a:
            q[i].append(aa)

    ans = 0

    current = defaultdict(int)
    for i, v in enumerate(q):
        current[i + 1] = v[0]

    while True:
        v = set()
        for k in current.keys():
            if k == q[current[k] - 1][0]:
                v.add(k)
                v.add(current[k])

        current = defaultdict(int)

        if len(v) == 0:
            break

        for vv in v:
            q[vv - 1].popleft()
            if len(q[vv - 1]):
                current[vv] = q[vv - 1][0]

        ans += 1

    # 全て空なら
    size = 0
    for i in range(N):
        size += len(q[i])

    if size == 0:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 111028
A,B,C,X,Y = map(int,input().split())

min_cost = 1000000000

for i in range(0,2*max(X,Y) +1,2):
    cost = i * C + max(0,(Y - i//2))*B+ max(0,(X - i//2))*A
    if cost < min_cost:
        min_cost = cost

print(min_cost)

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

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

  set<int> prime;
  prime.insert(2);
  for(int i=3; i<=100003; i+=2){
    bool finished = false;
    for(int x : prime){
      if(i%x == 0){
        finished = true;
        break;
      }
    }
    if(finished)
      continue;
    prime.insert(i);
  }

  int ans;
  for(int i=n; i<=100003; i++){
    if(prime.count(i)){
      cout << i << endl;
      break;
    }
  }

  return 0;

}


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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

signed main() {
    int n;
    string s;
    cin >> n;
    cin >> s;

    int len = s.length();
    REP(i, len) {
        cout << (char) (((s[i] - 'A' + n) % 26) + 'A');
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(void){
    int a,p;
    cin >> a>> p;

    int pp = p;

    pp += a*3;

    int ans = pp/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
def main():
    # ダブリング
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    T = [[0]*(N+1) for _ in range(61)]
    T[0][1:] = A
    for t in range(1, 61):
        for i in range(1, N+1):
            T[t][i] = T[t-1][T[t-1][i]]
    v = 1
    B = "{:0b}".format(K)[::-1]
    for i, b in enumerate(B):
        if b == "1":
            v = T[i][v]
    print(v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 174460
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	ll a1,a2,a3;
	cin >> a1 >> a2 >> a3;
	if(a1+a2+a3<22)cout << "win";else cout << "bust";
    return 0;
}


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

using namespace std;
typedef long long ll;

int N;
ll A, B;
ll x[100010];

int main(){
  cin >> N >> A >> B;
  for(int i = 0; i < N; i++)  cin >> x[i];

  ll sum = 0;
  for(int i = 1; i < N; i++){
    sum += min((x[i]-x[i-1]) * A, B);
  }

  cout << sum << endl;


  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod ((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int N = (int)2e5+5;
const int M = (int)3e3+5;
const int Q = 301;
const int logN = 19;

void solve() {
    string s;
    cin>>s;
    int n = s.size();
    reverse(all(s));
    vector<int> p(n+1);
    int prod = 1;
    int m = 2019;
    unordered_map<int,int> mp;
    mp[0]++;
    ll ans = 0;
    REP(i,1,n) {
        p[i] = (p[i-1] + (prod*(s[i-1]-'0')))%m;
        prod = prod*10%m;
        ans += mp[p[i]];
        mp[p[i]]++;
    }
    cout<<ans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    int a,b;
    cin>>a>>b;
    if (a<=b)
    {
        for(int i=0;i<b;i++)
            cout<<a;
    }
    else
        for (int i = 0; i < a; i++)
        {
            cout<<b;
        }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
p = m // n
ans_1 = 0
if p > 100000:
    for i in range(1, 10001):
        if m % i == 0 and i >= n:
            ans_1 = m // i
            break
for i in range(min(p, 100000), 0, -1):
    if m % i == 0:
        ans_2 = i
        break
    else:
        continue
print(max(ans_1, ans_2))

Measured memory_bytes: 3060
A,B,C = list(map(int, input().split()))
count=0
while True:
    if A%2 ==1or B%2 ==1 or C%2 ==1:
        print(count)
        break
    elif  A==B and B==C and C==A:
        print(-1)
        break 
    elif A%2==0 and B%2==0 and C%2 == 0:
        A2 = 0.5*A
        B2 = 0.5*B
        C2 = 0.5*C
        A = B2+C2
        B = C2+A2
        C = A2+B2
        count=count+1

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            int[] inputArray = Array.ConvertAll<string, int>(input, delegate (string value) { return int.Parse(value); });
            var output = Math.Floor((inputArray[2] + 0.5) / inputArray[0]) * inputArray[1];
            Console.WriteLine(output);
            Console.ReadLine();
        }
    }


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define int ll
using namespace std;typedef long long ll;
#define DRP(t,a,b) for(register int t=(a),edd=(b);t>=edd;--t)
#define RP(t,a,b)  for(register int t=(a),edd=(b);t<=edd;++t)
#define ERP(t,a)   for(register int t=head[a];t;t=e[t].nx)
#define midd register int mid=(l+r)>>1
#define TMP template < class ccf >
#define lef l,mid,pos<<1
#define rgt mid+1,r,pos<<1|1
#define pushup(pos) (seg[pos]=seg[pos<<1]+seg[pos<<1|1])
TMP inline ccf qr(ccf b){
    register char c=getchar();register int q=1;register ccf x=0;
    while(c<48||c>57)q=c==45?-1:q,c=getchar();
    while(c>=48&&c<=57)x=x*10+c-48,c=getchar();
    return q==-1?-x:x;}
TMP inline ccf Max(ccf a,ccf b){return a<b?b:a;}
TMP inline ccf Min(ccf a,ccf b){return a<b?a:b;}
TMP inline ccf Max(ccf a,ccf b,ccf c){return Max(a,Max(b,c));}
TMP inline ccf Min(ccf a,ccf b,ccf c){return Min(a,Min(b,c));}
TMP inline ccf READ(ccf* _arr,int _n){RP(t,1,_n)_arr[t]=qr((ccf)1);}
//----------------------template&IO---------------------------
const int maxn=200005;
struct E{
    int fr,to,w;
    inline bool operator < (E a){return w<a.w;}
}e[maxn<<1];
int cnt;
int r[maxn];
inline void add(int fr,int to,int w){
    e[++cnt]=(E){fr,to,w};
}
inline int q(int x){
    register int t=x,i=x,temp;
    while(r[t]!=t) t=r[t];temp=t;
    while(r[i]!=i) {temp=r[i];r[i]=t;i=temp;}
    return t;    
}

inline bool in(int x,int y){return not(q(x)^q(y));}
inline void j(int x,int y){r[q(x)]=q(y);}

int f[maxn];
int n,m;
signed main(){
    n=qr(1LL);m=qr(1LL);
    RP(t,0,n) r[t]=t;
    register int t1,t2,t3;
    RP(t,0,n+1) f[t]=1LL<<50;
    RP(t,1,m){
	t1=qr(1);
	t2=qr(1);
	t3=qr(1);
	add(t1,t2,t3);
	f[t1]=Min(f[t1],t3+1LL);
	f[t2]=Min(f[t2],t3+2LL);
    }
    RP(t0,1,2) RP(t,0,n) f[t%n]=Min(f[t%n],f[(t-1+n)%n]+2LL);
    RP(t,0,n) add(t%n,(t+1)%n,f[t%n]);
    sort(e+1,e+cnt+1);ll ret=0;
    RP(t,1,cnt){
	if(not in(e[t].fr,e[t].to)){
	    ret+=(ll)e[t].w;
	    j(e[t].fr,e[t].to);
	}
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 12800
import sys
input = sys.stdin.readline

def dfs(edges, s):
    use = {s}
    stack = [s]
    while stack:
        v = stack.pop()
        for w in edges[v]:
            if w in use: continue
            use.add(w)
            stack.append(w)
    return use

def bellmanford(num_v, edges, source):
    inf = float('inf')
    dist = [inf] * num_v
    dist[source] = 0
    for i in range(num_v):
        flag = False
        for s, t, cost in edges:
            if dist[s] == inf: continue
            if dist[s] + cost < dist[t]:
                dist[t] = dist[s] + cost
                flag = True
        if not flag: break
    else:
        return False
    return dist

def main():
    N, M, P = map(int, input().split())
    G = [[] for _ in range(N)]
    G_rev = [[] for _ in range(N)]
    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G_rev[b].append(a)
        edges.append((a, b, P-c))
    
    use = dfs(G_rev, N-1)
    edges = [(a, b, c) for a, b, c in edges if a in use and b in use]
    dist = bellmanford(N, edges, 0)
    if dist:
        print(max(0, -dist[N-1]))
    else:
        print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 46188
/*
dp(i,j) = min cost to combine all the slimes (i,j) int one
base case: 
dp(i,i) = 0
dp(i,j) = sum(i,j) + dp(i,k) + dp(k+1,j) where k = i to j-1
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
ll dp[3001][3001];
ll sum[3001][3001];
ll solve(int *a , int i , int j){
   if(i == j){
       return 0;
   }
   if(dp[i][j] != -1){
       return dp[i][j];
   }
   ll minCost = (1ll<<60);
   for(int k=i ; k<j ; k++){
       minCost = min(minCost , sum[i][j] + solve(a , i , k ) + solve(a , k+1 , j));
   }
   return dp[i][j] = minCost;
}
void preproccesing(int *a , int n){
    for(int i=1 ; i<=n ; i++){
        for(int j=i ; j<=n ; j++){
            sum[i][j] = a[j] + ((i == j) ? 0 : sum[i][j-1]);
        }
    }
}
int main() {
    int n ;
    cin>>n;
    int a[n+1];
    memset(dp , -1 , sizeof(dp));
    for(int i=1 ; i<=n ; i++){  
        cin>>a[i];
    }
    preproccesing(a , n);
    cout<<solve(a , 1 , n);
    return 0;
}


Measured memory_bytes: 80128
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n;
	vector<int> a;
	cin >> n;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	int cnt = 0;
	for (int i = 0;i < n - 1;++i) {
		if (a[i] == i + 1) {
			swap(a[i], a[i + 1]);
			cnt++;
		}
	}
	if (a[a.size() - 1] == a.size()) {
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main()
{
	long long n,d;
	cin>>n>>d;
	int counter=0;
	while(n--)
	{
		long long x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)
		counter++;
	}
	cout<<counter<<endl;
	return 0;
}

Measured memory_bytes: 3640
import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;

public class Main{
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        int ans = 0;
        long q = 2;
        long div;
        int loops = 43;

        if(N == 1){
            System.out.println(0);
            return;
        }

        for(int e = 1; e < loops; e++){
            div = (long) Math.pow(q, e);
            if(N % div == 0){
                N /= div;
                ans++;
            }else{
                while(N % q == 0){
                    N /= q;
                }
                q++;
                if(q * q > N){
                    break;
                }
                e = 0;
            }
        }
        if(N != 1){
            ans++;
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 35836
n,K=map(int,input().split())

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

R=n-K
B=K

if R==0:
    for i in range(K):
        if i==0:
            print(1)
        else:
            print(0)
else:
    for i in range(1,K+1):
        A1=cmb(R-(i+1)+i,i,mod)*cmb(B-1,i-1,mod)
        A2=cmb(R-i+(i-1),i-1,mod)*cmb(B-1,i-1,mod)*2
        A3=cmb(R-(i-1)+(i-2),i-2,mod)*cmb(B-1,i-1,mod)
        print((A1+A2+A3)%mod)

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

int main()
{
    int A, B;
    cin >> A >> B;
    cout << max(A - 2 * B, 0) << endl;
    return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

void solve() {
    int h;
    cin >> h;

    int ans = 0, p = 1;

    while (h > 0) {
        ans += p;
        h /= 2;
        p *= 2;
    }
    cout << ans << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
cnt_AC = [0] * n
cnt = 0

for i in range(n - 1):
    if s[i] == "A" and s[i + 1] == "C":
        cnt += 1
    cnt_AC[i + 1] = cnt

for i in range(q):
    l, r = map(int, input().split())
    print(cnt_AC[r - 1] - cnt_AC[l - 1])

Measured memory_bytes: 51032
#include<iostream>
#include<cstdlib>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
typedef long long ll;

int getlowest(int a){if (a < 0)return (-a)%10;else return a%10;}

ll solve(int now,ll val,bool isplus){
  if (now == 0)return 0;
  int a = getlowest(now);
  if (a != 0){
    if (now < 0){
      if (isplus)a = 10-a;
      else a = -a;
      now -= a;
    }else{
      if (isplus)a=-a;
      else a = 10-a;
      now += a;
    }
  }
  //  cout << now <<" "<< a <<endl;
  return val*a + solve(now/10,val*-10,!isplus);
}

main(){
  int n;
  while(cin>>n && n){
    cout << llabs(solve(n,1,true)) << endl;
  }
}

/*
10
0*1
-9*10
1*100


-1944
=-2000 + 56
=-2000 + 100 -46
=-2000 + 100 -50 + 6
-2*(10^3) + 1*(10^2) -5*(10^1) + 6*(10^0)

 -305432133
-1000000000 + 694567867
-1000000000 + 700000000 +  5432133
-1000000000 + 700000000  -10000000 + -4567867
-1000000000 + 700000000  -10000000 +  5000000 + 432133
-1000000000 + 700000000  -10000000 +  5000000 - 500000 - 67867
-1000000000 + 700000000  -10000000 +  5000000 - 500000 + 70000 +2133
-1000000000 + 700000000  -10000000 +  5000000 - 500000 + 70000 -3000 -867
-1000000000 + 700000000  -10000000 +  5000000 - 500000 + 70000 -3000  900 33
-1000000000 + 700000000  -10000000 +  5000000 - 500000 + 70000 -3000  900 -40 + 7

 -305432133
7(7ツ暗クツつュ)
 -305432140
-40(-40ツ暗クツつュ)
 -305432100
900(900ツ暗クツつュ)
 -305433000
-3000(-3000ツ暗クツつュ)
 -305430000
70000(70000ツ暗クツつュ)
 -3055
-5(
 -305
5(ツ暗クツつュ
 -31
-1ツ暗クツつュ
 -3
7ツ暗クツつュ
-1
-1ツ暗クツつュ
0

1*-1000000000
7* 100000000
1*-10000000
5* 1000000
5*-100000
7* 10000
3*-1000
9* 100
4*-10
7* 1




          1
        -10
        100
      -1000
      10000
    -100000
    1000000
  -10000000
  100000000
-1000000000
10000000000

*/

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

int H, W, M[1500][1500], HIS[1500][1500];
struct rect { int h, pos; }r, pre;

int get(int his[])
{
	stack<rect>s;
	int M = 0;

	for (int i = 1; i <= W + 1; i++)
	{
		r.h = his[i], r.pos = i;

		if (s.empty())
			s.push(r);
		else
		{
			if (r.h >= s.top().h)
				s.push(r);
			else
			{
				int tar = i;

				while (!s.empty() && r.h <= s.top().h)
				{
					pre = s.top(), s.pop();
					tar = pre.pos;
					int area = pre.h * (i - pre.pos);
					M = max(M, area);
				}

				r.pos = tar;
				s.push(r);
			}
		}
	}

	return M;
}

int main()
{
	cin >> H >> W;
	
	for (int i = 1; i <= H; i++)
		for (int j = 1; j <= W; j++)
			cin >> M[i][j];
	
	for (int i = 1; i <= H; i++)
	{
		for (int j = 1; j <= W; j++)
		{
			if (M[i][j] == 0)
				HIS[i][j] = HIS[i - 1][j] + 1;
			else
				HIS[i][j] = 0;
		}
	}

	int MAX = 0;

	for (int i = 1; i <= H; i++)
		MAX = max(MAX, get(HIS[i]));

	cout << MAX << endl;
	return 0;
}


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

    using namespace std;


    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        string s,t;
        cin>>s>>t;
        t.pop_back();
        if(s==t)
            cout<<"Yes";
        else
            cout<<"No";
        return 0;
    }


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int mod = 1000000007;

int main(){
    int n,k,m=mod,mn;
    cin>>n>>k;
    rep(i,n){
        int a;
        m=min(m,a);
        if(m==a) mn=i;
    }
    int ans=divup(mn,k-1)+divup(n-mn-1,k-1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
import bisect
import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal


from numba import jit

@jit
def run_dp(MAP, dp, Rs, Cs):
    for i in range(1, len(Rs)+1):
        for j in range(1, len(Cs)+1):
            for k in range(4):
                dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][k])
                if MAP[i][j]:
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j][k]+MAP[i][j])

                dp[i][j][k] = max(dp[i][j][k], dp[i][j-1][k])
                if MAP[i][j] and k < 3:
                    dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j-1][k] + MAP[i][j])
    return dp

def run():
    R,C,K = map(int, sysread().split())
    Rs = set()
    Cs = set()
    vals = []
    for i in range(K):
        r, c, v = map(int, sysread().split())
        vals.append((r, c, v))
        Rs.add(r)
        Cs.add(c)
    #Rs = sorted(list(Rs))
    Rs = np.array(sorted(list(Rs)))
    #Cs = sorted(list(Cs))
    Cs = np.array(sorted(list(Cs)))
    r_idx = {r:i+1 for i, r in enumerate(Rs)}
    c_idx = {c:i+1 for i, c in enumerate(Cs)}
    #MAP = [[0] * (len(Cs)+1) for _ in range(len(Rs)+1)]
    MAP = np.zeros((len(Rs)+1, len(Cs)+1), dtype= np.int64)
    for r,c,v in vals:
        rn = r_idx[r]
        cn = c_idx[c]
        MAP[rn][cn] = v

    #dp = [[[0] * 4 for _ in range(len(Cs)+1)] for i in range(len(Rs)+1)]
    dp = np.zeros((len(Rs)+1, len(Cs)+1, 4), dtype= np.int64)

    run_dp(MAP, dp, Rs, Cs)

    #print(dp)
    #for m in MAP:
    #   print(m)
    dp = run_dp(MAP, dp, Rs, Cs)

    print(max(dp[len(Rs)][len(Cs)]))

if __name__ == "__main__":
    run()

Measured memory_bytes: 501868
#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 k, x;
	cin >> k >> x;
	if (500 * k >= x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int ans=0,sum=0,n,p=1,i,j,a,b;
	scanf("%d %d",&a,&b);
	if(a==1)
	{
		if(b==1)
		printf("Draw");
		else
		printf("Alice");
		return 0;
	}
	if(b==1)
	{
		if(a==1)
		printf("Draw");
		else
		printf("Bob");
		return 0;
	}
	//if(a==1)
	
		if(a>b)
		printf("Alice");
		else if(a==b)
		printf("Draw");
		else
		printf("Bob");
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

h, w = map(int, input().split())
s = [input() for _ in range(h)]
t = [[None]*w for _ in range(h)]

def dfs(i,j,color): # i,jの色がcolorと同じなら0, colorと異なるなら連結成分でまだカウントされていない要素を数えてその白黒の数を返す
    if not(0<=i<h and 0<=j<w): return 0,0 # i,jが意味をなさないとき
    if s[i][j]==color: return 0,0 # i,jの色がcolorと同じとき
    if t[i][j]: return 0,0 # すでにカウントしたi,jであったとき
    
    t[i][j]=True
    c = s[i][j]
    bl, wh=0,0
    if c=='#':
        bl+=1
    else:
        wh+=1
    

    tmp1,tmp2=dfs(i+1,j,c)
    bl,wh=bl+tmp1,wh+tmp2

    tmp1,tmp2=dfs(i-1,j,c)
    bl,wh=bl+tmp1,wh+tmp2
            
    tmp1,tmp2=dfs(i,j-1,c)
    bl,wh=bl+tmp1,wh+tmp2

    tmp1,tmp2=dfs(i,j+1,c)
    bl,wh=bl+tmp1,wh+tmp2

    return bl,wh

    # tmp1, tmp2 = dfs(i-1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i+1,j,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # tmp1, tmp2 = dfs(i,j-1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp1

    # tmp1, tmp2 = dfs(i,j+1,s[i][j])
    # bl,wh = bl+tmp1, wh+tmp2

    # return bl,wh

ans = 0
for i in range(h):
    for j in range(w):
        a,b = dfs(i,j,'!')
        ans += a*b
print(ans)
    

Measured memory_bytes: 138724
#include <stdio.h>
#define WHITE  0
#define GRAY   1
#define BLACK  2
#define NIL   -1
#define N    101

typedef struct{
  int id;
  int k;
  int v[1000];
}DATA;

void dfs(int,int);
void visit(int,int);
void push(int);
void pop(void);
int top(void);
int next(int,int);
  
int time,count=0;
int S[N],d[N],f[N],color[N],G[N][N];
DATA data[100];

int main() {

  int i,j,n;
  
  scanf("%d",&n);
  for(i = 1; i <= n; i++) {
    scanf("%d%d",&data[i].id,&data[i].k);
    if(data[i].k == 0 ) data[i].v[1] = 0;
    
    for(j = 1; j <= data[i].k; j++) {
      scanf("%d",&data[i].v[j]);
      if(data[i].v[j] == data[i].v[data[i].k]) data[i].v[(data[i].k)+1] = NIL;
    }
  }

  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      	G[i][j] = 0;   
    }
  }
  
  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      	G[i][data[i].v[j]] = 1;   
    }
  }


  dfs(data[1].id,data[n].id);

for(i = 1; i <= n; i++) {
  printf("%d %d %d\n",data[i].id,d[i],f[i]);
 }

return 0;
}

void dfs(int u,int V)
{
  int i;
  for(i = u; i < V; i++) {
    color[i] = WHITE;
  }
  time = 0;
  for(i = u; i < V; i++) {
    if(color[i] == WHITE) visit(i,V);
  }
}

void visit(int r,int V)
{
  int u,v;
  
  push(r);
  color[r] = GRAY;
  d[r] = ++time;
  
  while(count != 0) {
    u = top();
    v = next(u,V);
    if(v != 0) {
      if(color[v] == WHITE) {
	push(v);
	color[v] = GRAY;
	d[v] = ++time;
      }
    }
    else {
      pop();
      color[u] = BLACK;
      f[u] = ++time;
    }
  }
  
}

void push(int r)
{
  S[count] = r;
  count++;
}

void pop(void)
{
  count--;
}

int top(void)
{
  return S[count-1];
}

int next(int u,int V)
{
  int i,flag=0;
for(i = 1; i <= V; i++) {
  if(G[u][i] == 1) {
    G[u][i] = 0;
    flag++;
    break; 
}
 }
 if(flag == 0)
   return 0;
 else
   return i;
}




Measured memory_bytes: 2172
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    ll x;
    cin >> N >> x;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    
    
    vector<vector<ll>> B(N, vector<ll>(N));
    rep(i, N){
        B[i][0] = A[i];
        repd(j, 1, N){
            B[i][j] = min(B[i][j - 1], A[(i - j + N) % N]);
        }
    }
    
    ll ret = 1LL << 55;
    rep(j, N){
        ll sum = 0;
        rep(i, N){
            sum += B[i][j];
        }
        sum += x * j;
        ret = min(ret, sum);
    }
    
    output(ret, 0);
    
    return 0;
}

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

struct train {
    int station;
    int start;
    int interval;
    int duration;
};

int main() {
    int n;
    cin >> n;
    vector<train> trains(n-1);
    rep(i,n-1) {
        trains.at(i).station = i;
        cin >> trains.at(i).duration;
        cin >> trains.at(i).start;
        cin >> trains.at(i).interval;
    }

    rep(i,n) {
        if (i == n-1) {
            cout << 0 << endl;
            continue;
        }
        int time = 0;
        for (int j = i; j < n-1; ++j) {
            int start = trains.at(j).start;
            int interval = trains.at(j).interval;
            int duration = trains.at(j).duration;
            time = max(time, start);
            if ((time - start) % interval != 0) {
                time = start + ((time - start)/interval + 1) * interval;
            }
            time += duration;
        }
        cout << time << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <vector>
#include <string>

int main(){

    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);

    int64_t rowMatrix[n][m];
    int64_t colMatrix[m][l];

    for (int row = 0; row < n; row++){
        for (int col = 0; col < m; col++){
            int v;
            scanf("%d", &v);
            rowMatrix[row][col] = v;
        }
    }

    for (int row = 0; row < m; row++){
        for (int col = 0; col < l; col++){
            int v;
            scanf("%d", &v);
            colMatrix[row][col] = v;
        }
    }

    
    for (int i = 0; i < n; i++){
        for (int k = 0; k < l; k++){
            int64_t res = 0;
            for (int j = 0; j < m; j++){
                // printf("r: %d * c: %d\n", rowMatrix[i][j], colMatrix[j][k]);
                res += rowMatrix[i][j] * colMatrix[j][k];
            }
            printf("%zu", res);
            if( k != l - 1){
                printf(" ");
            }
        }
        printf("\n");
    }



}


Measured memory_bytes: 2828
import java.util.*;
public class Main{
    public static void main(String args[]) {
      Scanner in = new Scanner(System.in);
      int n = in.nextInt();
      int k = in.nextInt();
      
      int[] arr = new int[n];
      int[] dp = new int[n];
      if(k>n){
           arr = new int[k+1];
      dp = new int[k+1];
      }
      dp[0]=0;
      
      for(int i=0; i<n;i++){
          arr[i] = in.nextInt();
      }
      for(int i=1; i<=k;i++){
          dp[i] = Math.abs(arr[i]-arr[0]);
      }
    //   for(int i=0; i<n; i++){
    //       System.out.print(dp[i]+" ");
    //   }
      
    //   System.out.println();
      for(int i=k+1; i<n;i++){
          dp[i] = dp[i-1]+Math.abs(arr[i]-arr[i-1]);
          for(int j=1; j<=k; j++){
              dp[i] = Math.min(dp[i],dp[i-j]+Math.abs(arr[i]-arr[i-j]));
          }
          
      }
      
    //   for(int i=0; i<n; i++){
    //       System.out.print(dp[i]+" ");
    //   }
    //   System.out.println();
      System.out.print(dp[n-1]);
      
    }
}

Measured memory_bytes: 62968
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << (s == "abc" ? "Yes" : "No") << endl;
}


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 mut 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")
    };
}

#[allow(non_snake_case, unused_variables)]
fn main() {
    input!{
        N: u32,
    }
    let mut ans = "No";
    for i in 0..N+1 {
        if i%4==0 && (N-i)%7==0 {
            ans = "Yes";
            break;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;
ll n, m, q;
vector<ll> a, b, c, d;
ll ans = 0;
vector<ll> e;
map<vector<ll>, ll> ma;
void dfs(void){
  if (ma[e] != 0)
    return;

  
  
  if (e[n-1] > m)
    return;

  ll t = 0;
  for (int i = 0; i < q; i++){
    if (e[b[i]-1] - e[a[i]-1] == c[i])
      t += d[i];
  }
  ma[e] = 1;
  ans = max(ans, t);

  for (int i = 0; i < n - 1; i++){
    if (e[i] < e[i + 1]){
      e[i]++;
      dfs();
      e[i]--;
    }
  }
  e[n-1]++;
  dfs();
  e[n-1]--;
  
}

int main(void){
  cin >> n >> m >> q;
  a = vector<ll>(q);
  b = vector<ll>(q);
  c = vector<ll>(q);
  d = vector<ll>(q);
  for (int i = 0; i < q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }


  
  e = vector<ll>(n, 1);
  dfs();

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 27740