akhauriyash/Code-Regression huggingface dataset:
package main

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

type Dish struct {
	A, B int
}

func main() {
	N, T := ReadInt(), ReadInt()
	dishes := make([]Dish, N)
	for i := 0; i < N; i++ {
		dishes[i].A, dishes[i].B = ReadInt(), ReadInt()
	}
	sort.Slice(dishes, func(i, j int) bool {
		return dishes[i].A < dishes[j].A
	})
	dp := make([][]int, N+1)
	for i := 0; i <= N; i++ {
		dp[i] = make([]int, T)
	}
	ans := -1
	for i := 0; i < N; i++ {
		for j := 0; j < T; j++ {
			dp[i+1][j] = Max(dp[i+1][j], dp[i][j])
			nj := j + dishes[i].A
			if nj < T {
				dp[i+1][nj] = Max(dp[i+1][nj], dp[i][j]+dishes[i].B)
			}
		}
		for j := i; j < N; j++ {
			ans = Max(ans, dp[i][T-1]+dishes[j].B)
		}
	}
	fmt.Println(ans)
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 77004
while 1:
	n=input()
	if n==0:break
	ap=bp=0
	for i in range(n):
		a,b=map(int,raw_input().split())
		if a>b:ap+=a+b
		elif a<b:bp+=a+b
		else:ap+=a;bp+=b
	print ap,bp

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

int main()
{
    int n;cin>>n;
    bitset<64>mask[n];
    REP(i,n)
    {
        int k;cin>>k;
        REP(j,k)
        {
            int64_t x;
            cin>>x;
            mask[i].set(x);
        }
    }
    int q;cin>>q;
    bitset<64>a;
    REP(i,q){
        int comm,m;cin>>comm>>m;
        switch (comm){
            case 0:
                cout<<a.test(m)<<endl;
            break;
            case 1:
                a|=mask[m];
            break;
            case 2:
                a&=~mask[m];
            break;
            case 3:
                a^=mask[m];
            break;
            case 4:
                cout<<((a&mask[m])==mask[m])<<endl;
                
            break;
            case 5:
                cout<<(a&mask[m]).any()<<endl;
            break;
            case 6:
                cout<<(a&mask[m]).none()<<endl;
            break;
            case 7:
                cout<<(a&mask[m]).count()<<endl;
            break;
            case 8:
                cout<<(a&mask[m]).to_ullong()<<endl;
            break;
    }
    }
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
int main(void)
{
    long long int a;
    double b;
    cin >> a;
    cin >> b;
    long long int bi = (long long int)(( b + 0.00001) * 100);

    cout << (a * bi / 100);
}


Measured memory_bytes: 3704
{-# LANGUAGE ViewPatterns #-}

import Data.Sequence (Seq, (<|), (|>), fromList, viewl, ViewL((:<)), ViewL(EmptyL))

type TotalTime = Int
type UnitTime = Int

{-
roundRobin :: [(String, Int)] -> [(String, Int)] -> UnitTime -> TotalTime -> [(String, Int)]
roundRobin [] ys _ _ = ys
roundRobin (x:xs) ys u t
  | (snd x) == consume = roundRobin xs ((fst x, total):ys) u total
  | otherwise          = roundRobin (xs ++ [(fst x, snd x - consume)]) ys u total
  where consume = min (snd x) u
        total = t + consume
-}

roundRobinS :: Seq (String, Int) -> [(String, Int)] -> UnitTime -> TotalTime -> [(String, Int)]
roundRobinS (viewl -> EmptyL) ys _ _ = ys
roundRobinS (viewl -> x :< xs) ys u t
  | (snd x) == consume = roundRobinS xs ((fst x, total):ys) u total
  | otherwise          = roundRobinS (xs |> (fst x, snd x - consume)) ys u total
  where consume = min (snd x) u
        total = t + consume

main = do
  u <- fmap (read . (!! 1) . words) getLine
  input <- fmap ((map words) . lines) getContents
  let queue = map (\[x, y] -> (x, read y))  input
  let result = roundRobinS (fromList queue) [] u 0
  mapM_ putStrLn (reverse $ map (\(x, y) -> x ++ " " ++ show y) result)

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

int main()
{
  int64_t N, M, R, INF = (1LL << 60), a, b, c, ans = INF;
  cin >> N >> M >> R;
  vector<int64_t> rs(R);
  for (int i = 0; i < R; i++)
  {
    cin >> rs[i];
    rs[i]--;
  }
  vector<vector<int64_t>> path(210, vector<int64_t>(210, INF));
  for (int i = 0; i < N; i++)
  {
    path[i][i] = 0;
  }
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b >> c;
    a--;
    b--;
    path[a][b] = c;
    path[b][a] = c;
  }
  for (int k = 0; k < N; k++)
  {
    for (int i = 0; i < N; i++)
    {
      for (int j = 0; j < N; j++)
      {
        path[i][j] = min(path[i][j], path[i][k] + path[k][j]);
      }
    }
  }
  sort(rs.begin(), rs.end());
  do
  {
    int64_t prev = rs[0], tmp = 0;
    for (int i = 1; i < R; i++)
    {
      tmp += path[prev][rs[i]];
      prev = rs[i];
    }
    ans = min(ans, tmp);
  } while (next_permutation(rs.begin(), rs.end()));
  cout << ans << endl;
}

Measured memory_bytes: 3992
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int roots(int b, int c)
{
	int D = b * b - 4 * c;

	if (D < 0)
		return 0;

	int sq = sqrt(D);

	if (sq * sq != D)
		return 0;

	int num = - b + sq;
	int den = 2;

	if ((num % den) || num / den < 1)
		return 0;

	int r1 = num / den;

	num -= 2 * sq;
	int r2 = num / den;

	if (r2 >= 1)
		return 2;
	else
		return 1;
}

int32_t main()
{
	FIO;
	int nv; cin >> nv;
	for (int n = 1; n <= nv; ++n)
	{
		int ans = 0;
		for (int x = 1; x * x <= n; ++x)
			for (int y = 1; y * y <= n; ++y)
				ans += roots(x + y, x * x + y * y + x * y - n);

		cout << ans << '\n';
	}
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int goal = min(b,d);
  int start = max(a,c);
  
  int ans = max(0,goal - start);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,x;
        for(i=1;i<=10000;i++){
        scanf("%d",&x);
    if(1<=x&&x<=10000){
         printf("Case %d: %d\n",i,x);
    }else if(x<1&&10000<x){
       break;
    }
    }
        return 0;
    }


Measured memory_bytes: 2040
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
S = [input() for _ in range(N)]

cnt = Counter(S)
tmp = cnt.most_common()[0][1]

all_sort = sorted(cnt.most_common(), key=lambda x:x[0])

for key, val in all_sort:
  if val == tmp:
    print(key)

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

#define int long long

const int MOD = 1e9 + 7;
string K;
int D;

int dp[10010][2][110] = {0}; // dp[i桁目][K未満?][mod D] = 総数

signed main() {
  cin >> K >> D;
  int n = K.size();

  dp[0][0][0] = 1;
  for (int digit = 0; digit < n; digit++) {
    for (int smaller : {0, 1}) {
      int lim = smaller == 1 ? 9 : K[digit] - '0';
      for (int num = 0; num <= lim; num++) {
        for (int modD = 0; modD < D; modD++) {
          dp[digit+1][smaller || num < lim][(modD + num) % D] += dp[digit][smaller][modD] % MOD;
        }
      }
    }
  }

  cout << (dp[n][0][0] + dp[n][1][0] - 1 + MOD) % MOD << endl;

  return 0;
}

Measured memory_bytes: 17408
n = int(input())
a = list(map(int,input().split()))
def euclidean(a,b):
    cond = 1
    while cond:
        temp = a % b
        if temp == 0:
            return b
        else:
            a = b
            b = temp

lcm = a[0]
for i in range(1,n):
    lcm = euclidean(lcm,a[i])

print(lcm)


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

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

int main(){
    string s; cin >> s;
    int n = s.size();
    vector<int> a(n+1);
    vector<ll> l(n+1);
    vector<ll> r(n+1);
    rrep(i, n){
        if(s[i] == '>'){
          r[i]=r[i+1]+1;
        }
    }
    rep(i, n){
        if(s[i]== '<'){
          l[i+1]=l[i]+1;
        }
    }
    rep(i, n+1){
      a[i]=max(l[i],r[i]);
    } 
    ll ans = 0;
    for(int i =0; i<=n;++i){
          ans += a[i];
          //cout << a[i] << " ";
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10628
n=int(input())

start=[0,0,0]

ans=0

for i in range(n):
    
    cont=list(map(int,input().split()))
    
    x=abs(start[0]-cont[0])
    
    y=abs(start[1]-cont[1])+abs(start[2]-cont[2])
    
    
    if x<y:
        ans=1
        
    else:
        if x%2==0:
            if y%2!=0:
                ans=1
                
        else:
            if y%2!=1:
                ans=1
                

        
    start=cont
        
if ans==0:
    print('Yes')
    
else:
    print('No')

Measured memory_bytes: 3064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)





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

	int a, b, c, d;
	d = n % 10;
	n /= 10;
	c = n % 10;
	n /= 10;
	b = n % 10;
	n /= 10;
	a = n;


	if (a + b + c + d == 7) cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a + b - c + d == 7) cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a + b - c - d == 7) cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if (a + b + c - d == 7) cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a - b + c + d == 7) cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a - b + c - d == 7) cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a - b - c + d == 7) cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a - b - c - d == 7) cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;





	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    ll n;
    cin >> n;
    vector<int> A(n);
    REP(i,n) cin >> A[i];
    int max= -1;
    int t= -1;
    sort(A.begin(), A.end());
    REP(i,n-1){
        int x= min(A[i],A[n-1]-A[i]);
        if(x>max){
            max= x;
            t= i;
        }
    }
    cout << A[n-1] << " " << A[t] << endl;
}


