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

using namespace std;

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;
	vector<int> l(n);
	for(int i = 0; i < n; ++i){
		cin >> l[i];
	}

	sort(l.begin(), l.end());
	int res = 0;

	for(int i = 0; i < n - 2; ++i){  
        int k = i + 2;  
		for (int j = i + 1; j < n; ++j){  
			while (k < n && l[i] + l[j] > l[k]){  
				++k;
			}
			if(k > j){ 
				res += k - j - 1;
			}
			//cout << i << " " << res << endl;
		}  
	}  
  
	cout << res;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cassert>
#define fr first
#define sc second
#define MP make_pair
#define ad push_back
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define lli long long int
#define y1 arayikhalatyan
#define j1 jiglypuff
#define ld long double
#define itn int
#define pir pair<int, int> 
#define all(x) (x).begin(), (x).end()
using namespace std;

lli gcd(lli a, lli b) { return (b == 0LL ? a : gcd(b, a % b)); }
ld dist(ld x1, ld y1, ld x2, ld y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
lli S(lli a)
{
	return (a * (a + 1LL)) / 2;
}
char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0, -1, -1, 1, 1 };
int dy[] = { 0, 0, 1, -1, -1, 1, -1, 1 };


const int N = 2e5 + 30;
const lli mod = 998244353;
const ld pi = acos(-1);
const int T = 238;
const ld e = 1e-6;

lli bp(lli a, lli b = mod - 2LL)
{
	lli ret = 1;
	while (b)
	{
		if (b & 1) ret *= a, ret %= mod;
		a *= a;
		a %= mod;
		b >>= 1;
	}
	return ret;
}
ostream& operator<<(ostream& c, pir a)
{
	c << a.fr << " " << a.sc;
	return c;
}




int n;
vector <pir > g[N];
int ans[N];
vector <int> fp;
int c[N];
void dfs(int v, int par, int nax)
{
	bool bl = false;
	int i1 = 0, val = 0;
	if (nax > fp.back())
	{
		fp.ad(nax);
		bl = true;
	}
	else
	{
		int j = upper_bound(all(fp), nax) - fp.begin();
		if (fp[j - 1] < nax && nax < fp[j])
		{
			i1 = j;
			val = fp[j];
			fp[j] = nax;
		}
	}
	ans[v] = (int)fp.size() - 1;
	for (auto p : g[v])
	{
		if (p.fr == par) continue;
		dfs(p.fr, v, p.sc);
	}
	if (bl) fp.pop_back();
	else fp[i1] = val;
}
int main()
{
	fastio;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> c[i];
	}
	for (int i = 0; i < n - 1; i++)
	{
		int a, b;
		cin >> a >> b;
		g[a].ad(MP(b, c[b]));
		g[b].ad(MP(a, c[a]));
	}
	fp.ad(0);
	dfs(1, 0, c[1]);
	for (int i = 1; i <= n; i++)
	{
		cout << ans[i] << " ";
	}
	return 0;
}


/*


  __
*(><)*
  \/ /
  ||/
--||
  ||
  /\
 /  \
/    \
*/



Measured memory_bytes: 30420
import java.util.*;
import java.lang.*;
import java.io.*;
import java.awt.Point;
 
class Main{
 
      public static void main(String args[])throws IOException
    {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());   
    LinkedList<Point> list = new LinkedList<Point>();  
    for(int i=0;i<N;i++)
        {
        String line = in.readLine();
        int A,B;
        A = Integer.parseInt(line.substring(0,line.indexOf(" ")));
        B = Integer.parseInt(line.substring(line.indexOf(" ")+1));
        list.add(new Point(B-A,B));
        }
     
 
    Collections.sort(list,new Comparator<Point>(){
                        @Override
                            public int compare(Point a,Point b)
                        {
                if(a.x < b.x)
                {
                    return 1;
                }  
                else if(a.x == b.x)
                {
                    return 0;
                }  
                else
                {
                    return -1;
                }      
                        }
        });
 
    int cnt = 0;
    for(int i=0;i<list.size();i++)
        {
        if(list.get(i).x >= 0)
            {
            cnt++;
            for(int j=i+1;j<list.size();j++)
                {
                 
                if(list.get(j).y > list.get(i).x)
                    {
                    int dif = Math.min(list.get(j).y-list.get(i).x,list.get(i).y-list.get(i).x);
                    Point p = list.get(j);
                    list.set(j,new Point(p.x-dif,p.y-dif));
 
                    }
                 
 
                }
 
            Collections.sort(list,new Comparator<Point>(){
                @Override
                    public int compare(Point a,Point b)
                {
                    if(a.x < b.x)
                {
                    return 1;
                }  
                    else if(a.x == b.x)
                    {
                        return 0;
                    }  
                    else
                    {
                    return -1;
                    }      
                }
                });
             
            }
         
         
         
        }
 
     
    System.out.println(cnt);   
 
    }
 
}

