akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		ManyFormulas game = new ManyFormulas();
		game.run();
	}
}

class ManyFormulas {
	
	String S;
	String[] nums;
	
	ManyFormulas() {
		Scanner cin = new Scanner(System.in);
		this.S = cin.nextLine();
		this.nums = new String[S.length()];
		char[] tmp = S.toCharArray();
		for (int i = 0; i < S.length(); i++) {
			nums[i] = String.valueOf(tmp[i]);
		}
	}
	
	void run() {
		boolean[] contained = new boolean[nums.length];
		long allSum = dfs(0, contained);
		System.out.println(allSum);
	}
	
	long dfs(int depth, boolean[] contained) {
		if (depth == nums.length - 1) {
			contained[contained.length - 1] = false;
			return calculateSum(contained);
		}
		return dfs(depth + 1, copyArray(contained)) + dfs(depth + 1, setFlagAtIndex(contained, depth)); 
	}
	
	long calculateSum(boolean[] contained) {
		long sum = 0;
		long tmpNum = 0;
		int digit = 1;
	
		for (int i = contained.length - 1; i >= 0; i--) {
			if (contained[i]) {
				sum += tmpNum;
				digit = 1;
				tmpNum = 0;
			} 
			tmpNum += Long.valueOf(nums[i]) * digit;
			digit *= 10;
		}
		sum += tmpNum;
		return sum;
	}
	
	boolean[] setFlagAtIndex(boolean[] arr, int index) {
		boolean[] newArr = copyArray(arr);
		newArr[index] = true;
		return newArr;
	}
	
	boolean[] copyArray(boolean[] arr) {
		boolean[] newArr = new boolean[arr.length];
		for (int i = 0; i < arr.length; i++) {
			newArr[i] = arr[i];
		}
		return newArr;
	}
	
