akhauriyash/Code-Regression huggingface dataset:
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools
import heapq
#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)


def main():
    n,m,x=map(int,input().split())
    c=[]
    a=[]
    for i in range(n):
        temp=list(map(int,input().split()))
        c.append(temp[0])
        a.append(temp[1:])
    total=INFI
    for i in itertools.product(range(2),repeat=n):
        tempkin=0
        rik=[0 for _ in range(m)]
        for ii in range(n):
            for iii in range(m):
                if i[ii]==1:
                    rik[iii]+=a[ii][iii]
            if i[ii]==1:
                tempkin+=c[ii]
        ans=1
        for j in range(m):
            if rik[j]<x:
                ans=0
                break
        if ans==1:
            total=min(total,tempkin)
    if total==INFI:
        print(-1)
    else:
        print(total)








if __name__ == "__main__":

    main()

Measured memory_bytes: 74980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  string S;
  cin>>K>>S;
  string sum;  //出力する文字列
  
  if(S.size()>K){ //SがKを上回ったら
  	for(int i=0;i<K;i++){
    	sum+=S.at(i);
 	}
     cout<<sum<<"..."<<endl;
  }else{
  cout<<S<<endl;
  }
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <set>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int contained(int l, int r, vector<set<int> > &pos){
    int ret=0;
    for(int i=0; i<26; i++){
        auto it=pos[i].lower_bound(l);
        if(it!=pos[i].end() && *it<r){
            ret++;
        }
    }
    return ret;
}

int main(){
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<set<int> > pos(26);
    for(int i=0; i<N; i++){
        int c=S[i]-'a';
        pos[c].insert(i);
    }

    for(int i=0; i<Q; i++){
        int t;
        cin >> t;
        if(t==1){
            int j;char c;
            cin >> j >> c;
            j--;
            int s=S[j]-'a';

            pos[s].erase(j);
            pos[(int)c-'a'].insert(j);
            S[j]=c;
        }else{
            int l, r;
            cin >> l >> r;
            l--;
            cout << contained(l, r, pos) << endl;
        }
    }
}

Measured memory_bytes: 24196
#include <stdio.h>
#include <stdbool.h>

int n_from;
int from[20];

int id;
bool canMake(int id, int target);

int main(void)
{
    int i;

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

    int n_target;
    scanf("%d", &n_target);
    int target;
    while (n_target--) {
        id = 0;
        scanf(" %d", &target);
        if (canMake(id, target)) {
            printf("yes\n");
        } else {
            printf("no\n");
        }
    }

    return 0;
}

bool canMake(int id, int target)
{
    /*
    int i;
    printf("judging if can make %d from", target);
    for (i = id; i < n_from; i++) {
        printf(" %d", from[i]);
    }
    printf("\n");
    */

    if (id == n_from) {
        return (target == 0);
    }

    if (canMake(id + 1, target)) {
        return true;
    }
    if (canMake(id + 1, target - from[id])) {
        return true;
    }

    return false;
}

Measured memory_bytes: 580
#include <iostream>

using namespace std;

