akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        var evidences = new Tuple<int, int>[n][];

        // それぞれの証言を入力
        for(int i = 0; i < n; i++)
        {
            var evidenceNum = int.Parse(Console.ReadLine());
            evidences[i] = new Tuple<int, int>[evidenceNum];
            for (int j = 0; j < evidenceNum; j++)
            {
                var inputs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                evidences[i][j] = new Tuple<int, int>(inputs[0], inputs[1]);
            }
        }

        var answer = 0;

        // bit全探索
        foreach(var personsData in BitFullSearch(n))
        {
            var isOK = true;
            for(int i = 0; i < n; i++)
            {
                // 真実を言う人(true)の言うことが正しいか調べる
                if (personsData[i])
                {
                    for (int k = 0; k < evidences[i].Length; k++)
                    {
                        var index = evidences[i][k].Item1;
                        var isTrueMan = evidences[i][k].Item2 == 1;
                        if (personsData[index-1] != isTrueMan)
                        {
                            isOK = false;
                            break;
                        }
                    }
                }
            }

            if (isOK)
            {
                var truePersonCount = personsData.Count(p => p);
                if (answer < truePersonCount) answer = truePersonCount;
            }
        }

        Console.WriteLine(answer);
    }


    public static IEnumerable<bool[]> BitFullSearch(int n)
    {
        if (n < 0) yield return new bool[] { };

        for(int i = 0; i < Math.Pow(2, n); i++)
        {
            var array = new bool[n];
            for(int j = 0; j < n; j++)
            {
                var firstDigit = (i >> j) & 1;
                if (firstDigit == 1) array[j] = true;
            }

            yield return array;
        }
    }
}

Measured memory_bytes: 15444
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")


/// #pragma GCC optimize "trapv"

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define all(a) begin(a), end(a)
#define deb(x) cout << #x << " = " << x << endl
#define debu(x, y) cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl

typedef long long ll;
ll mod=1000000007;