Measured memory_bytes: 640
h, w, a, b = map(int, input().split())
A = [1]*w
m = 0
for i in range(b):
  A[a:] = [0]*(w-a)
  L=[str(a) for a in A]
  L="".join(L)
  print(L)
A = [1]*w
for j in range(h-b):
  A[:a] = [0]*a
  L=[str(a) for a in A]
  L="".join(L)
  print(L)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
ll i, j, k;
char S[1010][1010];

const char mk[10][20][20]={
    {},{},{},{},
    {
        "aacd",
        "bbcd",
        "cdaa",
        "cdbb"
    },
    {
        "aabba",
        "b..ca",
        "b..cb",
        "acc.b",
        "abbaa"
    },
    {
        "aabbaa",
        "c.c.c.",
        "c.c.c.",
        ".c.c.c",
        ".c.c.c",
        "aabbaa"
    },
    {
        ".aabbaa",
        "a.cc.cc",
        "ac..c..",
        "bc..c..",
        "b.cc.cc",
        "ac..c..",
        "ac..c.."
    },
};

void crS(ll a,ll p){
    ll i,j;
    fornum(i,0,a){
        fornum(j,0,a){
            S[p + i][p + j] = mk[a][i][j];
        }
    }
}
int main(){
    scanf("%lld", &N);
    if(N==2){
        printf("-1");
        return 0;
    }
    if(N==3){
        printf("aa.\n");
        printf("..a\n");
        printf("..a\n");
        return 0;
    }
    i = N % 4 + 4;
    crS(i, 0);
    while(i<N){
        crS(4, i);
        i+= 4;
    }
    fornum(i,0,N){
        fornum(j,0,N){
            printf("%c", S[i][j] ? S[i][j] : '.');
        }
        printf("\n");
    }
    
    return 0;
}

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

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

  vector<ll> a(3 * n);
  rep(i, 3 * n) cin >> a[i];

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

  ll ans = 0;
  for (int i = n; i < 3 * n; i += 2)
    ans += a[i];

  cout << ans << endl;
}

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