Measured memory_bytes: 17080
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()

    whole = sum(a)

    # if n == 0 and a[0] == 0:
    #     print(-1)
    #     exit(0)

    ans = 0
    base = 1
    for i in range(n + 1):
        ans += base
        base -= a[i]
        whole -= a[i]
        base = min(base * 2, whole)
        if (base <= 0 and i != n) or (i == n and base != 0):
            print(-1)
            exit(0)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21760
#include <stdio.h>
int main(void){
    int N;
    long long int K;
    scanf("%d %lld",&N,&K);
    long long int a[N],b[N];
    long long int ans=0;
    for(int i=0;i<N;i++)scanf("%lld %lld",&a[i],&b[i]);
    long long int po=1;
    while(po<=K)po<<=1;
    po-=1;
    do{
        do {po>>=1;}while((K^(po+1))>K&&po!=0);
        long long int tmp=(K^(po+1))|po;
        if(po==0)tmp=K;
        long long int tmpans=0;
        for(int i=0;i<N;i++){if((tmp|a[i])==tmp)tmpans+=b[i];}
        if(tmpans>ans){ans=tmpans;}
    }while(po);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int ans=(x-a)%b;
		System.out.println(ans);

	}

}


Measured memory_bytes: 20948
li=[]
N,M=map(int,input().split())

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

li.sort()

g=0
s=0

for i in range(N):
    if li[i][1]+s<M:
        s+=li[i][1]
        g+=li[i][1]*li[i][0]
    else:
        g+=(M-s)*li[i][0]
        print(g)
        exit()


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

using namespace std;

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

    long long int sum = 0;
    for(int i = 0; i <= max; i++) {
        if(!(i % 3 == 0 || i % 5 == 0)){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<map>
#define P pair<int,int>
using namespace std;
int main(){
	int m;
	vector<P>juels;
	while(cin>>m,m!=0){
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		juels.push_back(P(a,b));
	}
	
	int n,nx=10,ny=10;
	cin>>n;
	bool flag[100]={0};int cnt=0;
	for(int i=0;i<n;i++){
		int move;
		char muki;
		cin>>muki>>move;
		
		for(int k=0;k<move;k++){
		for(int j=0;j<juels.size();j++){
			if(juels[j].first==nx&&juels[j].second==ny)	flag[j]=1;
			}
		if(muki=='N')ny++;
		if(muki=='E')nx++;
		if(muki=='S')ny--;
		if(muki=='W')nx--;
				for(int j=0;j<juels.size();j++){
			if(juels[j].first==nx&&juels[j].second==ny)
				flag[j]=1;
			}
	}
	}
	for(int i=0;i<m;i++)if(flag[i])cnt++;
	if(cnt==m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	juels.clear();
	}
return 0;
}

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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> v(n);
    for(int i=0; i<m; i++){
        int a;
        cin >> a;
        v[a-1]++;
    }
    int ans = 1e9;
    int cnt = 0;
    for(int i=0; i<x; i++) cnt += v[i];
    ans = cnt;
    cnt = 0;
    for(int i=x; i<n; i++) cnt += v[i];
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var S string
	fmt.Scan(&S)
	var T string
	fmt.Scan(&T)
	//sc.Split(bufio.ScanWords)
	count := 0
	for i, sc := range S {
		if string(sc) == string(T[i]) {
			continue
		}
		count++
	}
	fmt.Print(count)
}
func nextLine() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func MySort(a []int) {
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })

}
func SortedBinaryAppend(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinaryDelete(sortedArr []int, targetValue int) []int {
	return []int{}
}
func SortedBinarySearch(sortedArr []int, targetValue int) int {
	post := len(sortedArr) - 1
	pre := 0
	for {
		div := (post + pre) / 2
		tim := sortedArr[div]
		if tim == targetValue {
			return pre + div
		} else if tim > targetValue {
			post = tim
		} else {
			pre = tim
		}
		if pre == post {
			return -1
		}
	}
}
func Abs(i int) int {
	if i < 0 {
		return -1 * i
	}
	return i
}
func Min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func Max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func CalcNum(tate int, yoko int, A int, B int, dp *map[[2]int]int) int {
	if (*dp)[[2]int{tate, yoko}] != 0 {
		return (*dp)[[2]int{tate, yoko}]
	}
	return yoko*CalcNum(tate-1, yoko, A, B, dp) + tate*CalcNum(tate, yoko-1, A, B, dp)
}
func arrSum(arr []int) int {
	sum := 0
	for _, a := range arr {
		sum += a
	}
	return sum
}
func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}
func scanStrings(len int) (strings []string) {
	var str string
	for i := 0; i < len; i++ {
		fmt.Scanf("%s", &str)
		strings = append(strings, str)
	}
	return
}