template <typename T> vector<T> readVector(int n) { vector<T> res(n); for (int i = 0 ; i < n ; i++) cin >> res[i]; return res; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, x, t;
    cin >> n >> x >> t;
    int ans = t*((n)/x);
  	if(n%x) ans+= t;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
// by syu
package main

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

func main() {
	in := NewScanner(os.Stdin, 0)
	a := in.ArrayInt(3)

	if Sum(a...) == 17 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

type Scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader, max int) *Scanner {
	s := bufio.NewScanner(r)
	s.Split(scanWords)
	if max <= 0 {
		max = 100000
	}
	s.Buffer([]byte{}, max)
	return &Scanner{s}
}

func (s *Scanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) UInt() uint64 {
	s.Scan()
	i, e := strconv.ParseUint(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) Double() float64 {
	s.Scan()
	i, e := strconv.ParseFloat(s.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) Float() float32 {
	return float32(s.Double())
}

func (s *Scanner) Int() int {
	return int(s.UInt())
}

func (s *Scanner) Int32() int32 {
	return int32(s.UInt())
}

func (s *Scanner) UInt32() uint32 {
	return uint32(s.UInt())
}

func (s *Scanner) ArrayString(n int) (r []string) {
	for i := 0; i < n; i++ {
		r = append(r, s.String())
	}
	return
}

func (s *Scanner) ArrayUInt(n int) (r []uint64) {
	for i := 0; i < n; i++ {
		r = append(r, s.UInt())
	}
	return
}

func (s *Scanner) ArrayInt(n int) (r []int) {
	for i := 0; i < n; i++ {
		r = append(r, s.Int())
	}
	return
}

func (s *Scanner) ArrayUInt32(n int) (r []uint32) {
	for i := 0; i < n; i++ {
		r = append(r, s.UInt32())
	}
	return
}

func (s *Scanner) ArrayInt32(n int) (r []int32) {
	for i := 0; i < n; i++ {
		r = append(r, s.Int32())
	}
	return
}

func (s *Scanner) ArrayDouble(n int) (r []float64) {
	for i := 0; i < n; i++ {
		r = append(r, s.Double())
	}
	return
}

func (s *Scanner) ArrayFloat(n int) (r []float32) {
	for i := 0; i < n; i++ {
		r = append(r, s.Float())
	}
	return
}

func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i + 1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}

func ArrayIntToArrayString(arr []int) (r []string) {
	for _, v := range arr {
		r = append(r, fmt.Sprintf("%d", v))
	}
	return
}

func ArrayStringToArrayInt(arr []string) (r []int) {
	for _, v := range arr {
		i, e := strconv.ParseInt(v, 10, 64)
		if e != nil {
			panic(e)
		}
		r = append(r, int(i))
	}
	return
}

func Sum(arr ...int) (sum int) {
	for _, x := range arr {
		sum += x
	}
	return
}

func Rappend(a int, arr []int) []int {
	return append(arr, a)
}

func AllInt(vs []int, f func(int) bool) bool {
	for _, v := range vs {
		if !f(v) {
			return false
		}
	}
	return true
}

func Abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){

	int N, M,ans=0;
	cin >> N >> M;
	vector<int> L(M), R(M);
	for (int i = 0; i < M; i++){
		cin >> L[i] >> R[i];
	}

	sort(L.begin(), L.end());
	sort(R.begin(), R.end());
	ans = max(R[0] - L[M-1]+1,0);
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 1024
N = int(input())
v = 0
if N >= 10:
    v += 9
    if N >= 100:
        if N >= 1000:
            v += 900
            if N >= 10000:
                if N >= 100000:
                    v += 90000
                    if N >= 1000000:
                        pass
                else:
                    v += N % 100000 - 10000 + 1
        else:
            v += N % 1000 - 100 + 1
else:
    v += N % 10
print(v)


Measured memory_bytes: 2940
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

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

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;
	
	int n, a, b;
	cin >> n >> a >> b;

	int x = 0, y = 0, z = 0;

	int p;

	rep(i, n) {
		cin >> p;
		if (a >= p) {
			x++;
		}
		else if (b >= p) {
			y++;
		}
		else {
			z++;
		}
	}
	cout << min(x, min(y, z)) << rt;

	please AC;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define zero(a) memset(a, 0, sizeof a)

template<class T> constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y<H&&0<=x&&x<W; }

vector<vector<string>> D[4] = {
{
  {
    "x#x",
    "<<x",
    "xxx"
  },
  {
    "x#x",
    "#<x",
    "xvx"
  },
  {
    "x#x",
    "#<>",
    "x#x"
  },
  {
    "x^#",
    "x<x",
    "xxx"
  },
},
{
  {
    "x^x",
    "x^#",
    "xxx"
  },
  {
    "x#x",
    "<^#",
    "xxx"
  },
  {
    "x#x",
    "#^#",
    "xvx"
  },
  {
    "xxx",
    "x^>",
    "xx#"
  },
},
{
  {
    "xxx",
    "x>>",
    "x#x"
  },
  {
    "x^x",
    "x>#",
    "x#x"
  },
  {
    "x#x",
    "<>#",
    "x#x"
  },
  {
    "xxx",
    "x>x",
    "#vx"
  },
},
{
  {
    "xxx",
    "#vx",
    "xvx"
  },
  {
    "xxx",
    "#v>",
    "x#x"
  },
  {
    "x^x",
    "#v#",
    "x#x"
  },
  {
    "#xx",
    "<vx",
    "xxx"
  },
}
};

const string dirs = "<^>v";
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};

char G[55][55];
int H, W;

tuple<int, int, int> walk(int y, int x, int d) {
  tuple<int, int, int> next;
  rep(i, D[d].size()) {
    auto& T = D[d][i];
    assert(dirs.find(T[1][1]) == d);

    bool ok = 1;
    int ry = -1, rx = -1, rd = -1;
    REP(i, -1, 2) REP(j, -1, 2) {
      if(i == 0 && j == 0) continue;
      const int ny = y + i, nx = x + j;
      if(T[i+1][j+1] == 'x') {
        continue;
      }
      else if(T[i+1][j+1] == '#') {
        ok &= !in_range(ny, nx, H, W) || G[ny][nx] == '#';
      }
      else {
        ok &= in_range(ny, nx, H, W) && G[ny][nx] != '#';
        if(ok) {
          assert(dirs.find(T[i+1][j+1]) != string::npos);
          ry = ny, rx = nx, rd = dirs.find(T[i+1][j+1]);
        }
      }
    }
    if(ok) {
      next = make_tuple(ry, rx, rd);
    }
  }
  return next;
}