	void printArray(boolean[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 9940
n,x=map(int,input().split())
b=[0]*(n+1)
p=[0]*(n+1)
s=[0]*(n+1)
p[0]=1
s[0]=1
for i in range(1,n+1):
    b[i]=2+b[i-1]*2
    p[i]=1+p[i-1]*2
    s[i]=b[i]+p[i]
count=0
for i in range(n):
    i=n-1-i
    if x==0:
        break
    x-=1
    if x>=s[i]:
        x-=s[i]
        count+=p[i]
        if x==0:
            break
        x-=1
        count+=1
        if x>=s[i]:
            x-=s[i]
            count+=p[i]
            break
print(count)

Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    string s;
    ll k;
    cin >> s >> k;
    int n = s.length();
    if(n >= k){
        for(int i = 0; i < n; ++i){
            if(s[i] != '1'){
                cout << s[i] << endl;
                return 0;
            }
            else{
                if(i + 1 == k){
                    cout << 1 << endl;
                    return 0;
                }
            }
        }
    }
    for(int i = 0; i < n; ++i){
        if(s[i] == '1') continue;
        cout << s[i] << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

int main(int argc, char *argv[]) {
  i64 N;
  string S;
  cin >> N;
  getchar();
  getline(cin, S);
  for(auto &c: S) {
    char d = c - 'A' + N;
    d %= 26;
    c = d + 'A';
  }
  cout << S << endl;

  return 0;
}


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

int a[100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif


	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}

	int ans = 0;
	for(int i = 1; i < N; i++){
		if(a[i] == a[i - 1]){
			a[i] = -1;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/*
                                Bismillahi-r-Rahmani-r-Rahim
                                        RhIeyAaD
                                    IIT-7th Batch,JU
*/
#include<bits/stdc++.h>
using namespace std;

#define ll              long long int
#define MAX             2134567891
#define fr(i,n)         for(i=0;i<n;i++)
#define rep(i,n)        for(i=1;i<=n;i++)
#define rev(i,a,n)      for(i=n;i>=a;i--)
#define FOR(i,a,n)      for(i=a;i<=n;i++)
#define ALL(n)          n.begin(),n.end()
#define mem(x,n)        memset(x,n,sizeof(x))
#define TC(t)           printf("Case %lld: ",t)
#define ans(t,c)        printf("Case %lld: %lld\n",t,c)
#define SETP(n)         cout<<setprecision(n)<<fixed
#define READ            freopen("F:\\Project\\Test_Case.txt","r",stdin)
#define WRITE           freopen("F:\\Project\\Output_Test.txt","w",stdout)
#define IO              ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define PAIR            pair<ll,ll>
#define MP              make_pair
#define pb(a)           push_back(a)
#define ff              first
#define ss              second
#define NL              printf("\n");
#define debug(a)        cout<<a<<" ";
#define hlw             printf("hlw\n");
#define NN              111
#define MOD             1000000007///10^9
#define N               4444 ///10^6->6 zero after 1 **

ll x[N],y[N],z[N],n;
string s,S;
vector<ll>v;
//map <ll,ll> mp;

int main()
{
    //IO;
    //while(1)
    //READ;WRITE;
{
    ll a=0,b=0,c=0,d,e,f,g,i,j,k,l,m,p,q,r,u,w,t,tc,in,mod,loc,diff,val,sz,lo,hi,mid,mn=MAX,mx=0,sum=0,ans=0;
    cin>>l>>s;
    fr(i,l)
    {
        if(s[i]=='R')x[i]=1;
        if(s[i]=='G')y[i]=1;
        if(s[i]=='B')z[i]=1;
    }

    for(i=l-1;i>=0;i--)
        x[i]+=x[i+1],y[i]+=y[i+1],z[i]+=z[i+1];



    fr(i,l)
    {
        for(j=i+1;j<l;j++)
        {
            if( (s[i]=='R' && s[j]=='G') || (s[i]=='G' && s[j]=='R') )
            {
                ans+=z[j+1];
                if(s[2*j-i]=='B')ans--,a--;
                a+=z[j+1];
            }
            if( (s[i]=='R' && s[j]=='B') || (s[i]=='B' && s[j]=='R') )
            {
                ans+=y[j+1];
                if(s[2*j-i]=='G')ans--,b--;
                b+=y[j+1];
            }
            if( (s[i]=='B' && s[j]=='G') || (s[i]=='G' && s[j]=='B') )
            {
                ans+=x[j+1];
                if(s[2*j-i]=='R')ans--,c--;
                c+=x[j+1];
            }
        }
    }
    //cout<<"a "<<a<<" b "<<b<<" c "<<c<<endl;
    cout<<ans<<endl;
}
    return 0;
}

/*

*/
/// Check for constraint 0 or 1?
/// long long or double? sqrt or division will work fine??


Measured memory_bytes: 3736
def read_i
  gets.chomp.split('').map(&:to_i)
end

s = read_i

count_0 = 0
s.each { |i| count_0 += 1 if i == 0 }
count_1 = s.count - count_0

if count_0 * count_1 == 0
  puts 0
elsif count_0 > count_1
  puts 2 * count_1
else
  puts 2 * count_0
end



Measured memory_bytes: 7676
N, A = map(int, input().split())
X = list(map(lambda x: int(x)-A, input().split()))
X_MAX = max(max(X), -min(X))
NX = N * X_MAX
dp = [[[0] * (N+1)  for i in range(N+1)] for _ in range(NX * 2 + 1)]
dp[NX][0][0] = 1
for i in range(1, N+1):
    for j in range(0, i+1):
        for k in range(NX * 2 + 1):
            if k == NX and j == 0:
                dp[k][i][j] = 1
                continue
            dp[k][i][j] += dp[k][i-1][j]
            if 0 <= k - X[i-1] < NX * 2 + 1:
                dp[k][i][j] += dp[k-X[i-1]][i-1][j-1]

print(sum(dp[NX][N]) - 1)

Measured memory_bytes: 192764
package main

import (
	"fmt"
	"math"
)

var A, B, C int

func main() {
	fmt.Scan(&A, &B, &C)
	if A <= C && C <= B {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

/*  ----------------------------------------  */

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

type XY struct {
	x int
	y int
}
type SortBy []XY

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	if a[i].x == a[j].x {
		return a[i].y > a[j].y
	}
	return a[i].x > a[j].x
}


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

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

int main(){
    int N,M;  
    cin >> N >> M;
    int ans = 0;
    if(N==1){
        cout << M << endl;
    }else{
        for(int i=1;i*N<=M;i++){
            if((M-i*N)%i == 0){
                ans = i;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> d(n);
    rep(i,n)cin>>d.at(i);
    sort(all(d));
    cout<<d.at(n/2)-d.at(n/2-1)<<endl;

}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if (c >= a && c <= b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int     ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;




int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0)
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<=n;i++)
    {
        ll j=n-i;
        if(i*2+4*j==m)
        {
            cout<<"Yes"<<nn;
            return 0;
        }

    }
    cout<<"No"<<nn;


}


/* Final check before submit :

1. array size or integer overflow.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***

*/



Measured memory_bytes: 3628
#include <stdio.h>

int selection_Sort(int A[], int N) {
	int n = 0, tmp, minj ;
	for (int i = 0; i < N-1; i++) {
	    minj = i;
		for (int j = i; j < N; j++) {
			if (A[minj] > A[j]) {
				minj = j;
			}
		}
		tmp = A[i];
		A[i] = A[minj];
		A[minj] = tmp;
		if (i != minj) n++;
		
	}
	return n;
}

int main() {
	int A[100], N, n;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);

	n = selection_Sort(A, N);
	for (int k = 0; k < N; k++) {
	    if(k > 0) printf(" ");
		printf("%d", A[k]);
	}
	printf("\n");
	printf("%d\n", n);

	return 0;
}




Measured memory_bytes: 2072
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a,n) a, a + n
using namespace std;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
using namespace std;

int h,w,m;
int main() {
    //freopen("input.txt", "r", stdin) ;
    //freopen("output.txt", "w", stdout) ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    cin>>h>>w>>m;
    set<pair<ll,ll>> lists;
    vll ycor(h+1,0);
    vll xcor(w+1,0);
    for(int i=0;i<m;i++){
        int sub1,sub2;
        cin>>sub1>>sub2;
        lists.insert({sub1,sub2});
        ycor[sub1]++;
        xcor[sub2]++;
    }
    int maxr=0;
    ll ans1=0;
    for(int i=0;i<h+1;i++){
        if(ans1<ycor[i]) {
            maxr=i;
            ans1=ycor[i];
        }
    }
    int maxc=0;
    ans1=0;
    for(int i=0;i<w+1;i++){
        if(ans1<xcor[i]){
            maxc=i;
            ans1=xcor[i];
        }
    }
    ll ans=0;
    for(int i=1;i<w+1;i++){
        ll sub=ycor[maxr]+xcor[i];
        if(lists.find(make_pair(maxr,i))!=lists.end()) sub--;
        ans=max(ans,sub);
    }
    for(int i=1;i<h+1;i++){
        ll sub=xcor[maxc]+ycor[i];
        if(lists.find(make_pair(i,maxc))!=lists.end()) sub--;
        ans=max(ans,sub);
    }
    cout<<ans;

    return 0;
}




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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  ll ans = c - min(a-b,c);
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
n, m, s, t = map(int, input().split())
edges_yen = [[]for _ in range(n)]
edges_snuuk = [[]for _ in range(n)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    edges_yen[u-1].append((a, v-1))
    edges_yen[v-1].append((a, u-1))
    edges_snuuk[u-1].append((b, v-1))
    edges_snuuk[v-1].append((b, u-1))


def dijkstra(init_v, edges):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist


dist_yen = dijkstra(s-1, edges_yen)
dist_snuuk = dijkstra(t-1, edges_snuuk)

ans = []
INF = 10**18
min_c = INF
for x, y in zip(dist_yen[::-1], dist_snuuk[::-1]):
    if x+y < min_c:
        min_c = x+y
    ans.append(10**15-min_c)
print(*ans[::-1], sep='\n')

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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10e18
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;

             
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
 
  long n; cin >> n;
  long x; cin >> x;
  long k = 3 * (n - gcd(n , x));
  cout << k << endl;  
 

#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;ll K; cin >> N >> K;
  vector<ll> A(N,0);
  FOR(i,0,N) cin >> A[i];
  sort(A.begin(), A.end());
  ll l, r, m;
  r = (ll)(1e18)+20; l = -r;
  while(r-l>1){
    m = (l+r)/2;
    auto F = [&](){
      ll cnt=0;
      FOR(i,0,N){
        int lll, rrr, mmm;
        ll X = m;
        ll smcnt=0;
        if(A[i]<0){
          lll=i; rrr=N;
          while(rrr-lll>1){
            mmm = (lll+rrr)/2;
            if(A[mmm]*A[i]<=X) rrr = mmm;
            else lll = mmm;
          }
          smcnt = (N-rrr);
        }
        else{
          lll=i; rrr=N;
          while(rrr-lll>1){
            mmm = (lll+rrr)/2;
            if(A[mmm]*A[i]<=X) lll = mmm;
            else rrr = mmm;
          }
          smcnt = (lll-i);
        }
        cnt += smcnt;
      }
      return cnt;
    };
    ll tmp = F();
    if(tmp<K) l = m;
    else r = m;
  }
  cout << r << endl;
}
//1 1 2 2 4 4-> f(0)=0/f(1)=2f(2)=4 f(3)=4 f(4)=6 f(n):n ika no kosu

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    string s;
    cin>>s;
    if(s.back()=='s')
    s+="es";
    else s+="s";
    cout<<s<<endl; 
}


Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

int A[20];

bool solve(int i, int m, int n){
    bool res;
    if(m==0) return true;
    if(i>=n) return false;
    res = solve(i+1,m,n) || solve(i+1,m-A[i],n);
    return res;
}

int main(void){
    int i,n,q,m;
    for(i=0;i<20;i++){
        A[i]=0;
    }
    cin >> n;
    for(i=0;i<n;i++){
        cin >> A[i];
    }
    cin >> q;
    for(i=0;i<q;i++){
        cin >> m;
        if(solve(0,m,n)==true) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

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

using namespace std;

int graph[400][400],n,dp[400];
bool visit[400];
vector<int> L;

void Tsort(int v){
    visit[v]=true;
    for(int i=0;i<n;i++)
        if(graph[v][i]>0 && !visit[i])Tsort(i);
    L.push_back(v);
}

int main(void){
    int m,a,b,c;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        cin >> a >> b >> c;
        graph[a][b]=c;
    }
    Tsort(0);
    reverse(L.begin(),L.end());
    for(int i=1;i<L.size();i++)
        for(int j=0;j<L.size();j++)
            if(graph[L[j]][L[i]]>0)
                dp[L[i]]=max(dp[L[i]],dp[L[j]]+graph[L[j]][L[i]]);
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <deque>
#include <set>
#include <complex>

#define P_P    const P& a, const P& b

using namespace std;

typedef long long int lint;
typedef complex<double> P;

namespace std {
bool operator < (P_P){
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
}
}
double cross(P_P){ return imag(conj(a) * b); }
double dot(P_P){ return real(conj(a) * b); }
int ccw(P a, P b, P c){
    b -= a; c -= a;
    if (cross(b, c) > 0)   return +1;
    if (cross(b, c) < 0)   return -1;
    if (dot(b, c) < 0)     return +2;
    if (norm(b) < norm(c)) return -2;
    return 0;
}
typedef vector<P> G;

G convex_hull(G ps){
    int n = ps.size(), k = 0;
    sort(ps.begin(), ps.end());
    G ch(2 * n);
    for (int i = 0; i < n; ch[k++] = ps[i++]){
        while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
    }
    for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--]){
        while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0) --k;
    }
    ch.resize(k - 1);
    return ch;
}

template<typename T> inline bool in(T& x){ return cin >> x; }
template<typename T> inline T in(){T x; cin >> x; return x; }

int main()
{
    int n;

    while (scanf("%d", &n), n){
        G g;
        for (int i = 0; i < n; i++){
            double x, y;
            scanf("%lf,%lf", &x, &y);
            g.push_back(P(x, y));
        }
        printf("%zu\n", g.size() - convex_hull(g).size());
    }
	return (0);
}

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

int main(){
    string S;
    long long K;
    cin >> S >> K;
    for(long long i=0; i<K; i++){
        if(i>=S.size()) break;
        if(S.at(i)!='1') {cout << S.at(i) << endl; return 0;} 
    }
    cout << '1' << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3776" ].parse.expand.solve == "Bad" );
	assert( [ "8080" ].parse.expand.solve == "Good" );
	assert( [ "1333" ].parse.expand.solve == "Bad" );
	assert( [ "0024" ].parse.expand.solve == "Bad" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	return ( s[ 0 ] == s[ 1 ] || s[ 1 ] == s[ 2 ] || s[ 2 ] == s[ 3 ] ) ? "Bad" : "Good";
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int no_rest = 0;
    for (int i = 0; i < m; i++){
        int a;
        cin >> a;
        no_rest += a;
    }
    if (no_rest > n){
        cout << -1 << endl;
    }
    else{
        cout << n - no_rest << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int N, K;
    cin >> N >> K;

    vector<int> person(N, 0);
    for (int i = 0; i < K; i++)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            int temp;
            cin >> temp;
            person[temp - 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (person[i] == 0)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return (0);
}

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 100005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll minim(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

ll power(ll x, ll y,ll p) 
{ 
    ll res = 1;      
     x = x % p;    
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
            y = y>>1;  
            x = (x*x) % p;   
    } 
    return res; 
}

ll modInverse(ll n,ll p) 
{ 
    return power(n, p-2, p); 
} 


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

bool comp(const point &p1,const point &p2){
	if(p1.first!=p2.first)return p1.first<p2.first;
	else return p1.second<p2.second;
}

string to(char x){
	string s(1,x);
	return s;
}

int main()
{
	fio;
	ll n,k;cin>>n>>k;
	vl a(n);
	f(n)cin>>a[i];
	vl dp(k+1,0);
	dp[0]=1;
	umpl pre_sum;
	pre_sum[0]=1;
	for(ll i=0;i<n;i++){
		for(ll j=1;j<=k;j++){
			pre_sum[j]=add(pre_sum[j-1],dp[j]);
		}		
		for(ll j=k;j>=0;j--){
			if((j-a[i])>=0){
				dp[j]=add(dp[j],sub(pre_sum[j-1],pre_sum[j-a[i]-1]));
			}else{
				dp[j]=add(dp[j],pre_sum[j-1]);
			}
		}
	}
	cout<<dp[k]<<endl;
}

Measured memory_bytes: 5156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  int n,x,t;
  scanf("%d%d%d",&n,&x,&t);
  int count=1;
  for(int i=1;i<n;i++){
    if(x*i<n){
      count++;
    }else{
      break;
    }
  }
  printf("%d\n",count*t);
  return 0;
}

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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

class UnionFind {
    public:
        UnionFind(){}
        UnionFind(int size) { Init(size); }
        // size: Union-Find で扱いたい要素の数
        void Init(int size) { m_Data.assign(size, -1); }

        // x と y の属する集合を併合
        // 既に一緒な集合内にいるなら false を
        // 新たに併合されたなら true を返す
        bool Unite(int x, int y) {
            x = Find(x), y = Find(y);
            if(x == y) { return (false); }
            if(m_Data[x] > m_Data[y]) { swap(x, y); }
            m_Data[x] += m_Data[y];
            m_Data[y] = x;
            return (true);
        }

        // 要素 k が属する集合の根を返す
        int Find(int k) {
            if(m_Data[k] < 0) { return (k); }
            return (m_Data[k] = Find(m_Data[k]));
        }

        // 要素 k と同じ集合の要素数を返す
        int Size(int k) { return (-m_Data[Find(k)]); }

        // 要素のうち独立しているグループの数 O(NlogN)
        int GetGroupNum() {
            map<int, bool> groups;
            for(int i = 0; i < m_Data.size(); ++i) { groups[Find(i)] = true; }
            return static_cast<int>(groups.size());
        }

    private:
        vector<int> m_Data;
};

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.Unite(a, b);
    }
    int ans = uf.GetGroupNum() - 1;
    print(ans);

    return 0;
}


Measured memory_bytes: 9288
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

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

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

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

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=300010;
int n;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n;
	cout<<3ll*n*n;
}




Measured memory_bytes: 256
<?php
$one = str_split(trim(fgets(STDIN)), 1);

foreach ($one as $key => $item) {
    if ($key % 2 !== 0) {
        if (!in_array($item, ['L', 'U', 'D'])) {
            echo 'No' . PHP_EOL;
            exit;
        }
    } else {
        if (!in_array($item, ['R', 'U', 'D'])) {
            echo 'No' . PHP_EOL;
            exit;
        }
    }
}

echo 'Yes' . PHP_EOL;



Measured memory_bytes: 4728
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor
#https://atcoder.jp/contests/tenka1-2018-beginner/tasks/tenka1_2018_c
#C - Align
"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
A = [0] * N
ais = [0] * N

for i in range(N):
    A[i] = gi()

A.sort()
base = 0
half_i = N // 2

for i in range(half_i):
    base -= 2 * A[i]

for i in range(half_i, N):
    base += 2 * A[i]

el = 0
ol_l = 0
ol_h = 0

if N % 2 == 0:
    el = base - A[half_i] + A[half_i - 1]

if (N >= 3 and N % 2):
    ol_l = base - 3 * A[half_i] + A[half_i - 1]
    ol_h = base - A[half_i] - A[half_i + 1]

print(max(el, ol_l, ol_h))

#HLHL


Measured memory_bytes: 17864
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Team {
  int index;
  int cnts[10];
  int solved;
  int penalty;
  Team() {;}
  bool operator<(const Team &rhs) const {
    if (solved != rhs.solved) { return solved < rhs.solved; }
    if (penalty != rhs.penalty) { return penalty > rhs.penalty; }
    return index < rhs.index;
  }
  void ac(int t, int p) {
    solved++;
    penalty += t + cnts[p] * 20;
  }
  void wa(int t, int p) {
    cnts[p]++;
  }
};

Team teams[100];
int M, T, P, R;
int main() {
  while (cin >> M >> T >> P >> R, M) {
    MEMSET(teams, 0);
    REP(i, T) { teams[i].index = i; }
    REP(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--; p--;
      if (j == 0) {
        teams[t].ac(m, p);
      } else {
        teams[t].wa(m, p);
      }
    }
    sort(teams, teams + T);
    reverse(teams, teams + T);
    REP(i, T) {
      printf("%d", teams[i].index + 1);
      if (i != T - 1) {
        if (teams[i].solved == teams[i + 1].solved && teams[i].penalty == teams[i + 1].penalty) {
          printf("=");
        } else {
          printf(",");
        }
      }
    }
    puts("");
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[2005][2005];   // dp[i][j] 前 i 个人放了 j 个左边的
ll n,ma;
struct stu
{
    ll pos,w;
}a[2004];
bool cmp(stu u,stu v)
{
    return u.w>v.w;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i].w);
        a[i].pos=i;
    }
    sort(a+1,a+n+1,cmp);
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        memset(dp[i],-1,sizeof(dp[i]));
        for(int j=0;j<=i;j++)
        {
            // dp[i][j]=max(dp[i-1][j-1]+a[i].w*abs(a[i].pos-n+i-j-1),
            //             dp[i-1][j]+a[i].w*abs(a[i].pos-j));
            if(dp[i-1][j]!=-1){
            dp[i][j]=max(dp[i][j],dp[i-1][j]+a[i].w*abs(a[i].pos-n+i-j-1));    // 放在右边
            dp[i][j+1]=max(dp[i][j+1],dp[i-1][j]+a[i].w*abs(a[i].pos-j-1));    // 放在左边
            }
        }
    }
    for(int i=0;i<=n;i++)
    {
        ma=max(ma,dp[n][i]);
    }
    cout<<ma;
    return 0;
}


Measured memory_bytes: 35160
import java.util.Scanner;
import java.util.Arrays;

public class Main{

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

