akhauriyash/Code-Regression huggingface dataset:
#ifdef Prateek
  #include "C:\Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 3e5 + 10; 

int t[4*N];

int sum(int v, int tl, int tr, int l, int r) {
    if (l > r) 
        return 0;
    if (l == tl && r == tr) {
        return t[v];
    }
    int tm = (tl + tr) / 2;
    return max(sum(v*2, tl, tm, l, min(r, tm))
          , sum(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = max(t[v*2] , t[v*2+1]);
    }
}

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n, k;
   cin >> n >> k;
   vector<int> A(n);
   for(int i = 0; i < n; ++i) {
      cin >> A[i];
   }
   int ans = 1;
   update(1, 0, N-1, A[n-1], 1);
   for(int i = n-2; i >= 0; --i) {
      int mn = max(0ll, A[i]-k);
      int mx = min(N-1, A[i]+k);
      int q = sum(1, 0, N-1, mn, mx);
      ans = max(ans, q+1);
      update(1, 0, N-1, A[i], q+1);
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 13896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int n,k;
    scanf("%d%d",&n,&k);
    if (n%k==0){
        printf("0\n");
    } else {
        printf("1\n");
    }
	return 0 ;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void){
    char str[3];
    int mem[3] = {0};
    scanf("%s",str);
    for(int i = 0;i < 3;i++){
        if(str[i] == 'a' || str[i] == 'b' || str[i] == 'c'){
            if(mem[((int)str[i]) % 97] < 1){
            mem[str[i] % 97]++;
            } else {
                printf("No");
                return 0;
            }
        } else {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int base = 0;
		int n = sc.nextInt();
		int[] b = new int[n];
		for (int i = 0; i < n; ++i) {
			b[i] = sc.nextInt();
			if (b[i] == 0)
				++base;
		}
		int Q = sc.nextInt();
		int[][] q = new int[Q][2];
		for (int i = 0; i < Q; ++i) {
			q[i][0] = sc.nextInt();
			q[i][1] = sc.nextInt();
		}
		Arrays.sort(q, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[0], o2[0]);
			}
		});
		RMQ rmq = new RMQ(n + 1);
		rmq.set(0, 0);
		int p = 0;
		for (int i = 0; i < Q; ++i) {
			while (q[i][0] - p > 1) {
				int c = b[p] == 1 ? 1 : -1;
				rmq.set(p + 1, Math.min(c + rmq.query(p), rmq.query(p + 1)));
				++p;
			}
			rmq.set(q[i][1], rmq.query(p, q[i][1] + 1));
		}
		while (n - p > 0) {
			int c = b[p] == 1 ? 1 : -1;
			rmq.set(p + 1, Math.min(c + rmq.query(p), rmq.query(p + 1)));
			++p;
		}
		System.out.println(base + rmq.query(n));
	}

	class RMQ {
		int n;
		int[] v;

		public RMQ(int n_) {
			n = 1;
			while (n < n_)
				n *= 2;
			v = new int[2 * n - 1];
			Arrays.fill(v, Integer.MAX_VALUE / 3);
		}

		void add(int k, int val) {
			k += n - 1;
			v[k] += val;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = Math.min(v[2 * k + 1], v[2 * k + 2]);
			}
		}

		void set(int k, int val) {
			k += n - 1;
			v[k] = val;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = Math.min(v[2 * k + 1], v[2 * k + 2]);
			}
		}

		int query(int a) {
			return v[a + n - 1];
		}

		int query(int a, int b) {
			return query(a, b, 0, n, 0);
		}

		int query(int a, int b, int l, int r, int k) {
			if (r <= a || b <= l)
				return Integer.MAX_VALUE / 3;
			else if (a <= l && r <= b)
				return v[k];
			else
				return Math.min(query(a, b, l, (l + r) / 2, 2 * k + 1), query(a, b, (l + r) / 2, r, 2 * k + 2));
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 161868
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> button (n);
  for (int i; i<n; i++) {
    string s;
    cin >> s;
    button[i] = stoi(s);//stoi>stringをintに変換。
  }
  int count = 1;
  int x = button.at(0);
  while(true){
    if (count == n){
      cout << -1 << endl;
      break;
    }
    else{
      if(x==2){
        cout << count << endl;
        break;
      }
      else{
        count ++;
        x = button.at(x-1);
      }
    }
  }
}    

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int a, b;
  while(input(a, b)) {
    if (a == b) cout << 2 *a  <<endl;
    else cout << 2 * max(a, b) - 1 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
int a[5020];

bool dp[5020];
bool F(int x){
	if(k-a[x]<0)return true;
	for(int i=0;i<5020;i++)dp[i]=false;
	dp[0]=true;
	for(int i=0;i<n;i++){
		if(i!=x){
			for(int j=5005;j>=0;j--){
				if(dp[j]==true&&j+a[i]<5010){
					dp[j+a[i]]=true;
				}
			}
		}
	}
	bool ok=false;
	for(int i=k-a[x];i<k;i++){
		if(dp[i]==true)ok=true;
	}
	return ok;
}//true 必要

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	
	int left=0,right=n,mid,ret=0;
	while(left<right){
		mid=(left+right)/2;
		if(F(mid)==false){
			ret=max(ret,mid+1);
			left=mid+1;
		}
		else right=mid;
	}
	cout<<ret<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<iomanip>
#include<utility>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#define ll long long
#define fi first
#define sec second
#define pb push_back
#define mp make_pair
#define rep(a,b,c) for(int a=1;a<=b;a+=c)
#define repp(a,b,c,d) for(int a=b;a<=c;a+=d)

const double PI=acos(-1);
const double EPS=1e-12;
const int MOD=1e9+7;
const int INF=1<<30;


using namespace std;

bool vis[10000005];
int dat[105];

int main(){
	//ios::sync_with_stdio(false);cin.tie(NULL);	cout.tie(NULL);
	int in,n;
	bool fl;
	cin>>in>>n;
	rep(i,in,1){
		cin>>dat[i];
	}
	repp(i,0,n,1){
		fl=vis[i]^true;
		rep(j,in,1){
			if(i+dat[j]<=n){
				vis[i+dat[j]]|=fl;
			}
		}
	}
	if(vis[n])cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}



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

using namespace std;

int main()
{
    int n; cin >> n;
    
    vector<vector<int> > c(n, vector<int>(n));
    
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            cin >> c[i][j];
        }
    }
    
    long long sum = 0;
    
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            sum += min(c[i][j], c[j][i]);
        }
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 3204
#include <iostream>