int main(){
    int a;
    int b;
    int c;
    int d;
    cin >> a >> b >> c >> d;
    int countc = 0;
    int counta = 0;
    for(int i = 0; i < 101; i++){
        c -= b;
        countc++;
        if(c <= 0){
            break;
        }
    }
    for(int i = 0; i < 101; i++){
        a -= d;
        counta++;
        if(a <= 0){
            break;
        }
    }
    if(countc <= counta){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int gcd(int a, int b) {
	return a % b ? gcd(b, a % b) : b;
}

int main() {
	int n, k, a[100000];
	bool r = false;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int d = a[0];
	for (int i = 1; i < n; i++) {
		d = gcd(d, a[i]);
	}
	for (int i = 0; i < n; i++) {
		if (k <= a[i] && (a[i] - k) % d == 0) {
			r = true;
			break;
		}
	}
	cout << (r ? "POSSIBLE" : "IMPOSSIBLE") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

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

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    ll X, t;
    cin >> X >> t;
    if (X - t < 0) {
        cout << 0 << endl;
    } else {
        cout << X - t << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int from_roman(const std::string &s){
    std::map<char, int> m = {
        { 'I', 1 },
        { 'V', 5 },
        { 'X', 10 },
        { 'L', 50 },
        { 'C', 100 },
        { 'D', 500 },
        { 'M', 1000 }
    };
    int n=0;
    for(int i = 0; i < (int)s.size(); ++i){
        if(m[s[i]] >= m[s[i+1]]) n += m[s[i]];
        else n -= m[s[i]];
    }
    return n;
}

// int to_roman(int n){
//     std::vector<std::pair<std::string, std::string>> res;
//     while(n){
//         int d = n
//     }
// }

using namespace std;
int main(){
    string n;
    while(cin >> n){
        cout << from_roman(n) << endl;
    }
}

Measured memory_bytes: 3184
n, p = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0, 0] for _ in range(n + 1)]
dp[0][0] = 1
for i in range(1, n + 1):
    if a[i - 1] % 2:
        dp[i][1] = dp[i - 1][0] + dp[i - 1][1]
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1]
    else:
        dp[i][0] = 2 * dp[i - 1][0]
        dp[i][1] = 2 * dp[i - 1][1]
print(dp[n][p])

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

#define INF             1e9
#define INFL            1e19
#define XX              first
#define YY              second
#define PB              push_back
#define MP              make_pair

#define NEWLINE         cout << endl;
#define HOISE           cerr << "hoise" << endl
#define PAUSE           system("pause")
#define DEBUG(x)        cerr << #x << " = " << x << endl
#define READ            freopen("alu.txt", "r", stdin)
#define WRITE           freopen("vorta.txt", "w", stdout)
#define FASTIO          ios_base::sync_with_stdio(false);cin.tie(NULL)

#define MASK(x)         for(int i = 0; i < 8; i++){ if(x&(1<<i)){ cout << i << " "; } } cout << endl;

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

const int MAX = 100 + 2;
const int MAXLOG = log2(MAX) + 2;
const int MAXN = 1e6 + 2;
const int MOD = 1000000007;


int main()
{
//    READ;
//    WRITE;
    FASTIO;

    string s;
    int n;
    cin >> n;
    cin >> s;
    if(n%2 == 0){
        if(s.substr(0, n/2) == s.substr(n/2, n/2))
            cout << "Yes";
        else
            cout << "No";
    }
    else{
        cout << "No";
    }

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n + 1, 0);
    rep(i, 0, n) cin >> a[i];
    int ans = 0, tmp = 0;
    rep(i, 0, n + 1){
        if(a[i] != 0){
            tmp += a[i];
        }else{
            ans += tmp / 2;
            tmp = 0;
        }
    }
    cout << ans << endl;
}

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


int64_t point(int64_t l, int64_t r, vector<int64_t> &D, int64_t n, vector<int64_t> &A, int64_t mm) {
  if (D[l*n + r] != mm) {
    return D[l*n + r];
    }
  else {
    if ((r-l+1)%2 == n%2) {
      D[l*n + r] = max(point(l, r-1, D, n, A, mm) + A[r], point(l+1, r, D, n, A, mm) + A[l]);
    }
    else {
      D[l*n + r] = min(point(l, r-1, D, n, A, mm) - A[r], point(l+1, r, D, n, A, mm) - A[l]);
    }
    return D[l*n + r];
  }
}

int main() {
  int64_t n;
  cin >> n;
  vector<int64_t> A(n);
  for (int i=0; i<n; i++) {
    cin >> A[i];
  }
  
  int64_t mm = pow(10, 14);
  int64_t f = 1;
  if (n%2 == 0) {f = -1;}

  vector<int64_t> D(pow(n, 2), mm);
  for (int i=0; i<n; i++) {
    D[i*n + i] = f * A[i];
  }


  cout << point(0, n-1, D, n, A, mm) << endl;
}

Measured memory_bytes: 74012
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

vector<int> to[2505];
vector<int> rto[2505];
bool reachablefrom1[2505];
bool reachableToN[2505];
bool ok[2505];

void dfs(int v) {
  if (reachablefrom1[v]) return;
  reachablefrom1[v] = true;
  for (int u : to[v]) {
    dfs(u);
  }
}
void rdfs(int v) {
  if (reachableToN[v]) return;
  reachableToN[v] = true;
  for (int u : rto[v]) {
    rdfs(u);
  }
}

