akhauriyash/Code-Regression huggingface dataset:
// Binary Search Tree III
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, nil;

// 木から key の値を持つノードを探す //
Node treeSearch(Node x, int k){
  if(x == nil || k == x->key) return x;
  if(k < x->key) treeSearch(x->left, k);
  else treeSearch(x->right, k);
}

// ノード x から最小の key を探す //
Node treeMinimum(Node x){
  while(x->left != nil)x = x->left;
  return x;
}

// ノード x から最大の key を探す //
Node treeMaximum(Node x){
  while(x->right != nil)x = x->right;
  return x;
}

//  二分探索木へkを挿入 //
void insert(int k){
  Node y = nil; // x の親
  Node x = root; // T の根
  Node z;
  
  //z->parent = y;
  z = (Node)malloc(sizeof(struct node));
  z->key = k;
  z->left = nil;
  z->right = nil;

  while(x != nil){
    y = x;   // 親を設定
    if(z->key < x->key)x = x->left; // 左の子へ移動
    else x = x->right;            // 右の子へ移動
  }
  z->parent = y;

  if(y == nil)root = z; // T が空の場合
  else if(z->key < y->key)y->left = z; // z を y の左の子にする
  else y->right = z; // z を y の右の子にする
}

// 再帰を使って中間順巡回(Inorder)で表示
void printInorder(Node u){
  if(u == nil)return;
  printInorder(u->left);
  printf(" %d", u->key);
  printInorder(u->right);
}

// 再帰を使って先行順巡回(Preorder)で表示
void printPreorder(Node u){
  if(u == nil)return;
  printf(" %d", u->key);
  printPreorder(u->left);
  printPreorder(u->right);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != nil) return treeMinimum(x->right);
  
  y = x->parent;
  while(y != nil && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == nil || z->right == nil) y = z;
  else y = treeSuccessor(z);
  if(y->left != nil) x = y->left;
  else x = y->right;
  if(x != nil) x->parent = y->parent;
  if(y == nil) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  if(y != z) z->key = y->key;
}

int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != nil ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      printInorder(root);
      printf("\n");
      printPreorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20428
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>

const int MAXN = 5e5 + 5;

char s[MAXN << 2], t[MAXN];
int lenS, lenT, copyLenS, copyLenT, ans;
int next[MAXN], sum;
int entry[MAXN], res[MAXN], dp[MAXN];
bool find[MAXN << 2];

std::vector<int> con[MAXN];
std::queue<int> q;

void init() {
    int place = 0;
    next[1] = 0;
    for (int i = 2; i <= lenT; ++i) {
        while (place && t[i] != t[place + 1]) {
            place = next[place];
        }
        if (t[i] == t[place + 1])
            ++place;
        next[i] = place;
    }
}

void kmp() {
    init();
    int place = 0;
    for (int i = 1; i <= lenS; ++i) {
        while(place && s[i] != t[place + 1]) {
            place = next[place];
        }
        if (s[i] == t[place + 1])
            ++place;
        if (place == lenT && i - lenT + 1 <= copyLenS) {
            find[i - lenT + 1] = true;
            place = next[place];
            ++sum;
        }
    }
}

void ins(int start,int end) {
    con[start].push_back(end);
    ++entry[end];
}

bool topSort() {
    int cnt = 0;
    for (int i = 1; i <= copyLenS; ++i) {
        if (find[i] && entry[i] == 0)
            q.push(i);
    }
    while (!q.empty()) {
        int cur = q.front();
        res[++cnt] = cur;
        for (int i = 0; i < con[cur].size(); ++i) {
            if (--entry[con[cur][i]] == 0)
                q.push(con[cur][i]);
        }
        q.pop();
    }
    return cnt == sum;
}

