akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

// #define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.141592653589793238
#define dcout cout<<fixed<<setprecision(20)

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long
#define double long double

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int r; cin >> r;
  cout << r*r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

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


string s;
int p;

void f(){
	if( s[p] == 'm' ){
		p++;
		f();
		if ( s[p] != 'e' ) throw(0);
		p++;
		f();
		if( s[p] != 'w') throw(0);
		p++;
	}
}
int main(){
	cin >> s;
	s += "~";
	try{
		f();
		if( s.size()-1 > p ) throw(0);
		cout << "Cat" << endl;
	}catch(int err){
		cout << "Rabbit" << endl;
	}	
}

Measured memory_bytes: 1248
N = int(input())
S = input()
max_count = 0
for i in range(1, N):
    X = set(list(S[:i]))
    Y = S[i:]
    count = 0
    for c in X:
        if c in Y:
            count += 1
    max_count = max(max_count, count)
print(max_count)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

ll dp[3020][3020],dp2[3020][3020];//dp[index][weight]

int main(){
  int n,W;
  cin >> n >> W;
  pair<ll,ll> p[n];
  ll w[n],v[n];
  rep(i,n)cin >> p[i].second >> p[i].first;
  sort(p,p+n);
  rep(i,n){
    w[i]=p[i].second;
    v[i]=p[i].first;
  }
  rep(i,n+1){
    rep(j,W+1){
      if(j-w[i]>=0){
        dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
      }
      else{
        dp[i+1][j]=dp[i][j];
      }
    }
  }
  ll ans=dp[n-1][W-1]+v[n-1];
  w[n-2]=p[n-1].second;
  v[n-2]=p[n-1].first;
  rep(i,n+1){
    rep(j,W+1){
      if(j-w[i]>=0){
        dp2[i+1][j]=max(dp2[i][j-w[i]]+v[i],dp2[i][j]);
      }
      else{
        dp2[i+1][j]=dp2[i][j];
      }
    }
  }
  ans=max(ans,dp2[n-1][W-1]+p[n-2].first);
  cout << ans << endl;
return 0;}

Measured memory_bytes: 142336
#include<bits/stdc++.h>
#define PRIME_MAX 500000
using namespace std;

bool prime[PRIME_MAX+1];

