akhauriyash/Code-Regression huggingface dataset:
/*
  問題：
  賢王が新しい暦を定めた．
  「明日を1年1月1日と定める．
  1年には1月から10月までの10ヶ月があり，大の月から始まる．
  ふつうの年は，1月が大の月，2月は小の月，3月は大の月，
  そして最後の10月は小の月というように，大の月と小の月が交互に訪れる．
  大の月の日数は20日，小の月の日数は19日である．
  しかし，3年，6年，9年，…のように，3で割り切れる年には，小の月は訪れず，
  10すべての月を大の月とする．」

  幾年月が流れた．やがて1000年1月1日のミレニアム記念日の祝賀式において，
  誕生してからの日数が王立のくじ引きで選ばれた数と一致する国民に景品を与えることになった．
  国民らを手助けして，生まれた日からミレニアム記念日までの日数を計算するプログラムを奉ぜよ．
*/

#include <stdio.h>

/* 1年1月1日から指定された日付（誕生日）までの日数を計算 */
int days(int y, int m, int d) { // 引数は年、月、日
  int i;
  int days; // 1年1月1日から指定された日付までの日数

  /* 1年1月1日から誕生年の前年の大晦日までの日数を計算 */
  days  = 0;
  for (i = 1; i<y; i++) {
    if (i%3 == 0) { // うるう年のとき
      days += 20 * 10; // すべて大の月。一年分の日数を加算
    } else { // うるう年でないとき
      days += 20 * 5 + 19 * 5; // 一年分の日数を加算
    }
  }

  /* 誕生年の元旦から誕生月の前の月の晦日までの日数を計算して加算 */
  if (y%3 == 0) { // もしうるう年だったら
    days += 20 * (m-1); // すべて大の月。日付を加算
  } else { // もしうるう年でなかったら
    for (i = 1; i<m; i++) { // 月ごとに日数をかさん
      if (i%2 == 1) { // 大の月だったら
	days += 20; // 20日加算
      } else { // 小の月だったら
	days += 19; // 19日加算
      }
    }
  }

  /* 最後に誕生月の誕生日までの日数を加算 */
  days += d;

  return days;
}

