akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    ll d = n-v;
    Vec a(n);
    Vec s(n);
    rep(i,n)cin>>a[i];
    ll b = n-p;
    sort(ALL(a));
    rep(i,n){
        if(i==0){
            s[0] = a[0];
            continue;
        }
        if(a[i])
            s[i] = s[i-1]+a[i];
    }

//    dbg(a);
//dbg(b)
    ll L=-1,R=n-1;
    while(L+1<R){
        ll c = (L+R)/2;
        bool ok = [&]{
            bool ok2 = true;
            if(c>=b)return true;
            if(a[b]-a[c]>m){
                ok2 = false;
            }
//            dbg(c);
//            dbg(s[b]-s[c]);
//            dbg((b-c)*s[c]);
//            dbg(m*(min(p-1-c,d)));
            //右　減らせる数　//左　減らさなきゃダメな数
            if(s[b]-s[c] - (b-c) * a[c] > m * (min(b-c,d))){
                ok2 = false;
            }
            return ok2;
        }();
        if(ok){
            R = c;
        }else{
            L = c;
        }
    }

    cout<<n-R<<endl;
    return  0;
}


Measured memory_bytes: 1792
def IsUnbalanced(S):
  #長さ3のSがアンバランスかどうか判定します
  if S[0]==S[1] or S[0]==S[2] or S[2]==S[1]:
    return True
  return False


f = True

s = input()
N = len(s)
if N == 2:
  if s[0]==s[1]:
    print("1 2")
  else:
    print("-1 -1")
else:
  for i in range(N-2):
    if IsUnbalanced(s[i:i+3]):
      f = False
      print(i+1, i+3)
      break
  if f:
    print("-1 -1")

Measured memory_bytes: 3188
using System.Linq;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G() => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		var N = int.Parse(ReadLine());
		var t = G();
		var v = G();
		var V = v.Max();
		// dp[n, v] = t[0]+...+t[n-1] を走り終えたときに速度が v/2 である場合の、そこまでの最大の走行距離 * 16
		// その速度に到達できなければ dp[n, v] = -1 とする
		// 答えは dp[N, 0] / 16
		var dp = new int[N + 1, 2 * V + 1];
		dp[0, 0] = 0;
		// dp[n, v] >= 0 となる v の最大値を M[n] とする
		var M = new int[N + 1];
		for (var i = 1; i <= 2 * V; i++) dp[0, i] = -1;
		for (var n = 0; n < N; n++)
		{
			M[n + 1] = Min(M[n] + 2 * t[n], 2 * v[n]);
			for (var w = M[n + 1] + 1; w <= 2 * V; w++) dp[n + 1, w] = -1;
			for (var w = 0; w <= M[n + 1]; w++)
			{
				for (var u = 0; u <= M[n]; u++)
				{
					// dp[n, u] => dp[n+1, w]
					if (u > 2 * v[n] || u - 2 * t[n] > w || u + 2 * t[n] < w) continue;
					int au = 2 * v[n] - u,  bw = 2 * v[n] - w, run;
					// 時間に余裕があれば、加速して速度キープして減速
					if (au + bw <= 2 * t[n]) run = 2 * (8 * t[n] * v[n] - au * au - bw * bw);
					// 加速して減速、最大速度は x/4 (< v[n]) までしか到達できない
					else
					{
						var x = 2 * t[n] + u + w;
						run = x * x - 2 * (u * u + w * w);
					}
					dp[n + 1, w] = Max(dp[n + 1, w], dp[n, u] + run);
				}
			}
		}
		WriteLine(dp[N, 0] / 16m);
	}
}

Measured memory_bytes: 13436
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 2000000000
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
bool matrix[1005][1005];
int main(){
	//freopen("test.out","w",stdout);
	int n;
	scanf("%d",&n);
		int maxV=-INF;
		while(n--){
			VgetII(u,k);
			if(u>maxV) maxV=u;
			while(k--){
				VgetI(to);
				if(to>maxV) maxV=to;
				matrix[u-1][to-1]=1;
			}
		}
		F(i,0,maxV){
			F(j,0,maxV) j==maxV-1?printf("%d\n",matrix[i][j]):printf("%d ",matrix[i][j]);
			//if(i!=maxV-1) puts("");
		}
	//fclose(stdout);
}



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

#ifdef ONLINE_JUDGE
#define freopen(N, M, Q)
#endif

#define ll long long
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(N) N.begin(), N.end()

using namespace std;

const ll INF = 1e9;

int main() {
    ios_base::sync_with_stdio(false);
	//freopen("input.txt", "r", stdin);

	int a, b;
	cin >> a >> b;

    if (b <= 1)
        cout << 0 << endl;
    else
	    cout << (b + a - 3) / (a - 1) << endl;

    

    return 0;
}