namespace AtCoder {

    class Program {

        static void Main(string[] args) {

            var N = int.Parse(Console.ReadLine());

            var p = new List<int>();

            for(int i = 0; i < N; i++) {

                p.Add(int.Parse(Console.ReadLine()));
            }

            var expensive = p.Max();

            var result = p.Sum();
            result = result - expensive + (expensive / 2);

            Console.WriteLine(result);
        }
    }
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll A, B;
    cin >> A >> B;
    REP(i, 3) {
        if (i + 1 != A && i + 1 != B) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)

	count := map[string]int{}
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s", &s)
		count[s]++
	}

	fmt.Printf("AC x %d\n", count["AC"])
	fmt.Printf("WA x %d\n", count["WA"])
	fmt.Printf("TLE x %d\n", count["TLE"])
	fmt.Printf("RE x %d\n", count["RE"])
}


Measured memory_bytes: 6344
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long Q, long long H, long long S, long long D, long long N){
    vector<pll> A;
    N *= 4;
    A.push_back(make_pair(Q*8, 1));
    A.push_back(make_pair(H*4, 2));
    A.push_back(make_pair(S*2, 4));
    A.push_back(make_pair(D,   8));
    sort(ALL(A)); 
    ll ans = 0;
    REP(i, 4){
        ans += N/A[i].second * A[i].first/(8/A[i].second);
        N = N%A[i].second;
        if(N == 0)
            break;
    }
    cout<<ans <<endl;
}

int main(){
    long long Q;
    scanf("%lld",&Q);
    long long H;
    scanf("%lld",&H);
    long long S;
    scanf("%lld",&S);
    long long D;
    scanf("%lld",&D);
    long long N;
    scanf("%lld",&N);
    solve(Q, H, S, D, N);
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=input()
cnt=0
def judge(n):
    pos=0
    pos=s.find(n[0],pos)
    if pos==-1:
        return 0
    pos=s.find(n[1],pos+1)
    if pos==-1:
        return 0
    pos=s.find(n[2],pos+1)
    if pos==-1:
        return 0
    return 1
for i in range(1000):
    p=str(i).rjust(3,'0')
    if judge(p):
        cnt+=1
print(cnt)

Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int N;
string s, t;

bool solve() {
  repp(i, 2, N - 1) {
    if ((t[i - 1] == 'S' && s[i - 1] == 'o') ||
        (t[i - 1] == 'W' && s[i - 1] == 'x')) {
      t[i] = t[i - 2];
    } else {
      if (t[i - 2] == 'S')
        t[i] = 'W';
      else
        t[i] = 'S';
    }
  }

  bool ok = true;
  if ((t[0] == 'S' && s[0] == 'o') || (t[0] == 'W' && s[0] == 'x')) {
    if (t[1] != t[N - 1])
      ok = false;
  } else {
    if (t[1] == t[N - 1])
      ok = false;
  }

  if ((t[N - 1] == 'S' && s[N - 1] == 'o') ||
      (t[N - 1] == 'W' && s[N - 1] == 'x')) {
    if (t[0] != t[N - 2])
      ok = false;
  } else {
    if (t[0] == t[N - 2])
      ok = false;
  }
  return ok;
}

int main() {
  cin >> N;
  cin >> s;

  t = string(N, '.');

  t[0] = 'S';
  t[1] = 'S';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'S';
  t[1] = 'W';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'W';
  t[1] = 'S';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  t[0] = 'W';
  t[1] = 'W';
  if (solve()) {
    cout << t << endl;
    return 0;
  }

  cout << -1 << endl;
}

Measured memory_bytes: 512
fn main() {
  let s = get::chars();
  
  let mut i = 0;
  let mut j = s.len() - 1;
  let mut ans = Some(0);
  while i < j {
    match (s[i], s[j]) {
      (ci, cj) if ci == cj => {i+=1; j-=1},
      ('x', _) => {i+=1; ans = ans.map(|a|a+1)},
      (_, 'x') => {j-=1; ans = ans.map(|a|a+1)},
      _ => {ans = None; break}
    }
  }
  
  println!("{}", ans.unwrap_or(-1))
}

#[allow(dead_code)]
mod get {
  use std::io::*;
  use std::str::*;

  pub fn val<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().parse::<T>().ok().unwrap()
  }

  pub fn vals<T: FromStr>(n: usize) -> Vec<T> {
    let mut vec: Vec<T> = vec![];
    for _ in 0 .. n {
      vec.push(val());
    }
    vec
  }

  pub fn tuple<T1: FromStr, T2: FromStr>() -> (T1, T2) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    (x, y)
  }

  pub fn tuples<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)> {
    let mut vec: Vec<(T1, T2)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple());
    }
    vec
  }

  pub fn tuple3<T1: FromStr, T2: FromStr, T3: FromStr>() -> (T1, T2, T3) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    let mut it = buf.trim().split_whitespace();
    let x = it.next().unwrap().parse::<T1>().ok().unwrap();
    let y = it.next().unwrap().parse::<T2>().ok().unwrap();
    let z = it.next().unwrap().parse::<T3>().ok().unwrap();
    (x, y, z)
  }

  pub fn tuple3s<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)> {
    let mut vec: Vec<(T1, T2, T3)> = vec![];
    for _ in 0 .. n {
      vec.push(tuple3());
    }
    vec
  }

  pub fn list<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
  }

  pub fn lists<T: FromStr>(h: usize) -> Vec<Vec<T>> {
    let mut mat: Vec<Vec<T>> = vec![];
    for _ in 0 .. h {
      mat.push(list());
    }
    mat
  }

  pub fn chars() -> Vec<char> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).ok();
    buf.trim().chars().collect()
  }
}