int main(void) {
  int days_milenium = days(1000,1,1); // まずミレニアムまでの日数を求める
  int n; // データの個数
  int y, m, d; // 読み込んだ誕生日（年、月、日）
  int i;
  
  scanf("%d", &n); // データの個数を読み込む

  /* 与えられたデータだけミレニアムまでの日付を求めて表示 */
  for (i=0; i<n; i++) {
    scanf("%d %d %d", &y, &m, &d); // 誕生日を読み込む
    printf("%d\n", days_milenium - days(y, m, d) ); // 誕生日からミレニアムまでの日数を表示
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define LL long long
#define maxn 200005
#define modn 998244353

using namespace std;
int main(){
	string s;
	while(cin>>s){
		int n = s.size();
		bool ans = true;
		for(int i=0; i<n/2; i++){
			if(s[i] != s[n-1-i]){
				ans = false;
			}
		}
		for(int i=0; i<(n-1)/2; i++){
			if(s[i] != s[(n-1)/2-1-i]){
				ans = false;
			}
		}
		cout << (ans?"Yes":"No") << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    set<double> st1,st2;
    int a1=0,a2=0;
    double cct=0;
    for(int i=0;i<=f;i++){
        for(int j=0;j<=f;j++){
            if(a*i*100+b*j*100>f)break;
            st1.insert(a*i*100+b*j*100);
        }
    }
    for(int i=0;i<=f;i++){
        for(int j=0;j<=f;j++){
            if(c*i+d*j>f)break;
            st2.insert(c*i+d*j);
        }
    }
    if(c>a*e){
        a1=a*100;
        cout << a1 << " " << a2 << endl;
        return 0;
    }
    
    for(auto itr1:st1){
        for(auto itr2:st2){
            if(itr1+itr2<=f && itr2*100/itr1<=e){
                if(cct<itr2*100/itr1){
                    cct=itr2*100/itr1;
                    a1=itr1+itr2;
                    a2=itr2;
                    
                }
                
            }
            
        }
    }
    cout << a1 << " " << a2 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int N = 100 + 5;

int n, a[N], b[N], sum1[N], sum2[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        sum1[i] = sum1[i - 1] + a[i];
    }
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &b[i]);
        sum2[i] = sum2[i - 1] + b[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans = max(ans, sum1[i] + sum2[n] - sum2[i - 1]);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, K;
string S;

int section_count(string S) {
    string aSa = "a" + S;
    int res = 0;
    for(int i = 1; i < N + 1; ++i) {
        if(aSa[i] != aSa[i - 1]) {
            res++;
        }
    }
    return res;
}

int score(string S) {
    string aSa = "a" + S + "a";
    int res = 0;
    int cont = 1;
    for(int i = 1; i < N + 2; ++i) {
        if(aSa[i] == aSa[i - 1])
            ++cont;
        else {
            res += cont - 1;
            cont = 1;
        }
    }
    return res;
}

int main(int argc, char **argv) {
    cin >> N >> K >> S;

    int sections = section_count(S);
    int res = score(S);

    int X = S[0] == S[N - 1] ? 
            (sections - 1) / 2 : (sections - 2) / 2;
    
    X = min(K, X);
    sections -= X * 2;
    K -= X;
    res += X * 2;

    if(K > 0 && sections > 1) {
        res++;
    }

    cout << res << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll w,h,x,y; cin >> w >> h >> x >> y;
  double area;
  int d;
  area = ((double)w * (double)h) / 2.0d;
  if(w/2==x &&  w%2==0 && h/2==y && h%2==0){
    d=1;
  } else {
    d=0;
  }
  cout << std::fixed << std::setprecision(11)<< area << " "<< d << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[200005];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k, n;
    cin >> k >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    a[n] = k + a[0];
    int dst = 0;
    for (int i = 0; i < n; ++i)
        dst = max(dst, abs(a[i + 1] - a[i]));
    cout << k - dst;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; --i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s,t; cin >> s >> t;
    if(t.substr(0,s.size()) == s) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3644
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w + 1);
    for(int i = 0; i < n; i++){
        int w2, v;
        cin >> w2 >> v;
        for(int j = w - 1; j >= 0; j--){
            if(j + w2 <= w){
                dp[j + w2] = max(dp[j + w2], dp[j] + v);
            }
        }
        printde(dp);
    }
    printde(dp);
    cout << *max_element(dp.begin(), dp.end()) << '\n';
}


Measured memory_bytes: 1024
#include <stdio.h>

typedef struct {
  char suit;
  int num;
  int idx;
} Card;

void BubbleSort(Card C[], int N){
Card tmp;
  int stable;
  int i, j;
  for(i = 0; i < N-1; ++i) {
    for(j = N-1; j > i; --j) {
      if(C[j].num < C[j-1].num) {
        tmp = C[j];
        C[j] = C[j-1];
        C[j-1] = tmp;
      }
       }
  }
  stable = 1;
  
  for(i = 0; i < N; ++i) {
    
    printf("%c%d%c", C[i].suit, C[i].num, " \n"[i==N-1]);
    
    if(i > 0 && C[i].num == C[i-1].num && C[i].idx < C[i-1].idx)
      stable = 0;
  }
  
  puts((stable ? "Stable" : "Not stable"));
}
void SelectionSort(Card C[], int N){
  
  Card tmp;
  int minj;
  int stable;
  int i, j;
  
  for(i = 0; i < N; ++i) {
    
    minj = i;
      
    for(j = i; j < N; ++j) {
      
      if(C[j].num < C[minj].num)
	minj = j;
    }
      
    tmp = C[i];
    C[i] = C[minj];
    C[minj] = tmp;
  }
  
  stable = 1;
  
  for(i = 0; i < N; ++i) {
    
    printf("%c%d%c", C[i].suit, C[i].num, " \n"[i==N-1]);
    
    if(i > 0 && C[i].num == C[i-1].num && C[i].idx < C[i-1].idx)
      stable = 0;
  }
  
  puts((stable ? "Stable" : "Not stable"));
}

int main() {
  
  int N;
  Card C1[36], C2[36];
  int i;

  scanf("%d", &N);
  
  for(i = 0; i < N; ++i) {
    
    scanf(" %c%d", &C1[i].suit, &C1[i].num);
    C1[i].idx = i;
    C2[i] = C1[i];
  }

  BubbleSort(C1, N);
  SelectionSort(C2, N);

  return 0;
}



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

struct RMQ{
  int n=(1<<17),data[(1<<18)];
  RMQ(){
    fill(data,data+(1<<18),INT_MAX);
  }
  void update(int k,int x){
    k+=n-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=min(data[k*2+1],data[k*2+2]);
    }
  }
  int find(int a,int b,int k=0,int l=0,int r=(1<<17)){
    if(r<=a || b<=l)return INT_MAX;
    if(a<=l && r<=b)return data[k];
    int v1=find(a,b,k*2+1,l,(l+r)/2);
    int v2=find(a,b,k*2+2,(l+r)/2,r);
    return min(v1,v2);
  }
};


int main(){
  RMQ a;
  int c,x,y,n,q;
  cin>>n>>q;
  for(int i=0;i<q;i++){
    scanf("%d%d%d",&c,&x,&y);
    if(c)cout<<a.find(x,y+1)<<endl;
    else a.update(x,y);
  }
}


Measured memory_bytes: 4280
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    let mut ans = t.len();
    for i in 0..s.len() - t.len() + 1 {
        let mut cnt = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] { cnt += 1; }
        }
        if cnt < ans { ans = cnt; }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2064
// C - Sum of gcd of Tuples (Easy)
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int k;
	cin >> k;
	int sum = 0;
	for (int a = 1; a <= k; a++)
		for (int b = 1; b <= k; b++) {
			int g = __gcd(a, b);
			for (int c = 1; c <= k; c++)
				sum += __gcd(g, c);
		}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3620
#include<cstdio>
using namespace std;
#define N 1050
#define K 36
char as[N][K];
int p[N][2],n,is1,is2;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&p[i][0],&p[i][1]);p[i][0]*=-1,p[i][1]*=-1;
		if((p[i][0]+p[i][1])&1)is1=1;
		else is2=1;
	}
	if(is1&&is2){printf("-1\n");return 0;}
	if(is1)
	{
		printf("31\n");
		for(int i=0;i<=30;i++)printf("%d ",1<<i);
		printf("\n");
		for(int i=0;i<30;i++)
		{
			int le=1<<i;
			for(int j=1;j<=n;j++)
			{
				if(p[j][0]>>i&1)
				{
					if(p[j][1]>>i&2)
					{
						int tp1=p[j][0]+le;
						if(tp1>>i&2)p[j][0]-=le,as[j][i]='L';
						else p[j][0]+=le,as[j][i]='R';
					}
					else
					{
						int tp2=p[j][0]-le;
						if(tp2>>i&2)p[j][0]-=le,as[j][i]='L';
						else p[j][0]+=le,as[j][i]='R';
					}
				}
				else
				{
					if(p[j][0]>>i&2)
					{
						int tp1=p[j][1]+le;
						if(tp1>>i&2)p[j][1]-=le,as[j][i]='D';
						else p[j][1]+=le,as[j][i]='U';
					}
					else
					{
						int tp2=p[j][1]-le;
						if(tp2>>i&2)p[j][1]-=le,as[j][i]='D';
						else p[j][1]+=le,as[j][i]='U';
					}
				}
			}
			for(int i=1;i<=n;i++)
			if(p[i][1])as[i][30]=p[i][1]>0?'D':'U';else as[i][30]=p[i][0]>0?'L':'R';
		}
		for(int i=1;i<=n;i++)printf("%s\n",as[i]);
	}
	else
	{
		printf("32\n1 ");
		for(int i=0;i<=30;i++)printf("%d ",1<<i);
		printf("\n");
		for(int i=1;i<=n;i++)p[i][0]--,as[i][0]='L';
		for(int i=0;i<30;i++)
		{
			int le=1<<i;
			for(int j=1;j<=n;j++)
			{
				if(p[j][0]>>i&1)
				{
					if(p[j][1]>>i&2)
					{
						int tp1=p[j][0]+le;
						if(tp1>>i&2)p[j][0]-=le,as[j][i+1]='L';
						else p[j][0]+=le,as[j][i+1]='R';
					}
					else
					{
						int tp2=p[j][0]-le;
						if(tp2>>i&2)p[j][0]-=le,as[j][i+1]='L';
						else p[j][0]+=le,as[j][i+1]='R';
					}
				}
				else
				{
					if(p[j][0]>>i&2)
					{
						int tp1=p[j][1]+le;
						if(tp1>>i&2)p[j][1]-=le,as[j][i+1]='D';
						else p[j][1]+=le,as[j][i+1]='U';
					}
					else
					{
						int tp2=p[j][1]-le;
						if(tp2>>i&2)p[j][1]-=le,as[j][i+1]='D';
						else p[j][1]+=le,as[j][i+1]='U';
					}
				}
			}
			for(int i=1;i<=n;i++)if(p[i][1])as[i][31]=p[i][1]>0?'D':'U';else as[i][31]=p[i][0]>0?'L':'R';
		}
		for(int i=1;i<=n;i++)printf("%s\n",as[i]);
	}
}//

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n, m;
  cin >> n >> m;
  VEC<pair<LL, int>> p(m);

  REP(i, 0, m) {
    cin >> p[i].second >> p[i].first;
    --p[i].second;
  }
  VEC<pair<LL, int>> orig=p;
  sort(ALL(p));
  VEC<VEC<LL>> city(n, VEC<LL>());
  VEC<map<LL, int>> index(n);
  REP(i, 0, m) {
    city[p[i].second].push_back(p[i].first);
    index[p[i].second][p[i].first] = city[p[i].second].size();
  }
  REP(i,0,m){
      int pre = orig[i].second;
      int year = orig[i].first;
      int num = index[pre][year];
      printf("%06d%06d\n", pre+1, num);
      
  }

  return 0;
}