#define int long long

using namespace std;


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

    int counter = 0;
    int l = 1, r = m + 1;
    while (l < r) {
        cout << l << " " << r << endl;
        l++;
        r--;
        counter++;
    }

    l = m + 2, r = 2 * m + 1;
    while (l < r) {
        cout << l << " " << r << endl;
        l++;
        r--;
    }
    
    return 0;
}

Measured memory_bytes: 3600
using static System.Math;
using System;

class M
{
    public const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(BigMul(a, b) % MOD);
    public M(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var ans = getAns(n, k);
        Console.WriteLine(ans);
    }
    static int getAns(int n, int k)
    {
        var dp = new long[n + 1, k + 1];
        dp[0, 0] = 1;
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= k; j++)
            {
                dp[i, j] = dp[i - 1, j] * j + dp[i - 1, j - 1];
                dp[i, j] %= M.MOD;
            }
        return (int)dp[n, k];
    }
}



Measured memory_bytes: 25272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
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; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
ll f(string S){
   int N=sz(S);
   ll sum=0;
   for(ll i=0,j=0;i<N;i=j){
      while(j<N && S[i]==S[j])j++;
      sum+=(j-i)/2;
   }
   return sum;
}

int main(){
   string S;ll K;
   cin>>S>>K;
   ll N=sz(S);
   bool same=true;
   rep(i,N){
      if(S[0]!=S[i])same=false;
   }
   if(same){
      cout<<(N*K)/2<<endl;
      return 0;
   }
   ll d1=f(S);
   ll d2=f(S+S);
   ll d=d2-d1;
   cout<<d1+(K-1)*d<<endl;
}

Measured memory_bytes: 3616
#include <set>
#include <cstdio>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

int e[1000];
ll dp[1000][2];

int cycle[1000];
int flag[1000];
int in[1000];

int n, m;