int main() {
  ll n = in();
  ll ans = n * (n - 1) / 2;
  cout << ans << endl;
  return 0;
}


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

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

  vector<int> a(n);
  int minv = 1e9;
  int maxv = -1e9;
  int itr_max = 0, itr_min = 0;
  rep(i,n) {
    cin >> a[i];
    if(a[i] < minv) {
      minv = a[i];
      itr_min = i;
    }
    if(a[i] > maxv) {
      maxv = a[i];
      itr_max = i;
    }
  }

  vector<pair<int,int>> ans;
  if(abs(maxv) >= abs(minv)) {
    for (int i = 0; i < n; i++) {
      ans.emplace_back(itr_max + 1, i + 1);
    }
    for (int i = 1; i < n; i++) {
      ans.emplace_back(i, i + 1);
    }
  } else {
    for (int i = 0; i < n; i++) {
      ans.emplace_back(itr_min + 1, i + 1);
    }
    for (int i = n - 2; i >= 0; i--) {
      ans.emplace_back(i + 2, i + 1);
    }
  }
  cout << (int)ans.size() << '\n';
  for (auto it : ans) {
    cout << it.first << " " << it.second << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		
		// 計算
		String result = "consonant";
		if(s.equals("a") || s.equals("i") || s.equals("u") || s.equals("e") || s.equals("o")) result = "vowel";
		
		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 21204
let m = 950527

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let to_x = Array.make 128 0

let to_key s =
  let n = String.length s in
  let rec doit i p acc =
    if i = n then acc
    else doit (i + 1) (5*p) (acc + p*(to_x.(Char.code s.[i]))) in
  doit 0 1 0

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  let rec doit i =
    if i < n then begin
      begin match split (read_line ()) ' ' with
      | ["insert"; s] -> insert s t
      | ["find"; s] -> print_endline (if find s t then "yes" else "no")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 20076
public class
Main
{
  public void
  run (
    java.io.InputStream in,
    java.io.PrintStream out
    )
  {
    java.util.Scanner sc = new java.util.Scanner ( in );
    UnionFind lis;
    int n;
    int i;

    lis = new UnionFind ( sc.nextInt ( ) );
    n = sc.nextInt ( );
    for ( i = 0; i < n; ++i )
    {
      int q, x, y;

      q = sc.nextInt ( );
      x = sc.nextInt ( );
      y = sc.nextInt ( );
      if ( q == 0 )
        lis.combine ( x, y );
      else
        out.println ( lis.combinedp ( x, y ) ? 1 : 0 );
    }

    sc.close ( );
  }

  public static void
  main (
    String[ ] args
    )
  {
    ( new Main ( ) ).run ( System.in, System.out );
  }

  /** ????????¢?????????????????? */
  private static class
  UnionFind
  {
    /** Union Find Node ??????????´? */
    private int[ ] h;
    /** Union Find (Sub-)Tree ???????´???° */
    private int[ ] w;

    public
    UnionFind (
      /** 0..(size-1) ?????§?????´??°??????????????±??? */
      int size
      )
    {
      h = new int[ size ];
      w = new int[ size ];
      java.util.Arrays.fill ( h, -1 );
      java.util.Arrays.fill ( w,  1 );
    }

    /** p ??¨q ???????????¨?????? */
    public void
    combine (
      int p,
      int q
      )
    {
      p = root ( p );
      q = root ( q );
      if ( p == q ) return ;
      if ( w[ q ] < w[ p ] )
      {
        final int t = p;
        p = q;
        q = t;
      }
      h[ p ] = q;
      w[ q ] += w[ p ];
    }

    /** p ??¨q ???????????§????????????????????? */
    public boolean
    combinedp (
      int p,
      int q
      )
    {
      return ( root ( p ) == root ( q ) );
    }

    /** ??£??¨???????????? */
    private int
    root (
      int p
      )
    {
      if ( h[ p ] == -1 )
        return ( p );
      h[ p ] = root ( h[ p ] );

      return ( h[ p ] );
    }
  }
}

Measured memory_bytes: 99868
from math import ceil
from collections import deque
N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]
XH.sort(key=lambda x: x[0])
ans = 0