int main() {

  cin >> H >> W;
  rep(i, H) {
    cin >> G[i];
  }

  int y, x, d;

  rep(i, H) rep(j, W) {
    if(dirs.find(G[i][j]) != string::npos) {
      y = i, x = j, d = dirs.find(G[i][j]);
    }
  }

  bool vis[55][55][4]; zero(vis);
  vis[y][x][d] = 1;

  while(1) {
    auto next = walk(y, x, d);
    tie(y, x, d) = next;
    if(vis[y][x][d]) break;
    vis[y][x][d] = 1;
    if(G[y][x] == 'G') {
      int ans = 0;
      rep(i, 55) rep(j, 55)
        ans += vis[i][j][0] || vis[i][j][1] || vis[i][j][2] || vis[i][j][3];
      cout << ans << endl;
      return 0;
    }
  }

  cout << -1 << endl;
  
  return 0;
}

Measured memory_bytes: 3248
#include<iostream>
#include<cstdio>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<vector>
#include<functional>
#include<string.h>
#include<limits.h>
#include<queue>
#include<deque>
#include<stack>
#include<stdlib.h>
#include<algorithm>
#include<cmath>
#define P pair<int,int>
using namespace std;

stack<int>E;
vector<P>V;
int C[100000];
bool K[100000];
signed main() {
	int r, c, n; scanf("%d%d%d", &r, &c, &n);
	int S = (r+c) * 2;
	for (int i = 0; i < n; i++) {
		int T = 0;
		int x, y; 
		scanf("%d%d", &x, &y);
		if (y == 0) {
			T++;
			V.push_back({x,i});
			V.push_back({ x+S,i });
		}
		else if (x == r) {
			T++;
			V.push_back({ x+y,i });
			V.push_back({ x+y + S,i });
		}
		else if (y == c) {
			T++;
			V.push_back({ r+c+r-x,i });
			V.push_back({ r+c+r-x + S,i });
		}
		else if (x == 0) {
			T++;
			V.push_back({ S-y,i });
			V.push_back({ 2*S-y,i });
		}
		scanf("%d%d", &x, &y);
		if (y == 0) {
			T++;
			V.push_back({ x,i });
			V.push_back({ x + S,i });
		}
		else if (x == r) {
			T++;
			V.push_back({ x + y,i });
			V.push_back({ x + y + S,i });
		}
		else if (y == c) {
			T++;
			V.push_back({ r + c + r - x,i });
			V.push_back({ r + c + r - x + S,i });
		}
		else if (x == 0) {
			T++;
			V.push_back({ S - y,i });
			V.push_back({ 2 * S - y,i });
		}
		if (T == 2) { K[i] = true;  }
	}
	sort(V.begin(), V.end());
	for (P i : V) {
		if (!K[i.second])continue;
	}
	for (P i : V) {
		if(!K[i.second])continue;
		if (C[i.second] == 1) {
			C[i.second]--;
			if (E.top() != i.second) { puts("NO"); return 0; }
			E.pop();
		}
		else {
			C[i.second]++;
			E.push(i.second);
		}
	}
	puts("YES");
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int n;
  int a[100];
  int b[100];
  cin >> n;
  rep(i, n - 1) {
    cin >> b[i];
  }

  int ans = 0;
  a[0] = b[0];
  for(int i = 1; i < n - 1; i++) {
    a[i] = min(b[i-1], b[i]);
  }
  a[n-1] = b[n-2];
  rep(i, n) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,k;
  cin>>n>>k;
  vector<int>trees;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    trees.push_back(x);
  }
  sort(trees.begin(),trees.end());
  int ans=INT_MAX;
  for(int i=0;i<n-k+1;i++){
    if(trees[i+k-1]-trees[i]<ans){
        ans=trees[i+k-1]-trees[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 892
#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)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    decp(10);
    ll w,h,x,y;cin>>w>>h>>x>>y;
    cout<<(double)w*h/2<<" ";
    if(!(w%2)&&!(h%2)&&x==w/2&&y==h/2)cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 256
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

X = INT()
if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)
elif 1800 <= X <= 1999:
    print(1)

Measured memory_bytes: 61780
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val l = Vector.fill(n)(sc.nextInt())

  val out = l.groupBy((x: Int) => x).map { case (x: Int, cs: Vector[Int]) =>
    val c = cs.size
    if (c - x < 0) c else c - x
  }.sum
//  val out = l.toSet.toVector.map { x: Int =>
//    val c = l.count(_ == x)
//  }.sum
  println(out)
}


Measured memory_bytes: 117768
#include<bits/stdc++.h>
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define sp fixed<<setprecision
#define sz sizeof
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
bool pr[1000007];
ll fpow(ll x,ll y){x=x%MOD;ll res=1;while(y){if(y&1)res=res*x;res%=MOD;y=y>>1;x=x*x;x%=MOD;}return res;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll a[200005],h[200005];
ll t[200005*4];
ll range(ll v,ll tl,ll tr,ll l,ll r)
{
	if(l>r)
	return 0;
	else if(l==tl && r==tr)
	return t[v];
	ll tm=(tl+tr)/2;
	return max(range(2*v,tl,tm,l,min(r,tm)),range(2*v+1,tm+1,tr,max(l,tm+1),r));
}
void update(ll v,ll tl, ll tr,ll pos, ll new_val)
{
	if(tl==tr)
	t[v]=new_val;
	else
	{
		ll tm=(tl+tr)/2;
		if(pos<=tm)
		update(2*v,tl,tm,pos,new_val);
		else
		update(2*v+1,tm+1,tr,pos,new_val);
		t[v]=max(t[2*v],t[2*v+1]);
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=0;i<n;i++)
		cin>>a[i];
	memset(t,0,sizeof(t));
	for(int i=0;i<n;i++)
	{
      ll x=h[i];
			ll maxi=max(range(1,0,n,x,x),range(1,0,n,0,x-1)+a[i]);
			update(1,0,n,x,maxi);
	}
  cout<<range(1,0,n,0,n)<<"\n";


}


Measured memory_bytes: 10496
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	bs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&as[i], &bs[i])
	}

	c := 0
	for i := n - 1; i >= 0; i-- {
		a, b := as[i], bs[i]
		m := (a + c) % b
		if m == 0 {
			continue
		}
		c += b - m
	}
	fmt.Println(c)
}


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