const int mod = 1000000007;

int check(int i){
  if(flag[i] == 2) return -1;
  if(flag[i] == 1){
    flag[i] = 2;
    return i;
  }

  flag[i] = 1;

  if(e[i] != -1){
    int c = check(e[i]);
    if(c != -1){
      flag[i] = 2;
      cycle[i] = c;
      if(c == i) return -1;
      else return c;
    }
  }
  flag[i] = 2;

  return -1;
}

int main(){
  n = getInt();
  m = getInt();

  REP(i,n){
    e[i] = -1;
    cycle[i] = i;
    dp[i][0] = dp[i][1] = 1;
  }

  REP(i,m){
    int s = getInt() - 1;
    int d = getInt() - 1;
    e[s] = d;
  }

  REP(i,n) if(!flag[i])
    check(i);

  REP(i,n) if(cycle[i] == i && e[i] != -1 && cycle[e[i]] != i){
    int ee = cycle[e[i]];
    if(ee != -1) in[ee]++;
  }

  queue<int> que;
  ll ans = 1;

  REP(i,n) if(cycle[i] == i){
    if(in[i] == 0) que.push(i);
  }

  while(que.size()){
    int pos = que.front(); que.pop();
    flag[pos] = 5;

    if(e[pos] == -1 || cycle[e[pos]] == pos){
      ans = (ans * ((dp[pos][0] + dp[pos][1]) % mod)) % mod;
    }else{
      int next = cycle[e[pos]];
      dp[next][0] = (dp[next][0] * dp[pos][0]) % mod;
      dp[next][1] = (dp[next][1] * ((dp[pos][0] + dp[pos][1]) % mod)) % mod;
      if(--in[next] == 0)
        que.push(next);
    }
  }

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

  return 0;
}

Measured memory_bytes: 0
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

LL n, k, s;

int main(){
    cin >> n >> k >> s;
    REP(i, k)cout << s << " ";
    REP(i, n - k)cout << (s == 1000000000LL ? 999999999LL : 1000000000LL) << " ";
    cout << endl;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    set<int>s;
    s.insert(1);
    s.insert(2);
    s.insert(3);
    int x,y;
    cin>>x>>y;
    s.erase(x);
    s.erase(y);
    cout<<*s.begin()<<endl;
    return 0;
}


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

const int MAX_N = 200005;
int N, K;
int logs[MAX_N];

bool check(int maxlen) {
  if (maxlen == 0) return false;
  int k = 0;
  for (int i = N -1; i  >= 0; --i) {
    int log = logs[i];
    if (log <= maxlen) continue;
    k += log / maxlen - !(log % maxlen);
    if (k > K) return false;
  }
  return true;
}

int main() {
  scanf("%d %d", &N, &K);
  int mm = 0;

  for (int i = 0; i < N; ++i) {
    scanf("%d", logs + i);
    mm = std::max(mm, logs[i]);
  }
  std::sort(logs, logs + N);

  long long hi = 1ll<<31;
  long long lo = 0;
  while (hi - lo > 1) {
    long long mid = (hi + lo) / 2;
    if (check(mid)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  if (check(lo)) printf("%lld\n", lo);
  else printf("%lld\n", hi);
}


Measured memory_bytes: 4472
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,i,ans=0;
  	cin>>n;
  	vector<int> a(n);
  	for(i=0;i<n;i++){
		cin>>a[i];
    }
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  	for(i=0;i<n;i++){
      if(i%2==0){
        ans+=a[i];
      }else{
        ans-=a[i];
      }
    }
	cout<<ans<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,maximum=0;
    cin>>n;
    map<string,int>m;
    map<string,int>::iterator it;
    for(int i=0; i<n; i++)
    {
        string a;
        cin>>a;
        m[a]++;
        maximum=max(maximum,m[a]);
    }
    for(it=m.begin(); it!=m.end(); it++)
    {
        if(it->second==maximum)
            cout<<it->first<<endl;
    }
    return 0;
}


Measured memory_bytes: 19256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int>> m(n, vector<int>(3));
    for(int i = 0; i < n; i++){
		cin >> m[i][0] >> m[i][1] >> m[i][2];
    }
    int dp[n][3];
    dp[n-1][0] = m[n-1][0];
    dp[n-1][1] = m[n-1][1];
    dp[n-1][2] = m[n-1][2];
    for(int i = n-2; i >= 0; i--){
		dp[i][0] = max(dp[i+1][1], dp[i+1][2]) + m[i][0];
		dp[i][1] = max(dp[i+1][0], dp[i+1][2]) + m[i][1];
		dp[i][2] = max(dp[i+1][1], dp[i+1][0]) + m[i][2];
	}
	cout << max(max(dp[0][0], dp[0][1]), dp[0][2]) << endl;
	return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	int b = n / 2 - 1;
	cout << vec.at(b + 1) - vec.at(b);
}

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

