akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;


double l[20],a[20],b[20];
double d[20][20];

double dis(int x, int y){
  return (l[x]-l[y])*(l[x]-l[y]) + (a[x]-a[y])*(a[x]-a[y]) + (b[x]-b[y])*(b[x]-b[y]);
}

int main(){
  int n,m;
  double dp[1<<20];
  
  cin >> n >> m;

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

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++)d[i][j] = dis(i,j);
  }

  for(int i=0;i<(1<<n);i++)dp[i] = 0.0;

  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if( i & (1<<j) ){
	int tmp = i - (1<<j);

	double sum = 0.0;
	for(int k=0;k<n;k++){
	  if( tmp & (1<<k) )sum += d[j][k];
	}
	dp[i] = max(dp[i],dp[tmp] + sum);
      }
    }
  }

  double mx = 0.0;
  for(int i=0;i<(1<<n);i++){
    int cnt = 0;
    for(int j=0;j<n;j++){
      if(i & (1<<j) )cnt++;
    }
    if(cnt == m)mx = max(dp[i],mx);
  }
  printf("%.8lf\n",mx);
}

Measured memory_bytes: 0
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n::Int=parseInt(readline())
    a::Vector{Int}=parseMap(split(readline()))
    cnt::Vector{Int}=[0 for i in 1:n]
    for i in a
        cnt[i+1]+=1
    end
    ans::Int=1
    if n%2==1 && cnt[1]!=1
        ans=0
    end
    for i in cnt[n%2+2:2:n]
        if i!=2
            ans=0
            break
        end
        ans*=2
        ans%=1000000007
    end
    println(ans)
end
main()

Measured memory_bytes: 166832
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

vector<vector<pair<ll, ll>>> G;
vector<ll> dist;