int main()
{
	prime[0] = false;
	prime[1] = false;
	for(int i=2; i<PRIME_MAX+1; i++) prime[i] = true; 
	for(int i=2; i<PRIME_MAX+1; i++) {
		if (prime[i]) { for (int j=i+i; j<PRIME_MAX+1; j+=i) prime[j] = false; }
	}

	int N;
	while(cin >> N, N) {
		int cnt=0;
		for(int i=N+1; i<=2*N; i++) {
			if (prime[i]) { cnt++; }
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 1648
n, m = map(int, input().split())
H = list(map(int, input().split()))
query = [tuple(map(int, input().split())) for _ in range(m)]

table = [0 for _ in range(n)]

for a, b in query:
    if H[a-1] > H[b-1]:
        table[b-1] += 1
    elif H[a-1] < H[b-1]:
        table[a-1] += 1
    else:
        table[a-1] += 1
        table[b-1] += 1

ans = 0
for i in table:
    if i == 0:
        ans += 1
print(ans)

Measured memory_bytes: 27412
package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	n := eAtoi(strings.TrimSpace(s))
	count := 0
	prev := '@'
	for i := 0; i < n; i++ {
		r, _, _ := reader.ReadRune()
		if prev != r {
			count++
		}
		prev = r
	}
	fmt.Println(count)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 640
N = gets.chomp
a = N.split('').map(&:to_i)
i = 0
b = 0
A = 0
while b == 0 
    i += 1
    if a[i] < a[0]
        b += 1
    elsif a[0] < a[i]
        b += 2
    elsif a[0] == a[i] && i == a.length-1
        b += 3
    end
end
if b == 1
    for i in 0..a.length-1
        A += a[0] * (10 ** i)
    end
elsif b == 2
    for i in 0..a.length-1
        A += (a[0] + 1) * (10 ** i)
    end
elsif b == 3
    A += N.to_i
end

puts A

Measured memory_bytes: 1788
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    n=n%10;
    if(n==2||n==4||n==5||n==7||n==9) printf("hon\n");
    else if(n==0||n==1||n==6||n==8) printf("pon\n");
    else printf("bon\n");
    return 0;
}


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

#define For( i, a, b)	for(int i=a;i<=b;i++)
#define Rep( i, a, b)	for(int i=a;i>=b;i--)
#define n	100005

int N,t[n],x[n],y[n],a=0,b=0,ans=0,F[n];

int main()
{
	scanf("%d",&N);
	
	For( i, 1, N)
	{
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
	}
	
	For( i, 1, N)
	{
		if(i!=1)	F[i]=t[i]-t[i-1];
		else
		F[i]=t[i];
		if(abs(x[i]-a)+abs(y[i]-b)<=F[i] && (F[i]-abs(x[i]-a)-abs(y[i]-b))%2==0)	ans++;
		a=x[i];
		b=y[i];
	}
	
	if(ans==N)		printf("Yes");
	else
	{
		if(ans!=N)		printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[103],b[103];
int main(){
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<m;i++)cin>>b[i];
	for(int i=x+1;i<=y;i++)
	{
		bool can=1;
		//if(x<i&&i<=y)can=1;
		for(int j=0;j<n;j++)
			if(a[j]>=i)
				can=0;
		for(int j=0;j<m;j++)
			if(b[j]<i)
				can=0;
		if(can){
			cout<<"No War";
			return 0;
		}
	}
	cout<<"War";
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static int ans;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> color = new HashMap<String, Integer>();
        color.put("Red", 1);
        color.put("Yellow", 2);
        color.put("Blue", 3);
        color.put("Magenta", 4);
        color.put("Green", 5);
        color.put("Cyan", 6);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            Set<String> set = new HashSet<String>();
            for (int i = 0; i < n; i++) {
                Dice d = new Dice(color.get(sc.next()), color.get(sc.next()),
                        color.get(sc.next()), color.get(sc.next()),
                        color.get(sc.next()), color.get(sc.next()));
                for (int j = 0; j < 4; j++) {
                    d = d.North();
                    for (int k = 0; k < 4; k++) {
                        d = d.Right();
                        set.add(d.toString());
                    }
                }
                d = d.East();
                for (int k = 0; k < 4; k++) {
                    d = d.Right();
                    set.add(d.toString());
                }
                d = d.East().East();
                for (int k = 0; k < 4; k++) {
                    d = d.Right();
                    set.add(d.toString());
                }
            }
            System.out.println(n - set.size() / 24);
        }
    }
}

class Dice {
    Integer cs[] = new Integer[7];

    Dice(Integer c1, Integer c2, Integer c3, Integer c4, Integer c5, Integer c6) {
        cs[1] = c1;
        cs[2] = c2;
        cs[3] = c3;
        cs[4] = c4;
        cs[5] = c5;
        cs[6] = c6;
    }

    public Dice North() {
        return new Dice(cs[2], cs[6], cs[3], cs[4], cs[1], cs[5]);
    }

    public Dice East() {
        return new Dice(cs[4], cs[2], cs[1], cs[6], cs[5], cs[3]);
    }

    public Dice Right() {
        return new Dice(cs[1], cs[4], cs[2], cs[5], cs[3], cs[6]);
    }

    public String toString() {
        return Arrays.toString(cs);
    }
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
    if((A == B && B != C) ||
       (A != B && B == C) ||
       (A == C && A != B)){
        cout << YES << endl;
    }else{
        cout << NO << endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
/* ***************************************
Author        :Scau.ion
Created Time  :2016/11/06 20:15:46 UTC+8
File Name     :ion.cpp
*************************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

const int maxn=100010;

int a[maxn];

int main()
{
    IOS;
    int n,t;
    cin>>n>>t;
    for (int j=1;j<=n;++j)
        cin>>a[j];
    int mi=2e9;
    int macha=0;
    int sum=0;
    for (int j=1;j<=n;++j)
    {
        if (a[j]<mi)
        {
            mi=a[j];
        }
        else if (a[j]-mi>macha)
        {
            macha=a[j]-mi;
            sum=1;
        }
        else if (a[j]-mi==macha) ++sum;
    }
    int bigans=sum;
    int ma=0;
    sum=0;
    for (int j=n;j>0;--j)
    {
        if (a[j]>ma)
        {
            ma=a[j];
        }
        else if (ma-a[j]==macha) ++sum;
    }
    int smaans=sum;
    int ans=min(bigans,smaans);
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int comp(const void* a, const void *b) {
	return *(int*)a - *(int*)b;
}

int main(){
    int X, N, p[102], num;
    bool flag = 1;

    cin >> X >> N;
    for(int i = 0; i < N; i ++){
        cin >> p[i];
    }
    qsort(p, N, sizeof(int), comp);

    for(int j = 0; j < N; j ++){
        if(X == p[j]){
            flag = 0;
            num = j;
        }
    }
    if(flag){
        cout << X << endl;
        return 0;
    }
    for(int k = 1; k <= N; k ++){
        if(p[num - k] != (p[num] - k)){
            cout << p[num] - k << endl;
            break;
        }
        if(p[num + k] != (p[num] + k)){
            cout << p[num] + k << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3580
N,M=list(map(int,input().split()))
inf=10**10
dp=[[inf]*(2**N) for _ in range(M+1)]
dp[0][0]=0

for i in range(M):
    a,b=list(map(int,input().split()))
    c=list(map(int,input().split()))

    s=0
    for cc in c:
        s+=2**(cc-1)
    
    for j in range(2**N):
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        dp[i+1][j|s]=min(dp[i+1][j|s],dp[i][j]+a)
    
print(dp[M][2**N-1] if dp[M][2**N-1]<inf else -1)


Measured memory_bytes: 107620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define INF 1e8
double pi = 2 * acos(0.0);
#define ALL(x) x.begin() , x.end()
#define UNIQUE(c) (c).resize(unique(ALL(c)) - (c).begin())
int n;
vector<vector<char> >c;
vector<char>ans;
void back_track(int in, char prev)
{
    if(in==n)
    {
        c.push_back(ans);
        return;
    }
    for(int i=0;i<=prev-'a';i++)
    {
        //if(prev!='a'&&char(i+'a')==prev)continue;
        ans[in]=char(i+'a');
        if(i==prev-'a')
            back_track(in+1,char(prev+1));
        else back_track(in+1,prev);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    ans.assign(n,'a');
    back_track(0,'a');
    sort(ALL(c));
    for(int i=0;i<c.size();i++)
    {
        for(int j=0;j<n;j++)
        {
            cout<<c[i][j];
        }cout<<"\n";
    }
    return 0;
}

Measured memory_bytes: 8756
#include <iostream>
#include <vector>
using namespace std;
bool flag[1000001];
int main() {
	long m,n; flag[1]=true;
	vector<long> v2,v3,v5;
	long tmp=2;
	while(tmp<=1e6) {v2.push_back(tmp); flag[tmp]=true; tmp*=2;}
	tmp=3;
	while(tmp<=1e6) {v3.push_back(tmp); flag[tmp]=true; tmp*=3;}
	tmp=5;
	while(tmp<=1e6) {v5.push_back(tmp); flag[tmp]=true; tmp*=5;}
	for(long i=0;i<v2.size();i++) {
		for(long j=0;j<v3.size();j++) {
			if(v2[i]*v3[j]>1e6) break;
			flag[v2[i]*v3[j]]=true;
		}
		for(long j=0;j<v5.size();j++){
			if(v2[i]*v5[j]>1e6) break;
			flag[v2[i]*v5[j]]=true;
		}
	}
	for(long i=0;i<v3.size();i++) {
		for(long j=0;j<v5.size();j++) {
			if(v3[i]*v5[j]>1e6) break;
			flag[v3[i]*v5[j]]=true;
		}
	}
	for(long i=0;i<v2.size();i++) {
		for(long j=0;j<v3.size();j++) {
			for(long k=0;k<v5.size();k++) {
				long long tmp=(long long)v2[i]*v3[j]*v5[k];
				if(tmp>1e6) break;
				flag[tmp]=true;
			}
		}
	}
	while(cin>>m>>n) {
		if(!m) break;
		long cnt=0;
		for(long i=m;i<=n;i++) if(flag[i]) cnt++;
		cout << cnt << '\n' ;
	}
}

Measured memory_bytes: 1880
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  static int n;
  static int[] l;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    l = new int[2 * n];
    for(int i = 0; i < 2 * n; i++){
      l[i] = sc.nextInt();
    }

    Arrays.sort(l);

    int sum = 0;
    for(int i = 0; i < 2 * n; i += 2){
      sum += l[i];
    }

    System.out.println(sum);
  }
}

Measured memory_bytes: 9684
#include<stdio.h>

int main(void){

int n,a,b,c,d, i;
int q = 0;
int z = 0;
char s[200000];
int w[200000];
int p = 0;

scanf("%d", &n);
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
scanf("%s", s);

for(i = 0; i < n; i++){
  if(s[i] == '.') w[i] = 0;
  else w[i] = 1;
}


if(c<d){
  for(i = b; i < d-1; i++){
    if(w[i]*w[i+1] != 0) q = 1;
  }
  for(i = a; i < c-1; i++){
    if(w[i]*w[i+1] != 0) z = 1;
  }
if(q == 0 && z==0) printf("Yes\n");
else printf("No\n");
}

else{
  for(i = b; i < d-1; i++){
    if(w[i]*w[i+1] != 0) q = 1;//先移動
  }
  for(i = a; i < c-1; i++){
    if(w[i]*w[i+1] != 0) z = 1;
  }
  for(i = b-2; i < d-1; i++){
    if(w[i] == 0 && w[i+1] == 0 && w[i + 2] == 0) p = 1;//先移動
  }
if(q == 0 && z == 0 && p == 1) printf("Yes\n");
else printf("No\n");
}


  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>

int main(){
  int h,w;
  int i,j;
  
  while(1)
    {
      scanf("%d %d",&h,&w);

      if(h==0 && w==0)
	{
	  break;
	}
      for(i=0;i<h;i++)
	{
	  for(j=0;j<w;j++)
	    {
	      printf("#");
	    }
	  printf("\n");
	}
      printf("\n");
    }
}


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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    ll n, w;
    cin >> n >> w;
    vll wt(n+1), vl(n+1);
    for(ll i=0;i<n;i++) {
    	cin >> wt[i+1] >> vl[i+1];
    }
    ll dp[n+1][w+1];
    for(ll i=0;i<=n;i++) {
    	for(ll j=0;j<=w;j++) {
    		if(i == 0) {
    			dp[i][j] = 0;
    			continue;
    		} 
    		ll x1, x2;
    		if(j - wt[i] < 0) {
    			x1 = -1;
    		}
    		else x1 = vl[i] + dp[i-1][j-wt[i]];
    		x2 = dp[i-1][j];
    		dp[i][j] = max(x1, x2);
    	}
    }
    cout << dp[n][w] << "\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
      // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

int cmp( const void *p, const void *q ) {
    return -*(int*)p + *(int*)q;
}

int main()
{
    int a[210000],i,n,j=0,m;
  double k, l;
	
	scanf("%d%d", &n, &m);
	for(i=0; i<n;i++){
		
		scanf("%d", &a[i]);
	}
		for(i=0; i<n;i++){
		j+=a[i];
	}
    qsort(a,n,sizeof(int),cmp);
	k=j*1/4.0/m;
  if(a[m-1]>=k){
    printf("Yes\n");
    return 0;
  }
      printf("No\n");
    return 0;
  
}


Measured memory_bytes: 128
import itertools

n = int(input())
lis = []
keep = [0, 1, 2, 3, 4, 5, 6, 7, 8]
keep = list(itertools.permutations(keep[:n]))
for i in range(n):
    s = list(map(int, input().split()))
    lis.append(s)
ans = 0
re_ans = 0
for j in range(len(keep)):
    for k in range(n - 1):
        ans = ((lis[keep[j][k]][0] - lis[keep[j][k + 1]][0])**2 +
               (lis[keep[j][k]][1] - lis[keep[j][k + 1]][1])**2)**(1 / 2)
        re_ans += ans
print(re_ans / len(keep))

Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k,cnt=0;
    cin >> a >> b >> c >> k;
    if(k<=a)
    {
        cout << k << endl;
        return 0;
    }
    if(k>a)
    {
        cnt+=a;
        k-=a;
        if(k<=b)
        {
            cout << cnt << endl;
            return 0;
        }
        if(k>b)
        {
            k-=b;
            if(k<=c)
            {
                cnt-=k;
                cout << cnt << endl;
                return 0;
            }

        }
    }
    return 0;
}


Measured memory_bytes: 3624
N, Y = map(int, input().split())
count = 0
yen = [0] * 3

for i in reversed(range(Y // 10000 + 1)):
    yen[0] = i
    for j in range(Y // 5000 + 1):
        yen[1] = j
        yen[2] = N - i - j
        if Y - 10000 * i - 5000 * j < 0 or yen[2] < 0:
            break
        elif Y - 10000 * i - 5000 * j == 1000 * yen[2]:
            print(' '.join(map(str, yen)))
            exit()
        else:
            continue
print('-1 -1 -1')

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
n = int(input())
li = [[] for i in range(n)]

for i in range(n-1):
  a,b,dist = map(int,input().split())
  li[a-1].append((b-1,dist))
  li[b-1].append((a-1,dist))

q,k = map(int,input().split())
tdp = [-1]*n
tdp[k-1] = 0

def dfs(x):
  for node in li[x]:
    if tdp[node[0]] == -1:
      tdp[node[0]] = tdp[x] + node[1]
      dfs(node[0])

dfs(k-1)
for i in range(q):
  a,b = map(int,input().split())
  print(tdp[a-1]+tdp[b-1])

Measured memory_bytes: 131760
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int X,Y;

signed main(){

    in(X,Y);
    out(X%Y==0?-1:X);

    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
A=[[] for i in range(N)]
B=[[] for i in range(M)]
for i in range(N):
  L=list(input())
  A[i]=L
for i in range(M):
  L=list(input())
  B[i]=L
for i in range(N-M+1):
  for j in range(N-M+1):
    ans=0
    for k in range(M):
      for s in range(M):
        #i,jを始点とした
        if B[k][s]!=A[i+k][j+s]:
          ans=-1
        if k==M-1 and s==M-1:
          if ans==0:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 9136
/*input
5 2
3 1 3 1 3
*/
#include<bits/stdc++.h>
using namespace std;
#define maxim 2048
#define fn(i,n) for(long long i=0;i<n;i++)
#define fn1(i,n) for(long long i=1;i<n;i++)
#define ll long long
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	fn(i,n)cin>>a[i];
	ll dp[n];
	dp[0]=0;
	for(ll i=1;i<n;i++)
	{
		ll count=min(i,k),check=100000000001;
		fn(j,count)
		check=min(check,dp[i-j-1]+abs(a[i]-a[i-j-1]));
		dp[i]=check;
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main(){
    int n; cin>>n; int k; cin>>k;
    vector<int> h(n);
    for(int i = 0; i<n; i++){
        cin>>h[i];
    }
    vector<int> dp(n ,INF);
    dp[0] = 0;
    for(int i = 0; i< n; i++){
        for(int j = i + 1; j <= i + k; j++){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    cout<<dp[n-1];
    
}


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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	if (S == T.substr(0, T.size() - 1)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


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

#define ll long long
#define PB push_back
#define PII pair<int, int>
#define MP make_pair
#define all(x) x.begin(), x.end()
#define REP(x, y, z) for(int x = y; x <= z; x++)
#define REPP(x, y, z) for(int x = y; x >= z; x--)
#define F first
#define S second
#define MSET(x, y) memset(x, y, sizeof(x)) 
#define EB emplace_back
#define maxn

//structure

//declaration

//functions

int main(void)
{
	#ifdef DBG
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
	#endif

	ll t1,t2,a1,a2,b1,b2;

	scanf("%lld %lld", &t1, &t2);
	scanf("%lld %lld", &a1, &a2);
	scanf("%lld %lld", &b1, &b2);
	
	ll p = (a1-b1)*t1;
	ll q = (a2-b2)*t2;

	

	if(p > 0)
	{
		p *= -1;
		q *= -1;
	}

	// cout << p << endl;
	// cout << q << endl;

	// cout << endl;
	// cout << -p << " / " << (p+q) << endl;

	if(p + q == 0)
	{
		printf("infinity\n");
	}

	else if(p+q < 0)
	{
		printf("0\n");
	}

	else
	{
		if(-p % (p+q) == 0)
		{
			printf("%lld\n", (-p)/(p+q)*2);
		}

		else
		{
			printf("%lld\n", (-p)/(p+q)*2+1);
		}
	}

	

	return 0;
}

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

int main()
{
    long long int a,b,c,d,sum=0;
    cin>>a;
    vector<int>v;
    while(a--)
    {
        cin>>b;
        v.push_back(b);
        sum=sum+b;
    }
    cin>>c;
    while(c--)
    {
        cin>>b>>d;
        int temp;
        temp=sum-v[b-1]+d;
        cout<<temp<<endl;
    }
}


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

X = N / 1.08

X_down = int(X)
X_up = int(X) + 1

bool_down = int(X_down * 1.08) == N
bool_up = int(X_up * 1.08) == N

if bool_down:
    print(X_down)
elif bool_up:
    print(X_up)
else:
    print(":(")


Measured memory_bytes: 9020
S = input()
lens1 = False
snum = [0]
st = 0
end = 0
count = 1
result = 0

if len(S) == 1:
    result = 1
    lens1 = True
else:
    for i, s in enumerate(S):
        if i == 0:
            if s == '>':
                st = 1
        elif i == len(S) - 1 :
            if s == '<':
                end = 1
            if s != S[i-1]:
                snum.append(count)
                snum.append(1)
            else:
                snum.append(count+1)
        elif s != S[i-1]:
            snum.append(count)
            count = 1
        else:
            count += 1

snum.append(0)

if not lens1:
    for i in range(1, len(snum)-1):
        n = snum[i]
        if st:
            if i % 2 == 0 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 != 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)
        else:
            if i % 2 == 1 and n <= snum[i+1]:
                result += int(n * (n - 1) / 2)
            elif i % 2 == 0 and n < snum[i-1]:
                result += int(n * (n - 1) / 2)
            else:
                result += int(n * (n + 1) / 2)

print(result)

Measured memory_bytes: 6300
#include<iostream>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define NODE 30
#define LIM 31
const double inf = 1e200;

class state{
public:
  int cur,prev,speed;
  double c;
  state(){};
  state(int tcur,int tprev,int tspeed,double tc):cur(tcur),prev(tprev),
						 speed(tspeed),c(tc){};
  bool operator<(const state & a)const{
    return c >a.c;
  }
};

double cost[30][30][31];
double dist[30][30];
int lim[30][30];
bool visited[30][30][31];

void solve(int n,int s,int g){
  rep(i,n)rep(j,n)rep(k,31)cost[i][j][k]=inf,visited[i][j][k]=false;
  priority_queue<state> Q;
  cost[0][0][1]=0;
  rep(i,n){
    if ( lim[s][i] >= 1){
      cost[i][s][1]=dist[s][i];
      Q.push(state(i,s,1,cost[i][s][1]));
    }
  }

  while(!Q.empty()){
    state now = Q.top();
    Q.pop();
    if ( visited[now.cur][now.prev][now.speed])continue;
    visited[now.cur][now.prev][now.speed]=true;
    if ( now.cur == g && now.speed == 1){
      printf("%.3lf\n",now.c);
      return;
    }
    rep(i,n){
      if ( i == now.prev || i == now.cur)continue;
      REP(j,-1,2){
	if ( now.speed + j > 0 && now.speed + j <= lim[now.cur][i] &&
	     cost[i][now.cur][now.speed+j] - now.c - dist[now.cur][i]/(now.speed+j) >0){
	  cost[i][now.cur][now.speed+j]=now.c+dist[now.cur][i]/(now.speed+j);
	  Q.push(state(i,now.cur,now.speed+j,cost[i][now.cur][now.speed+j]));
	}
      }
    }
  }
  

  puts("unreachable");
  
}


main(){
  int n,m;
  while(cin>>n>>m && n){
    rep(i,n)rep(j,n)lim[i][j]=0,dist[i][j]=inf;
    int s,g;
    cin>>s>>g;
    s--;g--;
    rep(i,m){
      int f,t,v;
      double d;
      cin>>f>>t>>d>>v;
      f--;t--;
      dist[f][t]=dist[t][f]=d;
      lim[f][t]=lim[t][f]=v;
    }
    solve(n,s,g);
  }
}

Measured memory_bytes: 2428
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int v=a+b;
		System.out.println(v>=10?"error":v);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 23124
s = input()

ans = 0
for ch in s:
    ans += ord(ch) - ord('0')

N = int(s)
B = 0
while 10**B <= N:
    B += 1
B -= 1

ans = max(ans, B * 9 + (N // (10 ** B) - 1))
print(ans)


Measured memory_bytes: 2940
import queue


nq = input().split()
n = int(nq[0])
q = int(nq[1])

qu = queue.Queue()
for _ in range(n):
    nt = input().split()
    qu.put({"name": nt[0], "time": int(nt[1])})

t = 0
while not(qu.empty()):
    process = qu.get()
    if process["time"] > q:
        process["time"] -= q
        t += q
        qu.put(process)
    else:
        t += process["time"]
        print(process["name"], t)


Measured memory_bytes: 22400
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int p[5] = {3,5,7,11,13};
int eighter(int a) {
  int b=1;
  for(int i=0;i<5;i++){
    int cnt=1;
    while(a%p[i]==0){
      a/=p[i];
      cnt++;
    }
    b*=cnt;
  }
  return b;
}
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  if(n<105){
    P(0);
    return 0;
  }
  int ans=0;
  for(int i=105;i<=n;i++){
    if(i%2==0)continue;
    if(eighter(i)==8)ans++;
  }
  P(ans);
  return 0;
}


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

int main(){
    int A, B;

    cin >> A >> B;

    for (int i = 1; i < 1010; i++)
    {
        if((int(float(i)*0.08) == A) && (int(float(i)*0.1) == B)){
            cout << i;
            return 0;
        }
    }
    
    cout << -1;

    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){

	string s,p;
	getline(cin,s);
	getline(cin,p);


	for(int i =0;i < s.length() ;i++){
		for(int k = 0; k < p.length();k++){
			if(s[(i+k) % s.length()] != p[k % s.length()])
				break;

			if(p.length() == k+1){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 3200
// Problem : B - Making Triangle
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define vp vector<pair<ll,ll>>
#define mod 1000000007
#define M_PI 3.14159265358979323846
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define per(i,b,a) for(ll i=b; i>=a ;--i)
#define vin(a) for(auto &i:a) cin>>i
#define mms(a,n) memset(a,n,sizeof(a))
#define fill(a,value) fill(a.begin(),a.end(),value)
#define all(a) a.begin(),a.end()
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define see(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it){}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
template <typename T, typename U>inline void min_self(T &x, U y){if (y < x)x = y;}
template <typename T, typename U>inline void max_self(T &x, U y){if (x < y)x = y;}
template<class T1, class T2>ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<"["<<v.first<<", "<<v.second<<"]"; return out<<")"; }
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}

// cout << fixed << setprecision(10) << pi <<" "<<npi<<endl; 
// INT64_MAX
// transform(all(s), s.begin(), ::tolower);

ll XX[4] = {-1,0,1,0};
ll YY[4] = {0,-1,0,1};


void solve(){
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    ll res = 0;
    rep(i,0,n-1){
    	rep(j,i+1,n-1){
    		rep(k,j+1,n-1){
    			if(a[i]+a[j]>a[k] && a[k]+a[j]>a[i] && a[k]+a[i]>a[j]){
    				if(a[i]==a[j] || a[j]==a[k] || a[i]==a[k]) continue;
    				res++;
    			}
    		}
    	}
    }
    
    cout<<res<<endl;
    
	return;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3656
n, k = input().split()
n = int(n)
k = int(k)
xs = input().split()
xs = [int(x) for x in xs]
ans = 1e9
for i in range(0, n-k+1):
    l = xs[i]
    r = xs[i + k - 1]
    if l < 0 and r > 0:
        ans = min(ans, abs(l) + 2 * r)
        ans = min(ans, abs(l) * 2 + r)
    else:
        ans = min(ans, max(abs(l), abs(r)))
print(ans)

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

int main(){
    int n;
    cin >> n;
    int p[n];
    int max_p=0;
    int ans =0;
    for(int i=0;i<n;i++){
        cin >> p[i];
        ans+=p[i];
        max_p=max(max_p,p[i]);
    }
    cout << ans-max_p+0.5*max_p << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

//線形探索
int search(int A[],int n,int key){
	int i=0;
	A[n]=key;
	while(A[i]!=key)i++;
	return i!=n;
}

int main(){
	int i,n,A[100000+1],q,key,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&key);
		if(search(A,n,key))sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 644
#include<stdio.h>
int main(void){
  int n,count=0;
  int a,b,c,d;
  while(scanf("%d",&n)!=EOF){
    count=0;
    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
        for(c=0;c<=9;c++){
          for(d=0;d<=9;d++){
            if(a+b+c+d==n) count++;
          }
        }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

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

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;

  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  
  sort(d.begin(), d.end());
  int mid = d.size() / 2;
  int result = d[mid] - d[mid - 1];
  cout << result << "\n";

  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int>home(N);
    for(int i=0;i<N;i++){
        cin >> home[i];
    }
    sort(home.begin(),home.end());
    int s =(home[0]+home[N-1])/2;
    int ans = 0;
    for(int i=0;i<N;i++){
        if(home[i]<=s && ans<s-home[i]){
            ans = s-home[i];
        }else if(home[i]>=s && ans<home[i]-s){
            ans = home[i]-s;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 3176
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	
	string S; cin >> S;
  	int P = 2019;
  	int N = S.size();
	if (P == 2) {
		int res = 0;
		REP(i, N) {
			int a = S[i] - '0';
			if (a % 2 == 0)res += (i + 1);
		}
		cout << res << endl;
		return 0;
	}
	if (P == 5) {
		int res = 0;
		REP(i, N) {
			int a = S[i] - '0';
			if (a % 5 == 0)res += (i + 1);
		}
		cout << res << endl;
		return 0;
	}
	int cnt[1000000] = { 0 };

	int ans = 0;
	VI sum(N + 1, 0);
	int po = 1;


	cnt[0]++;

	for (int i = N - 1; i >= 0; i--) {
		int now = (S[i] - '0')*po%P;

		sum[i] = (sum[i + 1] + now) % P;

		po *= 10;
		po %= P;

		ans += cnt[sum[i]];
		cnt[sum[i]]++;

		
	}



	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 12840
#include <bits/stdc++.h>
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
using namespace std;
//using ll = int64_t;
typedef long long ll;

int main(){
    int n;
    cin>>n;
    char c[10005];
    cin>>c;
    int d='B'-'A';
    rep(i,0,strlen(c)){
        cout<<char('A'+((n*d+c[i]-'A')%26));
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
ll N,A,B;
int main() {
  cin >> N >> A >> B;
  if (A > B or (N == 1 and A != B)){
    cout << 0 << endl;
    return 0;
  }
  if (N == 1){
    cout << 1 << endl;
    return 0;
  }
  ll left = A + B + (N - 2) * A;
  ll right = A + B + (N - 2) * B;
  cout << (right - left + 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x <<  " " << x << endl;
#define all(x) x.begin(), x.end()
typedef std::vector<int> vi;
typedef std::vector<vector<int>> vvi;
typedef std::vector<string> vs;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef long long ll;
const int inf = 1e9 + 7;

template <typename T>
void print(T v){ for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(2)<<*i<<" ";cout<<endl; }
template <typename T>
void print_vv(T v, bool same_line=true){
for(auto i= 0; i<v.size(); i++){cout<<"{";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(3)<<v[i][j]<<",";}cout<<"},";if(same_line) cout<<endl;}cout<<endl;}

int main(){
    int h,w;
    while(cin>>h>>w){
        vector<string> grid(h);

        for(int i=0; i<h; i++)
            cin>>grid[i];
        
        vector<vector<ll>> dp(h, vector<ll>(w));

        dp[0][0] = 1;
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(grid[i][j]=='#')
                    dp[i][j] = 0;
                else{
                    int a = i-1>=0 ? dp[i-1][j] : 0;
                    int b = j-1>=0 ? dp[i][j-1] : 0;
                    dp[i][j] = (dp[i][j] + a + b+inf)%inf;
                }
            }
        }
        
        cout<<(dp[h-1][w-1])<<endl;
    }
    
}

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

int main(){
  long long a, b; cin >> a >> b;
  if(a < b){
    long long tmp = b;
    b = a; a = tmp;
  }
  while(a % b != 0){
    long long u = a % b;
    a = b; b = u;
  }
  if(b == 1){
    cout << 1;
    return 0;
  }
  vector<int> s(sqrt(b) + 2, 1);
  s.at(0) = 0; s.at(1) = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 1){
      long long j = 2 * i;
      while(j < s.size()){
        s.at(j) = 0;
        j += i;
      }
    }
  }
  long long out = 0;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == 1){
      if(b % i == 0){
        out++;
        while(b % i == 0){
          b /= i;
        }
      }
    }
  }
  if(out == 0){
    cout << 2;
    return 0;
  }
  if(b != 1) out++;
  cout << out + 1;
}


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

int main() {
	int a,b,cnta,cntb,maxa,maxb,max1,max2;
	cin >> a >>b;
	cnta=a+(a-1);
	cntb=b+(b-1);
	max1=max(cnta,cntb);
	max2=a+b;
	max1=max(max1,max2);
	cout << max1<< endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
ll  n,m;
ll mod=1000000007;
ll dp[1000+1][1000+1];
ll wt[100000+1],v[100000+1];
string s[1005];

int main() {
  cin>>n>>m;
  memset(dp,0,sizeof dp);
  dp[1][1] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			if (c == '#') continue;
			dp[i][j]=dp[i][j]+ dp[i-1][j]+dp[i][j-1];
      		dp[i][j]%=mod;
		}
	}
  cout<<dp[n][m]<<endl;
}

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


int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> v(n); rep(i, n) cin >> v[i];
	vector<int> c(n); rep(i, n) cin >> c[i];

	int ans = 0;
	rep(i, n) {
		if (v[i] - c[i] > 0) ans += v[i] - c[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.PriorityQueue;
import java.util.Comparator;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int q =sc.nextInt();
		PriorityQueue<Integer> sq=new PriorityQueue<>(Comparator.reverseOrder());
		PriorityQueue<Integer> lq=new PriorityQueue<>();
		long sumB=0;
		long sumsq=0;
		long sumlq=0;
		for(int i=0; i<q; i++){
			int x=sc.nextInt();
			if(x==1){
				int a=sc.nextInt();
				sumB+=sc.nextInt();
				sq.add(a);
				lq.add(a);
				sumsq+=a;
				sumlq+=a;
				if(sq.peek()>lq.peek()){
					int tsq=sq.poll();
					int tlq=lq.poll();
					sq.add(tlq);
					lq.add(tsq);
					sumsq+=-tsq+tlq;
					sumlq+=-tlq+tsq;
				}
			}else{
				long min=0;
				if(sq.peek()==lq.peek()){
					min=((sq.peek()*(sq.size()-1)-(sumsq-sq.peek()))+((sumlq-lq.peek())-lq.peek()*(lq.size()-1)))/2;
				}else{
					min=((sq.peek()*sq.size()-sumsq)+(sumlq-sq.peek()*sq.size()))/2;
				}
				min+=sumB;
				System.out.println(sq.peek()+" "+min);
			}
		}
	}
}



Measured memory_bytes: 156920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque> 
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype> 
using namespace std;

int main(){
    long long a, b, x;
    cin >> a >> b >> x;
    long long cnt;
    if (a==0) cout << b/x+1 << endl;
    else cout << (b/x+1)-((a-1)/x+1) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long K = sc.nextLong();
    long[] a = new long[50];
    long s = K / 50;
    long t = K % 50;
    for(int i = 0; i < 50; i++) {
      a[i] = s + i;
    }
    for(int i = 0; i < t; i++) {
      for(int j = 0; j < 50; j++) {
        if(j == i) {
          a[j] += 50;
        } else {
          a[j]--;
        }
      }
    }
    System.out.println(50);
    for(int i = 0; i < 50; i++) {
      System.out.print(a[i]);
      if(i < 49) System.out.print(" ");
    }
    System.out.println();
  }
}

Measured memory_bytes: 23636