akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    map<char, int> h;
    rep(i, n){
        string in; cin >> in;
        h[in[0]]++;
    }

    string T = "MARCH";
    int m = T.size();
    ll res = 0;
    rep(i, m){
        char e1 = T[i];
        rep(j, i+1, m){
            char e2 = T[j];
            rep(k, j+1, m){
                char e3 = T[k];
                res += 1LL * h[e1] * h[e2] * h[e3];
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
using namespace std;
#define endl '\n'
#define pi pair<int, int>

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long n, k;
	cin >> n >> k;
	
	
	long long ret = 0;
	long long a[n + 1];
	a[0] = 0;
	unordered_map<long long, long long> dp;
	dp[0] = 1;
	for(int i = 1; i <= n; i++){
		if(i >= k){
			dp[(k + a[i - k] - ((i - k) % k)) % k]--;
		}
		
		cin >> a[i];
		a[i] = (a[i - 1] + a[i]) % k;
		ret += dp[(k + a[i] - (i % k)) % k];
		dp[(k + a[i] - (i % k)) % k]++;
	}
	
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 10056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
ll n;
ll ans = 1ll << 60;
ll a[maxx];

int main() {
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	bool flg = 0;
	ll sum = 0;
	ll res = 0;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(!flg) {
			if(sum <= 0) {
				res = res + 1 - sum;
				sum = 1;
			}
		}
		else {
			if(sum >= 0){
				res = res + sum + 1;
				sum = -1;
			}
		}
		flg ^= 1;
	}
	ans = min(ans, res);
	res = 0;
	sum = 0;
	flg = 0;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(flg) {
			if(sum <= 0) {
				res = res + 1 - sum;
				sum = 1;
			}
		}
		else {
			if(sum >= 0) {
				res = res + sum + 1;
				sum = -1;
			}
		}
		flg ^= 1;
	}
	ans = min(ans, res);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

void solve() {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", std::max(a - 2 * b, 0));
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

int main(){
	ll n;
	cin>>n;
	ll p=n%1000;
	if(p==0){
		cout<<p;
	}
	else{
		cout<<1000-p;
	}
	
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int ans = 0;
		if (a == b) {
			ans +=1;
		}
		if(b==c) {
			ans +=1;

		}
		if(a==c) {
			ans +=1;
		}
		if(3-ans==0) {
			System.out.println("1");
		}
		else {
		System.out.println(3-ans);}}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int N; 
string S;
bool possible(int pos, int len) {
	vector<int> fail(len);
	for(int i = 1, j = 0; i < len; ++i) {
		while(j > 0 && S[pos + i] != S[pos + j]) j = fail[j - 1];
		if(S[pos + i] == S[pos + j]) fail[i] = ++j;
	}
	vector<int> res;
	for(int i = 0, j = 0; i < N; ++i) {
		while(j > 0 && S[i] != S[pos + j]) j = fail[j - 1];
		if(S[i] == S[pos + j]) {
			if(j == len - 1) {
				res.push_back(i - len + 1);
				j = fail[j];
			} else ++j;
		}
	}
	if(sz(res) >= 2 && res.back() - res.front() >= len) return true;
	else return false;
}

bool chk(int len) {
	for(int i = 0; i <= N - len; ++i) {
		if(possible(i, len)) return true;
	}
	return false;
}

int main() {
	FAST_IO();
	cin >> N;
	cin >> S;
	int ans = 0;
	int lo = 1, hi = N / 2;
	while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		if(chk(mid)) {
			ans = mid;
			lo = mid + 1;
		} else hi = mid - 1;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n;
	cin>>n;
	vector<int> h(n);
	rep(i,n)cin>>h[i];
	int ans = 0;
	int cnt = 0;
	rep(i,n-1){
		if(h[i]>=h[i+1])cnt++;
		else{
			ans = max(ans,cnt);
			cnt=0;
		}
	}
	ans = max(ans,cnt);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
using System;

namespace C103
{
    class Program
    {
        static void Main(string[] args)
        {
            var c = Console.ReadLine();
            if (c=="a"|| c =="e"||c=="i"||c=="o"||c=="u")
            Console.WriteLine("vowel");
            else
                Console.WriteLine("consonant");
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long  w,h,x,y;
  cin >> w >> h >> x >> y;
  long long s;
  s = w*h;
  
  double answer = double(s)/2.0;
  
  int flag=0;
  
  if( w == x*2 && h == y*2) flag = 1;
  
  
  cout << answer << ' ' << flag << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define M 1046527
#define L 14

char H[M][L];

int getChar(char);
long long getKey(char *);
int find(char *);
int insert(char *);

int main(){
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",com,str);
    if(com[0] =='i'){
      insert(str);
    }
    else{
      if(find(str)){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }
  return 0;
}
int getChar(char ch){
if(ch=='A')return 1;
 else if(ch=='C')return 2;
 else if(ch=='G')return 3;
 else return 4;
}

long long getKey(char *str){
  long long sum = 0,p = 1,i;
  for(i=0;i<strlen(str);i++){
    sum +=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}

int A(int key){return key %M;}
int B(int key){return 1+(key%(M-1));}

int find(char *str){
  long long key,i,a;
  key=getKey(str);
  for(i=0;;i++){
    a=(A(key)+i*B(key))%M;
    if(strcmp(H[a],str)==0)
      return 1;
    else if(strlen(H[a])==0)
      return 0;
  }
  return 0;
}
int insert (char *str){
  long long key,i,a;
  key=getKey(str);
  for(i=0;;i++){
    a=(A(key)+i*B(key))%M;
    if(strcmp(H[a],str)==0)return 1;
    else if(strlen(H[a])==0){
      strcpy(H[a],str);
      return 0;
    }
  }
  return 0;
}



Measured memory_bytes: 16104
N, M = list(map(int,input().split()))
L = [0] * M
R = [0] * M
for i in range(M):
    L[i], R[i] = list(map(int,input().split()))

min_temp = L[0]
max_temp = R[0]
ans = R[0] - L[0] + 1

for i in range(1, M):
    
    if min_temp < L[i]:
        ans -= (L[i] - min_temp)
        min_temp = L[i]
    
    if R[i] < max_temp:
        ans -= (max_temp - R[i])
        max_temp = R[i]
        
if ans < 0:
    ans = 0
    
print(ans)

Measured memory_bytes: 10996
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>
#include <tgmath.h>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {

    ll n,k;
    cin>>n>>k;

    vector<ll>h(n);
    rep(i,n)cin>>h[i];

    sort(h.begin(),h.end());

    ll ans=10e9;

    rep(i,n-k+1){
        ans=min(ans,abs(h[i]-h[i+k-1]));
    }

    cout<<ans<<endl;
}


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

int main(){
  int a,b,c,d,e,f,g,h,i;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> i;
  bool ans=false;
  if(a+e+i==c+d+h && a+e+i==b+f+g && c+e+g==a+f+h && c+e+g==b+d+i){
    ans=true;
  }
  cout << (ans?"Yes":"No") << endl;
}

Measured memory_bytes: 256
//OPTIMIZATONS
#pragma GCC optimize("02")
//CODE
#include<bits/stdc++.h>
#define int long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	cout<<fixed<<setprecision(10)<<2*M_PI*n<<endl;
	return 0;
}



Measured memory_bytes: 3804
n = int(input())
# [1桁目][1の位]のリストを作る
ho = [[0 for nesya in range(9)] for motsu in range(9)]
for i in range(1,n+1):
  if i%10 != 0:
    a = str(i)
    #数字ごとにhoリストに足していく
    (ho[int(a[0])-1])[int(a[-1])-1] += 1
ans = 0
#1桁目と1の位が同じものに注意して組み合わせの数を計算する
for j in range(9):
  for k in range(j+1):
    if k == j:
      ans += (ho[k][k])**2
    else:
      ans += (ho[j][k])*(ho[k][j])*2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair

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

    ll n,w;
    cin>>n>>w;

    vector<ll>wv(n+1);
    vector<ll>vv(n+1);

    for(ll i=1;i<=n;i++)
    {
        cin>>wv[i]>>vv[i];
    }

    vector<vector<ll> >dp(n+1,vector<ll>(w+1));

    dp[1][wv[1]]=vv[1];

    for(ll i=2;i<=n;i++)
    {
        for(ll j=0;j<wv[i];j++)
        {
            dp[i][j]=dp[i-1][j];
        }
        for(ll j=0;j+wv[i]<=w;j++)
        {
            dp[i][j+wv[i]]=max(dp[i-1][j+wv[i]],dp[i-1][j]+vv[i]);
        }
    }

//    for(ll i=0;i<=w;i++)
//    {
//        cout<<dp[n][i]<<" ";
//    }

    ll ans=-1;
    for(ll i=0;i<=w;i++)
    {
        //if(dp[n][i]==60)cout<<i;
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 80256
import java.util.Scanner;

public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(true) {
			int  H= sc.nextInt();
			int  W= sc.nextInt();
			if(H==0 && W==0) break;
			for (int i=0 ;i<H ;i++) {
				for (int j=0; j < W ; j++) {
					if((i+j) % 2 == 0) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
				}
					System.out.println();
				}
				System.out.println();
			}

		}
	}


Measured memory_bytes: 37536
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N,M,X,Y;
    cin >> N >> M >> X >> Y;
    int xmax,ymin;
    xmax = -100; ymin = 100;
    int x,y,i;
    for(i=0;i<N;i++){
        cin >> x;
        if(x>xmax) xmax = x;
    }
    for(i=0;i<M;i++){
        cin >> y;
        if(y < ymin) ymin = y;
    }
    if(max(X,xmax) < min(Y,ymin)) cout << "No War" << endl;
    else cout << "War" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

ll llabs(ll x){
    return x>0?x:-x;
}

int main(void){
    int N, M;
    cin >> N >> M;
    ll a[N], b[N], c[M], d[M];
    FOR(i, 0, N) cin>>a[i]>>b[i];
    FOR(i, 0, M) cin>>c[i]>>d[i];
    FOR(i, 0, N){
        ll MIN = 999999999;
        ll p;
        FOR(j, 0, M){
            if(MIN > llabs(a[i]-c[j]) + llabs(b[i]-d[j])){
                MIN = llabs(a[i]-c[j]) + llabs(b[i]-d[j]);
                p = j;
            }
        }
        cout << p+1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
char a[17];
int main()
{
	cin>>a;
	int l=strlen(a)-1;
//	cout<<l<<endl;
	int sum=0;
	for(int i=l;i>=1;i--)
	{
		if(a[i]!='9')
		{
			sum+=9;
			a[i-1]--;
		}
		else
		{
			sum+=9;
		}
	}
	sum+=a[0]-'0';
	cout<<sum<<endl;
 } 


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt(),m=scan.nextInt(),a,b,t[]=new int[100000],i;
		for(i=0;i<m;i++) {
			a=scan.nextInt();
			b=scan.nextInt();
			t[a-1]++;
			t[b-1]++;
		}
		scan.close();
		for(i=0;i<n;i++) System.out.println(t[i]);
	}
}

Measured memory_bytes: 21588
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
      	int x = s.nextInt();
      	int y = s.nextInt();
      	int z = s.nextInt();
      	System.out.printf("%d %d %d\n", z, x, y);
    }
}

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

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

int main(void) {
    int n, d;
    set<int> se;

    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    REP(i, n) {
        cin >> d;
        se.insert(d);
    }

    cout << se.size() << "\n";
    return 0;
}

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

int main()
{
  int a1,a2,a3,k;
  cin >> a1 >> a2 >> a3;
  k=a1+a2 +a3;
  if(k<22)
  {
    cout << "win";
  }
  else
  {
    cout << "bust";
  }
}  
  
  
  
  
	

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    cout << (1000-n%1000)%1000;
    return 0;
}


Measured memory_bytes: 3644
n,t=[int(x) for x in input().split()]
w=[]
for i in range(n):
    w.append(int(input()))
 
totalw=sum(w)  
pmax=totalw
pmin=int(totalw/t)-1
 
def check(ptest):
    tk=1
    p=0
    global t
    global w
    global n
    i=0
     
    while i<n:
        p+=w[i]
        if p<=ptest:
            i+=1
        else:
            tk+=1
            p=0
             
        if tk>t:
            return 0
            #break   
     
    return 1
     
         
while (pmax-pmin)>1:
    pmid=(pmax+pmin)//2
    if check(pmid)==1:
        pmax=pmid
    else:
        pmin=pmid
         
print(pmax)


Measured memory_bytes: 9568
package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	bad := [1e6 + 1]bool{}
	vis := [1e6 + 1]bool{}
	var n, ans int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if vis[a[i]] {
			bad[a[i]] = true
		}
		if !bad[a[i]] {
			for j := 2 * a[i]; j <= 1e6; j += a[i] {
				bad[j] = true
			}
		}
		vis[a[i]] = true
	}
	for _, v := range a {
		if !bad[v] {
			ans++
		}
	}
	Fprint(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int ans = 0;
    if (A + B <= 2 * C)
    {
        ans += A * X + B * Y;
    }
    else
    {
        if (X <= Y)
        {
            ans += 2 * C * X + min(B, 2 * C) * (Y - X);
        }
        else
        {
            ans += 2 * C * Y + min(A, 2 * C) * (X - Y);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
w,h,n=map(int,input().split())
y_max,x_max=h,w
y_min,x_min=0,0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    x_min=max(x_min,x)
  elif a==2:
    x_max=min(x_max,x)
  elif a==3:
    y_min=max(y_min,y)
  elif a==4:
    y_max=min(y_max,y)

width=max(x_max-x_min,0)
height=max(y_max-y_min,0)
print(int(width*height))





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

using namespace std;
typedef long long ll;

const ll INF = 1145141919810364364;

int main() {
    ll n, k;
    cin >> n >> k;

    vector<ll> plus, minus;
    ll zero = 0;
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        if (a > 0)plus.push_back(a);
        else if (a == 0)zero++;
        else minus.push_back(a);
    }
    sort(plus.begin(), plus.end()), sort(minus.begin(), minus.end());

    ll minusMul = plus.size() * minus.size();
    ll zeroMul = zero * (plus.size() + minus.size()) + zero * (zero - 1) / 2;

    if (k <= minusMul) { // 負の数はK個以上あるか？
        ll lower = -INF, upper = -1; // 答えは負
        while (upper - lower > 1) {
            ll mid = (lower + upper) / 2;

            ll count = 0;
            for (auto x:minus) { // 相手は正
                ll want = mid / x - 5;
                while (x * want > mid)want++; // 相手はwant以上の数
                count += plus.end() - lower_bound(plus.begin(), plus.end(), want);
            }

            if (count >= k)upper = mid;
            else lower = mid;
        }
        cout << upper << endl;
    } else if (k <= minusMul + zeroMul) {
        cout << 0 << endl;
    } else {
        ll lower = 0, upper = INF; // 答えは正
        k -= minusMul + zeroMul; // 1~midを数える
        while (upper - lower > 1) {
            ll mid = (lower + upper) / 2;

            ll count = 0;
            for (int i = 0; i < plus.size(); i++) { // 相手は正
                ll want = mid / plus[i] + 5;
                while (plus[i] * want > mid)want--; // 相手はplus[i]より大きくwant以下の数

                int now = upper_bound(plus.begin(), plus.end(), want) - plus.begin() - (i + 1);
                count += max(0, now);
            }
            for (int i = 0; i < minus.size(); i++) { // 相手は負
                ll want = mid / minus[i] - 5;
                while (minus[i] * want > mid)want++; // 相手はwant以上minus[i]未満の数

                int now = minus.end() - lower_bound(minus.begin(), minus.end(), want) - (minus.size() - i);
                count += max(0, now);
            }

            if (count >= k)upper = mid;
            else lower = mid;
        }
        cout << upper << endl;
    }
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
#define loop(i,x,z) for (int i=x;i<z;i++)
using ll = long long;
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
const ll M = 1000000007;
int n,a,b;
//string s;
int main()
{
    cin>>n;
    int cnt=0;
    bool flag=1;
    while(n--)
    {
        cin>>a>>b;
        if(a==b)cnt++;
        else cnt=0;
        if(cnt==3)
        {
            cout<<"Yes";
            flag=0;
            break;
        }
    }
    if(flag)cout<<"No";
}

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

int a[100010], b[100010];

int main () {
	int A, B, n; scanf("%d%d%d", &A, &B, &n);
	int mina = 0x3f3f3f3f, minb = 0x3f3f3f3f;
	for (int i = 1; i <= A; i++) {
		scanf("%d", &a[i]);
		mina = min(mina, a[i]);
	}
	for (int j = 1; j <= B; j++) {
		scanf("%d", &b[j]);
		minb = min(minb, b[j]);
	}
	int ans = mina + minb;
	for (int i = 0; i < n; i++) {
		int x, y, c; scanf("%d%d%d", &x, &y, &c);
		ans = min(ans, a[x] + b[y] - c);
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3508
from collections import deque
H , W = map(int,input().split())
A = []
start = []
for i in range(H):
    row = list(input())
    for j in range(W):
        if row[j] == "#":
            start.append([i , j])
    A.append(row)

def bfs(s):
    score = [[-1 for _ in range(W)] for _ in range(H)]
    q = deque()
    for y , x in s:
        score[y][x] = 0
        q.append([y,x])
    diff = [[0,1],[1,0],[-1,0],[0,-1]]

    while q:
        now_y , now_x = q.popleft()
        for dy , dx in diff:
            next_y , next_x = now_y + dy , now_x + dx
            if 0 <= next_y and next_y < H and 0 <= next_x and next_x < W and score[next_y][next_x] == -1:
                score[next_y][next_x] = score[now_y][now_x] + 1
                q.append([next_y,next_x])
    ret_val = 0
    for i in range(H):
        for j in range(W):
            ret_val = max(ret_val , score[i][j])
    return ret_val


print(bfs(start))

Measured memory_bytes: 267888
/**
 * This line was copied from template
 * This is asol.cpp
 * 
 * @author: Nikolay Kalinin
 * @date: Sat, 16 Mar 2019 15:39:44 +0300
 */
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int MOD = 1000000007;

int main()
{
    int n;
    string s;
    vector<int> cnt(300, 0);
    cin >> n >> s;
    for (auto c : s) cnt[c]++;
    ll ans = 1;
    for (int c = 'a'; c <= 'z'; c++) ans = (ans * (cnt[c] + 1)) % MOD;
    cout << (ans - 1 + MOD) % MOD << endl;
    return 0;
}


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

int main() {
    int n, w, total_values = 0;
    cin>>n>>w;
    vector<int> weights(n), values(n);
    for(int i = 0; i<n; i++) {
        cin>>weights[i]>>values[i];
        total_values += values[i];
    }
    vector<vector<long long> > dp(n+1, vector<long long>(total_values+1, 0));
    for(int i = 1; i<=total_values; i++) {
        dp[0][i] = INT_MAX;
    }
    for(int i = 1; i<=n; i++) {
        for(int j = 0; j<=total_values; j++) {
            if(values[i-1] > j) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = min(dp[i-1][j], weights[i-1] + dp[i-1][j-values[i-1]]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i<=total_values; i++) {
        if(dp[n][i] <= w) {
            ans = i;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 83092
#include<iostream>
#include<list>
using namespace std;
int main(){
	list<int>l;
	list<int>::iterator itr=l.begin();
	int q;
	cin>>q;
	while(q--){
		int n;
		cin>>n;
		if(n==0){
			int x;
			cin>>x;
			itr=l.insert(itr, x);
		}
		else if(n==1){
			int d;
			cin>>d;
			if(d>0){
				while(d--){
					itr++;
				}
			}
			else{
				while(d++){
					itr--;
				}
			}
		}
		else if(n==2){
			itr=l.erase(itr);
		}
	}
	//cout<<"-------------"<<endl;
	for(itr=l.begin(); itr!=l.end(); itr++){
		cout<<*itr<<endl;
	}
	return 0;
}


Measured memory_bytes: 18568
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
from heapq import heapify,heappush,heappop
n,m=n1()
A=n1()
h=[-i for i in A]
heapify(h)

for _ in range(m):
    a=heappop(h)
    heappush(h,a/2)

B=[int(-i) for i in h]
print(sum(B))

Measured memory_bytes: 15120
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n - 1)]

for i in range(n):
    t = 0
    for j in range(i, n - 1):
        c, s, f = csf[j]
        if t < s:
            t = s
        elif t % f == 0:
            pass
        else:
            t += f - t % f

        t += c

    print(t)


Measured memory_bytes: 9252
#include<bits/stdc++.h>
using namespace std;
int main() {
string s, t;
getline(cin >> ws, s);
getline(cin >> ws, t);
int cnt = 0;
for(int i=0;i<s.size(); i++){
if(s[i] != t[i])cnt++;
}
cout << cnt  << endl;
return 0;
}

Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main() {

	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;

}


Measured memory_bytes: 256
//Sasayego! Sasayego! Shinzou wo Sasageyo!

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x)  cerr << #x << " = " << x << endl
#define lid (id << 1)
#define rid (lid ^ 1)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

const int maxN = 5e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int a[maxN];

int main(){
	time_t START = clock();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n = 0;
	for (char ch = getchar(); ch != '\n'; ch = getchar(), n++)
		a[n] = ch - '0';
	reverse(a, a + n);
	int carry = 0;
	int sum = 0;
	for (int i = 0; i <= n; i++){
		int t = a[i] * 9 + carry;
		a[i] = t % 10;
		carry = t / 10;
		sum += a[i];
	}
	for (int x = 1; ; x++){
		int t = 9;
		for (int i = 0; t != 0; i++){
			sum -= a[i];
			a[i] += t;
			t = a[i] / 10;
			a[i] %= 10;
			sum += a[i];
			if (i > n)
				n++;
		}
		if (sum <= 9 * x)
			return printf("%d\n", x), 0;
	}
	time_t FINISH = clock();
	cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
	return 0;
}
 


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

int main() {
	string S;
  	cin >> S;
  
  	int sum = 0;
  
  	for(int i = 0; i < 4; i++) {
    	if(S.at(i) == '+') {
        	sum++;
        }else {
          	sum--; 
        }
    }
  	cout << sum << endl;
}


Measured memory_bytes: 256
a,b = map(int,input().split())
s = input()
f = True
numeric = set("1234567890")
if s[a] != "-":
    f = False
for i in s[:a]:
   if not i in numeric:
       f = False
for i in s[a+1:]:
    if not i in numeric:
        f = False
if f:
    print("Yes")
else:
    print("No")

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

int bit_count(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	return ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
}

int n, U;
int c[20];
int k[20];
int r[20][5];
int zyouken[20];

int memo[1 << 20];

int search(int current) {
	int ret = 100000;
	int i;
	int tani = 0;
	if (memo[current]) return ~memo[current];
	for (i = 0; i < n; i++) {
		if ((current >> i) & 1) {
			tani += c[i];
			if (tani >= U) return ~(memo[current] = ~bit_count(current));
		}
	}
	for (i = 0; i < n; i++) {
		if (!((current >> i) & 1)) {
			int candidate = search(current | (1 << i) | zyouken[i]);
			if (candidate < ret) ret = candidate;
		}
	}
	return ~(memo[current] = ~ret);
}

int main(void) {
	while (scanf("%d%d", &n, &U) == 2 && (n > 0 || U > 0)) {
		int i, j;
		int sinchoku;
		memset(memo, 0, sizeof(memo));
		for (i = 0; i < n; i++) {
			if (scanf("%d%d", &c[i], &k[i]) != 2) return 1;
			zyouken[i] = 0;
			for (j = 0; j < k[i]; j++) {
				if (scanf("%d", &r[i][j]) != 1) return 1;
				zyouken[i] |= 1 << r[i][j];
			}
		}
		do {
			sinchoku = 0;
			for (i = 0; i < n; i++) {
				int new_value = zyouken[i];
				for (j = 0; j < n; j++) {
					if ((zyouken[i] >> j) & 1) new_value |= zyouken[j];
				}
				if (new_value != zyouken[i]) {
					zyouken[i] = new_value;
					sinchoku = 1;
				}
			}
		} while (sinchoku);
		printf("%d\n", search(0));
	}
	return 0;
}

Measured memory_bytes: 4704
module ABC134

  ! <module>s to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none

  ! accessibility of <subroutine>s and <function>s in this <module>
  public :: task_C

  ! contained <subroutine>s and <function>s are below
  contains

  subroutine task_C

    ! variables for this <subroutine>
    integer(INT32) :: len_sequence
    integer(INT32) :: maxval_1st
    integer(INT32) :: maxval_2nd
    integer(INT32) :: maxval_answer
    logical        :: stat

    ! arrays for this <subroutine>
    integer(INT32), dimension(:), allocatable :: val_sequence

    ! support variables for this <subroutine>
    integer(INT32) :: itr

    ! STEP.01
    ! read out the given data
    ! (the length of the given sequence)
    read(unit=INPUT_UNIT, fmt=*) len_sequence

    ! STEP.02
    ! allocate the array to store the given sequence
    allocate( val_sequence(1:len_sequence) )

    ! STEP.03
    ! read out the given data
    ! (the values of the given sequence)
    do itr = 1_INT32, len_sequence, 1_INT32
      read(unit=INPUT_UNIT, fmt=*) val_sequence(itr)
    end do

    ! STEP.03
    ! find the maximum values of the given sequence

    maxval_1st = 0_INT32
    maxval_2nd = 0_INT32

    do itr = 1_INT32, len_sequence, 1_INT32

      if (maxval_1st .lt. val_sequence(itr)) then
        maxval_2nd = maxval_1st
        maxval_1st = val_sequence(itr)
      else if (maxval_2nd .lt. val_sequence(itr)) then
        maxval_2nd = val_sequence(itr)
      end if

    end do

    ! STEP.04
    ! output the answer of this task
    do itr = 1_INT32, len_sequence, 1_INT32

      if ( val_sequence(itr) .eq. maxval_1st ) then
        maxval_answer = maxval_2nd
      else
        maxval_answer = maxval_1st
      end if

      write(unit=OUTPUT_UNIT, fmt='(I0)', advance='yes') maxval_answer

    end do

    ! STEP.03
    ! deallocate the array to store the given data
    deallocate( val_sequence )

    ! STEP.END
    return

  end subroutine task_C

end module ABC134


program main

  ! <module>s to import
  use, non_intrinsic :: ABC134

  ! require all variables to be explicitly declared
  implicit none

  call task_C

end program main

Measured memory_bytes: 2304
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,q = readline() |> split |> parseMap
	e = [Int[] for i in 1:n]
	t = zeros(Int,n)
	t[1] = -1
	for i in 1:n-1
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	stack = Int[1]
	c = zeros(Int,n)
	for i in 1:q
		p,x = readline() |> split |> parseMap
		c[p]+=x
	end
	total = zeros(Int,n)
	while !isempty(stack)
		now = shift!(stack)
		for i in 1:length(e[now])
			if t[e[now][i]] == 0
				t[e[now][i]] = now
				c[e[now][i]] += c[now]
				push!(stack, e[now][i])
			end
		end
	end
	for i in 1:n-1
        print(c[i], " ")
    end
    println(c[n])
end

main()

Measured memory_bytes: 178280
n,a=int(input()),list(map(int,input().split()))
if sum(a)%(n*(n+1)/2):
	print("NO")
else:
	k=sum(a)/(n*(n+1)/2)
	a+=[a[0]]
	if sum([(k-i+j)%n for i,j in zip(a[1:],a)]) or sum([(k-i+j)/n>=0 for i,j in zip(a[1:],a)])!=n:
		print("NO")
	else:
		print("YES")

Measured memory_bytes: 66540
def test():
    s = str(input())
    l = len(s)
    if s[0] == "A":
        s_1 = s[1:]
        # print(s_1)
        for i in range(1,l-2):
            if s_1[i] == "C":
                # print(i)
                s_2 = s_1[:i] + s_1[i+1:]
                # print(s_2)
                if s_2.islower():
                    print("AC")
                    return 0
    print("WA")
    return 0

test()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define all(x) x.begin(), x.end()

using namespace std;

int n;
ll a, b, c, d;

int main() {
	scanf ("%d%lld%lld%lld%lld", &n, &a, &b, &c, &d);
	ll dif = d - c;
	rep(i, 0, n - 1) {
		ll A = a + -d * i + c * (n - i - 1);
		if (A <= b && b <= A + (n - 1) * dif) {
			printf ("YES\n");
			return 0;
		}
	}
	printf ("NO\n");
	return 0;
}	


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

using namespace std;

vector<vector<int>> a(100001);
map<pair<int, int>, int> mp;
vector<pair<int, int>> xy;

void dfs(int n, int p, int c);

int main()
{
	int n;
	cin >> n;
	int x, y;
	for (int i = 0; i < n - 1; i++) {
		cin >> x >> y;
		x--;
		y--;
		a[x].push_back(y);
		a[y].push_back(x);
		xy.push_back(make_pair(x, y));
	}

	int k = 0;
	for (int i = 0; i < a.size(); i++) {
		k = max(k, (int)a[i].size());
	}
	cout << k << endl;

	dfs(0, 0, 0);

	for (int i = 0; i < n - 1; i++) {
		cout << mp[xy[i]] << endl;
	}

	return 0;
}

void dfs(int n, int p, int c)
{
	mp[make_pair(p, n)] = c;

	int d = (c == 1) ? 2 : 1;
	for (auto & u : a[n]) {
		if (u == p) {
			continue;
		}
		dfs(u, n, d);
		d = (d + 1 == c) ? d + 2 : d + 1;
	}
}

Measured memory_bytes: 13176
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

int main(void)
{
	string s;
	cin >> s;
	stack<int> x;
	stack<pair<int, int>> keep;
	int sum = 0;
	rep(i, s.length()) {
		if (s[i] == '_') continue;
		else if (s[i] == '/') {
			if (!x.empty()) {
				int k = x.top();
				x.pop();
				sum += i - k;
				int a = i - k;
				while(!keep.empty()) {
					pair<int, int> p = keep.top();
					if (p.first < k) break;
					a += p.second;
					keep.pop();
				}
				keep.push(make_pair(k, a));
			}
		} else x.push(i);
	}

	vec<int> out;
	while(!keep.empty()) {
		out.pb(keep.top().second);
		keep.pop();
	}

	cout << sum << endl;
	cout << (int)out.size();
	reverse(out.begin(), out.end());
	rep(i, out.size()) cout << " " << out[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 3276
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int a, b;
	cin >> a >> b;
	if (a % b == 0) {
		cout << -1 << endl;
	}
	else {
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))

p=0
m=10**10

for i in range(N):
  d=abs(A-(T-0.006*H[i]))
  if d < m:
    m=d
    p=i+1
    
print(p)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string ss;cin>>ss;
    reverse(ss.begin(),ss.end());
    int x=1,tot=0;
    ll ans=0;
    std::vector<int> cnt(2019,0);
    for(int i=0;i<ss.size();i++){
        cnt[tot]++;
        tot+=(ss[i]-'0')*x;
        tot%=2019;
        ans+=cnt[tot];
        x=x*10%2019;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3776
// https://atcoder.jp/contests/abc118/tasks/abc118_d

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)
#define DUMP2DSTR(a, n, m) REP(_i, n) REP(_j, m) printf("%s%c", a[_i][_j].c_str(), _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
struct match {
  int w;
  string s;
};

bool compare_vd(const match& m1, const match& m2) {
  return m1.s > m2.s;
}

//------------------------------------------------------------------------------
const int N_MAX = 1e4;
const int M_MAX = 9;
const int A_I_MAX = 9;
const int WGT[] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

int N, M;
int A[M_MAX];

map<int, int> mp;
vector<match> x;

int K;
string dp[M_MAX + 1][N_MAX + 1];
int prv[M_MAX + 1][N_MAX + 1];

map<int, int, greater<int>> ans;

void solve() {
  sort(A, A + M);
  REP(i, M) mp[WGT[A[i]]] = A[i];
  ITR(mp, it) x.push_back({ it->first, to_string(it->second)});
  sort(x.begin(), x.end(), compare_vd);
  K = x.size();

  fill(dp[0], dp[0] + N + 1, "-");
  dp[0][0] = "";
  REP(i, K) {
    int w = x[i].w;
    REP(j, N + 1) {
      string s1 = dp[i][j];
      if (j < w) {
        dp[i + 1][j] = s1;
      } else {
        string s2 = dp[i + 1][j - w];
        if (s2 != "-") s2 += x[i].s;
        if (s2 == "-") {
          dp[i + 1][j] = s1;
        } else if (s1.length() > s2.length()) {
          dp[i + 1][j] = s1;
        } else if (s1.length() == s2.length() ) {
          dp[i + 1][j] = max(s1, s2);
        } else {
          dp[i + 1][j] = s2;
        }
      }
    }
  }

  // DUMP2DSTR(dp, K + 1, N + 1);

  printf("%s\n", dp[K][N].c_str());
}

void input() {
  scanf("%d%d", &N, &M);
  REP(i, M) scanf("%d", A + i);
}

int main() {
  input();
  solve();
  return 0;
}


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

int main(void){
  int N;
  long long res=1, m=pow(10.0,9.0)+7;
  cin >> N;
  for(int i=1;i<=N;i++){
    res*=i;
    res%=m;
  }
  cout << res << endl;
}


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

namespace ABC131A
{
    class Program
    {
        static void Main(string[] args)
        {
            var nl = Console.ReadLine().Split(' ');
            var n = int.Parse(nl[0]);
            var l = int.Parse(nl[1]);
            int[] a = new int[n];
            for(int i = 0; i < n; i++)
            {
                a[i] = l + i;
            }
            var result = a.Sum();
            if (l <= 0 && l + n - 1 >= 0)
            {
                Console.WriteLine(result);
            }
            else if(l >= 0)
            {
                Console.WriteLine(result - a[0]);
            }
            else
            {
                Console.WriteLine(result - a[n - 1]);
            }
        }
    }
}


Measured memory_bytes: 13268
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void sort(int &a,int &b)
{
	if(a>b)
		swap(a,b);
}
void open(const char *s)
{
#ifndef ONLINE_JUDGE
	char str[100];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
	sprintf(str,"%s.out",s);
	freopen(str,"w",stdout);
#endif
}
int rd()
{
	int s=0,c;
	while((c=getchar())<'0'||c>'9');
	do
	{
		s=s*10+c-'0';
	}
	while((c=getchar())>='0'&&c<='9');
	return s;
}
void put(int x)
{
	if(!x)
	{
		putchar('0');
		return;
	}
	static int c[20];
	int t=0;
	while(x)
	{
		c[++t]=x%10;
		x/=10;
	}
	while(t)
		putchar(c[t--]+'0');
}
int upmin(int &a,int b)
{
	if(b<a)
	{
		a=b;
		return 1;
	}
	return 0;
}
int upmax(int &a,int b)
{
	if(b>a)
	{
		a=b;
		return 1;
	}
	return 0;
}
const ll p=1000000007;
int n;
int d[200010];
pii a[200010];
int pre[200010];
int suf[200010];
vector<int> c[200010];
ll f[200010];
ll s[200010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].first,&a[i].second);
		d[i]=a[i].second;
	}
	sort(a+1,a+n+1);
	sort(d+1,d+n+1);
	for(int i=1;i<=n;i++)
		a[i].second=lower_bound(d+1,d+n+1,a[i].second)-d;
	for(int i=1;i<=n;i++)
		pre[i]=max(pre[i-1],a[i].second);
	suf[n+1]=0x7fffffff;
	for(int i=n;i>=1;i--)
		suf[i]=min(suf[i+1],a[i].second);
	for(int i=1;i<=n;i++)
		c[pre[i]].push_back(suf[i]);
	f[0]=1;
	s[0]=1;
	for(int i=1;i<=n;i++)
	{
		for(auto v:c[i])
		{
			s[i]=(s[i-1]+f[i])%p;
			f[i]=(f[i]+s[i]-(v>=2?s[v-2]:0))%p;
		}
		s[i]=(s[i-1]+f[i])%p;
	}
	ll ans=f[n];
	ans=(ans+p)%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18176
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const K = parseInt(arg[0].split(" ")[1]);
    
    let answer = 0;
    
    if(K % 2 !== 0) {
        // 奇数のとき
        // Kで割り切れる個数の3乗
        for(let i=1; i<=N; i++) {
            if(i % K === 0) answer++;
        }
        
        answer = Math.pow(answer, 3);
    } else {
        // 偶数のとき
        // Kで割り切れる個数の3乗と
        // K / 2の個数の3乗を足したもの 
        let half = 0;
        let mod0 = 0;
        
        for(let i=1; i<=N; i++) {
            if(i % K === K / 2) {
                half++;
            }
            
            if(i % K === 0) {
                mod0++;
            }
        }
        
        answer += Math.pow(half, 3);
        answer += Math.pow(mod0, 3);
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

vector<int> prime;
bool is_prime[1000010];
int min_factor[1000010];
int sieve(int n) {
  fill(is_prime + 2, is_prime + 1000010, true);
  min_factor[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (is_prime[i]) {
      prime.emplace_back(i);
      for (int j = 2 * i; j <= n; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0) min_factor[j] = i;
      }
    }
  }
  return prime.size();
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  sieve(60000);
  int n;
  while (cin >> n) {
    cout << *(lower_bound(prime.begin(), prime.end(), n) - 1) << " " << *upper_bound(prime.begin(), prime.end(), n) << endl;
  }

  return 0;
}


Measured memory_bytes: 4372
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int k = sc.nextInt();

      if(n<k){
        System.out.println(1);
        System.exit(0);
      }
      if(n%k==0){
        System.out.println(0);
      }
      if(n%k!=0){
        System.out.println(1);
      }

      }
}

Measured memory_bytes: 21844