XN = [[x, ceil(h/A)] for x, h in XH]
# 左端のモンスターに攻撃が必要な回数はそこから2*Dだけ右にあるモンスターにまで波及できる
cnum = 0
que = deque()
ans = 0
for x, n in XN:
    while que and x > que[0][0]:
        _, num = que.popleft()
        cnum -= num
    need = max(0, n - cnum)
    ans += need
    cnum += need

    if need:
        que.append([x+2*D, need])
print(ans)


Measured memory_bytes: 85896
package main

import (
	"fmt"
	"math"
)

func main() {
	var x1, x2, y1, y2 float64
	fmt.Scan(&x1, &y1, &x2, &y2)
	fmt.Println(math.Sqrt(math.Pow(x1 - x2, 2) + math.Pow(y1 - y2, 2)))
}


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

static const int MMAX = 20;
static const int NMAX = 50000;
static const int INFTY = (1 << 29);

int main() {
  int n, m;
  cin >> n >> m;
  int C[MMAX + 1];
  int T[NMAX + 1];

  for (int i = 1; i <= m; i ++) cin >> C[i];

  for (int i = 0; i <= NMAX; i ++) T[i] = INFTY;
  T[0] = 0;
  for (int i = 1; i <= m; i ++) {
    for (int j = 0; j + C[i] <= n; j ++) {
      T[j + C[i]] = min(T[j + C[i]], T[j] + 1);
    }
  }

  cout << T[n] << endl;
}



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

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

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


vvi g(200000);
vi cnt;

void solve(int x, int p=-1){
    for(auto v:g[x]){
        if(v==p)continue;
        cnt[v]+=cnt[x];
        solve(v,x);
    }
}

int main(){
    int n,q;
    scanf("%d %d", &n,&q);
    g.resize(n);
    cnt.resize(n);
    //グラフ作成
    rep(i,n-1){
        int a,b;
        scanf("%d %d",&a,&b);
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    //q回操作を行う
    int p,x;
    rep(i,q){
        scanf("%d %d",&p,&x);
        p--;
        cnt[p]+=x;
    }
    
    solve(0);
    
    rep(i, n)cout<<cnt[i]<<endl;
    return 0;
}

Measured memory_bytes: 23552
// A - Haiku

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
    string s;
    cin >> s;
    int sum = 0;
    int num = atoi(s.c_str());

    for(int i=0;i<s.size();i++){
        sum += s[i]-'0';
    }

    if(num%sum==0) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}


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

using namespace std;