Measured memory_bytes: 4352
import java.util.Scanner;

/**
 *
 * @author Usuario
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner in= new Scanner(System.in);
        int N = in.nextInt();
        int T = in.nextInt();
        int res[] = new int[T+1];
        int ini,fin;
        for (int i = 0; i < N; i++) {
            ini=in.nextInt();
            fin=in.nextInt();
            for (int j = ini; j < fin; j++) {
                res[j]++;    
            }
        }
        int max=0;
        for (int i = 0; i < T; i++) {
            if(res[i]>max){
                max=res[i];
            }
        }
        System.out.println(max);
    }
    
}


Measured memory_bytes: 69888
#include <iostream>
#include <list>
#include <set>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <queue>

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

int main()
{
    long long n, m;
    long long ans = 0;
    vector<int> numList;
    cin >> n >> m;

    priority_queue<pair<int, int>> q;
    rep(i, n)
    {
        int a;
        cin >> a;
        q.push(make_pair(a, 1));
    }

    rep(i, m)
    {
        int b, c;
        cin >> b >> c;
        q.push(make_pair(c, b));
    }

    rep(i, n)
    {
        auto p = q.top();
        q.pop();
        ans += p.first;
        if (p.second > 1)
        {
            p.second--;
            q.push(p);
        }
    }
    cout << ans << endl;
}

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

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    h /= 12.0;
    h *= 2 * M_PI;
    m /= 60.0;
    m *= 2 * M_PI;
    h += m / 12.0;
    double theta = abs(h - m);
    double ans = sqrt(a * a + b * b - 2 * a * b * cos(theta));
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}

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

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    vector<ll> x(n);
    for(int i = 0; i < n; i++)cin >> x[i];

    ll l;
    cin >> l;

    ll q;
    cin >> q;

    vector<ll> a(q),b(q);
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
        if(a[i] > b[i])swap(a[i],b[i]);
    }

    vector<vector<ll>> db(n,vector<ll>(20,-1));

    for(int i = n-2; i >= 0; i--){
        auto itr = upper_bound(x.begin(),x.end(),x[i] + l);
        int idx = (int)(itr - x.begin()) - 1;
        db[i][0] = idx;
        bool flag = true;
        int bit = 1;
        while(flag){
            if(db[db[i][bit-1]][bit-1] >= 0){
                db[i][bit] = db[db[i][bit-1]][bit-1];
                bit++;
            }else{
                flag = false;
            }
        }
    }

    vector<ll> bin(20,1);
    for(int i = 1; i < 20; i++){
        bin[i] = bin[i-1]*2;
    }

    for(int i = 0; i < q; i++){
        int bit = 19;
        int s = a[i];
        ll ans = 0;
        while(bit >= 0){
            while(bit >= 0 && (db[s][bit] < 0 || db[s][bit] >= b[i])){
                bit--;
            }
            if(bit >= 0){
                s = db[s][bit];
                ans += bin[bit];
            }
        }
        cout << ans + 1 << endl;
    }

    /*for(int i = 0; i < n; i++){
        for(int j = 0; j < 20; j++){
            cout << db[i][j] << " ";
        }
        cout << endl;
    }*/
    
    
    return 0;
}