const int N=1e5+5;
const int M=3e5+5;
int n,u,v,x,ans[N];
int E,ot[M],ne[M],g[N],w[M];

void add(int u,int v,int x)
{
	ot[++E]=v;
	ne[E]=g[u];
	g[u]=E;
	w[E]=x&1;
}

void init()
{
	scanf("%d",&n);int i;
	for(i=1;i<n;++i)
	{
		scanf("%d%d%d",&u,&v,&x);
		add(u,v,x),add(v,u,x);
	}
}

void dfs(int x,int fath)
{
	int p,to;
	for(p=g[x];p;p=ne[p])
	{
		to=ot[p];
		if(to==fath) continue;
		if(!w[p]) ans[to]=ans[x];
		else ans[to]=ans[x]^1;
		dfs(to,x);
	}
}

int main()
{
	init();dfs(1,0);int i;
	for(i=1;i<=n;++i) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 6528
import itertools
n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))
if p == q:
    print(0)
else:
    l = list(itertools.permutations(range(1,n+1)))
    p_i = l.index(p)
    q_i = l.index(q)
    print(abs(p_i-q_i))

Measured memory_bytes: 8052
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    int x,n;
    cin >> x >> n;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    int ans = x;
    for(int i = 0; i < 500; i++){
        rep(j,n){
            if(x - i == p[j]){
                break;
            }
            if(j == n-1){
                ans = x-i;
                goto end;
            }
        }
        rep(j,n){
            if(x + i == p[j]){
                break;
            }
            if(j == n-1){
                ans = x+i;
                goto end;
            }
        }
    }
    end:
    dunk(ans);
    return 0;
}

Measured memory_bytes: 3700
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
          
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
	// 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define endl '\n'

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

	int n;
	cin >> n;
	int h[n+1], ans[n+1];
	for(int i=1; i<=n; i++)
	{
		cin >> h[i];
		ans[i] = -1;
	}
	h[0] = h[1];
	ans[0] = ans[1] = 0;
	for(int i=2; i<=n; i++)
		if( ans[i] == -1 )
			ans[i] = min( abs(h[i]-h[i-1]) + ans[i-1] , abs(h[i]-h[i-2]) + ans[i-2] );
	cout << ans[n];
	return 0;
}

Measured memory_bytes: 1024
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      x: i32,
   }
   let mut x = x;
   let mut a = vec![];
   for _ in 0..4 {
      a.push(x % 10);
      x /= 10;
   }
   a.reverse();
   for i in 0..8 {
      let mut ans = a[0];
      for j in 0..3 {
         if (i >> j) & 1 == 1 {
            ans += a[j + 1];
         } else {
            ans -= a[j + 1];
         }
      }
      if ans == 7 {
         print!("{}", a[0]);
         for j in 0..3 {
            if (i >> j) & 1 == 1 {
               print!("+{}", a[j+1]);
            } else {
               print!("-{}", a[j+1]);
            }
         }
         println!("=7");
         return;
      }
   }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n,m,dp[1010][1010];
char s[1010][1010];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	rep(i,1,n) scanf("%s",s[i]+1);
	dp[1][1]=1;
	rep(i,1,n)
		rep(j,1,m)
		{
			if ((i==1) && (j==1)) continue;
			if (s[i][j]=='#') continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%maxd;
		}
	printf("%d",dp[n][m]);
	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dump(X) cout << #X << ' ' << X << endl