int main() {
    scanf("%s%s", s + 1, t + 1);
    copyLenS = lenS = strlen(s + 1);
    copyLenT = lenT = strlen(t + 1);
    while (copyLenT > 0) {
        for (int i = 1; i <= copyLenS; ++i) {
            s[++lenS] = s[i];
        }
        copyLenT -= copyLenS;
    }
    kmp();
    /*for (int i = 1; i <= lenS; ++i) {
        printf("%c", s[i]);
    }
    printf("\n");
    for (int i = 1; i <= lenT; ++i) {
        printf("%c", t[i]);
    }
    printf("\n");
    for (int i = 1; i <= lenT; ++i) {
        printf("%d ", next[i]);
    }
    printf("\n");
    printf("%d\n", sum);*/
    //printf("%d\n", sum);
    for (int i = 1; i <= copyLenS; ++i) {
        int k = ((i + lenT) % copyLenS == 0) ? copyLenS : ((i + lenT) % copyLenS);
        if (find[i] && find[k])
            ins(i, k);
    }
    /*for (int i = 1; i <= copyLenS; ++i) {
        printf("cur: %d | ", i);
        for (int j = 0; j < con[i].size(); ++j) {
            printf("%d ",con[i][j]);
        }
        printf("\n");
    }*/
    if (topSort()) {
        for (int k = 1; k <= sum; ++k) {
            int i = res[k];
            if (dp[i] == 0)
                dp[i] = 1;
            for (int j = 0; j < con[i].size(); ++j) {
                dp[con[i][j]] = std::max(dp[con[i][j]], dp[i] + 1);
            }
        }
        for (int i = 1; i <= sum; ++i) {
            //printf("%d ", dp[res[i]]);
            ans = std::max(ans, dp[res[i]]);
        }
    }
    else
        ans = -1;
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 38784
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


string s;
ll cnt[33];
ll n;
int main()
{
        cin >> s;
        n = s.length();
        ll yo = (n + 2)/3;
        for(ll i=0;i<n;i++) {
                cnt[s[i] - 'a']++;
                if(cnt[s[i]-'a'] > yo) {
                        cout << "NO\n"; return 0;
                }
        }
        cout << "YES\n";
        return 0;
}


Measured memory_bytes: 512
import itertools

N = int(input())
L = []

for i in range(N):
    x,y = map(int,input().split())
    L.append([x,y])

cnt = 0
total = 0
for v in itertools.permutations(L):
    for i in range(N-1):
        x_1 = v[i][0]
        y_1 = v[i][1]
        x_2 = v[i+1][0]
        y_2 = v[i+1][1]
        total += ((x_2 - x_1) ** 2 + (y_2 - y_1) ** 2) ** 0.5
    cnt += 1

print(total/cnt)

Measured memory_bytes: 9424
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
   string S;
   cin >> S;
   int N = S.length();
   int sum = 0;
   for(int i=0;i<N;i++){
     if(S[i]=='0') sum -= 1;
     else sum += 1;
   }

   cout << N - abs(sum) <<endl;

    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int w,h;
ll p[100005],q[100005];

int main(void){
	scanf("%d%d",&w,&h);
	for(int i=0;i<w;i++){
		scanf("%lld",&p[i]);
	}
	for(int i=0;i<h;i++){
		scanf("%lld",&q[i]);
	}
	sort(p,p+w);
	sort(q,q+h);
	ll res=0;
	int nw=0,nh=0;
	while(nw<w || nh<h){
		if(nw<w && (nh==h || p[nw]<q[nh])){
			res+=p[nw]*(ll)(h+1LL-nh);
			nw++;
		}else{
			res+=q[nh]*(ll)(w+1LL-nw);
			nh++;
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 1920
MAX = 1000000

hamming_list = [False] * (MAX + 1)

hamming_list[0] = False
hamming_list[1] = True

for index in range(2, MAX + 1):

    if index / 2 % 1 == 0:
        if hamming_list[index // 2]:
            hamming_list[index] = True
    elif index / 3 % 1 == 0:
        if hamming_list[index // 3]:
            hamming_list[index] = True
    elif index / 5 % 1 == 0:
        if hamming_list[index // 5]:
            hamming_list[index] = True

while True:

    input_data = input()

    if input_data == "0":
        break

    start, end = [int(item) for item in input_data.split(" ")]

    count = sum(hamming_list[start:end + 1])
    print(count)



Measured memory_bytes: 21216
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def tami(a,b,i):
  num = (a*i)//b - a*(i//b)
  return num

a,b,N = IL()

l = [0,b-1,N,(N//b)*b-1]
ans = 0
for i in l:
  if 0 <= i <= N:
    ans = max(ans, tami(a,b,i))
print(ans)

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

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A!=B && A!=C && B!=C)cout << "No";
    else {
        if(A==B && A==C){
            cout << "No";
        }
        else cout <<  "Yes";
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main() {
    int x, y;
    cin >> x >> y;
    for(int i=x*2; i<=x*4; i+=2){
        if(i == y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#define foor for(int i=0;i<n;i++)
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define ic int a;cin>>a;
#define ic2 ic int b;cin>>b;
int s = 0;
using namespace std;
int main() {
	ic2
		if (a >= 10) cout << b << endl;
		else cout << b + 100 * (10 - a) << endl;
}

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

template <class T>
inline bool read(T &ret)
{
    char c;
    int sgn;
    if (c = getchar(), c == EOF)
    {
        return 0;
    }
    while (c != '-' && (c < '0' || c > '9'))
    {
        c = getchar();
    }
    sgn = (c == '-') ? -1 : 1;
    ret = (c == '-') ? 0 : (c - '0');
    while (c = getchar(), c >= '0' && c <= '9')
    {
        ret = ret * 10 + (c - '0');
    }
    ret *= sgn;
    return 1;
}

template <class T>
inline void write(T x)
{
    if (x > 9)
    {
        write(x / 10);
    }
    putchar(x % 10 + '0');
}

long long n;

int main()
{
    cin>>n;
    n--;
    cout<<(1+n)*(n)/2<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;
#define max(a, b) ((a) > (b) ? (a) : (b))



int main(void){
	int n;
	cin >> n;
	int a[n+1][n-1];
	rep(i,n){
		rep(j,n-1){
			cin >> a[i+1][j];
		}
	}
	int idx[n+1];
	rep(i,n)idx[i+1] = 0;
	vector<int> work(n+1,0);
	bool flag = true;
	int day = -1;
	while(flag){
		day++;
		//cout << "day:" << day << endl;
		flag = false;
		for(int i=1;i<=n;i++){
			if(idx[i] == n-1) continue;
			int dist = a[i][idx[i]];
			if(a[dist][idx[dist]] == i){
				flag = true;
				work[i] = 1;
				work[dist] = 1;
				//cout << i << "vs" << dist << endl;
			}
		}
		rep(i,n){
			idx[i+1] += work[i+1];
			work[i+1] = 0;
			//cout << idx[i+1] << " ";
		}
		//cout << endl;

	}

	flag = true;
	rep(i,n){
		if(idx[i+1] != n-1)flag = false;
	}

	if(flag)cout << day << endl;
	else cout << -1 << endl;



	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    ll a, b, k;
    cin >> a >> b >> k;
    if(a >= k){
        cout << a - k << " " << b << endl;
        return 0;
    }
    if(a + b >= k){
        cout << "0 " << a + b - k << endl;
        return 0;
    }
    cout << "0 0" << endl;

    return 0;
}


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

double sabs(double a, double b){
  double sub = max(a,b)-min(a,b);
  return sub;
}

int main() {
  int n,t; double a; cin >>n >>t >>a;
  double buf;
  double minsub = 9999;
  int ans;
  
  for (int i=1; i<n+1; i++){
    cin >>buf;
    buf = t - buf*0.006;
    if (sabs(buf,a)<minsub){
      ans = i; minsub = sabs(buf,a);}
  }
  
  cout <<ans;
  cout <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
double dp[3001][3001];

int main()
{
   int n;
   string s;
   cin>>n;
   cin>>s;
   int i=0,j=n-1,cnt=0;
   while(i<j){
      if(s[j]=='R'){
        if(s[i]=='W'){
            swap(s[i],s[j]);
            i++;
            j--;
            cnt++;
        }
        else{
            i++;
        }
      }
      else
        j--;
   }
   for(int i=1; i<n; i++)
    if(s[i]=='R' && s[i-1]=='W')
        cnt++;

   cout<<cnt<<endl;
   return 0;

}


Measured memory_bytes: 3724
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	sort.Ints(aa)

	l := 0
	r := n
	for l < r {
		m := (l + r) >> 1
		if aa[m] > (aa[n-1] >> 1) {
			r = m
			continue
		}
		l = m + 1
	}

	if n-1 > l && aa[l-1] < aa[n-1]-aa[l] {
		fmt.Fprintf(writer, "%d %d", aa[n-1], aa[l])
	} else {
		fmt.Fprintf(writer, "%d %d", aa[n-1], aa[l-1])
	}
	fmt.Fprintln(writer, "")

	writer.Flush()
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e2 + 9, M = 1e5 + 5, oo = 0x3f3f3f3f;
ll mem[N][M];
ll n, W, wei[N], cost[N];
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cin>>n>>W;
   for(int i = 0; i < n; i++)
   {
      cin>>wei[i]>>cost[i];
   } 
   for(int i = 1; i <= n; i++)
   {
      for(int w = 1; w <= W; w++)
      {
         mem[i][w] = mem[i - 1][w];
         if(wei[i - 1] <= w)
         {
            mem[i][w] = max(mem[i][w], cost[i - 1] + mem[i - 1][w - wei[i - 1]]);
         }
      }
   }
   cout<<mem[n][W]<<endl;
   return 0;
}

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

int main() {
    string s;
    int ans = 0;
    cin >> s;
    for (unsigned int i = 0; i < 8; i++){
        bitset<3> op(i);
        ans = s[0] - '0';
        //cout << op[0] << op[1] << op[2] << '\n';
        if(op[0]){
            ans += s[1] - '0';
        }else{
            ans -= s[1] - '0';
        }
        if(op[1]){
            ans += s[2] - '0';
        }else{
            ans -= s[2] - '0';
        }
        if(op[2]){
            ans += s[3] - '0';
        }else{
            ans -= s[3] - '0';
        }
        if(ans == 7){
            vector<char> ope(3);
            ope[0] = 45 - 2 * op[0];
            ope[1] = 45 - 2 * op[1];
            ope[2] = 45 - 2 * op[2];
            cout << s[0] << ope[0] << s[1] << ope[1] << s[2] << ope[2] << s[3] << "=7";
            break;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N,Q,a;
set<int> t;
int ans[500];

int main(){
  scanf("%d %d",&N,&Q);
  for(int i=0;i<N;i++){
    scanf("%d",&a);
    t.insert(-a);
    for(int j=1;j<500;j++)ans[j]=max(ans[j],a%j);    
  }
  for(int i=0;i<Q;i++){
    scanf("%d",&a);
    if(a<500){
      printf("%d\n",ans[a]);
    }else{
      int maxm=0;
      for(int j=a;j<=300000;j+=a){
        int k= -(*t.upper_bound(-j));
        maxm=max(maxm, k%a);
      }
      printf("%d\n",maxm);
    }
    
  }
  return 0;
}

Measured memory_bytes: 15248
#include <bits/stdc++.h>
#define ll long long
#define PI 2 * acos(0)
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MAX 300000
#define debug cout << "asfasf" << endl;
#define READ freopen("input.txt", "r", stdin)
#define PRINT freopen("output.txt", "w", stdout);
#define MOD 1e7
#define print(a, b) printf("Case %d: %d\n", a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
/*................OMI.................*/

bool isPrime(ll n)
{
   if (n <= 1)
      return false;
   if (n <= 3)
      return true;

   if (n % 2 == 0 || n % 3 == 0)
      return false;

   for (ll i = 5; i * i <= n; i = i + 2)
      if (n % i == 0)
         return false;

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

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

///palindrome check!
bool palindrome(string s)
{
   for (ll i = 0; i < s.length() / 2; i++)
   {
      if (s[i] != s[s.length() - i - 1])
         return 0;
   }
   return 1;
}
/// divisors->>
void printDivisors(int n)
{
   for (int i = 1; i <= sqrt(n); i++)
   {
      if (n % i == 0)
      {
         if (n / i == i)
            printf("%d ", i);

         else
            printf("%d %d ", i, n / i);
      }
   }
}
/// string to INT
int convert_number(string s)
{
   int n;
   stringstream(s) >> n;
   return n;

   // int v=atoi(ss.c_str());
   // atoi is better than this function in case of complexity
}

///prime storage>>>

vector<ll> prime;

void primes(ll m)
{

   bool isprime[m];
   for (int i = 0; i <= m; i++)
      isprime[i] = true;

   for (int i = 3; i * i <= m; i++)
   {
      if (isprime[i])
      {

         for (int j = i * i; j <= m; j += i)
            isprime[j] = false;
      }
   }
   prime.push_back(2);
   for (int i = 3; i <= m; i += 2)
      if (isprime[i])
         prime.push_back(i);
}

/************MAIN_FUNCTION***********/

int main(int argc, char *argv[])
{
   FAST;

   int N;
   cin >> N;
   cout << (1000 - (N % 1000))%1000 << endl;

   return 0;
}

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    for (auto& e : c) cin >> e;

    i64 ans = 0;
    for (i64 selh = 0; selh < (1 << h); selh++) {
        for (i64 selw = 0; selw < (1 << w); selw++) {
            i64 cnt = 0;
            for (i64 i = 0; i < h; i++) {
                for (i64 j = 0; j < w; j++) {
                    if (((selh >> i) & 1) || ((selw >> j) & 1)) continue;
                    if (c[i][j] == '#') cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int count = 0;

    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                if (i * 500 + j * 100 + k * 50 == X) count++;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve()
{
    ll N,i,j,k,r=0;
    cin>>N;
    ll L[N];
    for(i=0;i<N;i++) cin>>L[i];
    for(i=0;i<N-2;i++){
        for(j=i+1;j<N-1;j++){
            for(k=j+1;k<N;k++){
                if(L[i]!=L[j]&&L[j]!=L[k]&&L[k]!=L[i]){
                    if(L[i]+L[j]>L[k]&&L[j]+L[k]>L[i]&&L[k]+L[i]>L[j]) r++;
                }
            }
        }
    }
    cout<<r<<endl;
    return;
}
int main()
{
    solve();
}

Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main() {
    int N; cin >> N;
    for (int i = max(2, N); i <= 10e9; i += max(2, N)) {
        if (i % N == 0 && i % 2 == 0) {
            printf("%d\n", i); break;
        }
    }
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<vector<int> >  vec2int;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  ll n, a, b; cin >> n >> a >> b;
  vecll x(n,0);
  REP(i,n)cin >> x[i];
  ll ans = 0;
  REP(i,n - 1){
    ans += min(a*(x[i + 1] - x[i]), b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_3D
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] inString = Console.ReadLine().Split(' ');
            int intA = int.Parse(inString[0]);
            int intB = int.Parse(inString[1]);
            int intC = int.Parse(inString[2]);
            int count = 0;
            
            for(int i = intA; i <= intB; i++)
            {
                if (intC % i == 0) count++;
            }

            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 9208
import numpy as np
K,N = list(map(int,input().split()))
arr = np.array(list(map(int,input().split())))
arr = arr.cumsum()
_sum = 0
for i in range(len(arr)-N+1):
  if i==0:
    tmp = arr[N-1]
  else:
    tmp = arr[N+i-1]-arr[i-1]
  _sum = max(_sum,tmp)

print((_sum+N)/2)


Measured memory_bytes: 33904
H, W = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])

ans = 0
for i in range(H):
    for j in range(W):
        if wall[i][j] != -1:
            ans += cost[wall[i][j]][1]

print(ans)


Measured memory_bytes: 3444
#include<cstdio>
#include<map>
#include<algorithm>
#define MAXN 100006
using namespace std;
map<int,int> ma;
int a[MAXN],b[MAXN],n,now,ans,sum[MAXN],cnt,tot,fa[MAXN];
int root(int x)
{
	if(x!=fa[x]) fa[x]=root(fa[x]);
	return fa[x];
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]);
	for(int i=1;i<=n;i++)
		now^=a[i];
	ma[now]++;
	for(int i=1;i<=n;i++)
	{
		if(b[i]==now&&a[i]!=now) tot++;
		ma[a[i]]++;
		ma[b[i]]--;
		if(a[i]!=b[i]) ans++;
	}
	int ok=-1;
	for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++)
	{
		if(it->second)
		{
			if(ok!=-1)
			{
				printf("-1");
				return 0;
			}
			ok=it->first;
		}
	}
	if(ans&&tot) ans--;
	for(map<int,int>::iterator it=ma.begin();it!=ma.end();it++)
		it->second=++cnt;
	for(int i=1;i<=cnt;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=b[i])
		{
			fa[root(ma[a[i]])]=root(ma[b[i]]);
		}
	}
	for(int i=1;i<=cnt;i++)
		sum[root(i)]++;
	for(int i=1;i<=cnt;i++)
		if(sum[i]>1) ans++;
	printf("%d",ans);
}

Measured memory_bytes: 7680
//Inshallah , Boys played well..!!

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pb push_back
#define pf push_front
#define mk make_pair
#define f(i,j,n) for(ll i=j;i<n;i++)
#define r(i,n,j) for(ll i=n-1;i>=j;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define Test int t;cin>>t;while(t--)
#define mod 1000000007
#define md 998244353
#define MIN INT_MIN
#define MAX INT_MAX
#define inf LLONG_MAX
#define all(container) container.begin() , container.end()
#define rall(container) container.rbegin() , container.rend()
#define sz(container) (int)container.size()
#define vll vector<long long>
#define vi vector<int>
#define pii pair <int , int>
#define pll pair <ll , ll>
#define fi first
#define se second
#define setp(x) setprecision(x)
#define meme(x,i) memset(x,i,sizeof(x))
const int N = 100005;

void solve() {
    int n;
    cin >> n;
    ll ans=0,sq=sqrt(n);
    f(i,1,sq+1){
        ans+=(ll)((n-1)/i)-i+1;
    }
    if(sq*sq==n)
        sq--;
    cout << 2*ans-sq << endl;
}

int main() {
    fast;
    int t = 1;
    //cin >> t;
    while (t--)  solve();
}

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

using ll = long long;
ll S[1001][1001];
ll M = (ll)(1e9 + 7);

int main() {
  int N, K;
  cin >> N >> K;
  S[0][0] = 1;
  for (int k = 1; k <= K; ++k)
    for (int n = k; n <= N; ++n)
      S[n][k] = (k * S[n - 1][k] + S[n - 1][k - 1]) % M;
  ll res = 0;
  for (int k = 1; k <= K; ++k)
    res = (res + S[N][k]) % M;
  cout << res << endl;
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	if(a == 1 && b == 2 || a == 2 && b == 1)
		cout << 3 << endl;
	else if(a == 1 && b == 3 || a == 3 && b == 1)
		cout << 2 << endl;
	else if(a == 2 && b == 3 || a == 3 && b == 2)
		cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
#define INF 1e9 //10^9
#define MOD 1000000007
#define INFL 100000000000000000//10^18 = 2^60


int main(void){
    int N;
    cin >> N;
    vector<tuple<int, int, int>> trip(N+1);
    get<0>(trip[0]) = 0;
    get<1>(trip[0]) = 0;
    get<2>(trip[0]) = 0;
    for(int i = 1; i <= N; i++){
        cin >> get<2>(trip[i]) >> get<0>(trip[i]) >> get<1>(trip[i]);
    }
    
    bool l = 1;
    
    for(int i = 0; i < N; i++){
        int fromX, fromY, fromT;
        tie(fromX, fromY, fromT) = trip[i];
        int toX, toY, toT;
        tie(toX, toY, toT) = trip[i+1];
        
        if(abs(fromX-toX) + abs(fromY - toY) > toT - fromT) l = 0;
        if((abs(fromX-toX) + abs(fromY - toY)) % 2 != (toT - fromT) % 2) l = 0;
        
    }
    if(l){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}



Measured memory_bytes: 1408
N, M, C = map(int, input().split())
B = [int(a) for a in input().split()]

ans = 0
for _ in range(N):
    A = [int(a) for a in input().split()]
    if sum([A[i]*B[i] for i in range(M)]) + C > 0:
        ans += 1
    
print(ans)

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

sum_left, sum_right = 0, 0
total = sum(W)
ans = float('inf')
for w in W:
    sum_left += w
    sum_right = total - sum_left
    ans = min(ans, abs(sum_left - sum_right))
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{ll N,M;
ll min = INT_MAX;
ll max = INT_MIN;
cin>>N>>M;
ll l[N],r[M];
for(ll i=0;i<M;i++)
   {cin>>l[i]>>r[i];
   if(r[i]<min)
      min = r[i];
   if(l[i]>max)
      max = l[i];
   }

if(min<max)
  cout<<0;
else
  cout<<min-max+1;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll=long long;
ll factorial[2000010];

ll power(ll n,ll m)
{
    ll ans=1;
    for (ll r=0;m>>r>0;r++)
    {
        if ((m>>r)&1) ans=ans*n%mod;
        n=n*n%mod;
    }
    return ans;
}

ll inv(ll n)
{
    return power(n,mod-2);
}

void fact()
{
    factorial[0]=1;
    for (ll i=1;i<2000010;i++) factorial[i]=i*factorial[i-1]%mod;
    return;
}

ll cmb(ll n,ll r)
{
    if (r>n) return 0;
    else return factorial[n]*inv(factorial[n-r])%mod*inv(factorial[r])%mod;
}

int main()
{
    fact();
    ll k;cin >> k;
    string S;cin>> S;
    ll si=S.size();
    ll ans=0;
    for (ll i=si;i<si+k+1;i++)
    {
        ans=(ans+power(25,i-si)*cmb(i-1,si-1)%mod*power(26,si+k-i)%mod)%mod;
    }
    cout << ans%mod << endl;
    return 0;
}

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

const ll INF = 1000000000;

ll H, W;
vector<string> A;

void DPfunc() {
    vector<ll> v(W, INF);
    vector<vector<ll>> DP(H, v);
    if(A[0][0] == '#') DP[0][0] = 1;
    else DP[0][0] = 0;
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            //cout << i << " " << j << endl;
            if(i+j==0) continue;
            if(i==0) {
                if(A[i][j-1]=='.'&&A[i][j]=='#') {
                    DP[i][j] = min(DP[i][j-1]+1, DP[i][j]);
                }
                else {
                    DP[i][j] = min(DP[i][j-1], DP[i][j]);
                }
                continue;
            }
            if(j==0) {
                if(A[i-1][j]=='.'&&A[i][j]=='#') DP[i][j] = min(DP[i-1][j]+1, DP[i][j]);
                else DP[i][j] = min(DP[i-1][j], DP[i][j]);
                continue;
            }
            if(A[i-1][j]=='.'&&A[i][j]=='#') DP[i][j] = min(DP[i-1][j]+1, DP[i][j]);
            else DP[i][j] = min(DP[i-1][j], DP[i][j]);
            if(A[i][j-1]=='.'&&A[i][j]=='#') DP[i][j] = min(DP[i][j-1]+1, DP[i][j]);
            else DP[i][j] = min(DP[i][j-1], DP[i][j]);
        }
    }
    cout << DP[H-1][W-1] << endl;
}

signed main(){
    cin >> H >> W;
    A.resize(H);
    for(int i=0;i<H;i++) cin >> A[i];
    DPfunc();
    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String w = sc.next();
    char[] a = {'a', 'b', 'c','d','e','f', 'g', 'h', 'i', 'j', 'k', 'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int[] check = new int[26];
    int out =0;
    for (int j =0; j<26; j++) {
      for (int i =0; i< w.length(); i++) {
        if (w.charAt(i) == a[j]){
          check[j]++;
        }
      }
    }
    for (int i=0 ; i<26; i++) {
      if(check[i] % 2 != 0){
        out++;
      }
    }
    if (out != 0) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }
  }
}

Measured memory_bytes: 35556
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
const int INF = 2147483647;
const ll LLINF = 9223372036854775807;

#define MAX_E 200001
#define MAX_V 100001

struct edge{
    int to;
};
typedef pair<int, int> P;//firstは最短距離、secondは頂点の番号

int V,E;                //頂点数、辺数
vector<edge> G[MAX_V];  //隣接リスト。各頂点にedgeがある分をつなげる。
int d[MAX_V];           //頂点sからの最短距離
int myprev[MAX_V];

//隣接リストデータinput。
void input_graph(){
    int s,t;
    REP(i,E){
        cin>>s>>t;s--;t--;
        G[s].push_back({t});
        G[t].push_back({s}); //無向グラフの場合
    }
}

void dijkstra(int s){
    // greater<P>を指定することでfirstが小さい順に取り出せる様にする
    priority_queue<P, vector<P>, greater<P>> que; //未確定頂点の内、最短距離のものがtopにくる
    fill(d, d+V, INF);
    REP(i,V) myprev[i]=-1;
    d[s]=0;
    que.push(P(0,s));

    while(!que.empty()){
        P p=que.top(); que.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
      	REP(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+1){
                d[e.to]=d[v]+1;
                que.push(P(d[e.to], e.to));
                myprev[e.to]=v;
            }
        }
    }
}

int main(){
    cin>>V>>E;
    input_graph();
    dijkstra(0);

    REP(i,V-1) if(myprev[i+1]==-1){
      cout<<"No";
      return 0;
    }
    cout<<"Yes"<<endl;
    REP(i,V-1) cout<<myprev[i+1]+1<<endl;
}

Measured memory_bytes: 11060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {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;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  ll n;
  cin>>n;
  vi a(n);
  ll ans=0;
  map<ll,ll> mp;
  rep(i,n) {
    cin>>a[i];
    mp[a[i]]++;
    ans+=a[i];
  }
  ll q;
  cin>>q;
  v(ll) ansz(q);
  rep(i,q){
    ll b,c;
    cin>>b>>c;
    ansz[i]=ans+(c-b)*mp[b];  
    ans+=(c-b)*mp[b];  
    mp[c]+=mp[b];
    mp[b]=0;
  }
  rep(i,q){
    cout<<ansz[i]<<endl;
  }
}

Measured memory_bytes: 10264
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


N = int(input())
aa = inpl()

b = 1
for a in aa:
	b |= b << a

S = sum(aa)
half = (S+1)//2
b >>= half

print((b&-b).bit_length()+half-1)


Measured memory_bytes: 6600
#include <iostream>
#include <cstdio>
#define fi first
#define se second
using namespace std;
const int maxn = 2e5 + 100;
typedef pair<int, int> PII;
PII q[maxn];
int cnt[maxn], f[maxn], a[maxn];
int main()
{
    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for(int i = 1; i <= m; i++) scanf("%d %d", &q[i].fi, &q[i].se);
    for(int i = 1; i <= n; i++) cnt[a[i]]++;
    for(int i = 1; i <= n; i++){
        if(cnt[i]){
            for(int j = max(0, i-cnt[i]); j < i; j++) f[j]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) if(!f[i]) ans++;
    for(int i = 1; i <= m; i++){
        int x = a[q[i].fi], y = q[i].se;
        a[q[i].fi] = y;
        if(x-cnt[x] >= 0){
            f[x-cnt[x]]--;
            if(f[x-cnt[x]] == 0) ans++;
        }
        cnt[x]--;
        if(y-cnt[y]-1 >= 0){
            f[y-cnt[y]-1]++;
            if(f[y-cnt[y]-1] == 1) ans--;
        }
        cnt[y]++;
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n,d;
	cin>>n>>d;
	ll res=0;
	for(ll i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)
			res++;
	}
	cout<<res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 3748
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <vector>
#include <numeric>
#include <algorithm>
#include <utility>
#include <sstream>
#include <iterator>

using namespace std;
// #define int long long
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)


int main(int argc, const char * argv[]) {

    char S[4];

    cin >> S;

    bool flag = false;
    rep(i,3){
      if (S[i] == S[i+1]){
        flag = true;
      }
    }

    if (flag){
      cout << "Bad" << endl;
    }else{
      cout << "Good" << endl;
    }

    return 0;
}


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

int main() {
  while(1) {
    ll n,x;
    cin >> n >> x;
    if(n==0&&x==0) {
      break;
    }
    ll count=0;
    for(ll i=1;i<n;i++) {
      for(ll j=i+1;j<n;j++) {
        if((x-i-j>j)&&(x-i-j<=n)) {
          count++;
        }
      }
    }
    cout << count << endl;
  }
}


Measured memory_bytes: 3084
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()

UMaxY = DMaxY = OMaxY = -INF
UMinY = DMinY = OMinY = INF
LMaxX = RMaxX = OMaxX = -INF
LMinX = RMinX = OMinX = INF

for i in range(N):
    x, y, d = raw_input().split()
    x, y = int(x) * 2, int(y) * 2
    if d == 'U':
        UMaxY = max(UMaxY, y)
        UMinY = min(UMinY, y)
        OMaxX = max(OMaxX, x)
        OMinX = min(OMinX, x)
    if d == 'D':
        DMaxY = max(DMaxY, y)
        DMinY = min(DMinY, y)
        OMaxX = max(OMaxX, x)
        OMinX = min(OMinX, x)
    if d == 'L':
        OMaxY = max(OMaxY, y)
        OMinY = min(OMinY, y)
        LMaxX = max(LMaxX, x)
        LMinX = min(LMinX, x)
    if d == 'R':
        OMaxY = max(OMaxY, y)
        OMinY = min(OMinY, y)
        RMaxX = max(RMaxX, x)
        RMinX = min(RMinX, x)
'''
print UMaxY, DMaxY, OMaxY
print UMinY, DMinY, OMinY
print LMaxX, RMaxX, OMaxX
print LMinX, RMinX, OMinX
'''
ts = [0]
ts += [DMaxY - OMaxY, OMaxY - UMaxY, (DMaxY - UMaxY) / 2]
ts += [DMinY - OMinY, OMinY - UMinY, (DMinY - UMinY) / 2]
ts += [LMaxX - OMaxX, OMaxX - RMaxX, (LMaxX - RMaxX) / 2]
ts += [LMinX - OMinX, OMinX - RMinX, (LMinX - RMinX) / 2]

ans = 10 ** 30
for t in ts:
    if t < 0 or 10 ** 10 < t:
        continue
    maxY = max(DMaxY - t, UMaxY + t, OMaxY)
    minY = min(DMinY - t, UMinY + t, OMinY)
    maxX = max(LMaxX - t, RMaxX + t, OMaxX)
    minX = min(LMinX - t, RMinX + t, OMinX)
    ans = min(ans, (maxY - minY) * (maxX - minX))
print float(ans) / 4

Measured memory_bytes: 34660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define num_max(p,q)((p)>(q)?(p):(q))
#define num_min(p,q)((p)<(q)?(p):(q))
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
	 //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
	int N,i,j;
	int ans = 0;
	int d[110];
	scanf("%d", &N);
	for (i = 0;i < N;i++)scanf("%d", &d[i]);
	for (i = 0;i < N;i++)
	{
		for (j = i+1;j < N;j++)
		{
			ans += d[i] * d[j];
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
 
char s[30005];
int cnt[15];
int v[30005];

int main() {
	int n;
 
	scanf("%d %s", &n, s);
 

	for(int i = 0; s[i]; i++)
		v[i] = s[i]-'0';

	int ans = 0;
	for(int a = 0; a < 10; a++)
		for(int b = 0; b < 10; b++)
			for(int c = 0; c < 10; c++) {
				vector<int> aux{a,b,c};
				int j = 0;
				for(int i = 0; s[i]; i++) {
					if(v[i] == aux[j])
						j++;
					if(j == 3) {
						ans++;
						break;
					}
				}
			}

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

    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int N = sc.nextInt();
		int[] A = new int[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		sc.close();
		int m=0;
		for(int i=0;i<N-1;i++)
		{
			if(i==0)
			{
				m=Math.max(m,A[i]-A[N-1]+K);
			}
			else
			{
				m=Math.max(m,(A[i+1]-A[i]));
			}
		}
		System.out.println(K-m);
	}

}

Measured memory_bytes: 77520
n, m = map(int, input().split())

c = list(map(int, input().split()))
c.sort()

inf = float("inf")
dp = [inf for _ in range(n+1)] #最小化問題の時はinfのほうが良いのかな
dp[0] = 0

for i in range(1, n+1):
    for j in range(m):
        if i >= c[j]:
            dp[i] = min(dp[i-c[j]]+1, dp[i])
        else:
            dp[i] = dp[i]


print(dp[n])


Measured memory_bytes: 7388
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    char X,Y;

    cin>>X>>Y;

    int x=X-'A',y=Y-'A';

    if(x>y){
        cout << ">"<<endl;
    }else if(x==y){
        cout<<"="<<endl;
    }else{
        cout<<"<"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#author : dokueki

import sys
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)
sys.setrecursionlimit(10**7)
mod = 1000000007


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    a, b, c = map(int, sys.stdin.readline().split())
    print(c,a,b)

if __name__ == "__main__":
    try:
        IOE()
    except:
        pass
    main()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

/*
void dfs(int v){
    印つける
    for(auto next_v:G[v]){
        探索済->continue
        dfs(next_v);
    }
}
*/
int main()
{
    string s;
    cin >> s;
    if(s[s.size()-1]=='s'){
        cout << s << "es" << endl;
    }else{
        cout << s << "s" << endl;
    }
}

Measured memory_bytes: 3628
# https://atcoder.jp/contests/abc139/tasks/abc139_d
# math
import sys
input = sys.stdin.readline
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
# ans = 0
# for i in range(n):
#     ans += i
# print(ans)

ans = (n + 1) * n // 2 - n
print(ans)

Measured memory_bytes: 38384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
B = [bin(a) for a in A]

maxA = max(A)
mask = 1

count = 0
i = 0
while maxA >> i:
    zeros = sum([1 for a in A if (mask * 2**i) & a == 0]) % MOD
    ones = (len(A) - zeros) % MOD
    count += zeros * ones * ((2**i) % MOD)
    count %= MOD
    i += 1

print(count)

Measured memory_bytes: 220812
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int n;cin>>n;
    int dp[50];
    dp[0] = 1;
    dp[1] = 1;
    for(int i=2;i<n+1;i++){
        dp[i] = dp[i-1] + dp[i-2];
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 3092
#ifdef ConanYu
#include "local.hpp"
#else
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

int a[200005];

void Main() {
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mn = INT_MAX;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] < mn) {
      ans++;
    }
    mn = min(mn, a[i]);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scan = new Scanner(System.in);
        long K = scan.nextInt();
        final long A = scan.nextInt();
        final long B = scan.nextInt();

        long biscuit = 1;
        long jpy = 0;

        if (B - A <= 2) {
            while (K > 0) {
                biscuit++;
                K--;
            }
            System.out.println(biscuit);
            return;
        }

        while (K > 0) {
            if (jpy > 0) {
                jpy--;
                biscuit += B;
                K--;
                continue;
            }

            if (biscuit >= A && K >= 2) {
                biscuit -= A;
                jpy++;
                K--;
                continue;
            }

            biscuit++;
            K--;
        }
        System.out.println(biscuit);
    }
}

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

// using Graph = vector<vector<int>>;

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

  vector<vector<int>> G(n);
  vector<map<int, bool>> Color(n);
  map<pair<int, int>, int> number;
  for(int i=0; i<n-1; i++) {
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
    pair<int, int> p;
    p.first = a-1;
    p.second = b-1;
    number[p] = i;
  }

  int ans[n-1];
  bool seen[n];
  for(int i=0; i<n; i++) seen[i] = false;
  queue<int> todo;
  todo.push(0);
  while(!todo.empty()) {
    int now = todo.front();
    todo.pop();
    seen[now] = true;

    int cl = 1;
    for(int next: G[now]) {
      if(seen[next]) continue;

      while(Color[now][cl]) {
        cl++;
      }
      Color[now][cl] = true;
      Color[next][cl] = true;
      pair<int, int> p;
      p.first = min(now,next);
      p.second = max(now,next);
      ans[number[p]] = cl;

      todo.push(next);
    }
  }

  int max = *max_element(ans, ans+n-1);
  cout<<max<<endl;
  for(int i=0; i<n-1; i++) cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 26880
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        if ("0".equals(n)) {
            System.out.println("Yes");
        } else {
            long sum = 0;
            for (int i = 0; i < n.length(); i++) {
                sum += Integer.parseInt(n.substring(i, i + 1));
            }
            System.out.println((sum % 9 == 0) ? "Yes" : "No");
        }

    }
}


Measured memory_bytes: 49860
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f(i,a,b) for(ll int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define maxv(a,b) *max_element(a, b)
#define minv(a,b) *min_element(a, b)
#define cv(a,b,x) count(a, b,x) 
#define vi vector<int>
#define mii map<int,int>
#define si set<int>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define fv(i,v) for(auto i=v.begin();i!=v.end();++i)
#define fdv(i,v) for(auto i=v.rbegin();i!=v.rend();++i)
#define print(a,n) f(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printv(v) for(auto iv: v) cout<<iv<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
#define input(v,n) f(i,0,n) {int x; cin>>x; v.pb(x);}
#define r(a,n) ll a[n+1]; f(i,1,n) cin>>a[i];
#define N 200005
using namespace std;

bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
   
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 

void solve() 
{
int c=0;
string s,t;
cin>>s;
cin>>t;
f(i,0,s.size()){if(s[i]!=t[i]) c++;}
cout<<c;
}


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

   ll int t;
   //cin>>t;
   t=1;
   while(t--)
   { 
     solve();}
}




Measured memory_bytes: 3808