Measured memory_bytes: 256
import sys
class IoTool:  # a tool for input redirection 
    DEBUG = 0
    def _reader_dbg():
        with open('./input.txt', 'r') as f:
            lines = f.readlines()
        for l in lines: yield l.strip() 
    def _reader_oj():  
        return iter(sys.stdin.read().split('\n'))
    reader = _reader_dbg() if DEBUG else _reader_oj()
    def read(): return next(IoTool.reader)

input = IoTool.read

def main():
    n, m, v, p = map(int, input().split())
    val = list(map(int, input().split()))
    val.sort(reverse=True)
    ans, presum, v = p, val[p-1], v-p+1
    for i in range(p, n):
        if val[i] + m < val[p-1] or (val[i] + m)*(i-p+1) - presum < m*(v-1-(n-i-1)):
            break
        presum += val[i]
        ans += 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 15460
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;

vector<int> dp(100010,0);
vector<vector<int> > g(100010, vector<int> ());
int N,M;

int dfs( int u ){
  if( dp[u] ) return dp[u];
  int cu = 0;
  for( int i = 0 ; i < g[u].size() ; i++ ){
    int to = g[u][i];
    int nxt = dfs( to );
    dp[u] = max( dp[u] , dp[to] + 1 );
  } 
  return dp[u];
  
}
int main(){
  cin >> N >> M;
  for( int i = 0 ; i < M ; i++ ){
    int x,y;
    cin >> x >> y;
    g[x].push_back(y);
  }
//  for( int i = 1 ; i <= N ; i++ ){
//    cout << i << ":";
//    for( int j = 0 ; j < g[i].size() ; j++ ){
//      cout << g[i][j] << " " ;
//    }
//    cout << endl;
//  }
  int ret = 0 ;  
  for( int i = 1 ; i <= N ; i++ ){
    ret = max( ret , dfs( i ) );
  }
  cout << ret << endl;
  return 0;
}


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

using namespace std;

const int N = 200000 + 7;

typedef long long ll;

void gen() {
  string s = "ABC";
  for(int i = 0; i < (N - 9) / s.size(); ++i) {
    cout << s;
  }
  cout << "\n";
}