Measured memory_bytes: 20992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException{
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    
    if(s.equals("ABC"))
      System.out.println("ARC");
    else
      System.out.println("ABC");
  }
}

Measured memory_bytes: 32468
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000
#define F first
#define S second
#define forn(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)

using namespace std;

int h[123456];


int main(){
	int n,a,b;
	scanf("%d %d %d", &n, &a, &b);
	rep(i,n) scanf("%d", &h[i]);
	int mx = -1;
	rep(i,n) mx = max(mx, h[i]);
	int l = 0;
	int r = 2*((mx+b-1)/b+1);
	while(l!=r){
		int mid = (l+r)/2;
		ll ack = 0;
		rep(i,n){
			int mina = max(0,(h[i]-b*mid+a-b-1)/(a-b));
			ack += mina;
		}
		if(ack > mid) l = mid+1;
		else r = mid;
	}
	printf("%d\n", l);
	return 0;
}


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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m, a, b;
	cin >> n >> m;
	vector<vector<int>> v(n + 1, vector<int>());
	vector<int> dp(n + 1, -1);
	while(m--){
		cin >> a >> b;
		v[a].push_back(b);
	}
	function<int(int)> dfs;
	dfs = [&](int j){
		if(dp[j] != -1) return dp[j];
		if(v[j].empty()) return 0;
		int depth = 0;
		for(auto&x: v[j])
			depth = max(depth, dfs(x));	
		dp[j] = 1 + depth;
		return 1 + depth;
	};
	int ans = 0;
	for(int i = 1;i <= n; ++i){
		ans = max(ans, dfs(i));
	}
	cout << ans << endl;
	return 0;
}


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