int main() {
    string s1, s2;
    while(cin >> s1 >> s2) {
        //vector<vector<int> > dp(s1.size(), vector<int>(s2.size(), 0));
        vector<int> dp[2];
        dp[0].resize(s2.size());
        dp[1].resize(s2.size());
        fill(dp[0].begin(), dp[0].end(), 0);
        fill(dp[1].begin(), dp[1].end(), 0);

        int ans = 0;
        int l1 = s1.size();
        int l2 = s2.size();
        for(int i = 0; i < l1; ++i) {
            int curr = i&1;
            int prev = 1-curr;
            for(int j = 0; j < l2; ++j) {
                if(s1[i] == s2[j]) {
                    if(i > 0 && j > 0) dp[curr][j] = dp[prev][j-1]+1;
                    else dp[curr][j] = 1;
                }
                else dp[curr][j] = 0;
                if(dp[curr][j] > ans) ans = dp[curr][j];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 968
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define sort(v)     sort((v).begin(),(v).end())
#define rall(v)     (v).rbegin(),(v).rend()
#define rsort(v)     sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;
//x.substr(start, length);
struct type{
    int k, i, j;
};
//to check if a no is prime or not?
bool isPrime(int n) 
{ 
    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; 
}

// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k)
{
	int window_sum = 0;
	int min_window = INT_MAX;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		window_sum += arr[i];
		if (i + 1 >= k)
		{
			if (min_window > window_sum)
			{
				min_window = window_sum;
				last = i;
			}
			window_sum -= arr[i + 1 - k];
		}
	}
	int sum=0;
	for(int i=last-k+1;i<=last;i++)
	{
	    sum+=arr[i];
	}
	return sum;
}
signed main() 
{
    fastio;
    int n,k;
    cin>>n>>k;
    vi a(n);
    f(i,n)cin>>a[i];
    vi dp(n);
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
        for(int j=2;j<=min(k,i);j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
//Sum of gcd of Tuples
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;

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

int main ()
{
    int K;
    cin >> K;
    long long sum = 0;
    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int k = 1; k <= K; k++) {
                sum += gcd(gcd(i,j),k);
            }
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3188
from fractions import gcd
a, b, c, d = [int(x) for x in input().split(' ')]

num = b-a+1
e = b//c - (a-1)//c 
f = b//d - (a-1)//d
g = c*d//gcd(c, d)
print(num - e - f + b//g - (a-1)//g)


Measured memory_bytes: 5048
#include<stdio.h>
int main(){
	int n;
	long long int a,b;
	scanf("%d %lld %lld",&n,&a,&b);
	int i;
	long long int x[100005];
	for (i=0;i<n;i++)
		scanf("%lld",&x[i]);
	long long int ans=0;
	for (i=1;i<n;i++){
		if (a*(x[i]-x[i-1])<b)
			ans+=a*(x[i]-x[i-1]);
		else
			ans+=b;
	}
	printf("%lld\n",ans);
	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    ll N, M, V, P;
    cin >> N >> M >> V >> P;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
  
    ll th = A[N-P];
    ll left = distance(A.begin(), lower_bound(A.begin(), A.end(), th));
    ll right = distance(A.begin(), upper_bound(A.begin(), A.end(), th));
    ll value = th * (right - left);
    ll cnt = right - left;
    ll margin = N - right;
    ll ans = N - left;
    for (ll l = left-1; l >= 0; l--) {
        if (A[l] + M < th) break;
        ll tmp = l + 1ll;
        tmp += margin;
        if (tmp < V && (A[l] + M) * cnt - value < M * (V - tmp)) continue;
        ans++;
        value += A[l];
        cnt++;
    }
    print(ans);
}

signed main() {
    solve();
}


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

int top,S[100];

void push(int x){

  S[++top]=x;

}


int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];
  while(scanf("%s",s) != EOF){
    if(s[0] == '+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]== '-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]== '*'){
      a=pop();
      b=pop();
      push(a*b);
    }else {
      push(atoi(s));
    }
  }

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

  return 0;
}



Measured memory_bytes: 2144
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn check_prime(x: usize) -> bool {
    for y in 2..((x as f64).sqrt() as usize) {
        if x % y == 0 && x != y {
            return false;
        }
    }
    return true;
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let mut x = parse!(it);
    loop {
        if check_prime(x) {
            println!("{}", x);
            return;
        }
        x += 1;
    }
}


Measured memory_bytes: 4352
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    H = string_to_int(inputs[0])

    max_heigh = 0
    count = 0
    for h in H:
        if h >= max_heigh:
            max_heigh = h
            count += 1
    return count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3316
#include<stdio.h>
int main(void)
{
	int a[3],i,j,x;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				x=a[i];
				a[i]=a[j];
				a[j]=x;
			}
		}
	}
	x=a[0]+a[1];
	printf("%d\n",x);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> rui(n);
  for (int i = 0;i < n;i++){
    if (i == 0){
      rui.at(0)=1;
    }else{
      rui.at(i)=rui.at(i-1)+i+1;
    }
  }

  int noke = 0;
  for (int i = 0;i < n;i++){
    if (rui.at(i) >= n){
        noke=rui.at(i)-n;

        if (noke == 0){
          for (int j = 0;j <= i;j++){
            cout << j+1 << "\n";
          }
          break;
        }else{
          for (int j = 0;j <= i;j++){
            if (j != noke-1){
              cout << j+1 << "\n";
            }
          }
          break;
        }
    }
  }


  return 0;
}


Measured memory_bytes: 39296
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> PI;
#define MAX 99999999
int mx[]={1,2,3,-1,-2,-3,0,0,0,0,0,0};
int my[]={0,0,0,0,0,0,1,2,3,-1,-2,-3};
vvi v(9,vi(9,0));
void dfs(int y,int x){
    if(!v[y][x])return;
    v[y][x]=0;
    rep(i,12){
        int tx=x+mx[i]; int ty=y+my[i];
        if(0<=tx&&tx<8&&0<=ty&&ty<8){
           if(v[ty][tx]==1) dfs(ty,tx);
        }
    }
    return ;
}
int main(){
    int n; cin>>n;
    rep(Q,n){
        char c;
        rep(i,8){rep(j,8){cin>>c;v[i][j]=atoi(&c);}}
        int x,y;cin>>x>>y;
        dfs(--y,--x);
        cout<<"Data "<<Q+1<<":"<<endl;
        rep(i,8){rep(j,8)cout<<v[i][j];cout<<endl;}
    }
}