Measured memory_bytes: 22784
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define fs first
#define sc second
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
int main(){
  int n;
  cin>>n;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  int m; cin>>m;
  vector<string>t(m); rep(i,m)cin>>t[i];
  int ans=0;
  rep(i,n){
  int cnt=count(s.begin(),s.end(),s[i]);
  cnt-=count(t.begin(),t.end(),s[i]);
    ans=max(ans,cnt);
  }
  cout <<ans<<endl;
}

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

long long cake[3][1000];
long long lim[3],k;
bool f[1000][1000][1000];
struct cakeSet{
  long long a,b,c;
  cakeSet(long long x,long long y,long long z){
	a=x;
	b=y;
	c=z;
  }
  cakeSet(){};
};

multimap<long long,cakeSet> nextCake;

int main(){
  for(long long i=0;i<3;++i)cin>>lim[i];
  cin>>k;
  for(long long i=0;i<3;++i)
	for(long long j=0;j<lim[i];++j)
	  cin>>cake[i][j];
  for(long long i=0;i<3;++i)
	sort(cake[i],cake[i]+lim[i],greater<long long>());

  nextCake.insert(pair<long long, cakeSet>(cake[0][0]+cake[1][0]+cake[2][0],cakeSet(0,0,0)));
  f[0][0][0]=true;

  for(long long i=0;i<k;++i){
	long long  key=nextCake.rbegin()->first;
	cakeSet value=nextCake.rbegin()->second;
	cout<<key<<endl;

	auto it = nextCake.end();
	it--;

	nextCake.erase(it);//nextCake.rbegin());

	if(lim[0]>value.a+1&&!f[value.a+1][value.b][value.c]){
	  nextCake.insert(pair<long long, cakeSet>(key-cake[0][value.a]+cake[0][value.a+1],cakeSet(value.a+1,value.b,value.c)));
	  f[value.a+1][value.b][value.c]=true;
	}
					  
	if(lim[1]>value.b+1&&!f[value.a][value.b+1][value.c]){
	  nextCake.insert(pair<long long, cakeSet>(key-cake[1][value.b]+cake[1][value.b+1],cakeSet(value.a,value.b+1,value.c)));
	  f[value.a][value.b+1][value.c]=true;
	}

	if(lim[2]>value.c+1&&!f[value.a][value.b][value.c+1]){	  
	  nextCake.insert(pair<long long, cakeSet>(key-cake[2][value.c]+cake[2][value.c+1],cakeSet(value.a,value.b,value.c+1)));
	  f[value.a][value.b][value.c+1]=true;
	}
   
  }

  return 0;
  
}

Measured memory_bytes: 973568
open Batteries

let id x = x

(* 整数を各桁ごとに分解する
 * 下位桁が先頭で，上位桁が末尾
 *)
let decompose n =
  let rec f n l = if n = 0 then l else f (n / 10) (n mod 10 :: l) in
  List.rev (f n [])

let reconstruct l = List.fold_left (fun n m -> n * 10 + m) 0 (List.rev l)

let sum l = List.fold_left (+) 0 l

let digit_sum n = sum (decompose n)

let rec expt ( * ) e a n =  
  if n = 0 then
    e
  else if n land 1 = 1 then
    a * expt ( * ) e (a * a) (n / 2)
  else
    expt ( * ) e (a * a) (n / 2)

(* n / S(n) <= m / S(m) かどうか *)
let pred n m = n * digit_sum m <= m * digit_sum n

let is_snuke_number n =
  (* リスト内で最も左にある 9 未満の整数に 1 を加える．
   * 存在しない場合は末尾に 1 を付け加える．
   *)
  let rec f l = match l with
      [] -> [1]
    | x :: l -> if x < 9 then (x + 1) :: l else x :: f l in
  let rec loop l =
    if List.for_all (fun n -> n = 9) l then
      pred n (reconstruct l)
    else
      pred n (reconstruct l) && loop (f l) in
  loop (decompose n)

(* n 桁のsnuke数 *)
let snuke_numbers n =
  if n < 4 then
    (1 --^ 1000)
    |> Enum.filter (fun m -> expt ( * ) 1 10 (n - 1) <= m && m < expt ( * ) 1 10 n)
    |> Enum.filter is_snuke_number
    |> List.of_enum
  else
    (1000 --^ 10000)
    |> Enum.map (fun m -> (m + 1) * expt ( * ) 1 10 (n - 4) - 1)
    |> Enum.filter is_snuke_number
    |> List.of_enum

let snuke_numbers =
  (1 -- 15)
  |> Enum.map snuke_numbers
  |> List.of_enum
  |> List.fold_left (@) []
  |> List.sort compare
  |> Array.of_list

let () =
  let k = Scanf.scanf "%d" id in
  for i = 0 to k - 1 do
    Printf.printf "%d\n" snuke_numbers.(i)
  done

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
ll fact[2005];
    ll invfact[2005];