namespace College
{
    class Program
    {
        static string Join(int[] input)
        {
            string result = "";

            foreach(int i in input)
                result += (" " + i.ToString());

            return result;
        }

        static void Main(string[] args)
        {
            List<List<int[]>> college = new List<List<int[]>>(){
                new List<int[]>(){
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0}
                },
                new List<int[]>(){
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0}
                },        
                new List<int[]>(){
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0}
                },
                new List<int[]>(){
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0},
                    new int[]{0, 0, 0, 0, 0, 0 ,0, 0, 0, 0}
                }
            };

            int limit = int.Parse(Console.ReadLine());

            for(int i = 0; i < limit; i++)
            {
                int[] _c = Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray();
                college[_c[0] - 1][_c[1] - 1][_c[2] - 1] = college[_c[0] - 1][_c[1] - 1][_c[2] - 1] + _c[3];
            }

            for(int j = 0; j < college.Count; j++)
            {
                List<int[]> b = college[j];

                foreach(int[] r in b)
                {
                    Console.WriteLine(Join(r));
                }

                if(j != college.Count - 1)
                    Console.WriteLine(new string('#', 20));
            }
        }
    }
}

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



int main(){
	int N, K, X, Y;
	cin>>N>>K>>X>>Y;
	int ans = 0;
	if(N > K){
		for(int i = 0; i < K; i++){
			ans += X;
		}
	
	for(int i = 0; i < N - K; i++){
		ans += Y;
	}
	}
	else {
		for(int i = 0; i < N; i++){
			ans += X;
	}
	}
	cout<<ans<<endl;
	return 0;
}

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