int main() {
  //change BC to D ????

  char ch[N];
  scanf("%s", ch);
  int n = strlen(ch);
  string s = "";
  for(int i = 0; i < n; ++i) {
    if(ch[i] == 'A') s += 'A';
    else if(i + 1 < n && ch[i] == 'B' && ch[i + 1] == 'C') {
      s += 'D';
      ++i;
    } else s += 'B';
  }
  n = s.size();
  //cout << s << endl;
  long long cnt = 0;
  int p = 0;
  long long a = 0;
  while(p < n) {
    while(p < n && s[p] != 'A') {
      a = 0;
      ++p;
    }
    while(p < n && s[p] == 'A') {
      ++a;
      ++p;
    }
    long long d = 0;
    while(p < n && s[p] == 'D') {
      ++d;
      ++p;
    }
    cnt += a * d;
  }

  printf("%lld\n", cnt);

  //gen();

  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;

const int MAX_N = 3005, MOD = 1000000007;
typedef long long i64;
i64 f[2][MAX_N], C[MAX_N][MAX_N];
int L[MAX_N], R[MAX_N];
char s[MAX_N];

int main() {
  int N, M;
  
  scanf("%d%d", &N, &M);
  scanf("%s", s + 1);

  assert(strlen(s + 1) == N);
  
  for (int i = 1; i <= M; ++i) {
    scanf("%d%d", &L[i], &R[i]);
    assert(L[i] >= L[i - 1]);
    assert(L[i] < R[i]);
    assert(R[i] <= N);
    if (R[i] <= R[i - 1]) i--, M--;
    else if (L[i] == L[i - 1] && R[i - 1] <= R[i]) {
      R[i - 1] = R[i];
      i--, M--;
    }
  }
  
  for (int i = 0; i <= N; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
  }
  
  int o = 0, p;
  R[0] = L[1] - 1, f[0][0] = 1, L[M + 1] = N + 1;
  
  for (int i = 1; i <= M; ++i) {
    p = o, o ^= 1;
    memset(f[o], 0, sizeof f[o]);
    int num = 0;
    for (int j = R[i - 1] + 1; j <= R[i]; ++j)
      if (s[j] == '1') num++;
    
    int temp1 = R[i - 1] - L[i] + 1, temp2 = max(R[i] - L[i + 1] + 1, 0);
    
    for (int k1 = 0; k1 <= temp1; ++k1) {
      int num1 = num + k1, num0 = R[i] - L[i] + 1 - num1;
      if (!f[p][k1]) continue;
      for (int k2 = max(0, temp2 - num0); k2 <= min(temp2, num1); ++k2) {
	int rest1 = num1 - k2, rest0 = num0 - temp2 + k2;
	if (rest1 < 0 || rest0 < 0) continue;
	f[o][k2] = (f[o][k2] + C[rest1 + rest0][rest1] * f[p][k1] % MOD) % MOD;
      }
    }
    if (R[i] < L[i + 1] - 1) R[i] = L[i + 1] - 1;
  }

  printf("%lld\n", (f[o][0] + MOD) % MOD);
  
  return 0;
}


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

int main() {
  int k, n;
  long long s;
  s = 0;
  cin >> n >> k;
  vector<int> c(n);
  for(int i = 0; i < n; i++)
    cin >> c[i];
  sort(c.begin(),c.end());
  for(int i = 0; i < n - k; i++){
    s = s + c[i];
  }
  cout << s << endl;
}

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

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

    vector<int> P(N);
    rep(i, N) {
        cin >> P[i];
    }

    int min_num = INT_MAX;
    int count = 0;

    rep(i, N) {
        if (P[i] < min_num) {
            count++;
            min_num = P[i];
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
  string a1,a2,a3;
  int b;
  cin>>b;
  cin>>a1;
  if(b%2==1){
    cout<<"No"<<endl;
  }else{
  for(int i=0;i<b/2;i++){
    a2=a1[i]+a2;
    a3=a1[b/2+i]+a3;
  }
  if(a2==a3){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int N;

    cin >> N;

    int n = N % 10;
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
        cout << "hon" << endl;
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a[100001] = {}, cs[100001];
  rep(i, 0, n) {
    cin >> a[i + 1];
  }

  int ans = 0;
  n += 2;
  rep(i, 1, n) {
    if(a[i] >= 0 && a[i - 1] >= 0 || a[i] <= 0 && a[i - 1] <= 0) cs[i] = abs(a[i] - a[i - 1]);
    else cs[i] = abs(a[i]) + abs(a[i - 1]);
    ans += cs[i];
  }
  rep(i, 1, n - 1) {
    int kans = ans;
    kans -= cs[i], kans -= cs[i + 1];
    if(a[i - 1] >= 0 && a[i + 1] >= 0 || a[i - 1] <= 0 && a[i + 1] <= 0) kans += abs(a[i - 1] - a[i + 1]);
    else kans += abs(a[i - 1]) + abs(a[i + 1]);
    cout << kans << endl;
  }
}


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

using namespace std;

int main(){
  int n;
  cin>>n;
  long long a[100010];
  long long prod=1;
  int zero=0;
  for(int i=0;i<n;i++){  cin>>a[i];
    if(a[i]==0)zero++;}
  if(zero>0){
    puts("0");
    return 0;
  }
  for(int i=0;i<n;i++){
    if(a[i]<=1000000000000000000/prod)
      prod*=a[i];
    else{
      puts("-1");
      return 0;
    }
  }
  cout<<prod<<endl;
}


Measured memory_bytes: 4404
#include <stdio.h>

#define INF 33333333

#define KI_MAX (1 << 18) /* 262144 */

int set_value[KI_MAX * 2 - 1];
int get_value[KI_MAX * 2 - 1];

void ki_set_i(int idx, int qs, int qe, int ss, int se, int value) {
	if (qe <= ss || se <= qs) { /* 関係ない */
		/* nop */
	} else if (qs <= ss && se <= qe) { /* セグメントがクエリに完全に含まれる */
		set_value[idx] = value;
		get_value[idx] = value - (se - 1);
	} else {
		int sm = ss + (se - ss) / 2;
		int li = idx * 2 + 1, ri = idx * 2 + 2;
		if (set_value[idx] >= 0) {
			set_value[li] = set_value[ri] = set_value[idx];
			get_value[li] = set_value[idx] - (sm - 1);
			get_value[ri] = set_value[idx] - (se - 1);
			set_value[idx] = -1;
		}
		ki_set_i(li, qs, qe, ss, sm, value);
		ki_set_i(ri, qs, qe, sm, se, value);
		get_value[idx] = get_value[li] <= get_value[ri] ? get_value[li] : get_value[ri];
	}
}

void ki_set(int qs, int qe, int value) {
	if (qs < qe) ki_set_i(0, qs, qe, 0, KI_MAX, value);
}

int ki_get_i(int idx, int qs, int qe, int ss, int se) {
	if (qe <= ss || se <= qs) { /* 関係ない */
#if 0
		printf("debug! (%d %d) %d %d -> INF\n", qs, qe, ss, se);
#endif
		return INF * 3;
	} else if (qs <= ss && se <= qe) { /* セグメントがクエリに完全に含まれる */
#if 0
		printf("debug! (%d %d) %d %d -> %d\n", qs, qe, ss, se, get_value[idx]);
#endif
		return get_value[idx];
	} else if (set_value[idx] >= 0) {
#if 0
		printf("debug! (%d %d) %d %d --> %d\n", qs, qe, ss, se, set_value[idx] - ((qe <= se ? qe : se) - 1));
#endif
		return set_value[idx] - ((qe <= se ? qe : se) - 1);
	} else {
		int sm = ss + (se - ss) / 2;
		int left = ki_get_i(idx * 2 + 1, qs, qe, ss, sm);
		int right = ki_get_i(idx * 2 + 2, qs, qe, sm, se);
#if 0
		printf("debug! (%d %d) %d %d ---> %d\n", qs, qe, ss, se, left <= right ? left : right);
#endif
		return left <= right ? left : right;
	}
}

int ki_get(int qs, int qe) {
	return qs < qe ? ki_get_i(0, qs, qe, 0, KI_MAX) : INF;
}

int H, W;
int A[212345], B[212345];

int main(void) {
	int i;
	for (i = 0; i < KI_MAX * 2 - 1; i++) {
		set_value[i] = -1;
	}
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%d%d", &A[i], &B[i]) != 2) return 1;
		A[i] = W - A[i];
		B[i] = W - B[i];
	}
	for (i = 0; i < W; i++) {
		ki_set(i, i + 1, i);
	}
	ki_set(W, W + 1, INF * 2);
	for (i = 0; i < H; i++) {
		int ret;
		ki_set(B[i], A[i] + 1, ki_get(A[i] + 1, A[i] + 2) + (A[i] + 1));
#if 0
		printf("debug [%d %d %d]", B[i], A[i], ki_get(A[i] + 1, A[i] + 2));
		for(int j = 0; j <= W; j++) printf(" %d", ki_get(j, j + 1));
		puts("");
#endif
		ret = ki_get(0, W);
		printf("%d\n", ret < INF ? ret + (i + 1) : -1);
	}
	return 0;
}

/*

右か下に移動 → 右に移動すると制約が強まる

右への移動回数min

.*** 0000
*... 0123
.**. x123
.*** xxx3
.... xxxx

上が*(下移動不可)のとき、左の数字+1
上が*(下移動不可)でないとき、min(左の数字+1, 上の数字)

セグ木
範囲set
indexを引き算した値のmin

左右反転
***. 0123
...* 3333
.**. 333*
***. 3***
.... ****

上が下移動不可の範囲を、その範囲の右の値にset

*/


Measured memory_bytes: 6896
use std::process::exit;
use proconio::input;
use proconio::marker::Chars;

fn main() {
  input! {
    s: Chars,
    t: Chars,
  };
  if s.len()+1 != t.len() {
    println!("No");
    exit(0);
  }
  for i in 0..s.len() {
    if s[i] != t[i] {
      println!("No");
      exit(0);
    }
  }
  println!("Yes");
}

Measured memory_bytes: 2084
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
        int n,m;
        while(scanf("%d%d",&n, &m )!=EOF)
        {
                int t=1<< m;
                printf("%d\n", 1900 * m * t + (n-m) * 100 * t);


        }




return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstdio>
#include <ctime>
#include <random>
#include <string>

using namespace std;

int main()
{
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    long long sum = 0;
    for(int i = 0;i * R <= N;i++)
    {
        for(int j = 0;j * G <= N; j++)
        {
            int t = N - i * R - j * G;
            if(t < 0)
            {
                continue;
            }
            if(t % B == 0)
            {
                sum++;
            }
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    string s;
    cin >> s;
    ll ans = 0;
    for (int i = 0; i < 1 << (s.size() - 1); i++) {
        ll sum = 0;
        ll a = s[0] - '0';
        for (int j = 0; j < s.size() - 1; j++) {
            if (i & (1 << j)) {
                sum += a;
                a = 0;
            }
            a = a * 10 + (s[j + 1] - '0');
        }
        sum += a;
        ans += sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
unsigned int n,k,l[101][101],m[101],u[101],f,a,b,c,i,j;
#define INF 200000000
#define min(a,b)a<b?a:b
int main()
{
	for(;scanf("%d%d",&n,&k),n;)
	{
		for(i=0;i<=n;i++)
			for(j=0;j<=n;j++)
				l[i][j]=INF;
		for(;k--;)
		{
			scanf("%d",&f);
			if(!f)
			{
				scanf("%d%d",&a,&b);
				for(i=0;i<=n;i++)
					m[i]=INF,u[i]=0;
				m[a]=0;
				for(;;)
				{
					c=-1;
					for(i=1;i<=n;i++)
						if(!u[i]&&(c==-1||m[i]<m[c]))
							c=i;
					if(c==-1)break;
					u[c]=1;
					for(i=1;i<=n;i++)
						m[i]=min(m[i],m[c]+l[c][i]);
				}
				printf("%d\n",m[b]==INF?-1:m[b]);
			}
			else
			{
				scanf("%d%d%d",&a,&b,&c);
				l[a][b]=l[b][a]=min(l[a][b],c);
			}
		}
	}
	return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int K, S;
    cin >> K >> S;
    int ans = 0;
    REP0 (X, K + 1)
    {
        REP0 (Y, K + 1)
        {
            int rem = S - (X + Y);
            if (0 <= rem and rem <= K)
                ans++;
        }
    }
    std::cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
struct node
{
    string a;
    int b,id;
    bool operator<(const node&o)const
    {
        if(a==o.a) return b>o.b;
        return a<o.a;
    }
}p[105];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].a>>p[i].b;
        p[i].id=i;
    }
    sort(p+1,p+1+n);
    for(int i=1;i<=n;i++)
        printf("%d\n",p[i].id);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  // fast;
  map<string,int> days = {{"SUN",0},
                          {"MON",1},
                          {"TUE",2},
                          {"WED",3},
                          {"THU",4},
                          {"FRI",5},
                          {"SAT",6} } ;

  string s1; cin >> s1;
  int i = days[s1] , d = days[s1];
  int c = 0;

  do{
    c++;
    i = (i+1)%7;
  }while(i!=0);

  cout << c;
  return 0;
}

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

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

using namespace std;

const ll inf=8e18;
const int mod=1e9+7;
const int M=100005;
const int lim=5005;
int n,m,s;
vector<pp>adj[52];
int dp[52][lim+5];
int coin[52],cost[52];
 main()

{
    fast
    cin>>n>>m>>s;
    s=min(s,lim);
    f(i,1,m)
    {
        int u,v,a,b;
        cin>>u>>v>>a>>b;
        adj[u].pb(node(v,a,b));
        adj[v].pb(node(u,a,b));
    }
    f(i,1,n)f(j,0,lim)dp[i][j]=inf;
    f(i,1,n)
    {
        cin>>coin[i]>>cost[i];
    }
    priority_queue<pp,vector<pp>,greater<pp> >pq;
    pq.push(node(0,1,s));
    dp[1][s]=0;
    while(!pq.empty())
    {
        pp tmp=pq.top();
        pq.pop();
        int u=tmp.si.fi;
        int silver=tmp.si.si;
        int c=tmp.fi;
        if(dp[u][silver]<c)continue;
        if(silver+coin[u]<=lim){
            int tval=silver+coin[u];
          if(dp[u][tval]>(dp[u][silver]+cost[u]))
          {
              dp[u][tval]=dp[u][silver]+cost[u];
              pq.push(node(dp[u][tval],u,tval));
        }
        }
        for(auto x:adj[u])
        {
            int v=x.fi;
            int w_silver=x.si.fi;
            int w_min=x.si.si;
            if(silver-w_silver<0)continue;
            if(dp[v][silver-w_silver]>dp[u][silver]+w_min)
            {
                dp[v][silver-w_silver]=dp[u][silver]+w_min;
                pq.push(node(dp[v][silver-w_silver],v,silver-w_silver));
            }

        }
    }
    f(i,2,n)
    {
        int ses=inf;
        f(j,0,lim)
        {
            ses=min(ses,dp[i][j]);
        }
        cout<<ses<<"\n";
    }
    return 0;

}






































Measured memory_bytes: 11388
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
H = LIST()

H = [-INF] + H

ma = 0
ma2 = 0
for i in reversed(range(1, N + 1)):
	if H[i] <= H[i - 1]:
		ma += 1
		if ma2 < ma:
			ma2 = ma
	else:
		ma = 0

print(ma2)

Measured memory_bytes: 16312
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >>s;
  string t="CODEFESTIVAL2016";
  int count=0;
  for(int i=0;i<16;i++){
    if(s[i]!=t[i])count++;
  }
  cout <<count <<endl;
}

Measured memory_bytes: 256
while True:
    try:
        s=input()
        J=0
        I=0
        for i in range(len(s)-2):
            m=s[i]+s[i+1]+s[i+2]
            if m=="JOI":
                J+=1
            elif m=="IOI":
                I+=1
        print(J)
        print(I)
    except:
        break


Measured memory_bytes: 5572
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define ll long long int 
#define pii pair<int, int>
#define fi first
#define se second
#define maxn 300020
using namespace std;

int n, k, a[2][maxn];

int main(){ 
	scanf("%d%d", &n, &k);
	rep(i, 1, n) scanf("%d", a[0] + i);
	int d = 0;
	while (k--){ 
		rep(i, 1, n) a[d ^ 1][i] = 0;
		rep(i, 1, n){
			a[d ^ 1][max(i - a[d][i], 1)]++;
			a[d ^ 1][min(n + 1, i + a[d][i] + 1)]--;
		}
		d ^= 1;
		rep(i, 1, n) a[d][i] += a[d][i - 1];	
		bool f = 1;
		rep(i, 1, n) if (a[d][i] != a[d ^ 1][i]) {f = 0; break;}
		if (f) break;
	}
	rep(i, 1, n) printf("%d ", a[d][i]);
	return 0;
}



Measured memory_bytes: 5396
#include <iostream>
#include <string>
using namespace std;
using ll = long long;

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    string ans;
    while(a > 0 && c > 0){
        c-= b;
        if(c <= 0){
            ans = "Yes";
            break;
        }
        a -= d;
        if(a <= 0) {
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cctype>
#include <string>

using namespace std;
     
int main() {
  std::string s;
  cin >> s;
  int ans1, ans2;
  int s1,s2,s3,s0;
  s0 = s[0] - '0';
  s1 = s[1] - '0';
  s2 = s[2] - '0';
  s3 = s[3] - '0';
  
  if (s0 == 0) {
    if(s1<=9&s1>=1){
      ans1 = 0;
    } else {
      ans1 = 1;
    }
  } else if (s0==1) {
    if(s1<=2&s1>=0){
      ans1 = 0;
    } else {
      ans1 = 1;
    }
  } else {
    ans1 = 1;
  }
  
  if (s2 == 0) {
    if(s3<=9&s3>=1){
      ans2 = 0;
    } else {
      ans2 = 1;
    }
  } else if (s2==1) {
    if(s3<=2&s3>=0){
      ans2 = 0; 
    } else {
      ans2 = 1;
    }
  } else {
    ans2 = 1;
  }
    
  if (ans1 == 0 && ans2 == 0){
    cout << "AMBIGUOUS" << endl;
  } else if (ans1 == 0 && ans2 == 1){
    cout << "MMYY" << endl;
  } else if (ans1 == 1 && ans2 == 0){
    cout << "YYMM"<< endl;
  } else if (ans1 == 1 && ans2 == 1){
    cout << "NA"<< endl;
  }
   
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main(){
  std::cout<<std::fixed<<std::setprecision(9);
	double W, H, x, y; cin >> W >> H >> x >> y;
  double ans;
  ans = (1.0*W*H)/2.0;

  if((x==W/2)&&(y==H/2)){
    cout << ans << ' ' << 1 << endl;
  }else if((x==W/2)||(y==H/2)){
    cout << ans << ' ' << 0 << endl;
  }else{
    cout << ans << ' ' << 0 << endl;
  }

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int B[25],A[25][25];
int main()
{
    int n,m,c;
    scanf("%d%d%d",&n,&m,&c);
    for(int i=1;i<=m;i++) scanf("%d",&B[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) scanf("%d",&A[i][j]);
    int s=0;
    for(int i=1;i<=n;i++)
    {
        int ans=c;
        for(int j=1;j<=m;j++)
            ans+=A[i][j]*B[j];
        if(ans>0) s++;
    }
    printf("%d\n",s);
}


Measured memory_bytes: 256
a,b,c,x,y = map(int,input().split())
c *= 2
ans = 10 ** 16
for i in range(max(x,y) + 1):
    p = 0
    p += c * i
    p += a * (max(0,x - i))
    p += b * (max(0,y - i))
    ans = min(ans,p)
print(ans)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

map<int, int> prime_factor(int n){
    map<int, int> res;
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n]++;
    return res;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p;
    cin >> n >> p;
    map<int, int> mp = prime_factor(p);
    int ans = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        int tmp = it -> second;
        while(tmp >= n){
            ans *= it -> first;
            tmp -= n;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int getMin(int min, int &wild){
    if (min == 0){
      	wild--;
        return 1;
    }else{
        return min;
    }
}
 
int getMax(int min, int wild){
    int max = 0;
    
    // if (min + wild >= 8){
    //     max = 8;
    // }else{
    //     max = min + wild;
    // }
    max = min + wild;
 
    return max;
}
 
int main(){
 
    int n;
    cin >> n;
 
    vector<bool> colors(8, false);
    int wild = 0;
 
    for (int i = 0; i<n; i++){
        int a;
        cin >> a;
        if (a >= 3200){
            wild++;
            continue;
        }
        
        colors.at(a/400) = true;
    }
 
    int min = 0;
    int max = 0;
 
    for (bool i: colors){
        if (i){
            min++;
        }
    }
 
    min = getMin(min, wild);
    max = getMax(min, wild);
    
    cout << min << " " << max << endl;
 
    return 0;    
}

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

int main(void) {
	int R, P, Q,min;
		cin >>P>>Q>>R;
		min = P + Q;
		if (min > R + Q)
			min = Q + R;
		if (min >  P+ R)
			min = P + R;

		cout << min;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main() {
    int n; cin >> n;
    cout << 1110 - n << endl;
}

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

int main() {
  string s,t; cin >> s >> t;
  ll a = s.size();
  ll b = 0;
  for(ll i = 0; i<a; i++){
    if(s[i]!=t[i]) b++;
  }
  cout << b << endl;
    
  return 0;
}

Measured memory_bytes: 3912
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>

using namespace std;

int main(){
	int32_t n;
	cin>>n;
	int32_t *a = new int32_t[n];
	for(int32_t i1=0;i1<n;i1++){
		cin>>a[i1];
	}
	int32_t sc=1;
	int32_t prev=100000;
	int32_t ans=0;
	for(int32_t i1=0;i1<n;i1++){
		if(prev==a[i1]){
			sc++;
		}else{
			ans+=sc/2;
			prev=a[i1];
			sc=1;
		}
	}
	ans+=sc/2;
	cout<<ans<<endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
bool is_square(int n)
{
    for (int i = 0; i <= n; i++)
    {
        if (i * i == n)
        {
            return true;
        }
    }
    return false;
}

int main()
{
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int n = min(x, y);
    int ans = 0;
    if (a + b < 2 * c)
    {
        ans += n * (a + b);
    }
    else
    {
        ans += n * c * 2;
    }
    if (a < 2 * c)
    {
        ans += a * (x - n);
    }
    else
    {
        ans += 2 * c * (x - n);
    }
    if (b < 2 * c)
    {
        ans += b * (y - n);
    }
    else
    {
        ans += 2 * c * (y - n);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2])
print(dp[n-1])

Measured memory_bytes: 20412
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

long long int dp[3][100001];

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

    vector<int>a(n);
    vector<int>b(n);
    vector<int>c(n);

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

    for(int i = 0;i < 3;i++)
        for(int j = 0;j < 100001;j++)
            dp[i][j] = 0;

    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j < 3;j++){
            if(j == 0)dp[j][i+1] = max(dp[j+1][i]+a[i+1],dp[j+2][i]+a[i+1]);
            else if(j == 1)dp[j][i+1] = max(dp[j-1][i]+b[i+1],dp[j+1][i]+b[i+1]);
            else dp[j][i+1] = max(dp[j-2][i]+c[i+1],dp[j-1][i]+c[i+1]);
        }
    }

    cout << max({dp[0][n-1],dp[1][n-1],dp[2][n-1]}) << endl;

    return 0;
}

Measured memory_bytes: 3712
import itertools
N, M = list(map(int, input().split()))
path = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    path[a-1][b-1] = 1
    path[b-1][a-1] = 1

count = 0

for p in itertools.permutations(range(N)):
    if p[0] != 0:
        break
    check = 1
    for search in range(N-1):
        check = check * path[p[search]][p[search+1]]
    count += check

print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int dx[] = {0, 0, 1, -1};
constexpr int dy[] = {1, -1, 0, 0};

double heron(double a, double b, double c)
{
    double s = (a + b + c) / 2;
    return sqrt(s * (s - a) * (s - b) * (s - c));
}

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

    int x[3], y[3];

    REP(i, 3)
    cin >> x[i] >> y[i];

    double l = 0, r = 10000;

    REP(a, 100)
    {
        double mid = (l + r) / 2;

        double d[3];
        double dsum = 0;

        REP(i, 3)
        {
            d[i] = sqrt((x[i] - x[(i + 1) % 3]) * (x[i] - x[(i + 1) % 3]) +
                        (y[i] - y[(i + 1) % 3]) * (y[i] - y[(i + 1) % 3]));
            dsum += d[i];
        }

        double ir = heron(d[0], d[1], d[2]) * 2 / dsum;

        double rt = 1 - mid / ir;

        bool check = false;

        REP(i, 3)
        check |= (rt * d[i]) >= 2 * mid;

        if (check)
            l = mid;
        else
            r = mid;
    }

    cout << setprecision(15) << l << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
int main()
{
  int a;
  ll b, n;
  cin >> a >> b >> n;
  ll c = a * (b - 1) / b;
  ll d = a * n / b;
  ll ans = min(c, d);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
S = input()[::-1]

res = 0
tmp = [0] * 2019
tmp[0] = 1
sum_of_digits = 0
d = 1

for c in S:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    tmp[sum_of_digits] += 1

for t in tmp:
    res += (t * (t - 1)) // 2

print(res)


Measured memory_bytes: 9108
N = int(input())
A = list(map(int, input().split(' ')))
if len(A) != N:
    raise ValueError('N個の整数を入力してください。')
elif N < 1 or N > 100:
    raise ValueError('1から100までの整数を入力してください')

frag = 1
count = 0

def print_num(A):
    for i in range(len(A)):
        if i != N-1:
            print(A[i], end=' ')
        else:
            print(A[i])
    
while frag:
    frag = 0
    for j in reversed(range(1, N)):
        if A[j]<A[j-1]:
            v = A[j]
            A[j] = A[j-1]
            A[j-1] = v
            frag = 1
            count += 1
            
print_num(A)
print(count)



Measured memory_bytes: 5612
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import math
from collections import defaultdict


def main():
    n = int(input().strip())

    divs = get_divs(n)
    ans = 0
    for p in divs:
        ans += s_to_n(divs[p])
    print(ans)


def get_divs(n: int) -> dict:
    divs = defaultdict(int)
    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            divs[i] += 1
            n //= i
    if n != 1:  # n が残ってたら、それも入れる
        divs[n] += 1
    return divs


def s_to_n(s: int):
    ss = 0
    n = 1
    while ss < s:
        n += 1
        ss += n
    return n - 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 9484
a,b,k = map(int, input().split())
d=[]
for i in range(a,a+k):
    if a <= i <= b:
        if not i in d:
            d.append(i)
            print(i)
for i in range(b-k+1,b+1):
    if a <= i <= b:
        if not i in d:
            d.append(i)
            print(i)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int d5 = 1000000000;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,s;
    cin>>n>>k>>s;
    int cnt=k;
    vector<int> res(n);
    if(s==1){
        for(int i=0;i<k;i++){
            res[i]=s;
        }
        for(int i=k;i<n;i++){
            res[i]=d5-16;
        }
    }
    else if(n==k){
        for(int i=0;i<n;i++){
            res[i]=s;
        }
    }else{
        res[0]=s-1;
        for(int i=1;i<n;i++){
            if(cnt){
                if(res[i-1]==1){
                    res[i]=s-1;
                }else{
                    res[i]=1;
                }
                cnt--;
            }
            else{
                res[i]=d5-16;
            }
        }
    }
    for(auto it:res){
        cout<<it<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 2176
use std::cmp::{max, min};
use std::collections::VecDeque;

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

fn main() {
    input! {
        n: usize,
        m: usize,
        ab: [(usize1, usize1);m],
    }

    let mut pairs = vec![vec![]; n];
    for pair in ab {
        pairs[pair.0].push(pair.1);
        pairs[pair.1].push(pair.0);
    }
    let pairs = pairs;
    // println!("{:?}", pairs);

    let mut seen = vec![false; n];
    seen[0] = true;
    println!("{}", dfs(0, &pairs, &mut seen));
}

fn dfs(i: usize, pairs: &[Vec<usize>], seen: &mut [bool]) -> usize {
    if seen.iter().all(|&b| b) {
        return 1;
    }

    let mut cnt = 0;
    for &next in pairs[i].iter() {
        if seen[next] {
            continue;
        }
        seen[next] = true;
        cnt += dfs(next, pairs, seen);
        seen[next] = false;
    }
    cnt
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n, a, b;
  cin >> n >> a >> b;
  ll d = b-a;
  if (d%2 == 1) {
    cout << "Borys" << endl;
  } else {
    cout << "Alice" << endl;
  }
}


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

int h, w;
int d[22][22];
string s[22];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> s[i];
    int ans = 0;
    for (int sy = 0; sy < h; sy++) {
        for (int sx = 0; sx < w; sx++) {
            if(s[sy][sx] == '#') continue;
            for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) d[i][j] = 10101;
            queue<pair<int, int>> que;
            que.push({sy, sx});
            d[sy][sx] = 0;
            while(que.size()) {
                int y, x;
                tie(y, x) = que.front();
                que.pop();
                for (int i = 0; i < 4; i++) {
                    int ny = y + dy[i], nx = x + dx[i];
                    if(ny < 0 || ny >= h || nx < 0 || nx >= w || s[ny][nx] == '#') continue;
                    if(d[ny][nx] != 10101) continue;
                    d[ny][nx] = d[y][x] + 1;
                    que.push({ny, nx});
                }
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if(s[i][j] == '#') continue;
                    ans = max(ans, d[i][j]);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
x=[]
y=[]
a=[]
for i in range(n):
    a1,b,c=map(int,input().split())
    x.append(a1)
    y.append(b)
    a.append(c)

w1=0#左の削り
w2=0#右の削り
h1=0#下の削り
h2=0#上の削り
for i in range(n):
    if a[i]==1:
        w1=max(w1,x[i])
    if a[i]==2:
        w2=max(w2,w-x[i])
    if a[i]==3:
        h1=max(h1,y[i])
    if a[i]==4:
        h2=max(h2,h-y[i])


if (w-w1-w2)<0 and (h-h1-h2)<0:
    print(0)
else:
    print(max(0,(w-w1-w2)*(h-h1-h2)))




Measured memory_bytes: 3064
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
const int MAXN = 1e5 + 10;
#define LOCAL


map<string, int> m;
int main() 
{
	ios::sync_with_stdio(false);
	cout.tie(0), cin.tie(0);
	int t;
	cin >> t;
	string s;
	for (int i = 0; i < t; i++) {
		cin >> s;
		m[s]++;
	}
	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] <<endl;
    return 0;
}

Measured memory_bytes: 3664
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int x,a,b,c,t;
  cin >> a >> b >> c >> x;
  t = 0;
  REP(i,a+1){
    REP(j,b+1){
      REP(k,c+1){
        if (x==500*i+100*j+50*k) {
          t++;
        }
      }
    }
  }
  cout << t;
  return 0;
}

Measured memory_bytes: 256