Measured memory_bytes: 3108
/*
Look at the star
Look at the shine for U
*/
#include<bits/stdc++.h>
#define ll long long
#define PII pair<int,int>
#define sl(x) scanf("%lld",&x)
using namespace std;
const int N = 1e6+5;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}
ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}
char s[N];
vector <ll> vec;
int main()
{
	ll n,k = 0,i,j,m;
	scanf("%s",s);
	sl(n);
	for(i = 0;s[i];i++) if(s[i] == '1') k++; else break;
	if(k >= n) puts("1");
	else printf("%c\n",s[k]);
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    char[] s = scanner.next().toCharArray();
    int count = 0;
    for (int i = 1; i < s.length; i++) if (s[i] != s[i - 1]) count++;
    System.out.println(count);
  }
}


Measured memory_bytes: 26196
#include <iostream>
using namespace std;
#define MAX 100000

int main()
{
    int N, result=0;
    char S[MAX];

    cin >> N >> S;
    
    for (int i = 0; i < N-1; i++) {
        if (S[i] != S[i+1])
            result++;
    }
    result++;
    
    cout << result << endl;

    return 0;
}

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

int main() {

	int people[101];

	for (int i = 0; i < 101; i++) {
		people[i] = 0;
	}

	int N, K;

	std::cin >> N >> K;

	int d = 0;
	int A = 0;
	
	for (int i = 0; i < K; i++) {

		std::cin >> d;
		
		for (int j = 0; j < d; j++) {
			std::cin >> A;
			people[A]++;
		}
	}

	int sum = 0;

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

		if (people[i] == 0) {
			sum++;
		}
	}

	std::cout << sum;
}

Measured memory_bytes: 3592
# 今日の曜日を表す文字列 S
# S は SUN,MON,TUE,WED,THU,FRI,SAT のいずれか
# 次の日曜日（明日以降）が何日後か

S = input()

if S == 'SUN':
    print(7)
elif S == 'MON':
    print(6)
elif S == 'TUE':
    print(5)
elif S == 'WED':
    print(4)
elif S == 'THU':
    print(3)
elif S == 'FRI':
    print(2)
else:
    print(1)