        // input
        final int NUM = scan.nextInt();
        int[][] points = new int[NUM+1][3];
        points[0] = new int[]{0, 0, 0};
        for(int i = 1; i <= NUM; i++){
            points[i][0] = scan.nextInt();
            points[i][1] = scan.nextInt();
            points[i][2] = scan.nextInt();
        }

        // sort
        Arrays.sort(points, (a, b) -> Integer.compare(a[0], b[0]));

        // search
        String answer = "Yes";
        for(int i = 1; i <= NUM; i++){
            int grace = points[i][0] - points[i - 1][0];
            int distance = Math.abs(points[i][1] - points[i-1][1]) + Math.abs(points[i][2] - points[i-1][2]);
            if(grace >= distance ){
                if((grace % 2 == 0 && distance % 2 == 0) || (grace % 2 == 1 && distance % 2 == 1) ){
                    
                } else {
                    answer = "No";
                    break;
                }
            } else {
                answer = "No";
                break;
            }
        }

        // answer
        System.out.println(answer);

    }
}

Measured memory_bytes: 98088
from collections import deque
lunlun=[i for i in range(1,10)]
def bfs(K):
    d=deque([1,2,3,4,5,6,7,8,9])
    while(len(lunlun)<K):
        s=d[0]
        d.popleft()
        n=[]
        if(s%10!=0):
            n.append((s%10-1)+s*10)
        n.append(s%10+s*10)
        if(s%10!=9):
            n.append((s%10+1)+s*10)
        lunlun.extend(n);d.extend(n)