#define pe(X) cout << X << endl
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N;
ll f(vector<ll> vec){
	int sum = 0;
	int M = vec.size();
	for(int i=1;i<M-1;i++){
		if(i&1)sum += vec[i];
		else sum -= vec[i];
	}
	return vec[0]+vec[M-1]-sum;
}
ll ans[100100];
int main(){
	cin >> N;
	vector<ll> v(N);
	for(int i=0;i<N;i++){
		cin >> v[i];
	}
	ans[0]=f(v);
	for(int i=1;i<N;i++){
		ans[i] = (v[i-1]-ans[i-1]/2)*2;
	}
	for(int i=0;i+1<N;i++){
		cout << ans[i] << ' ';
	}
	cout << ans[N-1] << endl;
	return 0;
}

Measured memory_bytes: 2928
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++){
		if(i*2+(x-i)*4==y){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
  int n;
  cin>>n;
  vector<int>a;
  for(int i=0;i<n;i++)
  {
       int x;
       cin>>x;
       a.push_back(x);
  }
  sort(a.begin(),a.end());
  deque<int> emni;
  emni.push_back(a[0]);
  int mi=1,ma=n-1;
  int r=1;
  while (emni.size()<n)
  {
    if (r&1)
    {
      int x=a[ma];
      int y=(ma-1<mi)? 0 : a[ma-1];
      ma-=2;

      int f=emni.front(),b=emni.back();

      int conf1=abs(x-f)+abs(y-b);
    int conf2=abs(x-b)+abs(y-f);

      if (conf1 > conf2)
      {
        emni.push_front(x),emni.push_back(y);
      }
      else
      {
        emni.push_front(y),emni.push_back(x);
      }
    }
    else
    {
      int x=a[mi];
      int y=(mi+1>ma)? 0 : a[mi+1];
      mi+=2;

      int f=emni.front(),b=emni.back();

      int conf1=abs(x-f)+abs(y-b);
      int conf2=abs(x-b)+abs(y-f);

      if (conf1 > conf2)
      {
        emni.push_front(x),emni.push_back(y);
      }
      else
      {
        emni.push_front(y),emni.push_back(x);
      }
    }
    r++;
  }
  vector<int>ans;
  for (int i : emni)
  {
    if (i)
      ans.push_back(i);
  }

  

  int val1=0;
  for(int i=0;i<n-1;i++)
    val1+=abs(ans[i]-ans[i+1]);
  

  emni.clear();

  emni.push_back(a[n-1]);
  ma=n-2,mi=0;
  r=1;
  while (emni.size()<n)
  {
    if (r&1)
    {
      int x=a[mi];
      int y=(mi+1>ma)? 0 : a[mi+1];
      mi+=2;

      int f=emni.front(),b=emni.back();

      int conf1=abs(x-f)+abs(y-b);
      int conf2=abs(x-b)+abs(y-f);

      if (conf1 > conf2)
      {
        emni.push_front(x),emni.push_back(y);
      }
      else
      {
        emni.push_front(y),emni.push_back(x);
      }
    }
    else
    {
      int x=a[ma];
    int y=(ma-1<mi)? 0 : a[ma-1];
      ma-=2;

      int f=emni.front(),b=emni.back();

      int conf1=abs(x-f)+abs(y-b);
      int conf2=abs(x-b)+abs(y-f);

      if (conf1 > conf2)
      {
        emni.push_front(x),emni.push_back(y);
      }
      else
      {
        emni.push_front(y),emni.push_back(x);
      }
    }
    r++;
  }
  ans.clear();
  for (int i : emni)
  {
    if (i)
      ans.push_back(i);
  }



  int val2=0;
  for(int i=0;i<n-1;i++)
    val2+=abs(ans[i]-ans[i+1]);


  cout<<max(val1,val2)<<"\n";
  return 0;
}

Measured memory_bytes: 3444
/*
Dont BLUNDER
*/
#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
 
 */
//#define d long double
#define int long long
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define pi acos(-1)

#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod1=998244353;
int const mod=1000000007;
#define l first
#define r second
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// * Using PBDS *
 /*typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
                os; */
 
 
 
int modexp(int x, int n){
    if(n==0){
        return 1;
    }
    else if(n&1){
        return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
    }
    else{
        return (modexp((x*x)%mod, n/2)%mod);
    }
}
 
int modinv(int n)
{
    return modexp(n,mod-2);
}
 
int gcd(int a,int b) {
    if(b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

bool comp(pii a,pii b)
{
    return a.second>b.second;
}

int t=0;

signed main()
{
    haha
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++){
       cin>>arr[i];
   }
   sort(arr,arr+n,greater<int>());
   priority_queue<int> pq;
   int ans=0;
   ans+=arr[0];
   int curr=arr[1];
   int c=2;
   int in=1;
   
      for(int i=2;i<n;i++){
          if(c==0){
              c=2;
              in++;
              curr=arr[in];
          }
          
          ans+=curr;
          c--;
          
      }
      cout<<ans;
      
   
   

}

Measured memory_bytes: 5160
import math
n = int(input())
min_len = 15
for i in range(1, int(math.sqrt(n)+1)):
    if n % i == 0:
        k = list(map(str, [n//i, i]))
        min_len = min(min_len, len(max(k, key = lambda x:len(x))))
print(min_len)


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

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(void) {
    
    string s;
    cin >> s;
    int n = s.size() -1;
    int d[n+1];
    rep(i,n+1){
        d[i] = ctoi(s[i]);
    }

    ll ans = 0;

    rep(i, 1 << n){
        ll tmp = 0;
        ll sum = 0;
        rep(j, n){
            if(i >> j & 1){
                sum += tmp*10 + d[j];
                tmp = 0;
            }else{
                tmp = tmp * 10 + d[j];
            }
        }
        sum += tmp*10 + d[n];
        // cout << sum << endl;
        ans += sum;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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


int main() {
  int s[2], t[2];
  rep (i, 2) cin >> s[i];
  rep (i, 2) cin >> t[i];

  int yD = t[1] - s[1];
  int xD = t[0] - s[0];

  rep (i, yD) cout << "U";
  rep (i, xD) cout << "R";
  rep (i, yD) cout << "D";
  rep (i, xD + 1) cout << "L";
  rep (i, yD + 1) cout << "U";
  rep (i, xD + 1) cout << "R";
  cout << "DR";
  rep (i, yD + 1) cout << "D";
  rep (i, xD + 1) cout << "L";
  cout << "U" << endl;




  return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int H = scan.nextInt();
        int W = scan.nextInt();
        int h = scan.nextInt();
        int w = scan.nextInt();
        System.out.println((H - h) * (W - w));
        scan.close();
    }
}

Measured memory_bytes: 27104
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 1> { using type = vector<T>; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  string S, T;
  while (cin >> S >> T) {
    bool res = false;
    for (int i = 0; i < S.size(); i++) {
      res |= S == T;
      rotate(S.begin(), S.begin() + 1, S.end());
    }
    cout << (res ? "Yes" : "No") << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

char mat[7][7];
char grid[7][7];
int n, m, k;

bool Set(int r, int c){
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            mat[i][j] = grid[i][j];

    for(int i = 0; i < n; i++){
        if(r & (1 << i))
            for(int j = 0; j < m; j++)
                mat[i][j] = '@';
    }

    for(int i = 0; i < m; i++){
        if(c & (1 << i))
            for(int j = 0; j < n; j++)
                mat[j][i] = '@';
    }

    int cnt = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cnt += mat[i][j] == '#';
    return cnt == k;
}

int main(){
    cin >> n >> m >> k;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            cin >> grid[i][j];

    int ans = 0;
    for(int i = 0; i < (1<<n); i++){
        for(int j = 0; j < (1<<m); j++)
            ans += Set(i, j);
    }
    cout << ans << endl;

}


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

int main(){
    int n,total=1;
    string s;
    cin>>n>>s;
    char buf = s.at(0);
    for(int i=0;i<n;i++){
        if(buf!=s.at(i)){
            buf = s.at(i);
            total++;
        }
    }
    cout<<total<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  string w;
  cin >> w ;
  if((w[0]==w[1] && w[2]==w[3] && w[0]!=w[2]) || (w[0]==w[2] && w[1]==w[3] && w[0]!=w[1]) || (w[0]==w[3] &&w[1]==w[2] && w[0]!=w[1])){
    cout << "Yes" <<endl;
  }
    else{
      
  cout << "No" <<endl;
}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;

void solve(){
	int n,k;cin>>n>>k;vector<int> v(n) , dp(n,INT_MAX);
	for(int i=0;i<n;++i) cin>>v[i];
	dp[0]=0;
	for(int i=0;i<n;++i){
		for(int j=1;j<=k;++j){
			if(i+j<n){
				dp[i+j]=min(dp[i+j],dp[i]+abs(v[i+j]-v[i]));
			} else break;
		}
	}
	cout<<dp[n-1];
}		
 
int main(){
	//ll t;cin>>t;while(t--)	
	solve();
	return 0;
}

Measured memory_bytes: 3980
Imports System.Console
Module Module1
    Dim w As Int64
    Dim ii, iii As Int64
    Dim ans As Int64
    Dim md As Int64 = (10 ^ 9) + 7
    Dim max, min As Int64
    Dim n, k, x, t, d, m As Int64
    Sub Add(ByRef arr() As Integer, ByVal num As Integer)
        If arr Is Nothing Then
            ReDim arr(0)
            arr(0) = num
        Else
            ReDim Preserve arr(arr.Length)
            arr(arr.Length - 1) = num
        End If
    End Sub
    Sub Main()
        n = ReadLine()
        Dim d1(n), d2(n) As Integer
        Dim cout As Integer
        Dim b As Boolean
        For i = 1 To n
            Dim s() As String = ReadLine().Split
            d1(i) = s(0)
            d2(i) = s(1)
            If d1(i) = d2(i) Then
                cout += 1
            Else
                cout = 0
            End If
            If cout >= 3 Then
                b = True
            End If
        Next
        If b Then
            WriteLine("Yes")
        Else
            WriteLine("No")
        End If
        'WriteLine(ans)
        ReadLine()
    End Sub
End Module


Measured memory_bytes: 28480
n, m, Q = map(int, input().split())
memo = [[0 for i in range(n)] for i in range(n)]
for i in range(m):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    memo[l][r] += 1

for i in range(n):
    for j in range(1,n):
        memo[i][j] += memo[i][j-1]
for j in range(n):
    for i in reversed(range(n-1)):
        memo[i][j] += memo[i+1][j]

pq = []
for i in range(Q):
    p, q = map(int, input().split())
    p -= 1
    q -= 1
    pq.append([p, q])
for p, q in pq:
    print(memo[p][q])


Measured memory_bytes: 23100
#出力の仕様うざすぎる

r_length,c_length  = map(int, input().split())

spread_sheet = [[0] * (c_length) for i in range(r_length + 1)]
for i in range(r_length):
    spread_sheet[i] = list(map(int, input().split()))

total = 0
for i in range(r_length):
    calc = 0
    for j in range(c_length):
        calc += spread_sheet[i][j]

    spread_sheet[i].append(calc)
    total += calc

for i in range (c_length):
    calc = 0
    for j in range(r_length):
        calc += spread_sheet[j][i]

    spread_sheet[r_length][i] = calc

spread_sheet[r_length].append(total)


for i in range(r_length + 1):
    print(spread_sheet[i][0], end='')
    for j in range(1,c_length + 1):
        print(f' {spread_sheet[i][j]}', end='')

   # if i != r_length:
    print('')


Measured memory_bytes: 6224
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>

using namespace std;

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

int main(){

	int r, c;
	int sum = 0;
	int RC[105][105] = {};
	int sumr[105] = {};
	int sumc[105] = {};

	cin >> r >> c;
	rep(i,r)
	rep(j,c){
		cin >> RC[i][j];
	}

	rep(i,r){

		rep(j,c){

			sumr[i] += RC[i][j];
			sumc[j] += RC[i][j];
			
			cout << RC[i][j] << " ";

			if(j == c - 1){
				cout << sumr[i];
				sum += sumr[i];
			}
		}
		cout << "\n";
	}

	rep(j, c){
		cout << sumc[j] << " ";
	}

	cout << sum << "\n";

	return 0;
}

Measured memory_bytes: 1216
a,b = list(map(int, input().split()))

if(a in {1,3,5,7,8,10,12} and b in {1,3,5,7,8,10,12}):
  print("Yes")
  exit()
if(a in {4,6,9,11} and b in {4,6,9,11}):
  print("Yes")
  exit()
if(a in {2} and b in {2}):
  print("Yes")
  exit()
print("No")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    String d = br.readLine();
    StringTokenizer st1 = new StringTokenizer(str);
    StringTokenizer st2 = new StringTokenizer(d);
    
    int datalen = Integer.parseInt(st1.nextToken());
    int useNum = Integer.parseInt(st1.nextToken());
    int[] data = new int[datalen];
    int sum = 0;
    
    for (int i = 0; i < datalen; i++) {
      data[i] = Integer.parseInt(st2.nextToken());
    }
    
    Arrays.sort(data);
    
    for (int i = 0; i < useNum; i++) {
      sum += data[datalen - 1 - i];
    }
    
    System.out.println(sum);
    
  }

}


Measured memory_bytes: 22996
import java.util.Scanner;

class Main{
	public static void main(String[] a) {


		Scanner sc = new Scanner(System.in);

		int suuji[] = new int[20];

		for(int i = 1; i < 21; i++) {
			suuji[i-1] = i;
		}


		int n = sc.nextInt();

		long ans = 1;
		for(int i = n; i > 0; i--) {
			ans = ans * suuji[i-1];
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 25804
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

int N, T;
int[] L;

bool input() {
    int l, b;
    scanf("%d %d %d %d\n", &N, &T, &l, &b);
    if (N == 0 && T == 0 && l == 0 && b == 0) return false;
    L = new int[N + 1];
    foreach (i; 0 .. l) { int x; scanf("%d\n", &x); L[x] = 1; }
    foreach (i; 0 .. b) { int x; scanf("%d\n", &x); L[x] = -1; }
    return true;
}

void solve() {
    auto dp = new double[][](T + 3, N + 1);
    foreach (t; 0 .. T + 3) dp[t][] = 0;
    dp[0][0] = 1.0;
    for (int t = 0; t < T; t++) {
        //writeln(t, ": ", dp[t]);
        for (int i = 0; i < N; i++) {
            for (int d = 1; d <= 6; d++) {
                auto x = i + d;
                auto nt = t + 1;
                if (L[i] == 1) {
                    nt++;
                }
                if (x > N) x = 2 * N - x;
                if (L[x] == -1) {
                    x = 0;
                }
                dp[nt][x] += dp[t][i] / 6.0;
            }
        }
    }
    double ans = 0;
    foreach (t; 0 .. T + 1) ans += dp[t][N];
    writefln("%.10f", ans);
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define LOG(...) printf(__VA_ARGS__)
using namespace std;

struct S {
    int c, s, f;
};

S sched[500];

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

    for (int i = 0; i < N - 1; ++i) {
        int c, s, f;
        cin >> c >> s >> f;

        sched[i] = { c, s, f };
    }

    for (int s = 0; s < N; ++s) {
        int t = 0;

        for (int i = s; i < N - 1; ++i) {
            if (t > sched[i].s) {
                int r = (t - sched[i].s) % sched[i].f;
                if (r != 0)
                    t += sched[i].f - (t - sched[i].s) % sched[i].f;
            }
            else {
                t = sched[i].s;
            }

            t += sched[i].c;
        }

        cout << t << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
struct edge{int to,cost;};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%MOD;
    int memo=modpow(a,b/2);
    return memo*memo%MOD;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
    x=modpow(x,MOD-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double dist(double ax,double ay,double bx,double by){
    return sqrt((bx-ax)*(bx-ax)+(ay-by)*(ay-by));
}
string s,t;
signed main(){
    cin>>s>>t;
    cout<<t<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
using namespace std;
const int N = 2e5 + 10;
int a[N] , n;
unordered_map <int,int> mp;
int main(){
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans = 0;
    for (int i = 1; i <= n; i++){
        ans = ans + mp[i - a[i]]; // get result at [i]
        mp[a[i] + i]++; // update result at [i]
    }
    cout << ans;
    return 0;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n; cin >> n;
	for (int i = 1; i <= n; i++) {
		ll x = i;
		if(x%3==0){
			cout << " " << i;
			continue;
		}
		while (x > 0) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}


Measured memory_bytes: 3216