int main () {
    char  S[3];
    cin >> S;
    bool ab[2] = {false, false};
    for(int i = 0; i < 3; i++) {
        if (S[i] == 'A') ab[0] = true;
        else ab[1] = true;
    }

    cout << ((ab[0] && ab[1]) ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
import sys
import fractions
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n, k = MAP()
h = LIST()

dp = [INF]*n
dp[0] = 0

for i in range(1,n):
    for j in range(1,min(i, k)+1):
        dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))

print(dp[n-1])


Measured memory_bytes: 78172
INF = float('inf')
N, K = map(int, input().split())
h = list(map(int, input().split()))

dp = [INF for _ in range(N)]
dp[0] = 0
for i in range(N):
    for j in range(K):
        j += 1
        if i + j < N:
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]))

print(dp[N-1])


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

typedef long long ll;
ll a[51], b[51];

ll f(int n, ll x);

int main() {
    
    int N;
    ll K;
    cin >> N >> K;

    a[0] = 1;
    b[0] = 1;
    for (int i = 1; i < 51; i++) {
        a[i] = a[i-1] * 2 + 3;
        b[i] = b[i-1] * 2 + 1;
    }

    ll ans = f(N, K);

    cout << ans << '\n';

}


ll f(int n, ll x) {
    if (n == 0) {
        if (x <= 0) return 0;
        else return 1;
    }
    else if (x <= 1 + a[n-1]) return f(n-1, x-1);
    else if (x == 2 + a[n-1]) return b[n-1] + 1;
    else if (x <= 2 + 2*a[n-1]) return b[n-1] + 1 + f(n-1, x-2-a[n-1]);
    else if (x == 3 + 2*a[n-1]) return 2 * b[n-1] + 1;
}


Measured memory_bytes: 256
import collections

n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
dc = collections.Counter(d)
tc = collections.Counter(t)
for i in tc:
    if tc[i] > dc[i]:
        print("NO")
        exit()
print("YES")

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

int main(void) {
        long long N; cin >> N;
        vector<string> str(N, "");

        for (int i=0; i<N; i++) {
                cin >> str[i];
        }
        sort(str.begin(), str.end());

        int count = 0;
        string before = "";
        for (int i=0; i<N; i++) {
                if ( before != str[i] ) {
                        count++;
                }
                before = str[i];
        }

        cout << count << endl;

        return 0;
}

Measured memory_bytes: 9600
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MOD (ll)1000000007

pll p[200001];

bool compare(pll a, pll b) {
    return a.first + a.second < b.first + b.second;
}

bool compare2(pll a, pll b) {
    return a.first - a.second < b.first - b.second;
}

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld %lld", &p[i].first, &p[i].second);

    sort(p + 1, p + 1 + n, compare);
    ll a = abs(p[1].first - p[n].first) + abs(p[1].second - p[n].second);
    sort(p + 1, p + 1 + n, compare2);
    ll b = abs(p[1].first - p[n].first) + abs(p[1].second - p[n].second);

    printf("%lld", max(a, b));
    return 0;
}


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

const int N = 100005;

int n, m, v, p;
int a[N];