K=int(input())
bfs(K)
print(lunlun[K-1])

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

int64_t m,n,res=1e18;

void Special(int64_t m,int64_t n)
{
    int64_t minn=(m/3)*n;
    int64_t maxn=(m/3+1)*n;
    res=min(res,maxn-minn);
}

int main()
{
    cin>>m>>n;
    if(m%3==0||n%3==0)
        cout<<0;
    else
    {
        Special(m,n);
        for(int i=0;i<=m;i++)
        {
            int64_t s1=i*n;
            int64_t s2=(m-i)*(n/2);
            int64_t s3=m*n-s1-s2;
            res=min(res,max(max(s1,s2),s3)-min(min(s1,s2),s3));
        }
        swap(m,n);
        Special(m,n);
        for(int i=0;i<=m;i++)
        {
            int64_t s1=i*n;
            int64_t s2=(m-i)*(n/2);
            int64_t s3=m*n-s1-s2;
            res=min(res,max(max(s1,s2),s3)-min(min(s1,s2),s3));
        }
        cout<<res;
    }
}


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

int main()
{
  int n;
  cin >> n;
  switch (n % 10)
  {
  case 3:
    cout << "bon" << endl;
    return 0;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon" << endl;
    return 0;
  default:
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)
#define pii pair<int, int>
#define vii vector<pair<int, int>>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define endl "\n"


int32_t main() {
    FAST
    int n;
    cin >> n;
    vi vec(n), dp(n);
    REP(i, 0, n)
        cin >> vec[i];
    dp[0] = 0;
    dp[1] = abs(vec[1] - vec[0]);
    REP(i, 2, n) {
        dp[i] = min(dp[i - 1] + abs(vec[i] - vec[i - 1]), dp[i - 2] + abs(vec[i] - vec[i - 2]));
    }

    cout << dp[n - 1] << endl;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;


string LCS(string A,string B){
    int m=A.sz(),n=B.sz();
	int dp[m+1][n+1];

	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++)
			dp[i][j]=0;
	}

	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(A[i-1]==B[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	//return dp[m][n];
    string res="";
    int x=m,y=n;

    while(x>0 && y>0){
        if(dp[x][y]==dp[x-1][y])
            x--;
        else if(dp[x][y]==dp[x][y-1])
            y--;
        else{
            res+=A[x-1];
            x--;
            y--;
        }
    }

    reverse(res.begin(),res.end());

    return res;
}

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    string s,t;
    cin >> s >> t;

    cout << LCS(s,t) << endl;

    return 0;
}


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

constexpr int INF = 2000000000;

int main(){

    int N,M,X;
    cin >> N >> M >> X;
    vector<int> price(N,0);
    vector<vector<int>> As(N, vector<int>(M,0)); 
    int i,j;

    for(i=0;i<N;++i){
        cin >> price[i];
        for(j=0;j<M;++j){
            cin >> As[i][j];
        }
    }

    int pattern(0);
    int ans(INF), tmp(0);
    vector<int> knowledges(M,0);

    for(pattern=0;pattern<(1 << N);pattern++){
        tmp = 0;
        for(j=0;j<M;++j){
            knowledges[j] = 0;
        }
        for(i=0;i<N;++i){
            if((pattern >> i) & 1 == 1){
                tmp += price[i];
                for(j=0;j<M;++j){
                    knowledges[j] += As[i][j];
                }
            }
        }

        for(j=0;j<M;++j){
            if(knowledges[j] < X) break;
        }
        if(j==M) ans = min(ans,tmp);
    }

    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
 

    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>

using namespace std;

const int N_MAX = 100;
int N, W;
int w[N_MAX+10], v[N_MAX+10];
int dp[N_MAX+10][10200] = {};

int main() {
  int i, j;
  scanf("%d %d", &N, &W);
  for (i = 0; i < N; i++) {
    scanf("%d %d", &v[i], &w[i]);
  }
  for (i = 0; i < W+1; i++) {
    dp[0][i] = 0;
  }
  for (i = 0; i < N; i++) {
    for (j = 0; j < W+1; j++) {
      if (j < w[i]) {
	dp[i+1][j] = dp[i][j];
      } else {
	dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
      }
    }
  }
  int ans = dp[N][W];
  //for (i = 0; i < N+1; i++) {
  //  for (j = 0; j < W+1; j++) {
  //    printf("%d ", dp[i][j]);
  // }
  //  printf("\n");
  // }
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 6764
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

string S,T;
int len_s,len_t,minn=0x3f3f3f3f;

int main(){
	cin>>S>>T;
//	cout<<S<<endl<<T;
	len_s=S.size(),len_t=T.size();
	for(int i=0;i+len_t-1<len_s;i++){
		int ans=0;
		for(int j=i;j<=i+len_t-1;j++) if(T[j-i]!=S[j]) ans++;
		minn=min(minn,ans);
//		cout<<i<<" "<<ans<<endl; 
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
l = [[0 for i in range(10)] for i in range(10)]
for i in range(1, N+1):
    l[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(1, 10):
    for j in range(i, 10):
        if i == j:
            ans += l[i][j] * l[j][i]
        else:
            ans += l[i][j] * l[j][i] * 2
print(ans)

Measured memory_bytes: 3064
N = int(input())
P = [int(input()) - 1 for i in range(N)]

A = [0] * N
for i, p in enumerate(P):
    A[p] = i

cnt, res = 1, 0
for i in range(N - 1):
    if A[i] < A[i + 1]:
        cnt += 1
    else:
        res = max(res, cnt)
        cnt = 1
res = max(res, cnt)
print(N - res)

Measured memory_bytes: 20904
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long[] bar = new long[N];
    long sum = 0;
    for(int i=0; i<N; i++){
      bar[i] = sc.nextLong();
      sum += bar[i];
    }
    long ans = sum;
    long temp = 0;
    for(int i=0; i<N-1; i++){
      temp += bar[i];
      ans = Math.min(ans, Math.abs(sum - temp - temp));
    }
    System.out.print(ans);
  }
}


Measured memory_bytes: 93336
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long 
signed main() 
{
    IOS;    
    int n,m,k;
    cin>>n>>m>>k;
    set<int>st;
    for(int x=0;x<=n;x++){
    	for(int y=0;y<=m;y++){
    		st.insert(m*x+n*y-2*x*y);
    	}
    }
    if(st.count(k)>0)cout<<"Yes";
    else cout<<"No";
    return 0; 
} 


Measured memory_bytes: 16476
# ABC064 C - Colorful Leaderboard
N = int(input())
A = list(map(int,input().split()))

C = set()
Tourist = 0

for a in A:
    if 1<=a<=399:
        C.add('Glay')
    elif 400<=a<=799:
        C.add('Brown')
    elif 800<=a<=1199:
        C.add('Green')
    elif 1200<=a<=1599:
        C.add('Water')
    elif 1600<=a<=1999:
        C.add('Blue')
    elif 2000<=a<=2399:
        C.add('Yellow')
    elif 2400<=a<=2799:
        C.add('Orange')
    elif 2800<=a<=3199:
        C.add('Red')
    elif 3200<=a:
        C.add('Tourist')
        Tourist += 1

MIN = len(C) - (1 if Tourist >= 1 else 0)
MAX = len(C) + (Tourist -1 if Tourist >= 1 else 0)

if Tourist == N:
    MIN = 1

print(MIN,MAX)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

#define lowbit(x) (x&(-x))
#define MAX(a,b) (a<b?b:a)
#define MIN(a,b) (a<b?a:b)
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e7;
const int maxn = 3e5 + 5;
ll mod = 1e9 + 7;

int n, m, a[maxn],p[maxn];

int find(int x)
{
	return (x == p[x] ? x : p[x] = find(p[x]));
}

void merge(int u, int v)
{
	u = find(u); v = find(v);
	if (u != v)
	{
		p[u] = v;
	}
}

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= 2*n; i++) p[i] = i;
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", a + i);
		merge(i, n + a[i]);
	}
	while (m--)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		merge(u, v);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans += (find(i) == find(n + i));
	}
	printf("%d", ans);
}

Measured memory_bytes: 1408