Measured memory_bytes: 4592
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
int a[50],b[50],c[50];
int main() {
boost
int n,i,sum=0;
cin>>n;
//int a[n],b[n],c[n];
{for(i=1;i<=n;++i)
	cin>>a[i];
for(i=1;i<=n;++i)
	cin>>b[i];
for(i=1;i<=n;++i)
	cin>>c[i];
}
//sum=b[a[1]];	
for(i=1;i<=n;++i){
	if(a[i]-a[i-1]==1)
		sum=sum+b[a[i]]+c[a[i]-1];
	else
		sum=sum+b[a[i]];
}
cout<<sum;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int even[100005];
int odd[100005];

int main() {
  int n;
  cin >> n;
  for(int i = 0; i < n; i++) {
    int v;
    cin >> v;
    if(i & 1) odd[v]++;
    else even[v]++;
  }
  int tmp1 = 0;
  int j = 0;
  int tmp2 = 0;
  int k = 0;
  for(int i = 0; i <= 100000; i++) {
    if(tmp1 < even[i]) {
      j = i;
      tmp1 = even[i];
    }
  }
  for(int i = 0; i <= 100000; i++) {
    if(tmp2 < odd[i]) {
      k = i;
      tmp2 = odd[i];
    }
  }

  
  sort(odd,odd+100000,greater<int> ());
  sort(even,even+100000,greater<int> ());
  if(j == k) {
    cout << min(n - odd[0] - even[1],n - odd[1] - even[0]) << endl;
  }
  else{
    cout << (n / 2 - even[0]) + (n / 2 - odd[0]) << endl;
  }
}
  
  


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////
ll fac[MAX], finv[MAX], inv[MAX];

void Pinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

ll P(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * finv[n-k] % MOD;
}


int main() {
	Pinit();

	ll N, X;
	cin >> N >> X;

	vector<ll> S(N + 1);
	repn(i, N) cin >> S[i];

	vector<ll> dp(X + 1,0);
	vector<ll> lb(X + 1);

	sort(++S.begin(), S.end());

	rep(K, X+1) {
		auto itr = upper_bound(++S.begin(), S.end(), K);
		lb[K] = distance(S.begin(), itr) - 1;

		
		if (lb[K] == 0) { dp[K] = K; }

		else {
			repn(i, lb[K]) {
				ll l = K % S[i];
				ll t = dp[l] * P(lb[K]-1, lb[K]-1-lb[l]) % MOD;
				dp[K] = (dp[K] + t) % MOD;
			}
		}

		//cout << K << lb[K] << dp[K] << endl;
	}

	ll ans = dp[X] * P(N, N-lb[X]) % MOD;

	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 25464
/*input
5 1
1
2
3
4
5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,d;
    cin>>n>>d;
    int arr[n][d];
    REP(i,n){
        REP(j,d){
            cin>>arr[i][j];
        }
    }
    int r=0;
    REP(i,n){
        for(int j=i+1;j<n;j++){
            double ans=0;
            REP(k,d){
                ans+=(arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]);
            }
            ans=sqrt(ans);
            if(ans==(int)ans) ++r;
        }
    }
    cout<<r;
}

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

int a[200005];

int main() {
	int n;
	long long tot = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", &a[i]);
	}
	for(int i = 2; i <= n; i ++) {
		if(a[i] - a[i - 1] < 0) {
			tot += a[i - 1] - a[i];
		}
		a[i] = max(a[i - 1], a[i]);
	}
	printf("%lld", tot);
}

Measured memory_bytes: 4012
//compiledef
#include <bits/stdc++.h>
#define rep(i, n) for(i=0;i<(n);i++)
#define per(i, n) for(i=(n);i>0;i--)
#define repx(i, n, x) for(i=(x);i<(n);i++)
#define xper(i, n, x) for(i=(n);i>(x);i--)
#define pback push_back

//c++def
using namespace std;
typedef long long int ll;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
int n;
int w[10003][10003];
void daikustra(){
	int color[10003];
	int d[10003];
	int i;
	int v;
	int u= -1;
	rep(i, n){
		d[i] = 2e9;
		color[i] = 0;
	}
	d[0] = 0;
	color[0] = 1;
	while(999){
		int mincost = 2e9;
		rep(i, n){
			if(mincost>d[i] && color[i] !=2){
				u = i;
				mincost =d[i];
			}
		}
		if(mincost==2e9) break;
		color[u] = 2;
		for(v=0;v<n;v++){
			if(color[v] !=2&&w[u][v] != 2e9){
				if((d[u] + w[u][v])<d[v]){
					d[v] = d[u] + w[u][v];
					color[v] =1;
				}
			}
		}
	}
	rep(i, n){
		cout << i << " ";
		if(d[i] == 2e9)
			cout << -1;
		else
			cout<< d[i];
		cout <<endl;
	}
}

int main(){
	int i, j, k, l, u, v;
	cin >> n;
	rep(i, n)rep(j, n)w[i][j] = 2e9;
	rep(i, n){
		cin >> k >> l;
		rep(j, l){
			cin >> u >> v;
			w[k][u] = v;
		}
	}
	daikustra();
}




Measured memory_bytes: 3476
while True:
    try:
        for i in range(3):
            line = raw_input().strip()
            if line == '0':
                raise Exception

            if line[0] == 'A':
                a, b = (-1, 0)
            else:
                a, b = (0, -1)
            for s in line:
                if s == 'A':
                    a += 1
                else:
                    b += 1
            if a > b:
                a += 1
            else:
                b += 1
            print a, b

    except:
        break

Measured memory_bytes: 4228
// わからない
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

struct data{
    int i, j, pos;
    bool operator<(const data other) const{
        if(i != other.i)    return i < other.i;
        else                return j < other.j;
    }
};

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

    vector<data> taka, aoki;
    int a, b;

    for(int i = 0; i < n; i++){
        cin >> a >> b;
        taka.push_back(data{a+b, a, i});
        aoki.push_back(data{b+a, b, i});
    }
    
    sort(taka.rbegin(), taka.rend());
    sort(aoki.rbegin(), aoki.rend());

    // for(data d : taka)  cout << d.i << " " << d.j << endl;
    // for(data d : aoki)  cout << d.i << " " << d.j << endl;

    bool used[n];
    memset(used, 0, sizeof(used));

    ll ta = 0, ao = 0;
    int curt = 0, cura = 0;

    for(int i = 0; i < n; i++){
        if(i%2 == 0){
            while(used[taka[curt].pos]) curt++;
            used[taka[curt].pos] = true;
            ta += taka[curt].j;
            curt++;
        }else{
            while(used[aoki[cura].pos]) cura++;
            used[aoki[cura].pos] = true;
            ao += aoki[cura].j;
            cura++;
        }
    }

    cout << ta-ao << endl;

    return 0;
}

Measured memory_bytes: 2988
#!/usr/bin/env python3

def calc(h):
    N = len(h)
    r = 0
    min_h = min(h)
    if 0 < min_h:
        r += min_h
        for i in range(N):
            h[i] -= min_h

    while h[0] != 0:
        j = N
        for i in range(1, N):
            if h[i] == 0:
                j = i
                break
        r += 1
        for i in range(j):
            h[i] -= 1

    if N == 1:
        return r
    else:
        return r + calc(h[1:])


def main():
    N = int(input())
    h = list(map(int, input().split()))

    r = calc(h)

    print(r)


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
class UF:
  def __init__(self,n=0):
    self.vertices=n
    self.mother=[-1 for i in range(self.vertices)]
  
  def root(self,x):
    normalize_v=[]
    while x!=-1:
      normalize_v.append(x)
      y=x
      x=self.mother[x]
    for i in normalize_v[:-1]:
      self.mother[i]=y
    return y
  
  def union(self,x,y):
    root_y=self.root(y)
    root_x=self.root(x)
    if root_x!=root_y:
      self.mother[root_x]=root_y
  
  def find(self,x,y):
    if self.root(x)==self.root(y):
      return True
    else:
      return False

n,m=map(int,input().split())
uf=UF(n)
for i in range(m):
  q=list(map(lambda x:int(x)-1,input().split()))
  uf.union(q[0],q[1])

l=[0 for i in range(n)]
ml=0
for i in range(n):
  r=uf.root(i)
  l[r]+=1
  ml=max(ml,l[r])

print(ml)

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    ll a;
    long double b;
    cin>>a>>b;
    ll c=b*1000;
    c/=10;
    //cout<<c<<endl;
    cout<<a*c/100<<endl;
    return 0;
}

//a=97,z=122

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

int main() {
int ans = 0;
int H,N;
cin >> H >> N;
vector<int> A(N),B(N);
for (int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
}
int max_A = *max_element(A.begin(), A.end());
vector<long long> DP(H+max_A,pow(10,10));
DP.at(0) = 0;
for (int i = 0; i < H+max_A; i++){
    for (int j = 0; j < N; j++){
        if (i-A.at(j) >= 0)
        DP.at(i) = min(DP.at(i-A.at(j))+B.at(j), DP.at(i));
    }
}
ans = *min_element(DP.begin()+H,DP.end());

cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int data[1010][1010];

int main(){

	int n,m,a;

	while(cin>>n>>m>>a){
		if(n==0 && m== 0&&a==0)break;

		for(int i=0;i<1010;i++){
			for(int j=0;j<1010;j++){
				data[i][j]=0;
			}
		}

		int cnt,start,end;
		int max=0;

		for(int i=0;i<m;i++){
			cin>>cnt>>start>>end;
			data[cnt][start]=end;
			data[cnt][end]  =start;

			if(max<=cnt)max=cnt;
		}

		for(int i=max;i>=1;i--){
			if(data[i][a]>0){
				a = data[i][a];
			}
		}

		cout<<a<<endl;

	}

	return 0;
}

Measured memory_bytes: 5144
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

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

  for(int i=0;i<m;i++){
    string train;
    cin >> train;
    set<string> st;
    for( int i = 1, length = train.length() ; i < length ; ++i ){
      string forward, backward;
      forward = train.substr(0,i);
      backward = train.substr(i, length-i);
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(backward.begin(), backward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(forward.begin(), forward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
      reverse(backward.begin(), backward.end());
      st.insert(forward+backward);
      st.insert(backward+forward);
    }
    cout << st.size() << endl;
  }
  return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	
	cin >> N;
	
	vector<pair<int, int>> A(N);
	
	rep(i, N){
		cin >> A[i].first;
		A[i].first--;
		A[i].second = i;
	}
	
	sort(A.begin(), A.end());
	
	rep(i, N)
		cout << A[i].second + 1 << " ";
	
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define int long long int
main()
{
	int n;
	cin>>n;int cou=0;
     for(int i=1;i<n;i++)
     {
     	int num;
		 int tempcou=1;
     	num=n-i;
		 int cou1=0;
		 while(num%2==0)
		 {
		 cou1++;
		 num/=2;
		 }tempcou*=(cou1+1);
		 cou1=0;
     for (long long d = 3; d * d <= num; d+=2) {
        while (num % d == 0) {
            //factorization.push_back(d);
            cou1++;
            num /= d;
        }
        tempcou*=(cou1+1);
        cou1=0;
    }
    if (num > 1)
		 tempcou*=2;
	//	 cout<<i<<" "<<tempcou<<endl;
		 cou+=tempcou;
	 }
	 cout<<cou<<endl;
}

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

using namespace std;

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

    int cnt = 0;
    int ans = 0;

    for (auto i : S) {
        if ( i != 'A' && i != 'C' && i != 'G' && i != 'T' ) cnt = 0;
        else if ( ++cnt > ans ) ans = cnt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#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<ll> a(n + 1), b(n);
	rep(i, n + 1) cin >> a[i];
	rep(i, n) cin >> b[i];

	ll ans = 0;
	rep(i, n) {
		// i
		ll d1 = min(a[i], b[i]);
		ans += d1;
		a[i] -= d1;
		b[i] -= d1;
		// i + 1
		ll d2 = min(a[i + 1], b[i]);
		ans += d2;
		a[i + 1] -= d2;
		b[i] -= d2;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

constexpr static int MOD = 1e9 + 7;
constexpr static int MAXN = 1e6;

int64_t x[MAXN], y[MAXN];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
        cin >> x[i];
    sort(x, x + n);
    for (int j = 0; j < m; j++)
        cin >> y[j];
    sort(y, y + m);

    int64_t xsum = 0;
    for (int i = 1; i < n; i++) {
        int64_t cnt = 1LL * i * (n - i) % MOD;
        xsum += cnt * (x[i] - x[i - 1]) % MOD;
    }
    int64_t ysum = 0;
    for (int j = 1; j < m; j++) {
        int64_t cnt = 1LL * j * (m - j) % MOD;
        ysum += cnt * (y[j] - y[j - 1]) % MOD;
    }
    xsum %= MOD;
    ysum %= MOD;
    int64_t total = xsum * ysum % MOD;
    cout << total << endl;
}


Measured memory_bytes: 5248
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int r;
  cin>>r;
  cout<<r*r<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

Int v[1005];
Int w[1005];
Int dp[1005][1005];
vector<Int> ans;
vector<Int> ans2;

void solve(Int W){
    Int N; cin >> N;
    memset(v, 0, sizeof(v));
    memset(w, 0, sizeof(w));
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < N; i++){
        char c;
        cin >> v[i] >> c >> w[i];
    }
    for (int i = 0; i < N; i++){
        for (int j = 0; j <= W; j++){
            if (j+w[i] <= W) dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }
    ans.push_back(dp[N][W]);
    for (int i = W; i >= 0; i--){
        if (dp[N][i] != dp[N][W]){
            ans2.push_back(i+1);
            break;
        }
    }

}

int main(){
    cin.tie(0);

    while (1){
        Int W; cin >> W;
        if (!W) break;
        solve(W);
    }
    for (int i = 0; i < ans.size(); i++){
        cout << "Case " << i+1 << ":" << endl;
        cout << ans[i] << endl;
        cout << ans2[i] << endl;
    }
}



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

int main() {
  char c;
  cin >> c;
  
  if (c=='a'|| c=='e' || c=='i' || c=='o' || c=='u' ) 
    cout << "vowel" << endl;
  else 
    cout << "consonant" << endl;
}


Measured memory_bytes: 256
import core.stdc.stdio;
import std.stdio;

void main(){
	int n;
	scanf("%d",&n);
	char[] buf = new char[n+1];
	scanf("%s",buf.ptr);
	buf = buf[0..n];
	bool[] used = new bool[n];
	int[] op = new int[n];
	bool Solve(char[] data,int c){
		used[] = false;
		int ic=n;
		int a;
		for(int i=n-1;i>=0;i--)
			if(a<c&&data[i]=='O')
				while(--ic>i)
					if(!used[ic]&&data[ic]=='I'){
						used[ic]=true;
						used[i]=true;
						a++;
						break;
					}
		if(a!=c)
			return false;
		int os=0;
		foreach(int i,u;used)
			if(u&&data[i]=='O')
				op[os++]=i;
		int oi=-1;
		foreach(int i,u;used)
			if(!u&&data[i]!='O')
				while(++oi<os)
					if(op[oi]>i){
						a--;
						break;
					}
		return a==0;
	}
	int l,r=n+1;
	while(r-l>1){
		int m=(r+l)/2;
		if(Solve(buf,m))
			l=m;
		else
			r=m;
	}
	printf("%d\n",l);
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A == 5 && B == 5 && C == 7) {
    cout << "YES" << endl;
  }
  else if (A == 5 && B == 7 && C == 5) {
    cout << "YES" << endl;
  }
  else if (A == 7 && B == 5 && C == 5) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

ll gcd(ll a, ll b){
  if(a<b) swap(a,b);
  if(b==0)return a;
  return gcd(b,a%b);
}

vector<PLL> prime_factor(ll n){
  vector<PLL> v;
  for(int i = 2; i<=sqrt(n); ++i){
    int num = 0;
    while(n%i==0){
      ++num;
      n/=i;
    }
    if(num!=0) v.push_back(PLL(i,num));
  }
  if(n!=1) v.push_back(PLL(n,1));
  return v;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll A,B;cin >> A >> B;
  ll GCD = gcd(A,B);
  vector<PLL> v = prime_factor(GCD);
  cout << v.size()+1 << endl;
  return 0;
}


Measured memory_bytes: 256
// AOJ 0351 Quiet Town
// 2018.2.25 bal4u

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

#define QMAX 2000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
#define MAX 1503
int n, dmax, sz;
short hi[MAX], *to[MAX], *dt[MAX];		// to, dist
short hi2[MAX], *to2[MAX];
int   dist[MAX];
char  mk[MAX], ans[MAX];
short q[2*MAX], top, tail;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void dijkstra(int start)
{
	int i, s, d, e;
	int max;

	memset(dist, INF, n << 2);
	memset(hi2, 0, n << 1);
	qsize = 0;
	dist[start] = 0, enq(start, 0);
	while (qsize) {
		s = que[0].s, deq();
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i], d = dist[s] + dt[s][i];
			if (dist[e] < d) continue;
			if (dist[e] > d) hi2[e] = 0, dist[e] = d, enq(e, d);
			to2[e][hi2[e]++] = s;
		}
	}

	top = 0, tail = 0;
	max = 0; for (i = 1; i < n; i++) {
		if (dist[i] > max) max = dist[i], q[0] = i, tail = 1;
		else if (dist[i] == max) q[tail++] = i;
	}

	if (max < dmax) return;
	if (max > dmax) { dmax = max, sz = 1, memset(ans, 0, n); }

	if (!ans[start]) sz++, ans[start] = 1;
	memset(mk, 0, n);
	while (top < tail) {
		s = q[top++];
		if (mk[s]) continue;
		mk[s] = 1;
		for (i = 0; i < hi2[s]; i++) {
			e = to2[s][i];
			if (mk[e]) continue;
			q[tail++] = e;
			if (!ans[s]) sz++, ans[s] = 1;
			if (!ans[e]) sz++, ans[e] = 1;
		}
	}
}

int main()
{
	int i, j, r, k, s, t, d;
	short *memo;
	
	n = in()+1, r = in();
	memo = malloc(r*6);
	j = 0, i = r; while (i--) {
		memo[j++] = s = in(), hi[s]++;
		memo[j++] = t = in(), hi[t]++;
		memo[j++] = in();
		
	}
	for (s = 0; s < n; s++) if (hi[s]) {
		to [s] = malloc(hi[s] << 1), dt[s] = malloc(hi[s] << 1);
		to2[s] = malloc(hi[s] << 1);
	}
	
	memset(hi, 0, n << 1);
	j = 0; while (r--) {
		s = memo[j++], t = memo[j++], d = memo[j++];
		k = hi[s]++, to[s][k] = t, dt[s][k] = d;
		k = hi[t]++, to[t][k] = s, dt[t][k] = d;
	}
	free(memo);

	sz = 1;
	for (s = 1; s < n && sz < n; s++) dijkstra(s);

	sz = n - sz;
	printf("%d\n", sz);
	if (sz) for (s = 1; s < n; s++) if (!ans[s]) printf("%d\n", s);
	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N;
    cin >> N;
    vector<int> b;
    b.push_back(100000);
    REP(i, N - 1) {
        int tmp;
        cin >> tmp;
        b.push_back(tmp);
    }
    b.push_back(100000);

    int ans = 0;
    REP(i, N) { ans += _min(b[i], b[i + 1]); }
    cout << ans;
    return 0;
}

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

int main()
{
	std::string S, ans;
	std::cin >> S;

	ans = S;
	for (int i = 0; i < S.size(); i++){
		ans[i] = 'x';
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define S_MAX 10000
#define T_MAX 500

int main(void){
	int n,q,i,j,cnt = 0;
	int S[S_MAX] = {0};
	int T[T_MAX] = {0};

	scanf("%d", &n);

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

	scanf("%d", &q);

	for(i = 0;i < q;i++){
		scanf("%d" ,&T[i]);
	}

	for(i = 0;i < q;i++){
		for(j = 0;j < n;j++){
			if(T[i] == S[j]){
				cnt++;
				break;
			}
		}
	}

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

	return 0;
}

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

constexpr int mod = 2019;
int power10 (int x) {
  int p = 10;
  int res = 1;
  while (x > 0) {
    if (x & 1) (res *= p) %= mod;
    p *= p;
    p %= mod;
    x >>= 1;
  }
  return res;
}

signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  long long ans = 0;
  int cur = 0;
  int cnt[2222] = {};
  cnt[0] = 1;
  for (int i = n - 1; i >= 0; i--) {
    cur += power10(n - 1 - i) * (s[i] - '0');
    cur %= mod;
    ans += cnt[cur]++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3732
#include<iostream>
#include<algorithm>
#include <map>
using namespace std;
long long a[200010];
map<long long, long long> mp;
long long ct(long long k)
{
	long long sum=0;
	for(int i=1;i<=k;i++)
		sum+=i;
	return sum;
}
int main()
{
	long long n;	cin>>n;
	long long x=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		x+=a[i];
		mp[x]++;
	}
	mp[0]++;
	map<long long , long long>::iterator iter;
	long long ans=0;
	for (iter = mp.begin();iter != mp.end();iter++)
	{
		long long x = iter->first;//記得  要用-> 
		long long y = iter->second;
		//cout<<x<<" "<<y<<endl;
		if(y==1)
			continue;
		ans+=ct(y-1);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14336
using System;
using System.Linq;

namespace ABC104
{
    class C
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int D = input[0];
            int G = input[1];

            int[] p = new int[D];
            int[] c = new int[D];
            for (int i = 0; i < D; i++)
            {
                input = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = input[0];
                c[i] = input[1];
            }

            long res = long.MaxValue;
            for (int bit = 0; bit < (1 << D); bit++)
            {
                long sum = 0;
                long num = 0;
                for (int i = 0; i < D; i++)
                {
                    if ((bit & (1 << i)) > 0)
                    {
                        sum += c[i] + p[i] * 100 * (i + 1);
                        num += p[i];
                    }
                }

                if (G <= sum)
                {
                    res = Math.Min(res, num);
                }
                else
                {
                    for (int i = D - 1; i >= 0; i--)
                    {
                        if ((bit & (1 << i)) > 0) continue;
                        for (int j = 0; j < p[i]; j++)
                        {
                            if (sum >= G) break;
                            sum += 100 * (i + 1);
                            num++;
                        }
                    }
                    res = Math.Min(res, num);
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13396
#define NAME "a"

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cctype>
#include <cassert>
#include <memory>
#include <stack>
#include <queue>
#include <deque>
#include <utility>
#include <iterator>

#define pb push_back
#define mp make_pair
#define frs first
#define snd second

using namespace std;

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int INF = (int) 1e9 + 7;
const ll INFLONG = (ll) 1e18 + 7;
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<string> vs;

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

typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;

template <typename T>
T sqr(T a) {
    return a * a;
}

char tmp[200010];

int main() {
    srand(time(0));

//    freopen(NAME".in", "r", stdin);
//    freopen(NAME".out", "w", stdout);

    scanf("%s", tmp);
    string s = (const char*) tmp;
    int n = s.length();
    vi mods_10(n, 1);

    for (int i = 1; i < n; i++) {
        mods_10[i] = mods_10[i - 1] * 10;
        mods_10[i] %= 2019;
    }

    int curr_mod = 0;
    vi mods(2019, 0);
    mods[0] = 1;
    ll ans = 0LL;

    for (int i = n - 1; i > -1; i--) {
        curr_mod += (int) (s[i] - '0') * mods_10[n - i - 1];
        curr_mod %= 2019;
        ans += (ll) mods[curr_mod];
        mods[curr_mod]++;
    }

    printf(lld"\n", ans);

//    printf("%.3lf\n", (double) clock() / CLOCKS_PER_SEC);
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int counter = 0;
  if (s[0] == 'o') ++ counter;
  if (s[1] == 'o') ++ counter;
  if (s[2] == 'o') ++ counter;
  cout << 700+100*counter <<endl;
}

Measured memory_bytes: 256
def is_prime(n):
    if n == 1:
        return False
    for k in range(2,int(n**0.5)+1):
        if n % k == 0:
            return False
    return True
while 1:
    a,d,n=map(int,input().split())
    if a==0:
        break
    if is_prime(a):
        n -= 1
    while n > 0:
        a += d
        if is_prime(a):
            n -= 1
    print(a)


Measured memory_bytes: 5660
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
    
int main()
{
	float a, m;
	int n;
	cin >> n;
	while(n) {
		m = 0;
		int *s = new int[n];
		for (int i = 0; i < n; i++) {
			cin >> s[i];
			m += s[i];
		}
		a = 0;
		for (int i = 0; i < n; i++)
			a += pow(s[i] - m / n , 2) / n;
		cout << fixed << setprecision(4) << sqrt(a) << endl;
		cin >> n;
	}
	return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <iostream>
#include <functional>
#include <vector>
#include <stdio.h>
#include <queue>
#include <string.h>
#include <math.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define rep1(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
#define per1(i,a,n) for (int i=a;i>n;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define pi 3.14159265358979323846264338327950288419716939937510
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
// head
ll n,m,a[1005],sum,cnt;
int main()
{
    //IOS;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        if(4*m*a[i]>=sum)
        {
            cnt++;
        }
    }
    if(cnt>=m)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll a,b,c,x,y;
 cin>>a>>b>>c>>x>>y;
 ll a1=a*x+b*y;//それぞれ買う
 ll a2=2*c*max(x,y);//全部cで済ませる
 ll a3=min(x,y)*2*c+(x-min(x,y))*a+(y-min(x,y))*b;
 ll ans=min(a1,a2);
 ans=min(ans,a3);
 pr(ans);
 return 0;}

Measured memory_bytes: 3672
n,q = map(int,input().split())
s = input()
word = list(s)
li = [list(input().split()) for _ in range(q)]
memo = {}

def dfs(m):
    k = m
    if m in memo:
        return memo[m]
    for x in li:
        if word[m] == x[0]:
            if x[1] == 'R':
                m += 1
            else:
                m -= 1
        if m < 0:
            memo[k] = 'Left'
            return 'Left'
        elif m > n-1:
            memo[k] = 'Right'
            return  'Right'
    memo[k] = True
    return True

def left(a,b):
    m = int((a+b)/2)
    if a == m:
        return b
    elif dfs(m) == 'Left':
        return left(m,b)
    else:
        return left(a,m)

def right(a,b):
    m = int((a+b)/2)
    if a == m:
        return a
    elif dfs(m) == 'Right':
        return right(a,m)
    else:
        return right(m,b)

if dfs(0) == 'Right':
    print(0)
elif dfs(0) == 'Left':
    if dfs(n-1) == 'Right':
        print(right(0,n-1) - left(0,n-1) + 1)
    elif dfs(n-1) == 'Left':
        print(0)
    else:
        print(n - left(0,n-1))
else:
    if dfs(b) == 'Right':
        print(right(0,n-1) + 1)
    elif dfs(b) == 'Left':
        print(0)
    else:
        print(n)


Measured memory_bytes: 28340
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int c = 0;
    for(int i = 0; i < N; i++){
        int l,r;
        cin >> l >> r;
        c += r-l+1;
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, m, p, x, ans = 0;
  scanf("%lld", &n);
  ll t[n];
  for(i = 0; i < n; ++i) scanf("%lld", &t[i]), ans += t[i];
  scanf("%lld", &m);
  for(i = 0; i < m; ++i) scanf("%lld%lld", &p, &x), printf("%lld\n", ans -t[--p] + x);
  return 0;
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int N;
vector<int> A;
map<int,vector<int>> B;
vector<long long> memo, memo_g;
long long f(int p);
long long g(int p, int x, int y) {
	if (memo_g[p] >= 0) return memo_g[p];
	long long r = f(x+1);
	if (y >= 0) (r += g(x, y, -1)) %= mod;
	return memo_g[p] = r;
}
long long f(int p) {
	if (p >= (int)A.size()) return 1;
	if (memo[p] >= 0) return memo[p];
	int x = A[p];
	const auto& b = B[x];
	long long r = f(p+1);
	vector<int> c;
	for (auto it = upper_bound(b.begin(), b.end(), p); it != b.end(); ++ it) {
		c.push_back(*it);
		if (c.size() >= 2) break;
	}
	if (c.size() == 2) (r += g(p, c[0], c[1])) %= mod;
	else if (c.size() == 1) (r += g(p, c[0], -1)) %= mod;
	return memo[p] = r;
}
int main() {
	cin >> N;
	for (int i = 0; i < N; ++ i) {
		int x;
		cin >> x;
		if (A.empty() || A.back() != x) {
			B[x].push_back((int)A.size());
			A.push_back(x);
		}
	}
	memo.resize(A.size(), -1);
	memo_g.resize(A.size(), -1);
	cout << f(0) << endl;
}


Measured memory_bytes: 44788