Measured memory_bytes: 8860
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){

	int s;
	cin >> s;
	int a[1000000];
	int ans;
	bool flag = false;
	a[0] = s;
	rep(i, 999999) {
		a[i+1] = (a[i] % 2 == 0)? a[i]/2 : 3*a[i]+1;
		rep(j, i) if (a[i] == a[j]) {
			ans = i+1;
			flag = true;
			break;
		}
		if (flag) break;
	}
	cout << ans << endl;
	

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 50;
const ll MOD = 998244353;

ll k, n;
ll a[N], d[N];


int main() {
    cin>>k>>n;
    for(int i=0;i<n;i++) {
        scanf("%lld", &a[i]);
        if(i >= 1)d[i-1] = a[i] - a[i - 1];
    }

    d[n-1] = (k - a[n-1]) + a[0];


    ll ans = 0;
    for(int i=0;i<n-1;i++) {
        ans += d[i];
    }
    ll t = ans;
    int l = 0, r = n-1;
    for(int i=2;i<=n;i++) {
        t = t + d[r] - d[l];
        ans = min(ans, t);
        r = (r + 1) % n;
        l = (l + 1) % n;
    }
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3456
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    last = [0]*26  # コンテストiを前回開催した日
    for d in range(ct):
        last[T[d]] = d + 1
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    score -= S[ct][prei]
    score += S[ct][ci]
    for d in range(ct, D):
        if d != ct and T[d] == prei:
            break
        score += C[prei]*(d + 1 - ct - 1)
        score -= C[prei]*(d + 1 - last[prei])
    for d in range(ct, D):
        if d != ct and T[d] == ci:
            break
        score += C[ci]*(d + 1 - last[ci])
        score -= C[ci]*(d + 1 - ct - 1)
    return score


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def greedy(D, C, S):
    Ts = []
    for k in range(5, 13):
        T = []  # 0-indexed
        max_score = -INF
        for d in range(D):
            # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
            max_score = -INF
            best_i = 0
            for i in range(26):
                T.append(i)
                score = evaluate(D, C, S, T, k)
                if max_score < score:
                    max_score = score
                    best_i = i
                T.pop()
            T.append(best_i)
        Ts.append((max_score, T))
    return max(Ts, key=lambda pair: pair[0])


def local_search(D, C, S, score, T):
    for _ in range(3000):
        ct = randint(0, D-1)
        ci = randint(0, 25)
        ori = T[ct]
        T[ct] = ci
        new_score = calc_score(D, C, S, T)
        # 差分更新がバグってそう
        if score < new_score:
            score = new_score
        else:
            T[ct] = ori

    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    init_score, T = greedy(D, C, S)
    T = local_search(D, C, S, init_score, T)
    for t in T:
        print(t+1)


Measured memory_bytes: 84916
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main() {
	char str[1001];
	int A;

	while(1){
		cin>>str;
		if (str[0]=='0')break;
		A=0;
		int B=strlen(str);
		for (int i=0;i<B;i++){
			A+=(str[i]-'0');
		}
		cout<<A<<endl;
	}



	return 0;
}

Measured memory_bytes: 3072
#include<stdio.h>
int main()
{
    long long s,m,h;
    while(scanf("%lld",&s)!=EOF && (s>=0 && s<=86400)){
        h=s/3600;
        s=s%3600;
        m=s/60;
        s=s%60;
        printf("%lld:%lld:%lld\n",h,m,s);
    }
    return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;

int main() {
	ll a, b, c[13] = { 0,1,2,1,3,1,3,1,1,3,1,3,1 };
	cin >> a >> b;
	cout << (c[a] == c[b] ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from numba import njit


def getInputs():
    D = int(readline())
    CS = np.array(read().split(), np.int32)
    C = CS[:26]
    S = CS[26:].reshape((-1, 26))
    return D, C, S


@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
    score = 0
    last = np.zeros((D, 26), np.int32)
    for d in range(len(out)):
        if d:
            last[d, :] = last[d - 1, :]
        i = out[d]
        score += S[d, i]
        last[d, i] = d + 1
        score -= np.sum(C * (d + 1 - last[d, :]))
    return last, score


def _update_score():
    pass

@njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True)
def _random_update(D, C, S, out, score):
    d = np.random.randint(0, D)
    q = np.random.randint(0, 26)
    p = out[d]
    out[d] = q

    if p == q:
        return out, score

    last, new_score = _compute_score1(D, C, S, out)
    if score < new_score:
        score = new_score
    else:
        out[d] = p

    return out, score


def _random_swap():
    pass


def step1(D, C, S):
    out = []
    LAST = 0
    for d in range(D):
        max_score = -10000000
        best_i = 0
        
        for i in range(26):
            out.append(i)
            last, score = _compute_score1(D, C, S, np.array(out, np.int32))
            if max_score < score:
                max_score = score
                LAST = last
                best_i = i
            out.pop()

        out.append(best_i)

    return np.array(out), LAST, max_score


def step2(D, C, S, out, score):
    for i in range(10 ** 4):
        out = out.astype(np.int32)
        out, score = _random_update(D, C, S, out, score)
    return out, score


def output(out):
    out += 1
    print('\n'.join(out.astype(str).tolist()))


D, C, S = getInputs()
out, _, score = step1(D, C, S)
#print(score)
out, score = step2(D, C, S, out, score)
output(out)
#print(score)

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

typedef long long ll;

ll N;
ll ans = 0;

void check(ll x) {
    if (x > N) return;
    map<ll, ll> mp;
    string s = to_string(x);
    rep(i, s.size()) {
        mp[s[i]]++;
    }
    if (mp.size() == 3) ans++;
}

void dfs(ll x) {
    // cout << x << endl;
    check(x);
    if (x <= 1e9) {
        dfs(10 * x + 3);
        dfs(10 * x + 5);
        dfs(10 * x + 7);
    }
}

int main() {
    cin >> N;
    dfs(0);

    cout << ans << endl;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t A,B,C;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> A >> B >> C;
	out << std::min({std::abs(A - B) + std::abs(B - C), std::abs(A - C) + std::abs(B - C), std::abs(B - A) + std::abs(C - A)}) << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int q;cin>>q;
    vector<pair<ll,ll>> ans;
    priority_queue<ll> small;
    priority_queue<ll,vector<ll>,greater<ll>> big;
    ll r=(ll)0,ssum=(ll)0,bsum=(ll)0,m=(ll)0,stmp,btmp;int res=0;
    int c;ll a,b;
    rep(i,q){
        cin>>c;
        if(c==1){
            cin>>a>>b;
            res++;
            stmp=(small.size())?small.top():-inf;
            btmp=(big.size())?big.top():inf;
            if(res%2){
                if(a<stmp){
                    ssum-=stmp;
                    m=stmp;
                    small.pop();
                    small.push(a);
                    ssum+=a;
                }
                else if(a>btmp){
                    bsum-=btmp;
                    m=btmp;
                    big.pop();
                    big.push(a);
                    bsum+=a;
                }
                else m=a;
            }
            else{
                if(small.size()==0){
                    small.push(min(m,a));
                    big.push(max(m,a));
                    bsum+=max(m,a);
                    m=min(m,a);
                    ssum+=m;
                }
                else if(a<stmp){
                    bsum+=m;
                    big.push(m);
                    ssum+=a;
                    small.push(a);
                    m=stmp;
                }
                else if(stmp<=a&&a<m){
                    bsum+=m;
                    big.push(m);
                    ssum+=a;
                    small.push(a);
                    m=a;
                }
                else if(m<=a&&a<btmp){
                    ssum+=m;
                    small.push(m);
                    bsum+=a;
                    big.push(a);
                }
                else{
                    ssum+=m;
                    small.push(m);
                    bsum+=a;
                    big.push(a);
                }
            }
            r+=b;
        }
        else{
            ans.push_back(mp(m,bsum-ssum+r));
            //cout<<bsum<<" "<<ssum<<" "<<r<<endl;
        }
    }
    for(auto A:ans)cout<<A.first<<" "<<A.second<<endl;
}

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

int n, A[30];

//入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if (m == 0) return 1;
    if (m < 0) return 0; //枝刈り
    if (i >= n) return 0; //枝刈り

    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    cin >> n ;
    for (int i = 0; i < n; i++) cin >> A[i];

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int M;
        cin >> M;
        if (solve(0, M)) cout << "yes" << endl;
        else cout << "no" << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int a[9][30];
int book[10],ans,n,m;
int dfs(int c,int step)
{
    if(step==n) { ans++; return 0;}
    for(int i=1;i<=n;i++)
    {
        if(a[c][i]==1&&book[i]==0)
        {
            book[i]=1;
            dfs(i,step+1);
            book[i]=0;

        }
    }
    return 0;
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        a[x][y]=a[y][x]=1;
    }
    book[1]=1;
    dfs(1,1);
    printf("%d\n",ans);

    return 0;
}


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

s = set()
sub = set()
for i in range(0, N - 2):
    s1 = S[i]
    if s1 in sub:
        continue
    sub.add(s1)
    for j in range(i + 1, N - 1):
        s2 = s1 + S[j]
        if s2 in sub:
            continue
        sub.add(s2)
        for k in range(j + 1, N):
            s3 = s2+S[k]
            s.add(s3)

print(len(s))

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n - 1);
	for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n - 1; i++) cin >> c[i];

    int ans = b[a[0] - 1];
    for (int i = 1; i < n; i++) {
    	ans += b[a[i] - 1];

    	if (a[i] == a[i - 1] + 1) {
    		ans += c[a[i - 1] - 1];
    	}
    }	
    cout << ans << "\n";

    return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

const li mod = 1e9 + 7;

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

    li h, w;
    cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; ++i) {
        cin >> grid[i];
    }

    vector<vector<li>> dp(h, vector<li>(w, 0));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i == 0 && j == 0) {
                dp[i][j] = 1;
            } else if (grid[i][j] == '#') {
                dp[i][j] = 0;
            } else if (i == 0) {
                dp[i][j] = dp[i][j - 1];
            } else if (j == 0) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
            }
        }
    }

    cout << dp[h - 1][w - 1] << endl;
    return 0;
}


Measured memory_bytes: 9216