ll ncr(ll n,ll r)
{
    if(n<0)
        return 0;
    if(n<r)
        return 0;
    if(n==r)
        return 1;
    ll ans=fact[n];
    ans*=invfact[r];
    ans%=hell;
    ans*=invfact[n-r];
    ans%=hell;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i;
    cin>>n;
    vector<pair<ll,ll> >v;
    for(i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        v.pb({x,y});
    }
    vector<ll> v1,v2;
    for(i=0;i<n;i++)
        v1.pb(v[i].F+v[i].S);
    for(i=0;i<n;i++)
        v2.pb(v[i].F-v[i].S);
    ll ans=0;
    ll max_b1=v1[0];
    ll max_b2=v2[0];
    ll min_b1=v1[0];
    ll min_b2=v2[0];
    for(i=0;i<n;i++)
    {
        max_b1=max(max_b1,v1[i]);
        min_b1=min(min_b1,v1[i]);

        max_b2=max(max_b2,v2[i]);
        min_b2=min(min_b2,v2[i]);
    }
    cout<<max(max_b1-min_b1,max_b2-min_b2);
    return 0;
}


Measured memory_bytes: 11656
import sys

class P(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __repr__(self):
        return 'P:{0:.3f} {1:.3f}'.format(self.x, self.y)

class Line(object):
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2
        self.epsilon = 1e-8

    def is_over(self, p):
        if abs(self.p2.x - self.p1.x) < self.epsilon:
            return self.p1.x > p.x
        elif abs(self.p2.y - self.p1.y) < self.epsilon:
            return self.p1.y > p.y
        else:
            a = (self.p2.y - self.p1.y) / (self.p2.x - self.p1.x)
            b = self.p1.y
            y = a * (p.x - self.p1.x) + b
            return y > p.y

def run():
    for i in sys.stdin:
        x1, y1, x2, y2, x3, y3, xp, yp = list(map(float, i.split()))
        p1, p2, p3, p = P(x1, y1), P(x2, y2), P(x3, y3), P(xp, yp)
        l_12 = Line(p1, p2)
        l_23 = Line(p2, p3)
        l_31 = Line(p3, p1)

        res = l_12.is_over(p3) == l_12.is_over(p)
        res &= l_23.is_over(p1) == l_23.is_over(p)
        res &= l_31.is_over(p2) == l_31.is_over(p)

        if res:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    run()




Measured memory_bytes: 5592
#include <iostream>
#include <stdio.h>
using namespace std;

struct Node {
	int left;
	int right;
	int parent;
	int depth;
	int height;
	int sibling;
	int degree;
};

int max(int a, int b) {
	return a < b ? b : a;
}

int depthHeight(Node* arr, int id, int d) {
	arr[id].depth = d;
	if ((arr[id].left != -1) && (arr[id].right != -1)) {
		arr[id].degree = 2;
		return arr[id].height = max(depthHeight(arr, arr[id].left, d + 1), depthHeight(arr, arr[id].right, d + 1)) + 1;
	}
	else if (arr[id].left != -1) {
		arr[id].degree = 1;
		return arr[id].height = depthHeight(arr, arr[id].left, d + 1) + 1;
	}
	else if (arr[id].right != -1) {
		arr[id].degree = 1;
		return (arr[id].height = depthHeight(arr, arr[id].right, d + 1) + 1);
	}
	else
		return arr[id].degree = arr[id].height = 0;
}

void print(Node* arr, int id) {
	printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
		, id, arr[id].parent, arr[id].sibling, arr[id].degree, arr[id].depth, arr[id].height);
	if (arr[id].parent == -1)
		cout << "root\n";
	else if (arr[id].height == 0)
		cout << "leaf\n";
	else
		cout << "internal node\n";
}

int main() {
	int len;
	cin >> len;
	Node* arr = new Node[len];

	//set all the fields to -1 (in order to represent the root and the leaf of the tree)
	for (int i = 0; i < len; i++)
		arr[i].parent = arr[i].left = arr[i].right = arr[i].sibling = -1;

	int id;
	for (int i = 0; i < len; i++) {
		cin >> id;
		cin >> arr[id].left >> arr[id].right;
		arr[arr[id].left].parent = arr[arr[id].right].parent = id;
		arr[arr[id].left].sibling = arr[id].right;
		arr[arr[id].right].sibling = arr[id].left;
	}

	int r;
	for (r = 0; arr[r].parent != -1; r = arr[r].parent);
	arr[r].height = depthHeight(arr, r, 0);

	for (int i = 0; i < len; i++)
		print(arr, i);
	//delete[] arr;
	return 0;
}


Measured memory_bytes: 3220
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define for1(i, n) for (int i = 1; i <= n; ++i)
#define for0(i, n) for (int i = 0; i < n; ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()

#define next qwerty1
#define left qwerty2
#define right qwerty3
#define y1 qwerty4
#define y0 qwerty5

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;