int func(int i){
    int val=0;
    while(i>0){
        val+=i%10;
        i/=10;
    }
    return val;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    for(int i=1;i<=n;++i){
        int val=func(i);
        if(a<=val && val<=b){
            ans+=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <vector>
#include <map>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

using ll = long long;

struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(){}
  UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};

ll N, M;
ll A[100010], B[100010];
ll ans = 0;
ll anss[100010];

int main()
{
  scanf( "%lld%lld", &N, &M );

  UnionFind uf( N+1 );

  rep( i, M )
    scanf( "%lld%lld", A+i, B+i );

  for( int i = M-1; i >= 0; --i )
  {
    anss[i] = N*(N-1)/2-ans; 

    ll preA = uf.size( A[i] ), preB = uf.size( B[i] );

    if( uf.same( A[i], B[i] ) )
      continue;

    uf.unite( A[i], B[i] );

    ans += preA*preB;
  }

  rep( i, M )
    printf( "%lld\n", anss[i] );

  return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define ALL(V) V.begin(),V.end()
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using PLL = pair<ll, ll>;
using TLL = tuple<ll, ll, ll>; // to, cost, upper

double eps = 0.0001;

bool solve() {
    ll N, M;
    cin >> N >> M;
    if(!(N + M)) return false;
    ll S, G;
    cin >> S >> G;
    S--; G--;
    VV<pair<ll, double>> edges(33 * 33 * 33 * 2 + 2);
    
    auto make_idx = [&](ll idx, ll vel, ll pre_city) { return 31 * 31 * idx + 31 * vel + pre_city; };

    auto add_edge = [&](ll from, ll to, ll dist, ll c) {
        for(ll from_c = 1; from_c <= c; from_c++) {
            for(ll add_c = -1; add_c <= 1; add_c++) {
                ll to_c = from_c + add_c;
                if(!(0 <= to_c && to_c <= 30)) continue;
                for(ll from_city = 0; from_city < N; from_city++) {
                    if(from_city == to) continue;
                    ll from_idx = make_idx(from, from_c, from_city);
                    ll to_idx = make_idx(to, to_c, from);
                    edges[from_idx].emplace_back(to_idx, (double)dist / from_c);
                }
            }
        }
    };

    for(ll i = 0; i < M; i++) {
        ll x, y, d, c;
        cin >> x >> y >> d >> c;
        x--; y--;
        add_edge(x, y, d, c);
        add_edge(y, x, d, c);
    }

    ll start_node = edges.size() - 2;
    ll goal_node = start_node + 1;
    for(ll i = 0; i < N; i++) {
        edges[start_node].emplace_back(make_idx(S, 1, i), 0);
        edges[make_idx(G, 0, i)].emplace_back(goal_node, 0);
    }

    const double inf = 5e15;

    V<double> dists(edges.size(), inf);
    priority_queue<pair<double, ll>, V<pair<double, ll>>, greater<pair<double, ll>>> pq;
    pq.emplace(0, start_node);
    dists[start_node] = 0;
    while(pq.size()) {
        double dist;
        ll now;
        tie(dist, now) = pq.top();
        pq.pop();
        if(dists[now] + eps < dist) continue;
        for(auto &&edge : edges[now]) {
            ll nxt;
            double cost;
            tie(nxt, cost) = edge;
            double nxt_dist = dist + cost;
            if(dists[nxt] < nxt_dist + eps) continue;
            dists[nxt] = nxt_dist;
            pq.emplace(nxt_dist, nxt);
        }
    }

    double ans = dists[goal_node];
    if(abs(ans - inf) < eps) cout << "unreachable";
    else cout << ans;
    cout << endl;
    return true;
}

int main() {
    cout << fixed << setprecision(30);
    while(solve());
    return 0;
}



Measured memory_bytes: 61600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MAX_INT 100000
bool inter(vector<ll> &a,vector<ll> &v,ll n,double t){
    double minr=1e9,maxl=-1e9;
    for(int i=0;i<n;i++){
        minr=min(minr,a[i]+t*v[i]);
        maxl=max(maxl,a[i]-t*v[i]);
    }
    if(maxl<=minr)return true;
    else return false;
}
int main()
{
  ll i,j,n,k;
  cin>>n;
  int flag=0;
  for(i=1;i<=n;i++){
  	cin>>k;
    if(k!=i)flag++;
  }
  if(flag<=2)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	
	int i = 0, no = 0;
	int array[10000] = { 0 };

	while (1) {
		scanf("%d", &array[i]);
		if (array[i] == 0) {
			break;
		}
		i++;
	}

	i = 1;
	
	while (1) {
		if (array[no] == 0) {
			break;
		}
		printf("Case %d: %d\n", i, array[no]);
		i++;
		no++;
	}

	return 0;
}

Measured memory_bytes: 644
#include<stdio.h>

int main(){
  long long int n,a[200001],sum=0,min=0;
  scanf("%lld",&n);
  for(int i=0;i<n;i++){
      scanf("%lld",&a[i]);
      if(min<a[i]){
          min=a[i];
        }else{
            sum+=min-a[i];
        }
  }
  printf("%lld\n",sum);
}

Measured memory_bytes: 3296
// author -> LetsGoAC
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using    namespace std;
using    namespace __gnu_pbds; 
#define  ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) cout<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
vector   <int> Fact(100005 , 0);
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int mod_inverse(int n , int m)
{   //mod = m; // change const mod;
    int modi = power(n , m-2);
    return modi;
}
int  pct(int x)
{    return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void cal_fac()
{
     Fact[0] = Fact[1] = 1;
     for(int i=2; i<1e5; i++)
         Fact[i] = (Fact[i-1]*i)%mod;
}
int C(int n , int k)
{
    int res = Fact[n];
    res = (res * mod_inverse( Fact[k] , mod ))%mod;
    res = (res * mod_inverse( Fact[n-k] ,mod ))%mod;
    return res;
}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- 1.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    //cout<<"Case #"<<tc<<": \n";
    int n,i,j,k,m,q,l,r;
    cin>>n;
    int ar[n];
    rep(i,n)
        cin>>ar[i];
    int mx = ar[0];
    int ans = 0;
    repv(i,1,n-1)
    {
        if(ar[i] < mx)
            ans += (mx - ar[i]);
        else
            mx = ar[i];
    }
    cout<<ans<<endl;
}   
signed main()
{
    // 1.cpp
    RAGE;
 //   db();  
    int t=1;
    //  cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
 //   timeit();
    return 0;
}
/*
    1. To find 2's complement , reverse all the bits after 1st set bit. (right - >left.)
*/


Measured memory_bytes: 5552
n, m = map(int, input().split())

divisors = set()

for i in range(1, int(m**0.5)+1):
    if m % i == 0:
        divisors.add(i)
        divisors.add(m//i)

divisors = sorted(list(divisors))
ans = 1

for d in divisors:
    if d <= m/n:
        ans = max(ans, d)
    else:
        break

print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <unordered_map>
#include <queue>
#include <set>
using namespace std;

bool comparison(const pair<long long, long long> &a, const pair<long long, long long> &b){
    return a.second < b.second;
}

int main(){
    int n;
    cin >> n;
    vector<pair<long long, long long> > a(n);
    for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end(), comparison);
    long long time=0;
    for (int i = 0; i < n; i++){
        time += a[i].first;
        if (time > a[i].second){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int m, f, r;
    while(1) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;
        int sum = m + f;
        
        if (m == -1 || f == -1) {
            cout << "F\n";
        } else if (sum >= 80) {
            cout << "A\n";
        } else if (sum >= 65 && sum < 80) {
            cout << "B\n";
        } else if (sum >= 50 && sum < 65) {
            cout << "C\n";
        } else if (sum >= 30 && sum < 50 && r >= 50) {
            cout << "C\n";
        } else if (sum >= 30 && sum < 50 && r < 50) {
            cout << "D\n";
        } else if (sum < 30) {
            cout << "F\n";
        }
    }
}


Measured memory_bytes: 3076
n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
for i in a[1:-1]:
    if i<0:
        print(a[-1],i)
        a[-1]-=i
    else:
        print(a[0],i)
        a[0]-=i
print(a[-1],a[0])

Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    int ans = 0;
    FOR(i, 0, n) {
        int a; cin >> a;
        bool is = true;
        for (int j = 2; j * j <= a; ++j) {
            if (a % j == 0) {
                is = false;
                break;
            }
        }
        if (is)++ans;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
long long x,a,b,j;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>x>>a>>b;

x-=a;
while(b<=x){
    x-=b;

}
cout<<x;
return 0;}



Measured memory_bytes: 3612
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

	readChars(): string[] {
		let S = this.readLine();
		return new Array(S.length).fill(null).map((_, i) => S.charAt(i));
	}

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
} 


let reader = new Reader();
let [A, B, Q] = reader.readInts();

let S: number[] = [],
	T: number[] = [];

for(let i=0; i<A; i++) {
	S.push(reader.readInt());
}

for(let i=0; i<B; i++) {
	T.push(reader.readInt());
}

function upperBound(array: number[], value: number): number {
	let low = 0,
		high = array.length-1;
	while (low < high) {
		let mid = Math.floor((low+high)/2);
		if (array[mid] < value) {
			low = mid+1;
		} else {
			high = mid;
		}
	}
	return low;
}

// console.log('S', S);
// console.log('T', T);

for(let i=0; i<Q; i++) {
	let x = reader.readInt();
	let upperS = upperBound(S, x),
		upperT = upperBound(T, x);
	// console.log('upperS', 'upperT', upperS, upperT);
	let answer = Math.min(Math.abs(x-S[upperS])+Math.abs(S[upperS]-T[upperT]),
						  Math.abs(x-T[upperT])+Math.abs(T[upperT]-S[upperS]));
	if (upperS > 0 && upperT > 0) {
		answer = Math.min(answer, Math.abs(x-S[upperS])+Math.abs(S[upperS]-T[upperT-1]));
		answer = Math.min(answer, Math.abs(x-T[upperT])+Math.abs(T[upperT]-S[upperS-1]));
		answer = Math.min(answer, Math.abs(x-S[upperS-1])+Math.abs(S[upperS-1]-T[upperT]));
		answer = Math.min(answer, Math.abs(x-S[upperS-1])+Math.abs(S[upperS-1]-T[upperT-1]));
		answer = Math.min(answer, Math.abs(x-T[upperT-1])+Math.abs(T[upperT-1]-S[upperS-1]));
		answer = Math.min(answer, Math.abs(x-T[upperT-1])+Math.abs(T[upperT-1]-S[upperS]));
	} else if (upperS > 0) {
		answer = Math.min(answer, Math.abs(x-S[upperS-1])+Math.abs(S[upperS-1]-T[upperT]));
		answer = Math.min(answer, Math.abs(x-T[upperT])+Math.abs(T[upperT]-S[upperS-1]));
	} else if (upperT > 0) {
		answer = Math.min(answer, Math.abs(x-T[upperT-1])+Math.abs(T[upperT-1]-S[upperS]));
		answer = Math.min(answer, Math.abs(x-S[upperS])+Math.abs(S[upperS]-T[upperT-1]));
	}
	console.log(answer);
}


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


long long saishou(long long x, long long y){
  
  long long a = x, b = y;
  long long r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
 
  return x * y / b;
}

int main(){
  
  long long A, B;
  cin >> A >> B;
  
  
  cout << saishou(A, B) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

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

int main() {
  ll n, a, b; cin >> n >> a >> b;
  vll p(n); REP(i, n) cin >> p[i];

  vvll dp(n+1, vll(n+1, HIGHINF));
  dp[0][0] = 0;
  REP(i, n) {
    REP(j, n+1) {
      if (dp[i][j] >= HIGHINF) continue;
      if (p[i] > j) {
        // p[i]を右にずらさない
        chmin(dp[i+1][p[i]], dp[i][j]);
        // p[i]を右にずらす
        chmin(dp[i+1][j], dp[i][j] + a);
      } else {
        // p[i]を左にずらさないといけない
        chmin(dp[i+1][j], dp[i][j] + b);
      }
    }
  }

  ll ans = HIGHINF;
  REP(i, n+1) chmin(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 195840
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)

using namespace std;

int main(void){
  int N,M,j=0,p=0;
  cin >> N >> M;
  int A[N];
  rep(i,N) cin >> A[i];
  pair<int,int> B[M];
  rep(i,M) cin >> B[i].second >> B[i].first;
  sort(B,B+M,greater<pair<int,int>>());
  int C[N]={};
  rep(j,M){
    while(B[j].second!=0){
      if(p==N)break;
      C[p]=B[j].first;
      p++;
      B[j].second--;
    }
    if(p==N)break;
  }
  int D[2*N];
  rep(i,N) D[i]=A[i];
  for(int i=N;i<2*N;i++) D[i]=C[i-N];
  sort(D,D+2*N,greater<int>());
  unsigned long long int ans=0;
  rep(i,N) ans+=D[i];
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)


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

    string s;
    cin >> s;
    int n = s.length();
    int m = 2019;
    
    vector<ll> dp(m, 0);
    dp[0] = 1;
    ll ans = 0;
    for(int i = 0; i < n; ++i){
        int num = s[i] - '0';
        vector<ll> nextdp(m, 0);
        for(int j = 0; j < m; ++j){
            if(!dp[j])  continue;
            int nj = (j * 10 + num) % m;
            nextdp[nj] += dp[j];
        }
        dp = nextdp;
        ans += dp[0]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	i64 a, b, c, d; scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	
	auto calc = [&](i64 n) {
		if(n < 0) return 0LL;
		i64 A = n / c;
		i64 B = n / d;
		i64 C = n / (c * d / std::__gcd(c, d));
		return n - (A + B - C);
	};
	
	printf("%lld\n", calc(b) - calc(a - 1));
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static BigInteger a, b;
	public static void main(String[] args) {
		while(read()){
			solve();
		}

	}
	static boolean read(){
		if(!sc.hasNext())
			return false;
		a = sc.nextBigInteger();
		b = sc.nextBigInteger();
		return true;
	}
	static void solve(){
		System.out.print(gcd(a, b) + " ");
		System.out.println(lcm(a, b, gcd(a, b)));
	}
	static BigInteger gcd(BigInteger a, BigInteger b){
		return a.gcd(b);
	}
	static BigInteger lcm(BigInteger a, BigInteger b, BigInteger gcd){
		return a.multiply(b).divide(gcd);
	}
}

Measured memory_bytes: 11000
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

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

	int A[n];
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
	}

//	4
//	2
//	1
//	6
//	3
//	5
	int L[n];
	L[0] = A[0];
	int length = 1;
	for (int i = 1; i < n; ++i) {
		if (A[i] > L[length - 1]) {
			L[length++] = A[i];
		} else {
			int left = 0;
			int right = length;
			while (left < right) {
				int mid = (left + right) / 2;
				if (L[mid] >= A[i]) {
					right = mid;
				} else {
					left = mid + 1;
				}
			}
			L[right] = A[i];
		}
	}
	cout << length << endl;

	return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S, T;
  cin >> S >> T;
  int N = S.size();
  int M = T.size();
  int ans = N;
  for (int i = 0; i <= N - M; i++){
    string S2 = S.substr(i, M);
    int cnt = 0;
    for (int j = 0; j < M; j++){
      if (S2[j] != T[j]){
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int N, M;
    cin >> N >> M;
    vector<vector<int>> s(M);
    vector<int> p(M);
    for(int i = 0; i < M; i++) {
        int K;
        cin >> K;
        s[i] = vector<int>();
        for(int k = 0; k < K; k++) {
            int tmp;
            cin >> tmp;
            s[i].push_back(--tmp);
        }
    }
    for(int i = 0; i < M; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for(int b = 0; b < (1 << N); b++) {
        bool flag = true;
        for(int i = 0; i < M; i++) {
            int acc = 0;
            for(int k = 0; k < s[i].size(); k++) {
                acc += (b >> s[i][k]) & 1;
            }
            if(acc % 2 != p[i]) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int main() {

    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;

    cout << H * W - h * W - H * w + h * w << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if(n % 2 == 0) cout << (n / 2) * (n / 2) << endl;
  else cout << (n / 2) * (n / 2 + 1) << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <stdio.h>
 
int main (void) {
    char T[200001];
    scanf("%s", T);
 
    for (int i = 0; T[i] != '\0'; i++) {
        if (T[i] == '?') {
            T[i] = 'D';
        }
    }
 
    printf("%s\n", T);
 
    return 0;
}

Measured memory_bytes: 1788
n, m = map(int, input().split())
A = []
for i in range(m):
    B = list(map(int, input().split()))
    A.append(B[1:])
P = list(map(int, input().split()))
ans = 0
for i in range(2**n):
    Q = []
    u = i
    for j in range(n):
        Q.append(u%2)
        u//=2
    pop = True
    for j in range(m):
        u = 0 
        for k in A[j]:
            if (Q[-k]==1):
                u+=1
        if ((u%2) != (P[j])):
            pop = False
            #print("!", u, P[j], j, i)
            break
    if (pop):
        ans+=1
print(ans)


Measured memory_bytes: 3064
import numpy as np
import sys

input = sys.stdin.buffer.readline

N,K = map(int,input().split())
A = np.array(input().split(),np.int64)
F = np.array(input().split(),np.int64)

A.sort()
F.sort()
F_ = F[::-1]

m = -1
M = (A*F_).sum()

while (m+1)<M:
    mid = (m+M) //2
    judge = np.maximum(0,A - mid//F_).sum() <= K
    if judge:
        M = mid
    else:
        m = mid
        
print(M)    

Measured memory_bytes: 26164
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int p[N];
    for (int i = 0; i < N; i++) cin >> p[i];
    int ans = 0;
    for (int i = 1; i < N-1; i++) {
        if (p[i-1] > p[i] && p[i+1] > p[i]) continue;
        if (p[i-1] < p[i] && p[i+1] < p[i]) continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define MX 100005
int A[MX];
int dp[MX];

int F(int n){
    if (n == 1){
        return dp[n] = 0;
    }
    if (n == 2){
        return dp[n] = abs(A[2] - A[1]);
    }
    if (dp[n] != -1) return dp[n];

    return dp[n] = min(F(n - 1) + abs(A[n] - A[n-1]),
               F(n - 2) + abs(A[n] - A[n-2]));
}

int main()
{
    int n; cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> A[i];
        dp[i] = -1;
    }
    cout << F(n) << endl;
    return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long res = 0;
        for(int i=0; i<n; i++) {
            int a = sc.nextInt();
            while(a % 2 == 0) {
                res++;
                a/=2;
            }
        }
        System.out.println(res);
    }

}


Measured memory_bytes: 35576