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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define all(v) (v).begin(), (v).end()
#define pb push_back

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

    ll n,ans;
    string s,t,ssub,tsub;
    cin >> n >> s >> t;
    ans = 2 * n;
    rep(i,n){
        ssub = s.substr(i);
        tsub = t.substr(0,n-i);
        if(ssub==tsub){
            ans -= (n-i);
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

AC = {}
WA = {}
PE = {}
for x in range(M):
    p, S = input().split()
    if S == "AC":
        AC[p] = {"AC"}
        if p in WA:
            PE[p] = WA[p]
    else:
        if p not in AC:
            if p not in WA:
                WA[p] = 1
            else:
                WA[p] += 1

print(len(AC), sum(PE.values()))


Measured memory_bytes: 78680
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " : " << x << endl
long long n, i, a[200001], ans, cnt[200001];
int main ()
{
    cin >> n;
    for(i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt[a[i]]++;
    }
    for(i = 1; i <= n; i++)
    {
        if(cnt[i] > 1)
        {
            ans += cnt[i] * (cnt[i]-1) / 2;
        }
    }
    for(i = 1; i <= n; i++)
    {
        cout << ans + 1 - cnt[a[i]] << endl;
    }
}


Measured memory_bytes: 4736
function Main(input) {
  input = input.split(' ').map(value => parseInt(value));

  const [N, M] = input;

  let ans = []
  if (N % 2){
    for (let l = 1, r = N - 1; l < r; l++, r--){
      ans.push(l + ' ' + r);
    }
  } else {
    let flag = false;
    for (let l = 1, r = N - 1; l < r; l++, r--) {
      if (!flag && r-l <= N/2){
        --r
        flag = true;
      }
      ans.push(l + ' ' + r );
    }
  }
  
  for (let i = 1; i <= M; i++){
    console.log(ans[i-1]);
  }
}

// Main('12 5')

// Don't edit this line!
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 58968
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a1: i32 = read();
    let a2: i32 = read();
    let a3: i32 = read();

    let ans = if a1 + a2 + a3 >= 22 { "bust" } else { "win" };

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <cstdio>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 200010;
long fac[MAX], inv[MAX], finv[MAX];
void init(){
  fac[0] = inv[0] = finv[0] = 1;
  fac[1] = inv[1] = finv[1] = 1;
  for(int i=2; i<MAX; ++i){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

ll comb(ll n, ll k) {
  ll res = 1;
  for(int i = 1; i <= k; ++i) {
    res = res * ((n - (i - 1)) * inv[i] % MOD) % MOD;
  }
  return res;
}

ll modpow(ll x, ll e) {
  ll res = 1;
  while(e) {
    if (e&1) res = res * x % MOD;
    x = x * x % MOD;
    e >>= 1;
  }
  return res;
}

ll n, a, b;

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> n >> a >> b;
  init();

  ll ans = modpow(2, n) - 1;
  ans = (ans - comb(n, a) + MOD) % MOD;
  ans = (ans - comb(n, b) + MOD) % MOD;
  cout << ans;
  return 0;
}



Measured memory_bytes: 4992
P = 10**9 + 7
N, M = map(int, input().split())
A = sorted([int(a) for a in input().split()])[::-1]
B = sorted([int(a) for a in input().split()])[::-1]

AA = [-1] * (N*M+1)
BB = [-1] * (N*M+1)

for i in range(N):
    AA[A[i]] = i
for i in range(M):
    BB[B[i]] = i
    
r = 0
c = 0
n = N * M

ans = 1
for i in range(N-1):
    if A[i] == A[i+1]:
        ans = 0
        break
for i in range(M-1):
    if B[i] == B[i+1]:
        ans = 0
        break

done = 0
if A[0] < N*M or B[0] < N*M:
    print(0)
else:
    while n > 0:
        if r+1 < N and A[r+1] == n:
            r += 1
        if c+1 < M and B[c+1] == n:
            c += 1

        if A[r] == n and B[c] == n:
            pass
        elif A[r] == n:
            ans *= (c+1)
            ans %= P
        elif B[c] == n:
            ans *= (r+1)
            ans %= P
        else:
            ans *= max((c+1)*(r+1) - done,0)
            ans %= P

        n -= 1
        done += 1

    print(ans)

Measured memory_bytes: 18804
N, M = map(int, input().split())
H = list(map(int, input().split()))
hlist = [0] * N
clist = [0] * N
cnt = 0

for i in range(M):
  A, B = map(int, input().split())
  clist[A-1] += 1
  clist[B-1] += 1
  if H[A-1] > H[B-1]:
    hlist[A-1] += 1
  elif H[A-1] < H[B-1]:
    hlist[B-1] += 1

for i in range(N):
  if hlist[i] == clist[i]:
    cnt += 1

print(cnt)

Measured memory_bytes: 20040
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int INF = 1e9 + 7;

int a[100005], b[100005];

int32_t main()
{
	IO_OP;
	
	int n;
	cin >> n;
	for(int i=0;i<n+1;i++)
		cin >> a[i];
	for(int i=0;i<n;i++)
		cin >> b[i];	
	int ans = 0;
	for(int i=0;i<n;i++) {
		int d = min(b[i], a[i]);
		b[i] -= d, a[i] -= d, ans += d;
		d = min(b[i], a[i+1]);
		b[i] -= d, a[i+1] -= d, ans += d;
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
s=input()

def kaibun(w):
    for i in range(len(w)):
        if w[i]!=w[len(w)-1-i]:
            return False
    return True
n=len(s)
print("Yes") if all([kaibun(s) , kaibun(s[:(n-1)//2]) , kaibun(s[(n+3)//2-1:])]) else print("No")

Measured memory_bytes: 61108
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ct_2=0;
	while(n>0)
	{
		int r = n%10;
		if(r==2)
		{
			ct_2++;
		}
		n/=10;
	}
	cout<<ct_2<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int ans=0;
    string s,s1;
    cin >> s >> s1;
    size_t n = s.size();
    rep(i,n){
        if( s[i]!=s1[i] )ans++;
    }
    if(ans==0) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}



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


def main():
    N = int(input())
    V = list(map(int, input().split()))
    C = list(map(int, input().split()))
    result = 0
    for c, v in zip(V, C):
        if c - v > 0:
            result += c - v

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll k; cin>>k;
	vector<ll> num(n,0);
	REP(i,k){
		ll d; cin>>d;
		REP(j,d){
			ll a;
			cin>>a;
			num[--a]++;
		}
	}
	ll ans=0;
	REP(i,n){
		if(num[i]==0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3628
int main(void){
  int a[4][13];
  int n,m,i,j,num;
  char mark;
  scanf("%d",&n);
  for(i=0;i<4;i++){
    for (j=0;j<13;j++){
      a[i][j]=0;
    }
  }
  for (i=0;i<n;i++){
    /*printf("%d\n",i);*/
    scanf(" %c %d",&mark,&num);
    if(mark=='S')  a[0][num-1]=1;
    else if (mark=='H')a[1][num-1]=1;
    else if (mark=='C')a[2][num-1]=1;
    else a[3][num-1]=1;
  }
  for (i=0;i<4;i++){
    for (j=0;j<13;j++){
      if (a[i][j]==0){
	if (i==0) printf("S %d\n",j+1);
	else if (i==1) printf("H %d\n",j+1);
	else if (i==2) printf("C %d\n",j+1);
        else printf("D %d\n",j+1);
      }    
    }
  }
  return 0;
}

Measured memory_bytes: 596
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();

        int[] dp = new int[N + 1];

        for (int i = 1; i <= N; i++) {
            dp[i] = 1 + Math.min(dp[i - maxPow(6, i)], dp[i - maxPow(9, i)]);
        }

        out.println(dp[N]);
    }

    // pow(a, n) <= b なる最大の pow(a, n) を求める
    static int maxPow(int a, int b) {
        int x = 1;
        while (x <= b) {
            x *= a;
        }
        return x / a;
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (!isDelimiter(c)) {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (isDelimiter(next()));
        back();
    }

    char[] s(int N) {
        char[] cbuf = new char[N];
        read(cbuf, 0, N);
        return cbuf;
    }

    public int read(char[] cbuf, int off, int len) {
        skip();
        int i;
        for (i = 0; i < cbuf.length; i++) {
            char c = next();
            if (isDelimiter(c)) {
                break;
            }
            cbuf[i] = c;
        }
        return i;
    }

    boolean isDelimiter(char c) {
        return c == ' ' || c == '\n' || c == '\r';
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 32844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  ll a[N];
  ll r[N] = {0};
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  r[0] = a[0];
  for (int i = 1; i < N; i++) {
    r[i] = r[i - 1] + a[i];
  }
  ll ans = 9999999999999;
  for (int i = 0; i < N - 1; i++) {
    ans = min(ans,abs(r[N - 1] - r[i] - r[i]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = input()

score = 0
back = 0

for fst in range(K):
  index = fst
  while True:
    ch = T[index]
    if ch != back:
      back = ch
      if ch == "r":
        score += P
      elif ch == "p":
        score += S
      else:
        score += R
    else:
        back = 0
    
    index += K
    if index >= N:
      break
  back = 0
  
print(score)
  

Measured memory_bytes: 3316
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define fo(i,j,k) for(int i=j;i<=k;++i)
#define fd(i,j,k) for(int i=j;i>=k;--i)
using namespace std;
const int N=2e5+10,mo=1e9+7;
int wz[N],a[N],f[N];
int main()
{
	int n;
	scanf("%d",&n);
	f[0]=1;
	fo(i,1,n){
		int x;
		scanf("%d",&x);
		f[i]=f[i-1];
		if(wz[x] && wz[x]<i-1) f[i]=(f[i]+f[wz[x]])%mo;
		wz[x]=i;
	}
	printf("%d",f[n]);
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
int N;
void solve() {
	vector<LL> A(N);
	cin >> A;
	for (int i : range(N)) {
		if (A[i] > i) {
			cout << -1 << endl;
			return;
		}
	}
	vector<pair<int, int>> seg;
	seg.push_back({ 0,1 });
	for (int i : range(1,N)) {
		if (A[i] == A[i - 1] + 1)seg.back().second++;
		else seg.push_back({ i - A[i],i + 1 });
	}
	int s = seg.size();
	LL ret = seg[0].second-seg[0].first-1;
	for (int i : range(1, s)) {
		if (seg[i - 1].first > seg[i].first) {
			cout << -1 << endl; return;
		}
		else {
			ret += seg[i].second - seg[i].first - 1;
		}
	}
	cout << ret << endl;
}
int main() {
	while (cin >> N) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4980
#include<stdio.h>

int main(void)
{
  int H[10000], W[10000];
  int i=0, j, k;
  int num;

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

  num=i;
  for(i=0;i<num;i++)
    {
      for(j=1;j<=H[i];j++)
	{
	  for(k=1;k<=W[i];k++)
	    {
	      if (j%2==1 && k%2==1)
		printf("#");
	      else if (j%2==0 && k%2==0)
		printf("#");
	      else
		printf(".");
	    }
	  printf("\n");
	}
      printf("\n");
    }

  return 0;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const int MOD = (int)1e9 + 7;
const long double PI = acos(-1.0L);

int main() {  // TODO
  int N;
  ll W;
  int MAX_V = 100100;
  cin >> N >> W;
  int value[N], weight[N];
  rep(i, N) cin >> weight[i] >> value[i];

  vector<vector<ll>> dp(N + 1, vector<ll>(MAX_V));
  rep(i, N + 1) rep(j, MAX_V) dp[i][j] = 1e18;
  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
      if (sum_v >= value[i]) {
        dp[i + 1][sum_v] =
            min(dp[i][sum_v - value[i]] + weight[i], dp[i + 1][sum_v]);
      }
      dp[i + 1][sum_v] = min(dp[i][sum_v], dp[i + 1][sum_v]);
    }
  }

  ll ans = 0;
  for (int v = 0; v < MAX_V; v++) {
    if (dp[N][v] <= W) {
      ans = v;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 83236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

class Main {

	public static void main (String [] a) throws ParseException{
		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
		String line;
		ArrayList<String> days = new ArrayList<String>();
		
		try {
			while ((line = stdin.readLine()) != null && 
					line.length()!= 0 ) {
				
				try {
					
					String[] tempInput = line.split(" ");
					
					if (tempInput[0].equals("0") || tempInput[1].equals("0") ){
						break;
					}
					
					if (tempInput.length == 2){
						String inputDate = tempInput[0] + "/" + tempInput[1] + "/2004";
						
						SimpleDateFormat format1 = new SimpleDateFormat("M/d/yyyy");
						Date testDate = format1.parse(inputDate);
						
						String pattern = "EEEE";
					    SimpleDateFormat format = new SimpleDateFormat(pattern);
					    
				        days.add(format.format(testDate));
					} else {
					}
					
				} catch (IllegalArgumentException e){
					// TODO Auto-generated catch block
					//e.printStackTrace();
				}
			}
			
			for (String s: days){
				System.out.println(s);
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			//e.printStackTrace();
		}
	}
	
}

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

n = 50
print(n)
a = [i + (K//n) for i in range(n)]

r = K%n
for i in range(n):
    if i <  r:
        a[i] = a[i] + n - r + 1
    else:
        a[i] = a[i] - r
    
print(*a)

Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n;
const int maxn=1e5+5;
char s[maxn],s2[maxn];
int sum[30];
int pos[30][maxn];
int sum2[30];
int main()
{
    scanf("%s",s+1);
    scanf("%s",s2+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    {
        sum[s[i]-'a']++;
        pos[s[i]-'a'][sum[s[i]-'a']]=i;
    }
    int m=strlen(s2+1);
    int t=0,res=0,now=0;
    for(int j=0;j<=30;j++)
            sum2[j]=1;
    for(int i=1;i<=m;i++)
    {
        int k=s2[i]-'a';
        if(sum[k]==0)
        {
            printf("-1");
            return 0;
        }
        while(pos[k][sum2[k]]<now && pos[k][sum2[k]])
        {
            sum2[k]++;
        }
        if(pos[k][sum2[k]]>now)
        {
            now=pos[k][sum2[k]];
            sum2[k]++;
        }
        else
        {
            for(int j=0;j<=30;j++)
                sum2[j]=1;
            res++;
            now=pos[k][sum2[k]];
            sum2[k]++;
        }
        //cout<<now<<endl;
    }
    ll ans=(ll)res*n+now;
    printf("%lld",ans);
    return 0;
}


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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int N;
  scanf("%d", &N);
  vi f(N, 0); int x = 0;
  rep(i, 1, N) {
    scanf("%d", &x);
    f[--x]++;
  }
  rep(i, 0, N)
    printf("%d\n", f[i]);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}



Measured memory_bytes: 4052
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

INF = float('inf')

from collections import deque
def solve():
    S = deque(list(input()))

    Q = II()
    rev = False
    for i in range(Q):
        q = list(input().split())
        # print(q)
        if q[0] == '1':
            rev = ~rev
        else:
            op = q[1]
            if (op == '1' and not rev) or op == '2' and rev:
                S.appendleft(q[2])
            else:
                S.append(q[2])

    S = list(S)
    if rev:
        S = S[::-1]

    print(''.join(S))

if __name__ == '__main__':
    solve()


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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define HMAX 100



int main(void)
{
    IOS
    int n;
    int h[HMAX],k[HMAX];
    cin >> n;
    for (int i = 0; i < n ; i++) cin >> h[i];
    for (int i = 0; i < HMAX ; i++) k[i] = 0;

    int next = 0;
    int count = 0;
    while(next < n) {
        int s,e;
        int i = next;
        while(i < n) {
            if (k[i] < h[i]) {
                s = i;
                break;
            }
            i++;
        }
        //cerr << "i:" << i << endl;
        if (i >= n) break;
        i = s;
        while(i < n) {
            if (k[i] >= h[i]) {
                break;
            }
            k[i]++;
            i++;
        }
        next = s;
        //cerr << "n:" << next << endl;
        count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(n):
    s[i+1]=s[i]+a[i]
s=s[1:]
l=1
ans=float("inf")
r=3
for i in range(2,n-1):
    while i-l>1 and abs(s[i-1]-s[l-1]-s[l-1])>abs(s[i-1]-s[l]-s[l]):
        l+=1
    while abs(s[n-1]-s[r-1]-(s[r-1]-s[i-1]))>abs(s[n-1]-s[r]-(s[r]-s[i-1])):
        r+=1
    ansl=[s[l-1],s[i-1]-s[l-1],s[r-1]-s[i-1],s[n-1]-s[r-1]]
    ans=min(ans,max(ansl)-min(ansl))
print(ans)


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

int main()
{
	int t1 = 0;
	int t2 = 0;
	int n;
	while(cin >> n)
	{
		if(n == 5)
			++t1;
		if(n == 7)
			++t2;
	}
	if(t1 == 2 && t2 == 1)
		cout << "YES";
	else
		cout << "NO";

	return 0;
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
D=LIST()

D.sort()
D1=D[:N//2]
D2=D[N//2:]

print(D2[0]-D1[-1])


Measured memory_bytes: 14428
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i, k;
        int h, w;
        h = sc.nextInt();
        w = sc.nextInt();
        char[][] weather = new char [h][w];
        int[][] cloud = new int [h][w];
        for(i = 0; i < h; i++){
                weather[i]= sc.next().toCharArray();
        }
        for(i = 0; i < h; i++){
        	int minutes = -1;
        	for(k = 0; k < w; k++){
        		if(weather[i][k] == 'c'){		//??????????????°????????????
        			minutes = 0;
        			cloud[i][k] = minutes;
        			minutes++;
        		}else if(minutes >= 0){		//??????????????°??????????????????????????????????????????
        			cloud[i][k] = minutes;
        			minutes++;
        		}else{		//????????\??????
        			cloud[i][k] = minutes;
        		}
        	}
        }
        for(i = 0; i < h; i++){
        	for(k = 0; k < w; k++){
        		if(k == w - 1){
        			System.out.print(cloud[i][k]);
        		}else{
        			System.out.print(cloud[i][k] + " ");
        		}
        	}
        	System.out.println();
        }
    }
}

Measured memory_bytes: 34328
package main

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


var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func gcd(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

// Pow の定義
type Pow struct {
	p, q int64
}

// Pow の生成
func newPow(p, q int64) *Pow {
	a := new(Pow)
	a.p, a.q = p, q
	return a
}

// Stringer の定義
func (p *Pow) String() string {
	return fmt.Sprintf("(%d, %d)", p.p, p.q)
}

// m で割り切れる回数を求める
func factorSub(n, m int64) (int64, int64) {
	i := int64(0)
	for ; n % m == 0; n /= m {
		i++
	}
	return i, n
}

// 素因数分解
func factorization(n int64) []*Pow {
	a := make([]*Pow, 0)
	c, m := factorSub(n, 2)
	if c > 0 {
		a = append(a, newPow(2, c))
	}
	for i := int64(3); m >= i * i; i += 2 {
		c, m = factorSub(m, i)
		if c > 0 {
			a = append(a, newPow(i, c))
		}
	}
	if m > 1 {
		a = append(a, newPow(m, 1))
	}
	return a
}

func solve(a int64, b int64) int64 {
	g := gcd(a, b)
	if g == 1 {
		return g
	}
	return int64(len(factorization(g)) + 1)
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	a := nextInt()
	b := nextInt()
	res := solve(a, b)
	fmt.Fprintln(out, res)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextStringAsBytes(n int64) []byte {
	sc.Scan()
	return []byte(sc.Text())
}

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int64) []int64 {
	ret := make([]int64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextFloats(n int64) []float64 {
	ret := make([]float64, n)
	for i := int64(0); i < n; i++ {
		ret[i] = nextFloat()
	}
	return ret
}
func nextStrings(n int64) []string {
	ret := make([]string, n)
	for i := int64(0); i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "orz")
	}
}

// mapからkeysとvaluesを返す
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "orz")
	}
	return
}


Measured memory_bytes: 640
import itertools

n, k = map(int, input().split())
lis = list(map(int,input().split()))

exlis = []


for i in lis:
    a = (1+i)/2
    exlis.append(a)


nlis = list(itertools.accumulate(exlis))


ans  = nlis[k-1]
for j in range(n-k):
    tmp = nlis[j+k] - nlis[j]
    ans = max(ans, tmp)

print(ans)

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

int dp[14][1<<14];
int INF = 1000000000;
int n;

bool contained(string a, string b){
  if(a.length() > b.length()) return false;
  for(int i = 0; i <= b.length()-a.length(); ++i){
    bool f = true;
    for(int j = 0; j < a.length(); ++j){
      if(a[j] != b[i+j]){
        f = false;
        break;
      }
    }
    if(f) return true;
  }
  return false;
}

int match(string a, string b){
  int ret = 0;
  for(int i = 1; i < a.length(); ++i){
    bool f = true;
    for(int j = 0; j < i; ++j){
      if(b[b.length()-i+j] != a[j]){
        f = false;
        break;
      }
    }
    if(f) ret = max(ret,i);
  }
  //cout << a << " " << b << " " << ret << endl;
  return ret;
}

int memo_dp(int i, int bit, vector<string> &names){
  if(dp[i][bit] < INF){
    return dp[i][bit];
  }
  int bit_ = bit - (1<<i);
  for(int j = 0; j < n; ++j){
    if((bit_>>j)&1){
      dp[i][bit] = min(dp[i][bit],memo_dp(j,bit_,names)+(int)names[i].length()-match(names[i],names[j]));
    }
  }
  //cout << i << " " << bit << " " << dp[i][bit] << endl;
  return dp[i][bit];
}

int main(){
  while(cin >> n, n){
    vector<string> cities(n);
   
    for(int i = 0; i < n; ++i){
      cin >> cities[i];
    }

    vector<string> names;
    for(int i = 0; i < n; ++i){
      bool f = true;
      for(int j = 0; j < n; ++j){
        if(i == j) continue;
        if(contained(cities[i],cities[j])){
          f = false;
          break;
        }
      }
      if(f) names.push_back(cities[i]);
    }

    n = names.size();
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < (1<<n); ++j) dp[i][j] = INF;
    }

    for(int i = 0; i < n; ++i)
      dp[i][(1<<i)] = (int)names[i].length();
    
    int ans = INF;
    for(int i = 0; i < n; ++i){
      ans = min(memo_dp(i, (1<<n)-1, names), ans);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4024
#include <stdio.h>

int main(void)
{
	long int a, b;
	char op;
	
	scanf("%ld %c %ld", &a, &op, &b);
	if (op == '+')
		printf("%ld", a + b);
	else
		printf("%ld", a- b);
	
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            //6
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("10");
            //3628800
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("100000");
            //457992974
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        const long Hou = 1000000007;

        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        long Answer = 1;
        for (int I = 1; I <= N; I++) {
            Answer *= I;
            Answer %= Hou;
        }
        Console.WriteLine(Answer);
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 231548613323;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
 
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}
 
ll rev(ll v){
	return mpow(v,MOD-2);
}

// ll bs(vp64 &v, ll val){
// 	ll l=-1,r=sz(v)-1;
// 	while(l!=r){
// 		ll mid=(l+r+1)/2;
// 		if(v[mid].fi <= val) l=mid;
// 		else r = mid-1;
// 	}
// 	return l;
// }
 
void solve(){
	ll n;
	cin >> n;
	vp64 v(n);
	forn(i,n) {
		ll t1,t2;
		cin >> t1 >> t2;
		v[i] = mp(t1+t2,t1-t2);
	}
	sort(all(v));
	ll ans = 0;
	ll r = -INF;
	forn(i,n){
		if(v[i].se >= r){
			ans++;
			r = v[i].fi;
		}
	}
	cout << ans << ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    // cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(void){
  int n,a[200000],x[200000];
    scanf("%d",&n);
   for(int i=1;i<=n;i++){
     scanf("%d",&a[i]);
     x[a[i]]=i;
   }
   for(int i=1;i<=n;i++){
     printf("%d",x[i]);
     printf(" ");
   }
   printf("\n");


  return 0;
}

Measured memory_bytes: 2508
#include <bits/stdc++.h>
using namespace std;
    int main(){
        int N,M;cin>>N>>M;
        int s[M],c[M];
        for(int i=0;i<M;i++){
            cin>>s[i]>>c[i];
            s[i]--;
        }
        int res=-1;
        for(int i=0;i<=999;i++){
            string str=to_string(i);
            bool ok=true;
            if(str.size()!=N)ok=false;
            for(int j=0;j<M;j++){
                if(str[s[j]]!=(char)(c[j]+'0'))ok=false;
            }
            if(ok){
                res=i;
                break;
            }

        }
        cout<<res<<endl;
    }






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

struct Rectangle {
  int h, w;
  Rectangle(int h, int w): h(h), w(w) {}
  int hypotsq() const {
    return h*h + w*w;
  }
  bool operator <(const Rectangle &rhs) const {
    if (hypotsq() != rhs.hypotsq()) {
      return hypotsq() < rhs.hypotsq();
    }
    return h < rhs.h;
  }
};

int main() {
  std::vector<Rectangle> v;
  for (int h=1; h<=151; ++h)
    for (int w=h+1; w<=151; ++w)
      v.emplace_back(h, w);

  std::sort(v.begin(), v.end());
  while (true) {
    int h, w;
    scanf("%d %d", &h, &w);

    if (h == 0 && w == 0)
      break;

    const auto it=std::upper_bound(v.begin(), v.end(), Rectangle(h, w));
    printf("%d %d\n", it->h, it->w);
  }
}



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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  bool a[31];
  REP1(i, 30) a[i] = false;
  REP(i, 28) {
    int n;
    cin >> n;
    a[n] = true;
  }
  REP1(i, 30) {
    if (!a[i]) cout << i << endl;
  }
  return 0;
}


Measured memory_bytes: 3112
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  double t,x;
  cin>>t>>x;
  cout<<fixed<<setprecision(20)<<t/x<<endl;
}


Measured memory_bytes: 764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        int count = 0;
        for (int i = 1; i <= n; i++) {
            if ((String.valueOf(i).length() % 2 ) != 0) {
                count++;
            }
        }
        System.out.print(count) ;



    }


}



Measured memory_bytes: 28244
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const LL INF = 1e10;
const int MXN = 1e5 + 1;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    // IOS;
    int N, W;
    vector<LL> dp(MXN, INF);
    cin >> N >> W;
    dp[0] = 0;
    FOR(i, 0, N)
    {
        LL v, w;
        cin >> w >> v;
        FORD(j, MXN - 1, v - 1) { dp[j] = min(dp[j], dp[j - v] + w); }
    }
    FORD(i, MXN - 1, 0 - 1)
    {
        if (dp[i] <= W)
        {
            cout << i << '\n';
            return 0;
        }
    }
}


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

int main(){
    int x, y;
    
    while(1){
        cin >> x >> y;
        
        if(x == 0 && y == 0){
            break;
        }
        else {
            if(x < y) cout << x << " " << y << endl;
            else cout << y << " " << x << endl;
        }
    }
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int n,m;

int solve(vector<int>& v,int x){
    int ret=0;
    rep(i,n){
        if(v[i]==1){
            ret+=pow(3,n-1-i);
            x^=2;
        }
        else if(v[i]!=x){
            ret+=2*pow(3,n-1-i);
        }
    }
    return ret;
}


int main(){
    
    while(1){
        cin>>n>>m;
        if(n==0 && m==0) break;
        vector<int> v(n);
        rep(i,3){
            int c;
            cin>>c;
            rep(j,c){
                int x;
                cin>>x;
                v[x-1]=i;
            }
        }
        int ans=min(solve(v,0),solve(v,2));
        cout<<((ans>m) ? -1 : ans)<<endl;
    }
}


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

int main() {
  string s;
  cin>>s;
  for (char c: s) {
    if (c == '1') {
      cout<<9;
    } else if (c == '9') {
      cout<<1;
    } else {
      cout<<c;
    }
  }
  cout<<endl;
}

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

int bucket[100010];

int main(){
	int n;
	scanf("%d", &n);
	unordered_map<int, int> m;
	for(int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		bucket[a]++;
		bucket[a + 1]++;
		if(a - 1 >= 0) bucket[a-1]++;
	}
	int ans = 1;
	for(int i = 0; i < n; i++)
		ans = max(ans, bucket[i]);
	printf("%d\n", ans);
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, 1, -1};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

int gcd (int a,int b){
    if(a < b){
        int c = b;
        b = a;
        a = c;
    }

    if(a % b == 0)
        return b;
    return gcd(b,a % b);
}

int lcm(int a,int b){
    return a * b / gcd(a,b);
}

int main(){
    while(1){
        int h,w;
        scanf("%d%d",&h,&w);
        if(h == 0 && w == 0)
            break;

        char donuts[10][21];
        for(int i = 0;i < h;i++)
            scanf("%s",&donuts[i][0]);

        int maxi = 0;
        char s[1000] = "";
        for(int i = 0;i < h * w * 8;i++){
            for(int j = i + 1;j < h * w * 8;j++){
                int h1 = i / (w * 8),w1 = i % (w * 8) / 8,d1 = i % (w * 8) % 8;
                int h2 = j / (w * 8),w2 = j % (w * 8) / 8,d2 = j % (w * 8) % 8;
                int maxlen;
                if(d1 < 2)
                    maxlen = w;
                else if(d1 < 4)
                    maxlen = h;
                else
                    maxlen = lcm(w,h);
                if(d2 < 2){
                    if(maxlen > w)
                        maxlen = w;
                }
                else if(d2 < 4 && maxlen > h)
                    maxlen = h;

                int len = 0;
                char kari[1000];
                for(int k = 0;k < maxlen;k++){
                    int y1 = (h1 + dy[d1] * k + h * 1000) % h,x1 = (w1 + dx[d1] * k + w * 1000) % w;
                    int y2 = (h2 + dy[d2] * k + h * 1000) % h,x2 = (w2 + dx[d2] * k + w * 1000) % w;
                    if(donuts[y1][x1] == donuts[y2][x2]){
                        len++;
                        kari[k] = donuts[y1][x1];
                        kari[k + 1] = '\0';
                    }else
                        break;
                }
                if(maxi < len){
                    maxi = len;
                    strcpy(s,kari);
                }else if(maxi == len && strcmp(s,kari) > 0){
                    strcpy(s,kari);
                }
            }
        }
        if(strlen(s) > 1)
            printf("%s\n",s);
        else
            printf("0\n");
    }
    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
string st;
int mb[2019];
const int mod=2019;
int main(){
    cin>>st;
    int n=sz(st);
    mb[0]++;
    int P=1;
    ll ans=0,cur=0;
    for(int i=n-1;i>=0;i--){
        int d=st[i]-'0';
        cur=(cur+d*P)%mod;
        ans+=mb[cur];
        mb[cur]++;
        P*=10;
        P%=mod;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3756
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
    int n, r;
    scanf("%d%d", &n, &r);
    if (n > 10)
        printf("%d\n", r);
    else
        printf("%d\n", 100 * (10 - n) + r);
    return 0;
}

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

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	int ans[200];

	for (int i = a; i <= min(b,a+k-1); i++){
		cout<<i<<endl;
	}
	for (int i = max(b-k+1,a+k); i <= b; i++){
		cout<<i<<endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,t;
    cin>>n>>t;
    int a[n];
    int a_max[n];
    int val[n-1];
    rep(i,n){cin>>a[i];}
    a_max[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){a_max[i]=max(a_max[i+1], a[i]);}
    int max_dif=0;
    rep(i,n-1){
        val[i] = max(0, a_max[i+1]-a[i]);
        max_dif = max(max_dif, val[i]);
    }
DEBUG{cout << "max dif" << max_dif << endl;}
    set<int> sell_st;
    unordered_map<int, vector<int> > valv;
    rep(i,n){
        if(sell_st.find(a[i])!=sell_st.end()){
            DEBUG{cout << "pass" << endl;}
            valv[a[i]-max_dif].push_back(1);
        }
        if(val[i]==max_dif){
            valv[a[i]].push_back(0);
            sell_st.insert(a[i]+max_dif);
        }
    }
    DEBUG{printf("test\n");}
    DEBUG{cout << valv.size() << endl;}
    DEBUG{
        for(auto x:sell_st){cout << x << " ";}
        cout << endl;
    }
    int res=0;
    for(auto v:valv){
        DEBUG{cout << v.second.size() << " " << endl;}
        int now=0;
        int cnt[2]={};
        for(auto x:v.second){
            if(now&&!x){
                res += min(cnt[0],cnt[1]);
                cnt[0]=0;
                cnt[1]=0;
            }
            cnt[x]++;
            now=x;
        }
        res += min(cnt[0], cnt[1]);
    }
    cout << res << endl;
    return 0;

}


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

long long gcd(long long a, long long b)
{
	if (a > b) {
		a += b;
		b = a - b;
		a -= b;
	}
	if (b % a == 0) return a;
	else return gcd(b % a, a);
}

int main()
{
	long long A, B;
	scanf("%lld %lld", &A, &B);
	
	int ans = 1;
	long long p, G = gcd(A, B);
	for (p = 2; p * p <= G; p++) {
		if (G / p * p == G) {
			ans++;
			for (G /= p; G / p * p == G; G /= p);
		}
	}
	if (G > 1) ans++;
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void) {
  int a,b,c,d,e;
  scanf("%d%d",&a,&b );
  c=a+b;
  d=a-b;
  e=a*b;
  if(d>c&&d>e)printf("%d\n",d);
  else if (e>d&&e>c)printf("%d\n",e );
  else if (c>=e&&c>=d)printf("%d\n",c );
}


Measured memory_bytes: 128
from math import ceil

n = int(input())
numeros = [int(x) for x in input().split()]
saida = 2000000000000000

for i in range(min(numeros), max(numeros)+1):
	valor = 0
	for j in numeros:
		valor += (j-i)**2
	
	saida = min(valor, saida)

print(saida)




Measured memory_bytes: 38512
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()
{
	const map<string, int> m = {
		{ "SUN", 7 },
		{ "MON", 6 },
		{ "TUE", 5 },
		{ "WED", 4 },
		{ "THU", 3 },
		{ "FRI", 2 },
		{ "SAT", 1 },
	};
	string S;
	cin >> S;
	cout << m.at(S) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000LL
#define rep(i,n) for(i=0;i<n;i++)
#define roop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;
int i,j;

int main(void) {

  string s;
  cin>>s;
  if(s[0]=='a' || s[0]=='i' || s[0]=='u' || s[0]=='e' \
|| s[0]=='o')cout<<"vowel"<<endl;
  else cout<<"consonant"<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<math.h>
    #include<vector>
    #include<array>
    #include<algorithm>
    #include<numeric>
    #include<map>
    #include<stack>
    #include<queue>
    #include<deque>
    #include<set>
    #include<cstdio>
    #include<cstring>
    #include<string>
    using namespace std;
    using ll = long long;
    using P = pair<int, int>;
    const ll INF=1e18;
    #define PI 3.14159265358979323846
     
    int main() {
        cin.tie(0);
        ios::sync_with_stdio(false);
     
        int N;
        cin >> N;
     
        cout << 2 * N * PI << '\n';
     
        return 0;
    }

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

#define N 256

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

    scanf ( " %s", s );
    if ( !strcmp ( s, "-" ) ) break ;

    scanf ( "%d", &n );
    while ( n-- )
    {
      char t[ N ];
      int h;

      scanf ( "%d", &h );
      strcpy ( t, s );
      strcpy ( s, t + h );
      strncat ( s, t, h );
    }

    puts ( s );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <stdlib.h>
/******memore********/
#define maxn
#define inf

int main()
{
	long long n, m;
	
	scanf("%lld%lld", &n, &m);
	if (m <= 2 * n)
		printf("%lld", m / 2);
	else
		printf("%lld",n + (m - 2 * n) / 4);
	return 0;		

}


Measured memory_bytes: 128