bool check(int x) {
  if (x < p) return true;

  int bound = a[x] + m;
  int vote = v - (n-x) - (p-1);

  if (bound < a[p-1]) return false;
  if (vote <= 0) return true;

  long long empty = 0;
  for (int i = p-1; i < x; ++i) {
    empty += bound - a[i];
  }

  if (empty < 1LL * vote * m) return false;
  return true;
}

int main() {  
  scanf("%d %d %d %d", &n, &m, &v, &p);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }

  sort(a, a + n, greater<int>());

  int l = 0, r = n-1, ans = -1;
  while (l <= r) {
    int mid = l + r >> 1;

    if (check(mid)) {
      ans = mid;
      l = mid + 1;
    } else r = mid - 1;
  }

  // while (ans + 1 < n && a[ans] == a[ans+1]) ++ans;
  printf("%d\n", ans+1);
  return 0;
}


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

using namespace std;
int main()
{
    int n,k,sum;
    while(cin>>n>>k)
    {
        int a[55];
        sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        for(int i=n-k;i<n;i++)
        {
            sum=sum+a[i];
        }
        printf("%d\n",sum);
    }
    return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <utility>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+5;

string s;
bool A, B;

int main() {
//#define LOCAL
#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif 
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s;
	for(int i = 0; i < s.length(); ++i) {
		if(s[i] == 'A') A = true;
		if(s[i] == 'B') B = true;
	}
	if(A & B) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,char> p2;
ll cnt[100005];
void solve(){
	ll n,q,res=0;
	cin>>n;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		cnt[x]++;
		res+=x;
	}
	cin>>q;
	for(ll i=0;i<q;i++){
		ll x,y;
		cin>>x>>y;
		res+=cnt[x]*(y-x);
		cnt[y]+=cnt[x];
		cnt[x]=0;
		cout<<res<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


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

int main() {
	
	string s, t, ans = "No";
	cin >> s >> t;
	
	for(int i = s.size() - 1; i >= 0; i--){
		if(s == t){
			ans = "Yes";
			break;
		}
		char tmp = s[s.size() - 1];
		for(int j = s.size() - 1; j > 0; j--){
			s[j] = s[j - 1];
		}
		s[0] = tmp;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<deque>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

using namespace std;

#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int x,a,b;cin >> x >> a >> b;
	cout << (x-a) % b << endl;
	
	return 0;
}

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

int a[200010];

int main(){
	int k, n;
	scanf("%d%d", &k, &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	a[n] = k + a[0];
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		ans = max(ans, a[i] - a[i-1]);
	}
	printf("%d\n", k - ans);
}


Measured memory_bytes: 1024
n=int(input(""))
a=[]
b=[]
for i in range(n):
    cc=input("").split(" ")
    a+=[int(cc[0])]
    b+=[int(cc[1])]
s=0
a.sort()
b.sort()
if (n%2==0):
    s=(a[int(n/2)]+a[int(n/2)-1]-b[int(n/2)]-b[int(n/2)-1])
else:
    s=a[int((n-1)/2)]-b[int((n-1)/2)]
print(int(-s+1))


Measured memory_bytes: 25448
def main():
  def add(i,x):
    i+=1
    while i<=n:
      bit[i-1]+=x
      i+=i&-i
  def sum_sub(i):
    a=0
    i+=1
    while i:
      a+=bit[i-1]
      i-=i&-i
    return a
  def sum(i,j):
    a=sum_sub(j+1)
    if i!=0:a-=sum_sub(i-1)
    return a
  
  n,q,*x=map(int,open(0).read().split())
  a=x[:n]
  queriess=[]
  for i in range(q):
    l,r=x[n+i*2:n+(i+1)*2]
    l-=1
    r-=1
    queriess.append(r<<40|l<<20|i)
  ans=[0]*q
  queriess.sort()
  queries=[]
  for i in range(q):
    ind=queriess[i]%(1<<20)
    queriess[i]>>=20
    l=queriess[i]%(1<<20)
    queriess[i]>>=20
    r=queriess[i]
    queries.append((r,l,ind))
  queries.append((10*20,0,0))
  lastAppeared=[-1]*n
  bit=[0]*n
  j=0
  for i in range(n):
    if lastAppeared[a[i]-1]!=-1:
      add(lastAppeared[a[i]-1],-1)
      add(i,1)
      lastAppeared[a[i]-1]=i
    else:
      add(i,1)
      lastAppeared[a[i]-1]=i
    while queries[j][0]==i:
      r,l,ind=queries[j]
      j+=1
      ans[ind]=sum(l,r-1)
  print(*ans)
if __name__ == "__main__":
  main()

Measured memory_bytes: 309944
#include <iostream>
#include <queue>

int main(){
	using namespace std;
	int m, f, r;
	int points;
	unsigned int size;
	queue<int> q;
	while (1){
		cin >> m >> f >> r;
		if (m < 0 && f < 0 && r < 0)
			break;
		q.push(m);
		q.push(f);
		q.push(r);
	}

	while(!q.empty()){
		m = q.front();
		q.pop();
		f = q.front();
		q.pop();
		r = q.front();
		q.pop();

		points = m + f;
		if (m<0 || f<0 || points<30){
			cout << 'F' << endl;
		}
		else if (points >= 80){
			cout << 'A' << endl;
		}
		else if (points >= 65 && points < 80){
			cout << 'B' << endl;
		}
		else if ((points >= 50 && points < 65) || r>=50){
			cout << 'C' << endl;
		}
		else if (points >= 30 && points < 50 && r < 50){
			cout << 'D' << endl;
		}
	}

}

Measured memory_bytes: 3112
# coding: utf-8
# Your code here!
N = int(input())
A = [0] * (N+1)
Flg = True
for i in range(N):
    a = int(input())
    if a == 2:
        Flg = False
    A[i+1] = a

if Flg:
    print(-1)

else:
    ans = -1
    i = 1
    cnt = 0
    while i != 2:
        i = A[i]
        cnt += 1
        if cnt > N:
            print(-1)
            Flg = True
            break
    if Flg == False:
        print(cnt)

Measured memory_bytes: 49752
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
 
int main() {
  int n, a, b, ans = 0;
  string s;
  cin >> s;
  n = s.size();
  //vector<int> v(n), c(n);
  //if(1) {}
  //((a == b)? "Yes" : "No")
  rep(i, (n - 1)/2){
    if(s.at(i) != s.at(n - 1 - i)){
      cout << "No" << endl;
      return 0;
    }
  }
  rep(i, (n - 1)/4){
    if(s.at(i) != s.at(n/2 - 1 - i)){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

// ll cnt_at(ll hp, int depth) {
//     if(hp > 1){
//         depth++;
//         return pow(2, depth)*cnt_at(hp / 2, depth);
//     }
//     else{
//         return pow(2, depth);
//     }
// }

int main() {
    ll hp;
    cin >> hp;
    int depth = 0;
    ll ans = 0;
    while(hp > 0){
        ans += pow(2, depth);
        hp /= 2;
        depth++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3952
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

using namespace std;



int main(void)
{
	//変数の宣言
	int n;
	char s[110][11];
	int p[110];
	int a[110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	char stemp[11];


	//データの読み込み


	scanf("%d",&n);
//	scanf_s("%d",&n);

//	scanf("%s",&s);
//	scanf_s("%s",&s,5);


	for(i=0;i<n;i++){
		scanf("%s",&s[i]);
		scanf("%d",&p[i]);
//		scanf_s("%s",&s[i],20);
//		scanf_s("%d",&p[i]);
	}

/*	for(i=0;i<m;i++){
//		scanf("%d %d",&card[i].kosu,&card[i].num);
		scanf_s("%d %d",&card[i].kosu,&card[i].num);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	for(i=0;i<n;i++){
		a[i]=i+1;
	}

	for(i=0;i<n;i++){
		for(j=0;j<n-1;j++){
			if(strcmp(s[j],s[j+1])>0||(strcmp(s[j],s[j+1])==0&&p[j]<p[j+1])){
				strcpy(stemp,s[j]);
				strcpy(s[j],s[j+1]);
				strcpy(s[j+1],stemp);
				temp=p[j];
				p[j]=p[j+1];
				p[j+1]=temp;
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
		}
	}

	

	//	printf("計算部分終了\n");

	//出力
	for(i=0;i<n;i++){
		printf("%d\n",a[i]);
	}
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
for i in range(int(input())):
	c,a,n = map(int,input().split())
	cnt1 = min(c,a,n)
	c -= cnt1
	a -= cnt1
	cnt2 = min(c//2,a)
	c -= cnt2*2
	cnt3 = c//3
	print(cnt1+cnt2+cnt3)

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int N, X;
int w[100];
int sum;
int mi = 1000000;

int main()
{
	cin >> N >> X;
	rep(i, N) {
		cin >> w[i];
		sum += w[i];
		mi = min(mi, w[i]);
	}
	int res = N;
	X -= sum;
	res += X / mi;
	cout << res << endl;
	return 0;
}

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


typedef long long ll;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
  //cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N;cin >> N;
  vector<pair<ll,ll>> x(N);
  rep(i,N) cin >> x[i].first >> x[i].second;
  sort(ALL(x));
  
  pair<ll,ll> a[100][100];
  
  map<pair<ll,ll>,ll> mp;
  
  rep(i,N){
    for(int j = i + 1;j < N;j++){
        a[i][j].first = x[j].first - x[i].first;
        a[i][j].second = x[j].second - x[i].second;
        mp[MP(a[i][j].first,a[i][j].second)]++;
    }
  }
  
  int max = 0;


  for(auto i:mp){
    //cout << i.first.first<< ' ' << i.first.second << ' ' << i.second << endl;
    chmax(max,i.second);
    //cout << max << endl;
  }
  
  
  cout << N - max << endl;
  
  
}

Measured memory_bytes: 384
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil
 
#include<bits/stdc++.h>
 
using namespace std;
 
typedef complex<double> base;
typedef long double ld;
typedef long long ll;
 
#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int func(string s, int pos){
   // cout<<pos<<endl;
	if(s[pos] == 'a')
      return 1;
  	else if(s[pos]=='b')
      	return 2;
 	else if(s[pos]=='c')
      return 3;
     return 0;
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    string s1,s2, s3;
  	cin>>s1>>s2>>s3;
  	int i=0,j=0,k=0;
  	int turn = 1;
  	while(true){
    	if(turn == 1){
        	turn = func(s1, i++);
        }
        else if(turn ==2){
      	    turn = func(s2, j++);
        }
        else if(turn == 3){
      	    turn = func(s3, k++);
        }
        else 
            break;
    }
    //cout<<i<<" "<<j<<" "<<k<<endl;
  	if(i==s1.size()+1){
      	    cout<<"A"<<endl;
            //  break;
        }
  	    else if(j==s2.size()+1){
              cout<<"B"<<endl;
            //  break;
          }
      	    
 	    else if (k==s3.size()+1){
            cout<<"C"<<endl;
            //break;
         }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#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 Clear(a) a = decltype(a)()
#define all(a) a.begin(),a.end()
#define vec vector
typedef long long ll;
typedef pair<ll,ll> P;
//const ll big=998244353LL;
const ll big=1000000007LL;
const ll INF=1e18;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
  	vec<ll> dp(n+100,INF);
  	dp[0]=0;
    rep(i,n+10){
      //受け取るdpする
      for(int j=0;exp(6,j)<=i;j++){
          dp[i]=min(dp[i],dp[i-exp(6,j)]+1);
      }for(int j=0;exp(9,j)<=i;j++){
          dp[i]=min(dp[i],dp[i-exp(9,j)]+1);
      }
    }
  	cout << dp[n] << endl;
}

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

int main(){
	int m;
	cin >> m;
	while(m--){
		set<string> S;
		string s;
		cin >> s;
		for(int i = 1 ; i < s.size() ; i++){
			string a = s.substr(0,i);
			string b = s.substr(i);
			string ra = a;
			string rb = b;
			reverse(ra.begin(),ra.end());
			reverse(rb.begin(),rb.end());
			S.insert(a+b);
			S.insert(b+a);
			S.insert(a+rb);
			S.insert(rb+a);
			S.insert(b+ra);
			S.insert(ra+b);
			S.insert(rb+ra);
			S.insert(ra+rb);
		}
		cout << S.size() << endl;
	}
}

Measured memory_bytes: 1000
package main

import (
	"bufio"
	"fmt"
	"os"
	"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 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)
	for i := 0; i < n; i++ {
		x := getNextString(scanner)
		y := getNextString(scanner)

		fmt.Fprintln(writer, lcs(x, y))
	}

	writer.Flush()
}

func lcs(x, y string) int {
	lx := len(x)
	ly := len(y)
	dp := make([][]int, lx+1)
	for i := 0; i <= lx; i++ {
		dp[i] = make([]int, ly+1)
	}
	for i := 0; i < lx; i++ {
		for ii := 0; ii < ly; ii++ {
			if x[i] == y[ii] {
				dp[i+1][ii+1] = dp[i][ii] + 1
				continue
			}
			dp[i+1][ii+1] = dp[i][ii+1]
			if dp[i+1][ii] > dp[i+1][ii+1] {
				dp[i+1][ii+1] = dp[i+1][ii]
			}
		}
	}
	return dp[lx][ly]
}



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

#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll 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;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}

vector<pair<int,ll>> vec[100000];
ll cost[100000];
void dfs(int now,ll COST){
    cost[now]=COST;
    int next;
    REP(i,vec[now].size()){
        next=vec[now][i].first;
        if(cost[next]<0){
            dfs(next,COST+vec[now][i].second);
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    int a,b,c;
    REP(i,N-1){
        cin>>a>>b>>c;
        vec[a-1].pb(mp(b-1,c));
        vec[b-1].pb(mp(a-1,c));
    }
    int Q=in();
    int K=in();
    REP(i,N){
        cost[i]=-1;
    }
    dfs(K-1,0);
    int x,y;
    ll ans[Q];
    REP(i,Q){
        cin>>x>>y;
        ans[i]=cost[x-1]+cost[y-1];
    }
    REP(i,Q){
        print(ans[i]);
    }
    //debug(vec[0][0].first);
    //debug(cost[1]);
    return 0;
}


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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int A = 0; A <= a; ++A){
    for(int B = 0; B <= b; ++B){
      for(int C = 0; C <= c; ++C){
        int total = 500*A + 100*B + 50*C;
        if(total == x ) ++ans;
      }
    }
  }
  cout << ans << endl;
}

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

int main() 
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> v(n,0);
    int count = 0;
    for (int i=0; i<s.size()-1; i++)
    {
        if (s[i]=='A' && s[i+1]=='C')
            count++;
        v[i+1]=count;
    }
    for (int i=0; i<q; i++)
    {
        int l,r; cin>>l>>r;
        cout << v[r-1]-v[l-1] << "\n";
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll x;
    cin >> x;
    if (x >= 30)
        putout("Yes");
    else
        putout("No");
    return 0;
}


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

int main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	vector<int> v(101);
	for(int i=a; i<b; i++) v[i]=1;
	vector<int> w(101);
	for(int i=c; i<d; i++) w[i]=1;
	int cnt=0;
	rep(i,101){
		if(v[i]+w[i]==2) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 3572
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};

lint LCM(lint a,lint b){
  if(a==0 || b==0) return 0;
  lint tmp,r,x;
  x=a*b;
  if(a<b) tmp=a,a=b,b=tmp;
  r=a%b;
  while(r!=0) a=b,b=r,r=a%b;
  x=x/b;
  return x;
}

lint GCD(lint a,lint b){
  if(a==0 || b==0) return max(a,b);
  else return (a*b)/LCM(a,b);
}
lint num[1000001];

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    rep(i,N) num[A[i]]++;
    bool che=true;
    for(int i=2;i<=1000000;i++){
        int cnt=0;
        for(int j=i;j<=1000000;j+=i){
            if(cnt && num[j]) che=false;
            cnt+=num[j];
            if(cnt>=2) che=false;
        }
    }
    if(che){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    lint now=A[0];
    for(int i=1;i<N;i++) now=GCD(now,A[i]);
    if(now==1) cout << "setwise coprime" << endl;
    else cout << "not coprime" << endl;
}

Measured memory_bytes: 19168
import sys
inp = sys.stdin.readline

class UnionFind:
  def __init__(self, n):
    self.n = n
    self.tree = [-1] * n

  def union(self, a, b):
    a = self.root(a)
    b = self.root(b)
    if(a == b):
      return
    if(self.size(a) < self.size(b)):
      tmp = a
      a = b
      b = tmp
    self.tree[a] += self.tree[b]
    self.tree[b] = a

  def size(self, a):
    return -self.tree[self.root(a)]

  def root(self, a):
    if(self.tree[a] < 0):
      return a
    res = self.root(self.tree[a])
    self.tree[a] = res
    return res

N, M = map(int,inp().split())
A = []
B = []
for _ in range(M):
  a, b = map(int,inp().split())
  A.append(a-1)
  B.append(b-1)

uf = UnionFind(N)

res = N*(N-1)//2
result = [0] * M
for i in range(M-1, -1, -1):
  result[i] = res
  if(uf.root(A[i]) != uf.root(B[i])):
    res -= uf.size(A[i]) * uf.size(B[i])
    uf.union(A[i], B[i])

for r in result:
  print(r)

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

int main(){
int a,b,c,tmp;
cin >> a;
cin >> b;
cin >> c;

if (a > b) {
   tmp = a;
   a = b;
   b = tmp; 
}

if (a > c) {
   tmp = a;
   a = c;
   c = tmp; 
}

if (b > c) {
   tmp = b;
   b = c;
   c = tmp; 
}
cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3080