void dfs(ll cur, ll pre, ll cost) {
	dist[cur] = cost;
	for (auto to : G[cur]) {
		if (to.first != pre) {
			dfs(to.first, cur, cost + to.second);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n;
	cin >> n;

	G.resize(n);

	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back(make_pair(b, c));
		G[b].push_back(make_pair(a, c));
	}

	ll q, k;
	cin >> q >> k;
	k--;

	dist.resize(n, 0);

	dfs(k, -1, 0);

	rep(i, q) {
		ll x, y;
		cin >> x >> y;
		x--; y--;
		out(dist[x] + dist[y]);
	}

	return 0;
}

Measured memory_bytes: 14336
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<string.h>
#include<string>
#include<stack> 
#include<set>
#include<map>
#include<iostream>
#include<assert.h>
//#define Min(a,b,c) min((a),min((b),(c)))
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pb(x) push_back(x)
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-11
#define pi 3.14159265359
#define pmm pair<map<int,int>*,map<int,LL>*>
typedef long long LL;
using namespace std;
const LL mod=1e9+7;
int main(){
	int n;
	scanf("%d",&n);
	pii p[100005];
	for(int i=0;i<n;i++)
	scanf("%d %d",&p[i].x,&p[i].y);
	long long int ans=0;
	for(int i=n-1;i>=0;i--)
	{
		LL c=ans+p[i].x;
		ans+=(p[i].y-c%p[i].y)%p[i].y;
	}
	printf("%lld\n",ans);
}

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

int main(){

    int N;
    cin >> N;

    vector<int> A(N);
    set<int> st;
    for(int i=0;i<N;i++){
        cin >> A[i];
        st.emplace(A[i]);
    }

    vector<int> v;
    copy(A.begin(),A.end(),back_inserter(v));
    sort(v.begin(),v.end(),greater<int>());

    int max1=0,max2=0;
    int maxc1=0;
    for(int i=0;i<N;i++){
        if(max1==v[i]){
            maxc1++;
        }else if(max1 < v[i]){
            max1 = v[i];
            maxc1=1;
        }
        if(max1!=0 && max1 > v[i] && max2 < v[i]){
            max2 = v[i];
            break;
        }
    }

    for(int i=0;i<N;i++){
        if(maxc1 >= 2)cout << max1 <<endl;
        else{
            if(A[i]==max1)cout << max2 <<endl;
            else cout << max1 << endl;
        }
    }

    return 0;
}

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

typedef long long int ll;

int n, x, y;
vector<int> adj[2010];
int d[2010], vis[2010];
ll k[2010];

void bfs(int v) {
	memset(vis, false, sizeof(vis));
	queue<int> q;
	q.push(v);
	d[v] = 0;
	while(!q.empty()) {
		int atual = q.front(); q.pop();
		for (auto u : adj[atual]) {
			if (vis[u]) continue;
			d[u] = d[atual] + 1;
			q.push(u);
			vis[u] = true;
		}
	}
}

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

	for (int i = 1; i < n; i++) {
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}
	adj[x].push_back(y);
	adj[y].push_back(x);

	for (int i = 1; i < n; i++) {
		bfs(i);
		for (int j = i+1; j <= n; j++) {
			k[d[j]]++;
		}
	}

	for (int i = 1; i < n; i++) {
		cout << k[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 384
N = int(input())

mod = 1000000007

def modpow(a, n, mod):
    res = 1
    while (n>0):
        if (n & 1):
            res = res*a%mod
        a = a*a%mod
        n = n >> 1
    return res

temp10 = modpow(10,N,mod)
temp9 = modpow(9,N,mod)
temp8 = modpow(8,N,mod)

ans = (temp10-temp9+mod)%mod
ans = (ans-temp9+mod)%mod
ans = (ans+temp8+mod)%mod

print(ans)

Measured memory_bytes: 9100
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
Arr.forEach(function(v){
   var arr=v.split(" ").map(Number);
   var cnt=0;
   (function(xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2){
      if(xb2>=xa1 && xb1<=xa2)cnt++;
      if(yb2>=ya1 && yb1<=ya2)cnt++;
   }).apply(null,arr);
   console.log((cnt==2)?"YES":"NO");
});

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


int D, N;
int t,ta;
int main(){
	cin >> D >> N;
	if (D == 0) t = 1;
	else t = pow(100,D);
	if(N != 100){
		cout << t * N << endl;
	}else{
		cout << t * (N+1)  << endl;
	}
	return 0;
}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()

typedef pair<int, int> P;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

struct Data{
    string title;
    string author;
    string date;
};

signed main(){
    int N, M;
    string t, n, df, dt;

    cin >> N;
    vector<Data> data;
    REP( i, N ){
        cin >> t >> n >> df;
        data.emplace_back( Data{ t, n, df } );
    }

    cin >> M;
    REP( i, M ){
        cin >> t >> n >> df >> dt;
        if( t == "*" ) t = ".*";
        if( n == "*" ) n = ".*";
        if( df == "*" ) df = "1970";
        if( dt == "*" ) dt = "2038";
        regex rt( t ), rn( n );

        REP( i, N ){
            if( regex_search( data[i].title, rt ) && regex_search( data[i].author, rn ) && data[i].date >= df && data[i].date <= dt ){
                cout << data[i].title << endl;
            }
        }
        if( i != M - 1 ) cout << endl;
    }
}



Measured memory_bytes: 3344
# AtCoder Beginner Contest 124
# https://atcoder.jp/contests/abc124
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(S):
    n1 = 0
    n2 = 0
    for i in range(len(S)):
        if i % 2 == 0:
            if S[i] == '0':
                n1 += 1
            else:
                n2 += 1
        if i % 2 == 1:
            if S[i] == '1':
                n1 += 1
            else:
                n2 += 1
    n = min(n1, n2)
    print(n)

S = i2s()
main(S)


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  lll ii,jj,kk;
  lll m,d,sum =0;
  lll d1,d10;
  cin >> m >> d;
  
  for(ii=1;ii<=m;ii++){
    for(jj=1;jj<=d;jj++){
      d10 = jj/10;
      d1 = jj  - (d10*10);
      if(ii == (d10*d1) && d1>=2 && d10 >= 2){
        //cout << "ii: "  << ii << "jj:" << jj<< " d10:" << d10 << " d1:" << d1 << endl;
        sum++;
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
S=input()
N=len(S)
Z={}

for i in range(N):
    if S[i] in Z:
        Z[S[i]].append(i)
    else:
        Z[S[i]]=[i]
    
M=float("inf")
for z in Z:
    L=[1*(i in Z[z]) for i in range(N)]

    K=0
    while sum(L)!=len(L):
        K+=1
        for i in range(len(L)-1):
            L[i]=max(L[i],L[i+1])
        L=L[:-1]
    
    M=min(M,K)
print(M)

Measured memory_bytes: 70372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)

string solve() {
    int a, b;
    cin >> a >> b;
    if (a <= 0 && b >= 0) return "Zero";
    if (a > 0) return "Positive";
    a = -a; b = -b;
    if ((b - a) % 2 == 0) return "Negative";
    else return "Positive";
}
int main() {
    out(solve());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main(void)
{
  int n, k, h[100000], min;
  std::cin >> n >> k;
  for(int i = 0; i != n; i++) std::cin >> h[i];
  std::sort(h, h + n);
  min = h[n - 1] - h[0];
  for(int i = 0; i <= n - k; i++)
    min = std::min(min, h[i + k - 1] - h[i]);
  std::cout << min << std::endl;
  return 0;
}

Measured memory_bytes: 640
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + end + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  myout((N >= 30) ? "Yes" : "No");
}


Measured memory_bytes: 30176
import sys
from collections import defaultdict
sys.setrecursionlimit(10**6)
def dfs(i,c):
    visited[i]=1
    col[i] = c
    for j in edge[i]:
        if not visited[j[0]]:
            if j[1]%2==0:
                dfs(j[0],c)
            else:
                dfs(j[0],-1*c)
class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0]*N
        self.count = 0
    def root(self, a):
        if self.parent[a]==a:
            return a
        else:
            self.parent[a]=self.root(self.parent[a])
            return self.parent[a]
    def size(x):
        return -par[root(x)]

    def is_same(self, a, b):
        return self.root(a)==self.root(b)
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return

        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]: self.rank[ra] += 1
        self.count += 1

def main():
    dd = defaultdict(int)
    n,m=map(int, input().split())
    uf = UnionFind(n)

    for i in range(m):
        x,y,z=map(int, input().split())
        uf.unite(x-1,y-1)
    for i in range(n):
        dd[uf.root(i)]+=1
    print(len(dd))


if __name__ == '__main__':
    main()


Measured memory_bytes: 20212
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;
int main() {
  int N,M;
  cin >> N >> M;
  vector<int> l(M); vector<int> r(M);
  for (int i=0; i<M; i++) cin >> l[i] >> r[i];
  int ma = l[0];
  int mi = r[0];
  for (int i=1; i<M; i++) {
    ma = max(l[i],ma);
    mi = min(r[i],mi);
  }
  int ans = max(mi-ma+1,0);
  cout << ans << endl;
}
  

Measured memory_bytes: 1024
from itertools import accumulate
from bisect import bisect_right

N, x, *A = map(int, open(0).read().split())

A.sort()
S = list(accumulate(A))

if S[-1] == x:
    print(N)
else:
    k = bisect_right(S, x)
    print(N - 1 if k == N else k)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const ll INF = LONG_LONG_MAX;

int main()
{
	
	ll a,b,c,d;
	cin >> a>>b >>c >> d;
	ll maxx = -INF;
	maxx = max(maxx,a*c);
	maxx = max(maxx,a*d);
	maxx = max(maxx,b*c);
	maxx = max(maxx,b*d);
	cout << maxx <<endl;
	return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
int main()
{
	int M,N,i,sum=0,temp;
	scanf("%d %d",&M,&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
		sum=sum+A[i];
	}
	temp=M-sum;
	if(temp>=0){
		printf("%d\n",temp);
	}
	else{
		printf("-1\n");
	}
	return 0;
}


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

#define ll long long
using namespace std;
const int maxn=2e5+5;
ll f[maxn];
int fa[maxn],dee[maxn],da[maxn];
int n;
char s[maxn];
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    a=a%mod;
    while(b)
    {
        if(b&1) ans=ans*a%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return ans;
}
int main()
{
    scanf("%d%s",&n,s+1);
    reverse(s+1,s+1+n);
    ll col=0,sum1=0,sum2=0;
    f[0]=0;
    for(int i=1;i<maxn;i++)
    {
        int kk=i%__builtin_popcount(i);
        f[i]=1+f[kk];
    }
    for(int i=1; i<=n; i++)
    {
        if(s[i]=='1')
            col++;
    }
    ll mod1=col-1,mod2=col+1;
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='1')
        {
            if(mod1!=0)
                sum1=(sum1+qpow(2,i-1,mod1))%mod1;
            sum2=(sum2+qpow(2,i-1,mod2))%mod2;
        }
    }

    //printf("%d %d\n",sum1,sum2);
    for(int i=1;i<=n;i++)
    {
        if(s[i]=='1' && col>1)
        {
            int tt=(sum1-qpow(2,i-1,mod1)+mod1)%mod1;
            da[i]=1+f[tt];
           // printf("%d %d\n",tt,f[tt]);
        }
        if(s[i]=='0')
        {
            int tt=(sum2+qpow(2,i-1,mod2)+mod2)%mod2;
            da[i]=1+f[tt];
            // printf("%d %d\n",tt,f[tt]);
        }
    }
    reverse(da+1,da+1+n);
    for(int i=1; i<=n; i++)
        printf("%d\n",da[i]);
}


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

void insertionSort(int*arr, int n);

int main(){
    int i,j,n;
    scanf("%d",&n);
    int *arr;
    arr = malloc(n*sizeof(int));
    for (i=0;i<n;i++){
        scanf("%d",arr+i);
        //printf("%d",arr[i]);
    }
    insertionSort(arr,n);
    return 0;
}

void insertionSort(int*arr, int n){
    int i,j,k,v;
    for (i=0;i<n;i++){
        v = *(arr+i);
        j = i-1;
        while (j>=0 && *(arr+j)>v){
            arr[j+1] = arr[j];
            j--;
        }
        *(arr+j+1) = v;
        //printf("why?");
        for (k=0;k<n;k++){
            if (k==(n-1)) printf("%d\n",arr[k]);
            else printf("%d ",arr[k]);
    }

    }
    return;
}


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

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

    for (int i = 0; i < n.size(); i++){
        if (n[i] == '1'){
            cout << 9;
        }else{
            cout << 1;
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, c, a[100005];
int main() {
	int i;
	scanf("%d", &n);
	if(n==1) {puts("1"); return 0;}
	for(i=0; i<n; i++) scanf("%d", &a[i]);
	for(i=1; i<n; i++) {
		if(a[i] - a[i-1] > 0) {
			c++;
			for(; a[i] - a[i-1] >= 0; i++);
		} else if(a[i] - a[i-1] < 0) {
			c++;
			for(; a[i] - a[i-1] <= 0; i++);
		}
		if(i==n-1) c++;
	}
	printf("%d", c);
	return 0;
}

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

typedef long long ll;

ll T[100005];
ll A[100005];

int ans[100005];
ll check[100005];
ll check2[100005];
ll check3[100005];

ll min(ll a, ll b);

ll mod = 1000000007;

int main() {

	int N;

	scanf("%d",&N);

	int i;

	for (i = 0; i < N; i++) {
		scanf(" %lld",&T[i]);
	}
	for (i = 0; i < N; i++) {
		scanf(" %lld", &A[i]);
	}

	memset(ans,-1,sizeof(ans));

	ans[0] = (int)T[0];
	ans[N - 1] = (int)A[N - 1];

	for (i = 0; i < N-1; i++) {
		if (T[i] != T[i + 1]) {
			ans[i + 1] = (int)T[i + 1];
		}
	}
	for (i = N - 1; i >= 1; i--) {
		if (A[i] != A[i - 1]) {
			ans[i - 1] = (int)A[i - 1];
		}
	}
	ll answer = 1ll;
	for (i = 0; i < N; i++) {
		if (ans[i] == -1) { 
			answer *= min(T[i], A[i]); 
			answer %= mod;
			check[i] = min(T[i],A[i]);
		}
		else {
			check[i] = (ll)ans[i];
		}
	}
	ll ma = -1ll;

	for (i = 0; i < N; i++) {
		if (ma < check[i]) {
			ma = check[i];
		}
		check2[i] = ma;
	}
	ma = -1ll;
	for (i = N-1; i >= 0; i--) {
		if (ma < check[i]) {
			ma = check[i];
		}
		check3[i] = ma;
	}

	int flag = 0;

	for (i = 0; i < N; i++) {
		if (check2[i] != T[i] || check3[i] != A[i]) { 
			flag = 1;
			break;
		}
	}
	if (flag == 0) { printf("%lld\n",answer); }
	else { printf("0\n"); }

	return 0;
}
ll min(ll a, ll b) {
	if (a >= b) { return b; }
	else { return a; }
}

Measured memory_bytes: 4480
#!/usr/bin/env ruby

numbers = []
strings = []
index = 0

loop do
    string = gets
    strings = string.split.map(&:to_i)
    if strings[0] == 0 and strings[1] == 0 then
        break
    end
    numbers[index] = strings[0]
    numbers[index + 1] = strings[1]
    index += 2
end


(index / 2).times do |i|
    if numbers[2 * i] < numbers[2 * i +1] then
        puts ("#{numbers[2 * i]} #{numbers[2 * i + 1]}")
    else
        puts ("#{numbers[2 * i + 1]} #{numbers[2 * i]}")
    end
end




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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, a, four = 0, two = 0, other = 0;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a % 4 == 0)
      four++;
    else if (a % 2 == 0)
      two++;
    else
      other++;
  }
  bool flg = false;
  if (two == 0) {
    if (four + 1 >= other) flg = true;
  } else {
    if (four >= other) flg = true;
  }
  // if (n <= 3 && four >= 1) {
  //   flg = true;
  // } else {
  //   if (two >= 2) {
  //     if (four >= other) flg = true;
  //   } else if (two <= 1) {
  //     if (four >= other + two) flg = true;
  //   }
  // }

  cout << (flg ? "Yes" : "No") << endl;
  return 0;
}

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

class Solution
{
    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int n = vals[0];
        int m = vals[1];
        var graph = Enumerable.Range(0, n + 1).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < m; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int a = vals[0];
            int b = vals[1];
            graph[a].Add(b);
            graph[b].Add(a);
        }

        var visited = new HashSet<int>();
        int count = 0;
        foreach (var start in Enumerable.Range(1, n))
        {
            if (visited.Contains(start) || graph[start].Count != 1)
            {
                continue;
            }

            var cur = start;
            visited.Add(cur);
            while (graph[cur].Count == 1 && !visited.Contains(graph[cur].First()))
            {
                var next = graph[cur].First();
                graph[cur].Remove(next);
                graph[next].Remove(cur);
                visited.Add(cur);
                count++;
                cur = next;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13536
#include<stdio.h>

int main(void)
{
	int H, W, i, j, k;
	for (;;)
	{
		scanf("%d %d", &H, &W);
		
		if (H != 0 && W != 0)
		{
			for (j = 0; j < H; j++)
			{
				if (j % 2 == 0)
				{
					for (i = 0; i < W; i++)
					{
						if (i % 2 == 0)
						{
							printf("#");
						}
						else
						{
							printf(".");
						}
					}
					printf("\n");
				}
				else
				{
					for (i = 0; i < W; i++)
					{
						if (i % 2 == 0)
						{
							printf(".");
						}
						else
						{
							printf("#");
						}
					}
					printf("\n");
				}
			}
			printf("\n");
		}
		else
		{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 572
#include<stdio.h>

#define NUMBER 100

int main(){
    int num[NUMBER];
    int i;
    int n;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&num[i]);
    }
    for(i=n-1;i>=0;i--){
        printf("%d",num[i]);
        if(i==0) break;
        printf(" ");
        }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2036
N = int(input())
W = [int(i) for i in input().split()]

s = 0
for i in range(N):
    s += W[i]
    if s > sum(W)/2:
        t = i
        break
else:
    t = N-1

s2 = s-W[t]
print(min(s-(sum(W)-s), -(s2-(sum(W)-s2))))

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll  = long long;
using ull = unsigned long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    ull N, K;
    std::cin >> N >> K;

    vector<ull> dig_cnt(40); // floor(log2(10^12) + 1)
    vector<ull> A(N);
    REP(i, N) {
        std::cin >> A[i];
        REP(j, 40) {
            dig_cnt[j] += ((A[i] & (1ULL << j)) != 0);
        }
    }

    ull X = 0;
    if(K != 0) {
        int K_digit = floor(log2(K) + 1);
        for(int i = K_digit - 1; 0 <= i; i--) {
            if(dig_cnt[i] <= N / 2) {
                if((X | (1ULL << i)) <= K) {
                    X |= 1ULL << i;
                }
            }
        }
    }

    ull ans = 0;
    REP(i, N) {
        ans += A[i] ^ X;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(a.begin(), a.end());
  sort(f.rbegin(), f.rend());
  ll l = -1, r = 1e13;
  while (l + 1 < r) {
    ll middle = (l + r) / 2;
    bool ok = [&]{
      ll s = 0;
      rep(i, n) {
        s += max(0LL, a[i] - middle / f[i]);
      }
      return s <= k;
    }();
    if(ok) r = middle;
    else l = middle;
  }
  cout << r << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i, N) cin >> a[i];
  int ki = 0;
  int bai2 = 0;
  int bai4 = 0;
  bool flag = false;
  for(int i = 0; i < N; i++) {
    if(a[i] % 2 != 0) {
      ki++;
    } else {
      if(a[i] % 4 != 0) {
        bai2++;
      } else {
        bai4++;
      }
    }
  }
  if(bai2 == 0) {
    if(ki - 1 <= bai4) { flag = true; }
  } else {
    if(ki <= bai4) { flag = true; }
  }
  if(flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, A, B;
    cin >> X >> A >> B;
    cout << (X - A) % B << endl;

    return 0;
}


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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

vector<int> insertionSort(vector<int> a, int n) {
  for (int i=1; i<n; i++) {
    rep(k, n) printf("%d%c", a[k], k == n-1 ? '\n':' ');
    int v = a[i];
    int j = i - 1;
    while ((j >= 0) && (a[j] > v)) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<int> ans = insertionSort(a, n);
  rep(i, n) printf("%d%c", ans[i], i == n-1 ? '\n':' ');
  return 0;
}



Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vvi            vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)        for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x)    ((c).find(x) != (c).end()) 
#define cpresent(c,x)    (find(all(c),x) != (c).end()) 
using namespace std;
ll mod=1e9+7;
#define N  200005
vi parent(N),tsz(N);
ll n,m;

void init(){
    rep(i,1,n+1){
        parent[i] = i;
        tsz[i] = 1;
    }
}

ll dsfind(ll a){
    if(parent[a]==a) return a;
    parent[a] = dsfind(parent[a]);
    return parent[a];
}

void dsunion(ll a, ll b){
    a = dsfind(a), b = dsfind(b);
    if(a==b) return;
    if(tsz[a]>=tsz[b]){
        parent[b] = a;
        tsz[a] += tsz[b];
    }
    else{
        parent[a] = b;
        tsz[b] += tsz[a]; 
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    //ll cs=1;
    while(TESTS--)
    {
        cin >> n >> m;
        init();
        rep(i,0,m){
            ll u,v; cin >> u >> v;
            dsunion(u,v);
        }
        ll ans = 0;
        rep(i,1,n+1){
            if(parent[i]==i) ans = max(ans,tsz[i]);
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 6284
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
int f(int n){
    if(n%2) return 3*n+1;
    else return n/2;
}
int main(){
    int s;
    cin>>s;
    if(s==1||s==2||s==4){
        cout<<4<<endl;
        return 0;
    }
    vector<int> a(1000000);
    a[1]=s;
    int ans;
    int i=2;
    while(1){       
        a[i]=f(a[i-1]);
        if(a[i]==4){
            ans=i+3;
            break;
        }
        i++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;

  int k = 1;
  while(k * (k - 1) / 2 < n){
    ++k;
  }

  if(k * (k - 1) / 2 != n){
    cout << "No" << endl;
    return 0;
  }

  set< int > g[MAX];
  int count = 1;
  for(int v = 0; v < k; v++){
    for(int w = v + 1; w < k; w++){
      g[v].insert(count);
      g[w].insert(count);
      ++count;
    }
  }

  string buf;
  buf += "Yes\n";
  buf += to_string(k) + "\n";
  for(int i = 0; i < k; i++){
    buf += to_string(g[i].size());
    for(int j: g[i]){
      buf += " " + to_string(j);
    }
    buf += "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 14324
#include <stdio.h>

typedef struct{
    int id;
    int parent;
    int left;
    int right;
    int depth;
}Tree;

Tree T[100000];

void print(int);

int main(){
    int i,j;
    int n;
    int id,pa,le,ri,depth;
    int data;
    scanf("%d",&n);
        //printf("n=%d\n",n);
    for(i=0;i<n;i++){
        T[i].id=-1;
        T[i].parent=-1;
        T[i].left=-1;
        T[i].right=-1;
        T[i].depth=0;
    }
    
    
    for(i=0;i<n;i++){
            //printf("i=%d{\n",i);
        scanf("%d",&id);
        T[id].id=id;
        
        scanf("%d",&j);
        if(j==0)continue;
        scanf("%d",&data);
        T[data].parent=id;
        T[id].left=data;
        j--;
        
        for(le=data;j>=1;j--){
                //printf("    j=%d\n",j);
            scanf("%d",&data);
            T[data].parent=id;
            T[le].right=data;
            le=data;
        }
            //printf("}\n");
    }
    
    for(i=0;i<n;i++){
        j=i;
        depth=0;
        while(T[j].parent!=-1){
            j=T[j].parent;
            depth++;
        }
        T[i].depth=depth;
    }
    
    for(i=0;i<n;i++){
        printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,T[i].depth);
        if(T[i].parent==-1)printf("root, [");
        else if(T[i].left==-1)printf("leaf, [");
        else printf("internal node, [");
        if(T[i].left!=-1){
            ri=T[i].left;
            printf("%d",ri);
            while(T[ri].right!=-1){
                printf(", %d",T[ri].right);
                ri=T[ri].right;
            }
        }
        printf("]\n");
    }
    
    return 0;
}

Measured memory_bytes: 2564
### subroutines

def lower_bound(arr, key, i0 = 0, i1 = arr.length)
  lb = i0 - 1
  ub = i1

  while lb + 1 < ub
    m = (lb + ub) / 2
    if arr[m] >= key
      ub = m
    else
      lb = m
    end
  end
  ub
end

### main

loop do
  n = gets.to_i
  break if n == 0

  swmrs = []
  n.times do
    ti, ci = gets.split.map(&:to_i)
    swmrs << [ti, ci]
  end
  swmrs.sort!{|a, b| b <=> a}
  #p swmrs

  t0s = 2.times.map{[]}
  t0tot1s = 2.times.map{{}}
  t0used = 2.times.map{[]}
  max_t = 0
  
  for i in (0...n)
    ti, ci = swmrs[i]
    t0 = 0
    t0s0 = 2.times.map{[]}
    for j in (0...ci)
      for l in (0..1)
        t1 = t0 + ti

        k = lower_bound(t0s[l], t0) - 1
        #p ['  lower_bound-1', t0, k]
          
        if k < 0
          if t0used[l][t0].nil?
            t0s0[l] << t0
            t0tot1s[l][t0] = t1
            t0used[l][t0] = true
          end
        else
          t1k = t0tot1s[l][t0s[l][k]]
          if t1 < t1k
            t1 = t1k
          elsif t0used[l][t0].nil?
            t0s0[l] << t0
            t0tot1s[l][t0] = t1
            t0used[l][t0] = true
          end
        end
        #p [i, j, l, t0, t1]
        
        t0 = t1
      end
    end
    
    for l in (0..1)
      t0s[l] = (t0s[l] + t0s0[l]).sort
    end
    #p (0..1).map{|l| t0s[l].map{|tt0| [tt0, t0tot1s[l][tt0]]}}

    max_t = t0 if max_t < t0
  end
  
  puts max_t
end

Measured memory_bytes: 16668
from collections import defaultdict
import sys
sys.setrecursionlimit(10**9)
n = int(input())
data = []
for i in range(n):
    data.append(list(map(int, input().split())))
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
unionfind = UnionFind(n)
x_d = defaultdict(set)
y_d = defaultdict(set)
for i in range(n):
    x_d[data[i][0]].add(i)
    y_d[data[i][1]].add(i)

for i in range(n):
    x, y = data[i]
    if len(x_d[x]) > 1 and len(y_d[y]) > 1:
        for j in x_d[x]:
            unionfind.union(i, j)
        for j in y_d[y]:
            unionfind.union(i, j)

point = [[] for i in range(n)]
for i in range(n):
    if unionfind.size(i) <= 2:
        continue
    else:
        point[unionfind.find(i)].append(i)
ans = 0
for i in range(n):
    if len(point[i]) > 2 :
        x_s = set()
        y_s = set()
        for j in point[i]:
            x, y = data[j]
            x_s.add(x)
            y_s.add(y)
        ans += len(x_s) * len(y_s) - len(point[i])
print(ans)


Measured memory_bytes: 149824
/*  ex9-1
    toshiwaka */

#include <stdio.h>
#include <stdlib.h>

//スタックに格納するデータの最大数
//1<=|s|<=10
#define SIZE 10

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

void print_stack(stack *stk){
  for(int i = 1; i <= stk->count; i++){
    printf("%c", stk->data[SIZE-i]);
  }
  putchar('\n');
}

int main(void){
    //スタック
    stack stk;
    //1<=|s|<=SIZEより最大の要素数は\0を含めてSIZE+1
    char input[SIZE+1];
    //入力の長さ
    int len;

    //スタックを初期化（ポインタ渡しで関数にわたすこと）
    initialize_stack(&stk);

    //入力
    scanf("%s", input);
    len = strlen(input);

    //データの格納
    for(int i = 0; i < len; i++){
      if(input[i] == 'B'){
        if(stk.count != 0) pop(&stk);
      } else {
        push(&stk, input[i]);
      }
    }

    //スタックの中身を出力
    print_stack(&stk);

    return 0;
}

Measured memory_bytes: 1596
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n;
string s,ans;
int main(){
    cin >> n >> s;
    ans = s;
    rep1(i,n-1){
        map<char,int> ini = {};
        map<char,int> input = {};
        cin >> s;
        rep(j,sz(ans)) ini[ans[j]]++;
        rep(j,sz(s)) input[s[j]]++;
        
        string res = "";
        repi(a,'a','z'){
            int x = min(input[a],ini[a]);
            rep(j,x) res += (char)a;
        }
        ans = res;
    }
    sort(ALL(ans));
    pr(ans);
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b;
	cin >> a >> b;
	if (a >= 13)cout << b << endl;
	else if (a >= 6)cout << b / 2 << endl;
	else cout << 0 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;
// cout << typeid('変数').name() << endl;

int main() {
    string input_s;
    cin >> input_s;
    deque<char> s;
    for (int i=0;i<input_s.size();++i){
        s.push_back(input_s.at(i));
    }
    int q;
    cin >> q;
    bool reverse_flag = false;
    for (int i=0;i<q;++i){
        int t;
        cin >> t;
        if(t==1){
            reverse_flag^=1;
        }
        if(t==2){
            int f;
            char c;
            cin >> f >> c;
            if(f==1&&reverse_flag==0||
                f==2&&reverse_flag==1){
                s.push_front(c);
            }
            else{
                s.push_back(c);
            }
            
        }
    }
    if(reverse_flag==1){
        for (int i=s.size()-1;i>=0;--i){
            cout << s.at(i);
        } 
    }
    else{
        for (int i=0;i<s.size();i++){
            cout << s.at(i);
        }
    }
    
    cout << endl;
    return 0;
}



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

ll INF = (1LL << 60);

const int maxtime = 10e5+1;
bool sTimes[30][maxtime];
bool eTimes[30][maxtime];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    ll N, C;
    cin >> N >> C;
    for (int i = 0; i < N; ++i) {
        ll s, t, c;
        cin >> s >> t >> c;
        --c;
        sTimes[c][s] = true;
        eTimes[c][t] = true;
    }

    for (int c = 0; c < 30; ++c) {
        for (int i = 0; i < maxtime; ++i) {
            if (sTimes[c][i] && eTimes[c][i]) {
                sTimes[c][i] = false;
                eTimes[c][i] = false;
            }
        }
    }

    int recorders = 0;
    int cur = 0;
    for (int t = 0; t < maxtime; ++t) {
        for (int c = 0; c < 30; ++c) {
            if (sTimes[c][t]) ++cur;
        }
        recorders = max(recorders, cur);
        for (int c = 0; c < 30; ++c) {
            if (eTimes[c][t]) --cur;
        }
    }
    cout << recorders;
}

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

#define MOD (2019)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(), x.end()
#define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl;
#define forf(i,a,b) for(int i = (a); i < (b); i++)
#define forr(i,a,b) for(int i = (a); i > (b); i--)
#define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i];

// template starts
typedef long long int ll;
ll fact(ll n, ll p){
	ll ans = 1;
	for(ll i = 1; i <= n; i++){
		ans *= i;
		ans %= p;
	}
	return ans;
}
ll power(ll x, ll n, ll p){
	ll res = 1;
	if(n == 1) return x%p;
	if(n%2 == 1) res = x%p;

	ll temp = power(x,n/2,p);
	return res*((temp*temp)%p)%p;
}
ll inv(ll a, ll p){
	return power(a,p-2,p);
}
ll nCr(ll n, ll r, ll p){
	if(r > n) return 0;
	ll t1 = fact(n,p);
	ll t2 = inv(fact(r,p),p);
	ll t3 = inv(fact(n-r,p),p);

	return (((t1*t2)%p)*t3)%p;
}
vector<vector<ll> > multiply(vector<vector<ll> > &a, vector<vector<ll> > &b, ll p){
	int r1,c1,r2,c2;
	r1 = a.size(); c1 = a[0].size();
	r2 = b.size(); c2 = b[0].size();

	vector<vector<ll> > result(r1,vector<ll>(c2,0));

	if(c1 != r2) return result;

	for(int i = 0; i < r1; i++){
		for(int j = 0; j < c2; j++){
			for(int k = 0; k < c1; k++){
				result[i][j] += a[i][k]*b[k][j];
				result[i][j] %= p;
			}
		}
	}
	return result;
}
vector<vector<ll> > power(vector<vector<ll> >&a,ll n, ll p){
	int r = a.size();
	vector<vector<ll> > result(r,vector<ll>(r,0));
	for(int i = 0; i < r; i++) result[i][i] = 1;

	while(n > 0){
		if(n%2 == 1){
			result = multiply(result,a,p);
		}
		n /= 2;
		a = multiply(a,a,p);
	}
	return result;
}
// template ends here

void solve(){
	// code starts from here
	string str;
	cin >> str;
	vector<ll> vec(MOD,0);
	vec[0] = 1;
	
	ll rem = 0;
	ll temp = 1;
	ll ans = 0;
	
	int N = str.size();
	for(int i = N-1; i >= 0; i--){
		ll m = str[i]-'0';
		
		rem = (m*temp + rem)%MOD;
			
		temp *= 10;
		temp %= MOD;
			
		ans += vec[rem];
		vec[rem]++;
	}
	cout << ans << endl;
}

int main(){
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int T;
	T = 1;
	while(T--){
		solve();
	}

	return 0;
}


Measured memory_bytes: 3788
#include<stdio.h>

int main(void){
int N,K,l[50];
int i,k,max,flag,j,max_add,max_i[50];

scanf("%d %d",&N,&K);
scanf("%d",&l[0]);
for(i=1;i<N;i++){
scanf(" %d",&l[i]);
}

max_add=0;
for(k=0;k<K;k++){
 max=0;
 for(i=0;i<N;i++){
  if(l[i]>max){
   for(j=0;j<k;j++){
    if(i==max_i[j]){
     flag=1;
    }
   }
   if(flag==0){
    max=l[i];
    max_i[k]=i;
   }
   flag=0;
  }
 }
max_add=max_add+max;
}


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


return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C103
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<long> a = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();

            long sum = a.Sum(x => x - 1);  
            Console.WriteLine(sum);
        }

    }
}


Measured memory_bytes: 13408
S=input()
L=len(str(S))

if L==1:
  j=0

if L>1:
  w=int(L/2)

  i=0
  j=0
  for i in range(w):
    if S[i:i+1]!=S[L-1-i:L-i]:
      j=j+1
  
print(j)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//typedef tree < int , null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> TREE;
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define pld pair<long double,long double >
#define ld long double
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
#define pll pair<ll,ll>
#define speed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define M_PI 3.14159265358979323846
//#define int long long
const int mod=1000000007;
//const int mod=998244353;
const int inf=1000000009;
const long long INF=1000000000000000009;
const long long big=1000000000000000;
const long double eps=0.000000000000000000001;
using namespace std;
int main()
{
    speed
    ll a,b;
    cin>>a>>b;
    if(a==1||b==1)
        cout<<1;
    else
    {
        ll x=a*b;
        ll y=x/2;
        if(x&1)
            y++;
        cout<<y;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        // 自分の得意な言語で
        // Let's チャレンジ！！

        Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int m[]=new int[n];
for(int i=0;i<n;i++)
m[i]=sc.nextInt();
for(int i=n-1;i>=0;i-=2)System.out.print(m[i]+" ");
for(int i=n%2;i<n;i+=2)System.out.print(m[i]+" ");
}
}

Measured memory_bytes: 93396
#include <stdio.h>
int main(void) {
  int i, n, num[100];

  scanf("%d", &n);

  for (i = 0; i < n; i++)
    scanf("%d", &num[i]);

  printf("%d", num[n - 1]);
  for (i =  n - 2; i >= 0; i--)
    printf(" %d", num[i]);
  puts("");

  return 0;
}

Measured memory_bytes: 1036
# -*- coding: utf-8 -*-
"""
http://abc070.contest.atcoder.jp/tasks/abc070_d
"""
# TLEするので、ダイクストラのアルゴリズムからの高速化が必要。
# 隣接行列をやめて隣接リストにしたところ、だいぶ速度が改善された。しかし、今度はWAが出るようになった。
# WAはコスト無限大の設定値が低すぎたため、経路コストがオーバーしてしまっていたため。float('inf')にして TLEのみになった
# d[]をnumpyの行列にしてみた → 遅くなっただけ
# クラスをやめてベタ書きに
from heapq import heappush, heappop


# データの入力
N = int(input())
adj = [[] for _ in range(N+1)]
for i in range(N-1):
    f, t, c = [int(x) for x in input().split(' ')]
    adj[f].append((t, c))
    adj[t].append((f, c))

queries = []
Q, K = [int(x) for x in input().split(' ')]
for _ in range(Q):
    queries.append([int(x) for x in input().split(' ')])

# 経路の探索
WHITE, GRAY, BLACK = 0, 1, 2
color = [WHITE] * (N+1)  # 各ノードの訪問状態
d = [float('inf')] * (N+1)  # 始点からの重み

# dijkstra
d[K] = 0
pq = [(0, K)]

while pq:
    cost, u = heappop(pq)
    color[u] = BLACK
    if d[u] < cost:
        continue

    for v, c in adj[u]:
        if color[v] == BLACK:
            continue
        if d[v] > d[u] + c:
            d[v] = d[u] + c
            heappush(pq, (d[v], v))
            color[v] = GRAY

# 結果の表示
for x, y in queries:
    print(d[x] + d[y])


Measured memory_bytes: 65188
def set_pdt(i, p, d):
    u = tree[i]
    u[0], u[1] = p, d
    for c in u[3]:
        set_pdt(c, i, d+1)
    else:
        if u[0] == -1:
            u[2] = "root"
        elif u[3]:
            u[2] = "internal node"
        else:
            u[2] = "leaf"

n = int(input())
tree = [[-1,0,0,0] for _ in range(n)]
root = set(range(n))

for _ in range(n):
    i, k, *c = map(int, input().split())
    tree[i][3] = c
    root -= set(c)
    
set_pdt(root.pop(), -1, 0)

for i in range(n):
    u = tree[i]
    print("node {}: parent = {}, depth = {}, {}, {}".format(i, *u))

Measured memory_bytes: 43820