int main() {
	ios::sync_with_stdio(false);
	cout.tie(nullptr);
	cin.tie(nullptr);
	int n;
	cin >> n;
	map<string, ll> cnt;
	ll ans = 0;
	for0 (i, n) {
		string s;
		cin >> s;
		sort(all(s));
		cnt[s]++;
	}
	for (auto& el : cnt) {
		ans += el.second * 1LL * (el.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<cmath>
#include<string>
#include<cstdio>
using namespace std;

class Dice{
public:
	int f[6];

	Dice (){}
	
	void move(char x){
		int c=0;
		if (x=='E'){
			c=f[5], f[5]=f[2], f[2]=f[0], f[0]=f[3], f[3]=c;
		}	
		if (x=='W'){
			c=f[3], f[3]=f[0], f[0]=f[2], f[2]=f[5], f[5]=c;
		}
		if (x=='S'){
			c=f[5], f[5]=f[1], f[1]=f[0], f[0]=f[4], f[4]=c;
		}		
		if (x=='N'){
			c=f[5], f[5]=f[4], f[4]=f[0], f[0]=f[1], f[1]=c;
		}			
	}


};

int main(){
	Dice d;
	
	for (int k=0; k<6; k++){
		cin >> d.f[k];
	}
	
	string DD;
	cin >> DD;
	
	for (int n=0; n<DD.size(); n++){
		d.move(DD[n]);
	}
	
	cout << d.f[0] << endl;
	
	return 0;
}

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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a == c-b){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
#define min(q,w) ((q)>(w)?(w):(q))
#define max(q,w) ((q)<(w)?(w):(q))
#define PR(...) printf(__VA_ARGS__)
#define EPR(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long LL;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n;
int ans;
int R,G,B;
int main()
{
	int q,w;
	read(R),read(G),read(B),read(n);
	q=n/R,w=n/G;
	fo(i,0,q)fo(j,0,w)if((n-i*R-j*G)>=0&&(n-i*R-j*G)%B==0)++ans;//printf("%d %d\n",i,j );;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int n;
    cin>>n;
    int arr[n]{};
    for(int i = 0 ; i<n; i++)cin>>arr[i];
    int cnt = 0;
    int currMax = arr[0];
    int currMin = arr[0];
    for(int i = 0 ; i<n ; i++)
    {
        if(arr[i]<=currMin)cnt++;
        currMin = min(arr[i] , currMin);
    }
    cout<<cnt<<endl;
    return 0;
}


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

#define int long long 

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

/*
symbol : !"#$%&'()*+,-./
digit : 0~9
symbol2 : :;<=>?@
upper : A~Z
symbol3 : [\]^_`
lower : a~z	
synbol4 : {|}~
*/
struct AhoCorasick{
	//  c \in [OFF,OFF+LEN)
	static const int OFF=(int)('a');
	static const int SUP=(int)('z');
	static const int LEN=SUP-OFF+1;
	struct Node{
		int nex[LEN];
		int failink;
		vector<int>suflist;
		Node():failink(0){memset(nex,-1,sizeof(nex));}
	};
	vector<Node>nds;

	AhoCorasick():nds(1){}

	int process(int k,int c){
		c-=OFF;
		while(nds[k].nex[c]==-1)k=nds[k].failink;
		return nds[k].nex[c];
	}

	void add(const string &s,int id){
		int k=0;
		for(auto c:s){
			c-=OFF;
			if(nds[k].nex[c]==-1){
				nds[k].nex[c]=nds.size();
				nds.emplace_back();
			}
			k=nds[k].nex[c];
		}
		nds[k].suflist.push_back(id);
	}

	void build(){
		queue<int>que;
		for(int i=0;i<LEN;i++){
			if(nds[0].nex[i]==-1)nds[0].nex[i]=0;
			else que.push(nds[0].nex[i]);
		}
		while(que.size()){
			int k=que.front();
			que.pop();
			for(int i=0;i<LEN;i++){
				if(nds[k].nex[i]==-1)continue;
				int nx=nds[k].nex[i];
				nds[nx].failink=process(nds[k].failink,i+OFF);

				vector<int>&curlist=nds[nds[nx].failink].suflist;
				vector<int>&nexlist=nds[nx].suflist;

				nexlist.insert(nexlist.end(),curlist.begin(),curlist.end());
				que.push(nx);
			}
		}
	}
};


signed main(){
	string S;cin>>S;
	int N;cin>>N;
	AhoCorasick ac;
	rep(i,N){
		string s;cin>>s;
		ac.add(s,i);
	}

	ac.build();

	int ans=0;
	int k=0;
	for(auto c:S){
		k=ac.process(k,c);
		if(ac.nds[k].suflist.size()){
			ans++;
			k=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 33912
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s; cin >> s;
    long long n = s.size();
    vector<long long> v(26, 0);
    for (int i = 0; i < n; i++) {
        v[s[i]-'a']++;
    }
    long long ans = n * (n-1) / 2;
    for (int i = 0; i < 26; i++) {
        ans -= v[i] * (v[i]-1) / 2;
    }
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int unused __attribute__((unused));
  int A[3], cnt5 = 0, cnt7 = 0, i;

  unused = scanf("%d %d %d", &A[0], &A[1], &A[2]);

  for(i=0; i<3; i++){
    if(A[i]==5) cnt5++;
    else if(A[i]==7) cnt7++;
  }
  if(cnt5==2 && cnt7==1) printf("YES");
  else printf("NO");
  return 0;
}

Measured memory_bytes: 128
import sys
input = lambda:sys.stdin.readline().strip()
n = int(input())
a = list(map(int,input().split()))
b = [0]*n
ans = 0
for i in range(n):
    if i+a[i]<n:
        b[i+a[i]]+=1
    if i-a[i]>=0:
        ans+=b[i-a[i]]
print(ans)
        
         

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

int main(void)
{
	int a, b, k,lnk[2000],count = 0;
	
	cin >> a >> b >> k;
	for (int i = 1; i <= min(a, b); i++)
	{
		if (a % i == 0 && b % i == 0)
		{
			lnk[count] = i;
			count++;
		}
	}
	cout << lnk[count - k] << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
int t[26];
#define DIV 4
ll dp[10001];
int main(void) {
	int n, k, ans = 0;
	string s;
	cin >> n >> k >> s;
	rep(i, 1, n) {
		if (s[i - 1] != s[i])ans++;
	}
	printf("%d\n", min(n - 1 - ans + 2 * k, n - 1));
	return 0;
}

Measured memory_bytes: 512
A, B, C = input().split()
result = max(
    int(A + B) + int(C),
    int(B + A) + int(C),
    int(A + C) + int(B),
    int(C + A) + int(B),
    int(B + C) + int(A),
    int(C + B) + int(A)
)
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
const int MAXN=200005;
int n,q;
vector<int> a[MAXN];
int cnt[MAXN];
int ans[MAXN];
void dfs(int p,int fa,int add){
	add+=cnt[p];
	ans[p]=add;
	for (int i=0;i<a[p].size();i++){
		int v=a[p][i];
		if (v!=fa)
			dfs(v,p,add);
	}
}

signed main()

{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	for (int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
		a[x].push_back(y);
		a[y].push_back(x);
	}

	for (int i=1;i<=q;i++){
		int x,c;
		cin>>x>>c;
		cnt[x]+=c;
	}

	dfs(1,0,0);
	for (int i=1;i<=n;i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 27136
#include <iostream>
#include <utility>
#include <vector>

int main()
{
    int h, w;
    std::cin >> h >> w;
    std::vector<std::pair<int, int> > answers;
    int moved_top = 0;

    for (int i = 0; i < h; i++) {
        int moved_left = 0;
        for (int j = 0; j < w; j++) {
            int a;
            std::cin >> a;

            if (i == h - 1 && j == w - 1) continue;

            // 上からの動きを足す
            if (j == w - 1) a += moved_top;

            a %= 2;

            // 左から動きがなく今も偶数だったら動かない
            // 左から動きがありで今が奇数だったら動かさない
            if ((a == 0 && moved_left == 0) ||(a == 1 && moved_left == 1)) {
                if (j == w - 1) moved_top = 0;
                else moved_left = 0;
                continue;
            }

            // 左から動きがあり今が偶数だったら動かす
            // 左から動きがなく今が奇数だったら動かす
            if ((a == 1 && moved_left == 0) || (a == 0 && moved_left == 1)) {
                if (j == w - 1) moved_top = 1;
                else moved_left = 1;

                answers.push_back(std::make_pair(i, j));
            }
        }
    }

    std::cout << answers.size() << std::endl;

    for (int i = 0; i < answers.size(); i++) {
        auto ans = answers[i];
        if (ans.second == w - 1) {
            std::cout << ans.first+1 << " " << ans.second+1 << " " << ans.first+2 << " " << ans.second+1 << std::endl;
        } else {
            std::cout << ans.first+1 << " " << ans.second+1 << " " << ans.first+1 << " " << ans.second+2 << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3188
<?php
  
  list($n, $m, $k) = explode(" ", trim(fgets(STDIN)));

  $uf = new UnionFind($n);

  $friends = [];
  $block = [];

  for($i=1; $i<=$n; $i++){
    $friends[$i] = 0;
    $block[$i] = 0;
  }
  for($i=0; $i<$m; $i++){
    list($x, $y) = explode(" ", trim(fgets(STDIN)));
    $uf->unite($x, $y);
    $friends[$x]++;
    $friends[$y]++;
  }

  for($i=0; $i<$k; $i++){
    list($x, $y) = explode(" ", trim(fgets(STDIN)));
    if($uf->isSame($x, $y)){
      $block[$x]++;
      $block[$y]++;
    }
  }
  for($i=1; $i<=$n; $i++){
    echo $uf->size($i)-1-$friends[$i]-$block[$i];
    //echo $uf->size($i);
    if($i!=$n){
      echo " ";
    }
  }

  class UnionFind {
    public $d = [];
    function __construct($n){
      for($i=1;$i<=$n;$i++){
        $this->d[$i] = -1;
      }
    }
    function unite($x, $y){
      $rx = $this->root($x);
      $ry = $this->root($y);
      if($rx == $ry) return;
      //echo $rx." ".$ry." ";
      if($this->size($rx) > $this->size($ry)){
        $this->d[$rx]+= $this->d[$ry];
        $this->d[$ry] = $rx;
        //echo $this->d[$rx].PHP_EOL;
      }else{
        $this->d[$ry]+= $this->d[$rx];
        $this->d[$rx] = $ry;        
        //echo $this->d[$ry].PHP_EOL;
      }
    }
    function root($x){
      //echo $x.PHP_EOL;
      if($this->d[$x] < 0){
        return $x;
      }
      return $this->d[$x] = $this->root($this->d[$x]);
    }
    function size($x){
      return $this->d[$this->root($x)]*-1;
    }
    function isSame($x, $y){
      return $this->root($x) == $this->root($y);        
    }
  }

Measured memory_bytes: 18932