akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int MAXN=55;

bool  w[MAXN][MAXN],f[MAXN][MAXN][105];
int vis[MAXN];

int main()
{
    int n,m,len[3];
    scanf("%d%d",&n,&m);
    memset(w,0,sizeof(w));memset(f,0,sizeof(f));memset(vis,0,sizeof(vis));
    for (int i=0;i<3;i++) scanf("%d",&len[i]);
    for (int u,v;m--;)
    {
        scanf("%d%d",&u,&v);
        w[u][v]=true;
    }
    for (int i=1;i<=n;i++)
    {
        f[i][i][0]=true;
        for (int j=1;j<=100;j++)
            for (int k=1;k<=n;k++)
                for (int l=1;l<=n;l++)
                    if (w[l][k]&&f[i][l][j-1])
                        f[i][k][j]=true;
    }
    fill(vis+1,vis+n,INT_MAX);
    for (int now=1;now<=n;now++)
        for (int i=1;i<=n;i++)
            if (vis[i]>now)
            {
                bool flag;
                for (int j=0;j<3;j++)
                {
                    flag=false;
                    for (int k=1;k<=n;k++)
                        if (vis[k]<now&&f[i][k][len[j]])
                        {
                            flag=true;
                            break;
                        }
                    if (!flag) break;
                }
                if (flag)
                {
                    if (i==1)
                    {
                        printf("%d\n",now);
                        return 0;
                    }
                    vis[i]=now;
                }
            }
    puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 1512
// Problem : K - Stones
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_k
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{"  << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> void chmax(T& a, T b) { a = max(a, b); }
template <typename T> void chmin(T& a, T b) { a = min(a, b); }
const int MAXN = 1e5+5;
#ifndef LOCAL
#define cerr if(0)cout
#endif
bool dp[MAXN];
vector<int>v;
int32_t main() 
{
	IAMSPEED
	int n,k; cin >> n >> k;
	FOR(i,1,n) {
		int x; cin >> x;
		v.pb(x);
	}
	dp[0] = 0;
	FOR(i,1,k) {
		for(auto j:v) {
			if(i-j<0)continue;
			chmax(dp[i],!dp[i-j]);
		}
		
	}
	if(dp[k])cout<<"First";
	else cout << "Second";	
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define endl ("\n")
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,s,n)        for(int i=s;i<n;i++)
int si= 2000005;
void io()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
int dp[1005][1005];
char a[1005][1005];
int fun(int n,int m)
{
    if(dp[0][0]==-1)
        return 0;
    for(int i=0;i<m;i++)
    {
        if(dp[0][i]==-1)
            break;
        dp[0][i]=1;
    }
    for(int i=0;i<n;i++)
    {
        if(dp[i][0]==-1)
            break;
        dp[i][0]=1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(dp[i][j]==-1)
                continue;
            if(dp[i-1][j]!=-1)
                dp[i][j]=(dp[i][j]+dp[i-1][j])%1000000007;
            if(dp[i][j-1]!=-1)
                dp[i][j]=(dp[i][j]+dp[i][j-1])%1000000007;
        }
    }
    if(dp[n-1][m-1]==-1)
        return 0;
    return dp[n-1][m-1];
}
void solve()
{
    int n,m;
    cin>>n>>m;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
            if(a[i][j]=='#')
            {
                dp[i][j]=-1;
            }                
        }
    }
    cout<<fun(n,m)<<endl;
}
int32_t main()
{
    io();
    solve();
    return 0;
}

Measured memory_bytes: 12504
#include "bits/stdc++.h"
  
using namespace std;

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>>edge(N,vector<int>(N));
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;
    b--;
    edge[a][b]=c;
    edge[b][a]=c;
  }
  vector<int>box(1<<N);
  for(int i=0;i<1<<N;i++){
    for(int j=0;j<N;j++){
      if((i>>j)&1){
      	for(int k=j+1;k<N;k++){
          if((i>>k)&1)box[i]+=edge[j][k];
        }
      }
    }
  }
  vector<vector<int>>dp(1<<N,vector<int>(N,-1e9));
  for(int i=1;i<1<<N;i+=2)dp[i][0]=box[i];
  for(int i=1;i<1<<N;i+=2){
    for(int j=0;j<N;j++){
      if(!((i>>j)&1))continue;
      int bag=(1<<N)-1-i;
      int c=bag;
      while(c>0){
        for(int k=1;k<N;k++){
          if(!edge[j][k])continue;
          if((c>>k)&1) dp[i|c][k]=max(dp[i|c][k],dp[i][j]+edge[j][k]+box[c]);
        }
        c--;
        c&=bag;
      }
    }
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++)ans+=edge[i][j];
  }
  cout<<ans-dp.back().back()<<endl;
}


Measured memory_bytes: 3712
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	map<string, int> mp;
	int mx = 0;
	REP(i, N) {
		string S;
		cin >> S;
		mx = max(mx, ++mp[S]);
	}
	vector<string> v;
	for (auto itr = mp.begin();itr != mp.end();++itr) {
		if (itr->second == mx) v.push_back(itr->first);
	}

	sort(v.begin(), v.end());
	for (auto itr = v.begin();itr != v.end();++itr) {
		cout << *itr << "\n";
	}
	

	return 0;
}

					

Measured memory_bytes: 25584
/*     ####   ####  #               ####  #        ##   #    # #    # ###### #####
	  #      #    # #              #      #       #  #  ##  ## ##  ## #      #    #
	   ####  #    # #               ####  #      #    # # ## # # ## # #####  #    #
		   # #  # # #                   # #      ###### #    # #    # #      #####
	  #    # #   #  #              #    # #      #    # #    # #    # #      #   #
	   ####   ### # ###### #######  ####  ###### #    # #    # #    # ###### #    #
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<pair<LL, LL> > VP;
 
 
#define For(in) for (LL i = 0; i < (n); i++)
#define FOR(in) for(LL i=1; i <= (n); i++)
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rev(v) reverse(v.begin(), v.end())
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end());
#define exit(); return 0;
#define no "NO"
#define yes "YES"
#define con continue;
 
 
LL concate(LL a, LL b)
{
	ostringstream os;
	os <<a <<b;
	istringstream is(os.str());
	LL c;
	is>> c;
	return c;
}
 
LL binpow(LL a, LL b, LL c)
{
	a %= c;
	LL res = 1 ;
	while(b > 0){
		if(b & 1)
		res = res * a % c ;
		a = a * a % c ;
		b >>= 1;
		//cout<<res<<endl;
	}
	return res;
}
 
LL check(char vowel)
{
	return vowel=='a' || vowel=='e' || vowel=='i' || vowel=='o' || vowel=='u';
}
LL mod = 1e9+7;
 
 
int main()
{
	//LL q,t;
	//cin>>t;
	//while(t--)
	//{
	    LL a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,r=0,u=0,w=0,x=0,y=0,z=0;
		LL aa[1000];
		LL flag=0, flag1=0, co=0, co1=0, co2=0, co3=0, x1=0, x2=0, y1=0, y2=0, z1=0, z2=0;
		LL ma=0, mi=100000000;
		LL mid=0, temp=0, stop=0, start=0;
		double pi= 3.141592653589793;
		double d1=0.0, d2, d3, d4;
		VLL v,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10;
		VS vs, vs1, vs2, vs3, vs4;
		VP vp, vp1,vp2;
		char ch, ch1, ch2[1001];
		string str, str1, str2, str3, str4, str5;
		pair<LL, LL> pa;
		list<LL> li, li1;
		map<LL, LL> mp, mp1;
		set<LL> st;
		map<LL ,LL> :: iterator imll;
		VLL :: iterator ivll;
		set<LL> :: iterator isll;
		VP :: iterator ivp;
 

		cin>>str>>str1;
		rev(str);
		if(str==str1)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	//}
	exit()
 
 
}


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

int main(){
  int a , b, c , d;
  cin >> a >> b >> c;
    if(a + b == c){
      d++;
    }if (b + c  == a){
      d++;
    }if (c + a == b){
      d++;
    }
  
  if(d >= 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}
      


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;

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

  if(n%2 == 1) cout << "No";
  else if(s.substr(0, n/2) == s.substr(n/2, n/2)) cout << "Yes" << endl;
  else cout << "No";
}


Measured memory_bytes: 256
x1, y1, x2, y2 = gets.chomp.split(" ").map(&:to_i)

x3 = - y2 + y1 + x2
y3 = x2 - x1 + y2
x4 = x3 + x1 - x2
y4 = y3 + y1 -y2

print("#{x3} #{y3} #{x4} #{y4}")

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

const ll mod = 1e9+7;

ll kol[60], ans;

int n;

int main(){

    cin >> n;
    for (int i = n; i >= 1; i--){
        ll x;
        cin >> x;
        for (ll bt = 0; bt < 60; bt++){
            if (x & (1ll<<bt)){
                ans += (n-i-kol[bt])%mod*((1ll<<bt)%mod)%mod;
                if (ans >= mod)
                    ans -= mod;
                ++kol[bt];
            } else {
                ans += kol[bt]*((1ll<<bt)%mod)%mod;
                if (ans >= mod)
                    ans -= mod;
            }
        }
    }
    cout << ans;


}

Measured memory_bytes: 384
#include <stdio.h>
int main(void)
{
  int a, b, c, mint, i;
  scanf("%d %d %d",&a, &b, &c);
  for(i=a, mint=0; i <= b; mint += !(c%i++));
  printf("%d\n", mint);
  return 0;
}
  


Measured memory_bytes: 2140
import sys

def main():
  input = sys.stdin.readline
  A = list(map(int, input().split()))
  A = sorted(A)
  a = A[2] - A[0]
  b = A[2] - A[1]
  if a%2 == 0 and b%2 == 0:
    ans = a // 2 + b // 2
  elif a%2 == 1 and b%2 == 1:
    ans = a // 2 + b // 2 + 1
  else:
    ans = a // 2 + b // 2 + 2
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}

#define NUM_MAX 100000

struct pair {
    int val;
    int idx;
};

int desc_by_val(const void *a1, const void *a2) {
    struct pair *p1 = (struct pair*)a1;
    struct pair *p2 = (struct pair*)a2;
    return p2->val - p1->val;
}

int main(void) {
    int num = get_int();
    int arr[NUM_MAX];

    fget_array(arr, num);
    static struct pair odd_map[NUM_MAX+1];
    int i, j;
    for(i = 0; i <= NUM_MAX; i++) odd_map[i].idx = i;
    static struct pair even_map[NUM_MAX+1];
    for(i = 0; i <= NUM_MAX; i++) even_map[i].idx = i;

    // even
    for(i = 0; i < num; i+=2) {
        even_map[arr[i]].val++;
    }
    for(i = 1; i < num; i+=2) {
        odd_map[arr[i]].val++;
    }

    // num >= 2
    qsort(odd_map, NUM_MAX+1, sizeof(struct pair), desc_by_val);
    qsort(even_map, NUM_MAX+1, sizeof(struct pair), desc_by_val);

    
    int ans = 0;
    for(i = 0; i < 2; i++) {
        for(j = 0; j < 2; j++) {
            if(odd_map[i].idx == even_map[j].idx) continue;
            ans = max(ans, odd_map[i].val + even_map[j].val);
        }
    }

    printf("%d\n", num-ans);
    return 0;
}

Measured memory_bytes: 2736
def read():
    return int(input())

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

n,m = reads()
cnt = {k:[] for k in range(n+1)}
buf = [None]*m
for i in range(m):
    p,y = reads()
    cnt[p].append((y,i))
for p,l in cnt.items():
    if not l:
        continue
    l.sort()
    for j,(y,i) in enumerate(l):
        buf[i] = '{:06d}{:06d}'.format(p,j+1)

print('\n'.join(buf))

Measured memory_bytes: 53088
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  vector<ll> v(n+1);
  vector<ll> u(n);
  rep(i,n+1) cin >> v[i];
  rep(i,n) cin >> u[i];
  ll ans = 0;
  rep(i,n) {
    ans += min(v[i], u[i]);
    u[i] = max((ll) 0, u[i] - v[i]);
    if (u[i] == 0) continue;
    ans += min(v[i+1], u[i]);
    v[i+1] = max((ll) 0, v[i+1] - u[i]);
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 4844
import java.util.Scanner;
//なんかよくわからないやつ
class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      //入力のやつ
        int X = sc.nextInt();
        //鉄道運賃
        int Y = sc.nextInt();
        //バス運賃
        System.out.println(X + Y / 2);
        //合計運賃を計算して出力
    }
}

Measured memory_bytes: 21716
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def getDivCount(x: Int): Int = {
    var tmp = x
    var count = 0
    while (tmp % 2 == 0) {
      count += 1
      tmp = tmp / 2
    }
    count
  }


  def getDivCount2(x: Int, c: Int = 0): Int = {
    if (x % 2 != 0) c
    else getDivCount2(x / 2) + 1
  }

  @scala.annotation.tailrec
  def getDivCount3(x: Int, c: Int = 0): Int = {
    if (x % 2 != 0) c
    else getDivCount3(x / 2, c + 1)
  }


  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val a = new Array[Int](n)
    for (i <- 0 until n) {
      a(i) = sc.nextInt
    }

    val loopCount =
      a.map(v =>
        if (v % 2 == 0) getDivCount3(v)
        else 0
      ).sum
    println(loopCount)
  }
}


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

int main() {
  int n;
  cin >> n;
  vector<bool> v(52, false);
  for (int i = 0; i < n; i++) {
    string mark;
    int val;
    cin >> mark >> val;
    val--;
    if (mark == "H") {
      val += 13;
    }
    if (mark == "C") {
      val += 26;
    }
    if (mark == "D") {
      val += 39;
    }
    v.at(val) = true;
  }
  for (int i = 0; i < 52; i++) {
    if (!v.at(i)) {
      switch (i / 13) {
        case 0:
          cout << "S " << i + 1 << endl;;
          break;
        case 1:
          cout << "H " << i - 12 << endl;;
          break;
        case 2:
          cout << "C " << i - 25 << endl;
          break;
        case 3:
          cout << "D " << i - 38 << endl;
          break;
      }
    }
  }
}



Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i < 10;i++)
  {
    for(int j = 1;j < 10;j++)
    {
      if(i*j == n)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

int main(){
  int N;
  cin>>N;
  int i=1, ans= 0;
  while(i<= N){
    int cnt = 0;
    for(int k=1; k<=i; k++){
      if(i%k == 0){
        cnt++;
        // printf("i = %d, cnt = %d, k = %d\n",i, cnt, k);
      }
    }
    if(cnt == 8) ans++;
    i+=2;
  }
  cout<<ans<<endl;
}


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

using namespace std;

typedef long long int lli;

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

    int n, l, x, ll = 0, ans = 1;

    cin >> n >> x;
    for (int i=0; i<n; i++) {
        cin >> l;
        ll += l;
        if (ll <= x) ans++;
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

void Main() {
    set<int> bought;
    REP(i,3) {
        int tmp;
        cin >> tmp;
        bought.insert(tmp);
    }
    cout << bought.size() << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


Measured memory_bytes: 256
import math
import collections
def prime_diviation(n):
    factors = []
    i = 2
    while i <= math.floor(math.sqrt(n)):
        if n%i == 0:
            factors.append(int(i))
            n //= i
        else:
            i += 1
    if n > 1:
        factors.append(n)
    return factors

N = int(input())
if N == 1:
  print(0)
  exit()
#pr:素因数分解 prs:集合にしたやつ prcnt:counter
pr = prime_diviation(N)
prs = set(pr)
prcnt = collections.Counter(pr)
#print(pr, prs, prcnt)
ans = 0

for a in prs:
  i = 1
  cnt = 2*prcnt[a]
  #2*prcnt >= n(n+1)となる最大のnを探すのが楽そう
#  print(cnt)
  while cnt >= i*(i+1):
    i += 1
  ans += i - 1 
  
print(ans)  

Measured memory_bytes: 9412
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	long long t, total = 0;
	scanf("%d%lld", &n, &t);
	for(long long i = 0, prev = 0, cur; i < n; ++i)
	{
		scanf("%lld", &cur);
		if(prev + t < cur)
		{
			total += t;
		}
		else
		{
			total += cur - prev;
		}
		prev = cur;
	}
	printf("%lld\n", total + t);
}

Measured memory_bytes: 256
n, k = map(int, input().split())
BASE = 10**9 + 7

def sm(mn :int, mx :int) -> int:
    n = mx - (mn - 1)
    return int((mx + mn) * (n / 2))

cnt = 0
for i in range(k, n+2):
    mn, mx = sm(0, i-1), sm(n-(i-1), n)
    cnt += mx - (mn-1)
    cnt = cnt % BASE
print(cnt)

Measured memory_bytes: 9196
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>
#include <fstream>
#include <cfloat>
#include <complex>
using namespace std;

struct Point {
	int x, y;
};
struct City {
	Point pos;
	int population;
};
int pow(int base, int e) {
	return e == 0 ? 1 : base * pow(base, e - 1);
}
std::vector<long long int> cal_min_length(const vector<City>& cities, const vector<int>& row_pos, const vector<int>& col_pos) {
	vector<long long int> result;
	for (const auto& ci : cities) {
		int min_sum = min(abs(ci.pos.x), abs(ci.pos.y));
		for (const auto r : row_pos) {
			min_sum = min<int>(min_sum, abs(cities[r].pos.y - ci.pos.y));
		}
		for (const auto c : col_pos) {
			min_sum = min<int>(min_sum, abs(cities[c].pos.x - ci.pos.x));
		}
		result.push_back((long long int)min_sum * ci.population);
	}
	return result;
}
int main() {
	int n; cin >> n;
	vector<City> cities(n);
	for (auto& c : cities) {
		cin >> c.pos.x >> c.pos.y >> c.population;
	}
	vector<vector<long long int>> min_for_row, min_for_col; min_for_row.reserve(1 << n); min_for_col.reserve(1 << n);
	const auto max = pow(3, n);
	vector<int> row, col;
	for (auto pat = 0; pat < (1 << n); ++pat) {
		row.clear();
		auto copy = pat;
		int count{ 0 };
		for (auto i = 0; i < n; ++i) {
			if (copy & 1) {
				row.push_back(i);
				++count;
			}
			copy >>= 1;
		}
		min_for_row.push_back(cal_min_length(cities, row, col));
		min_for_col.push_back(cal_min_length(cities, col, row));
	}
	vector<long long int> result(n + 1, LLONG_MAX);
	for (auto pat = 0; pat < max; ++pat) {
		int r{ 0 }, c{ 0 };
		auto copy = pat;
		int count{ 0 };
		for (auto i = 0; i < n; ++i) {
			c <<= 1;
			r <<= 1;
			if (copy % 3 == 2) {
				++c;
				++count;
			}
			else if (copy % 3 == 1) {
				++r;
				++count;
			}
			copy /= 3;
		}
		long long int sum = 0;
		for (auto i = 0; i < n; ++i) {
			sum += min(min_for_row[r][i], min_for_col[c][i]);
		}
		result[count] = min(result[count], sum);
	}
	for (const auto r : result) {
		cout << r << endl;
	}
}

Measured memory_bytes: 14084
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<vector<LL>> dp(n, vector<LL> (3, -LINF));
    if(n%2){
        dp[0][0] = a[0];
        dp[1][1] = a[1];
        dp[2][2] = a[2];
        for (int i = 0; i < n; i++) {
            if(i+2<n){
                chmax(dp[i+2][0],dp[i][0]+a[i+2]);
                chmax(dp[i+2][1],dp[i][1]+a[i+2]);
                chmax(dp[i+2][2],dp[i][2]+a[i+2]);
            }
            if(i+3<n){
                chmax(dp[i+3][2],dp[i][1]+a[i+3]);
                chmax(dp[i+3][1],dp[i][0]+a[i+3]);
            }
            if(i+4<n){
                chmax(dp[i+4][2],dp[i][0]+a[i+4]);
            }
        }
        cout << max({dp[n-1][2],dp[n-2][1],dp[n-3][0]}) << endl;
    }
    else{
        dp[1][1] = a[1];
        dp[0][0] = a[0];
        for (int i = 0; i < n; i++) {
            if(i+2<n){
                chmax(dp[i+2][1],dp[i][1]+a[i+2]);
                chmax(dp[i+2][0],dp[i][0]+a[i+2]);
            }
            if(i+3<n) chmax(dp[i+3][1],dp[i][0]+a[i+3]);
        }
        cout << max(dp[n-1][1],dp[n-2][0]) << endl;
    }
    return 0;
}



Measured memory_bytes: 15668
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;
using pint = pair<int,int>; // 「人」と「0 or 1」
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {
        
        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        
        // 矛盾 check
        if (judge(bit)) {
            
            // bit に含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; ++i) {
                if (bit & (1 << i)) ++count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,t ;   int i,d=0;
    cin>>s>>t;
    for(i=0;i<s.size();i++)
    {
        if(s[i]!=t[i]) d++;
    }
    cout<<d<<endl;
}


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

void solve() {
    int N;
    cin >> N;
    int P[N];
    int Q[N];
    vector<int> v;
    for (int i = 0; i < N; ++i) { cin >> P[i]; v.push_back(i+1); }
    for (int i = 0; i < N; ++i) { cin >> Q[i]; }
    int i = 0;
    int a = 0;
    int b = 0;
    do {
        bool ok = true;
        for (int j = 0; j < N; ++j) {
            if (P[j] != v[j]) {
                ok = false;
                break;
            }
        }
        if (ok) a = i;

        ok = true;
        for (int j = 0; j < N; ++j) {
            if (Q[j] != v[j]) {
                ok = false;
                break;
            }
        }
        if (ok) b = i;
        i++;
    } while(next_permutation(v.begin(), v.end()));
    cout << abs(a - b) << endl;
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

def io_generator():
	return input()

#+++++++++++++++++++

def main(io):
	a=int(io())
	l= map(int, io().split())
	ll=[x for x in l if x%2==1]
	
	return 'YES' if len(ll)%2==0 else 'NO'

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	print (main(io))

Measured memory_bytes: 12136
import sys
n, m = map(int, input().split())
lr = [list(map(int ,input().split())) for i in range(m)]

l = lr[0][0]
r = lr[0][1]

for i in range(1, m):
    l = max(l, lr[i][0])
    r = min(r, lr[i][1])
    if l > r:
        print(0)
        sys.exit()

print(r - l + 1)

Measured memory_bytes: 27332
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int pre[2* maxn];

int32_t main(){
	fastio();
	int n;
	cin >> n;
	string s;
	cin >> s;
	s = '*' + s;
	for(int  i = 1; i <= n; i++){
		pre[i] = (s[i] == 'R') + pre[i - 1];
	}
	int total = pre[n];
	int ans = mod;
	for(int i = 0; i <= n; i++){
		int want =  i - pre[i];
		int curr = 0;
		int take = min(pre[n] - pre[i] , want);
		curr += take;
		want -= take;
		curr += (pre[n] - pre[i] - take);
		curr += want;
		ans = min(ans,curr);
	}
	cout << ans;
}

Measured memory_bytes: 5296
#include <bits/stdc++.h>
using i64 = long long;

i64 cnt[2020][2020];

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int main() {
    std::string s;
    std::cin >> s;
    int n = s.size();
    constexpr i64 mod = 998244353;

    std::vector<i64> fact(n + 1), inv(n + 1);
    fact[0] = 1;
    for (i64 i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    inv[n] = inverse(fact[n], mod);
    for (i64 i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;

    if (s[0] == '0') {
        cnt[1][1] = 1;
    } else if (s[0] == '1') {
        cnt[1][0] = cnt[1][1] = 1;
    } else {
        cnt[1][0] = 1;
    }

    for (int i = 2; i <= n; i++) {
        for (int j = 0; j <= i - 1; j++) {
            if (s[i - 1] == '0') {
                cnt[i][j + 1] = (cnt[i][j + 1] + cnt[i - 1][j]) % mod;
                cnt[i][j + 2] = (cnt[i][j + 2] + cnt[i - 1][j]) % mod;
            } else if (s[i - 1] == '1') {
                cnt[i][j] = (cnt[i][j] + cnt[i - 1][j]) % mod;
                cnt[i][j + 1] = (cnt[i][j + 1] + cnt[i - 1][j]) % mod;
            } else {
                if (j) cnt[i][j - 1] = (cnt[i][j - 1] + cnt[i - 1][j]) % mod;
                cnt[i][j] = (cnt[i][j] + cnt[i - 1][j]) % mod;
            }
        }
    }

    i64 ret = 0;
    for (int i = 0; i <= n; i++) {
        ret = (ret + cnt[n][i] * fact[n] % mod * inv[i] % mod * inv[n - i] % mod) % mod;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 30336
#include <iostream>

using namespace std;

int main() {
	int n;
	cin >> n;
	int k, g;
	k = g = 0;
	long long int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) {
			g++;
		} else {
			k++;
		}
	}
	if (k % 2 == 0) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}

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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; k < (n); k++)
#define repl(n) for (int l = 0; l < (n); l++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
ll modpow(ll a, ll b, ll m) {
  ll re = 1, k = 1;
  while (k <= b) {
    if (b & k) {
      re *= a;
      re %= m;
    }
    k = k << 1;
    a *= a;
    a %= m;
  }
  return re;
}
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

int main() {
  string s, t;
  cin >> s >> t;
  cout << (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]) << endl;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<int> A(5);
	for (int i = 0; i < 5; i++) cin >> A[i];
	sort(A.begin(), A.end());

	int ans = 1e9;
	do {
		int cur = 0;
		for (int i = 0; i < 5; i++) {
			cur = 10 * ((cur + 9) / 10);
			cur += A[i];
		}
		ans = min(ans, cur);
	} while (next_permutation(A.begin(), A.end()));
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
import heapq
N = int(input())
a = list(map(int, input().split()))

heap_left = []
left = 0
for i in range(N):
    left += a[i]
    heapq.heappush(heap_left, a[i])

lst_left = [left]
for i in range(N, 2 * N):
    tmp = heapq.heappushpop(heap_left, a[i])
    left = left - tmp + a[i]
    lst_left += [left]

heap_right = []
right = 0
for i in range(2 * N, 3 * N):
    right += a[i]
    heapq.heappush(heap_right, -1 * a[i])

lst_right = [right]
for i in range(2 * N -1, N-1, -1):
    tmp = heapq.heappushpop(heap_right, -1 * a[i])
    right = right - (-1 * tmp) + a[i]
    lst_right += [right]

# print (lst_left)
# print (lst_right)
ans = -1 * 10 ** 20
for i in range(N+1):
    # print (lst_left[i], lst_right[-(i+1)])
    ans = max(ans, lst_left[i]-lst_right[-(i+1)])

print (ans)

Measured memory_bytes: 120592
#include<iostream>
using namespace std;
typedef long long int ll;
#define graphsize 500007

ll parent[graphsize];

ll find(ll curr){
    if(parent[curr]!=curr){
        parent[curr] = find(parent[curr]);
        return parent[curr];
    }else{
        return parent[curr];
    }
}

void combine(ll a,ll b){
    parent[find(a)]=find(b);
}

int main(){
    for(ll i=0;i<graphsize;i++){
        parent[i]=i;
    }
    ll n,q,a,b,c,x,y;
    cin>>n>>q;
    for(ll i=0;i<q;i++){
        cin>>a>>b>>c;
        if(a==0){
            combine(b,c);
        }else{
            x=find(b);
            y=find(c);
            if(x==y){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
}

Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll count = 1;
    rep(i,n) {
        cin >> a[i];
        if (a[i] == count) count++;
    }
    ll ans;
    if (count == 1 && n > 1) ans = -1;
    else ans = n - count + 1;
    cout << ans << endl;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  double l;
  cin >> l;
  double la = l / 3;
  double ans = la * la * la;
  printf("%.12lf\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#define rep(i,N) for(ll i=0;i<N;i++)
typedef long long int ll;
using namespace std;
using vl=vector<ll>;
 
int main(){
    ll N,ans;
    cin>>N;
    vl A(N+2);
    A[0]=0;
    A[N+1]=0;
    rep(i,N){
        cin>>A[i+1];
    }
    
    vl def(N+1);
    rep(i,N+1){
        def[i]=abs(A[i+1]-A[i]);
    }
    
    ll sum=accumulate(def.begin(),def.end(),0);
    
    rep(i,N){
      ans=sum-def[i]-def[i+1]+abs(A[i+2]-A[i]);
      cout<<ans<<endl;
    }
    
    
    return 0;}

Measured memory_bytes: 2816
/* ex6-2
   Sagzar1993  */

#include <stdio.h>
#include <string.h>

#define SIZE 256

int main(void) {
    int length, mid;
    char words[SIZE];

    //文字列の入力
    fgets(words, SIZE, stdin);

    //改行を除く文字列の長さを取得
    length = strlen(words) - 1;
    //先頭と語尾の間の文字数
    mid = length - 2;

    putchar(words[0]); //先頭文字を出力
    printf("%d", mid); //間の文字数を出力
    putchar(words[length-1]); //最後の文字を出力
    printf("\n"); //改行
    
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int n, k;
    scanf("%d%d", &n, &k);
    int a[n];
    for (int i=0; i<n; i++ )
        scanf("%d", &a[i]);

    int ans = 1;
    int rest = n - k;
    while ( rest > 0 ) {
        rest -= k - 1;
        ans++;
    }

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


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

ll dp[101][101010];

int main() {
    int N, W;
    cin >> N >> W;
    vector<ll> w(N+1), v(N+1);

    rep(i, N) cin >> w[i+1] >> v[i+1];

    for (int i = 1; i <= N; ++i) {
        for (int j = W; j >= 0; --j) {
            if (j - w[i] >= 0) {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i <= W; ++i) ans = max(ans, dp[N][i]);
    cout << ans << endl;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int x,y,z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
void solve()
{
    int n; cin>>n;
    vector<int>v;
    v.resize(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
    }
    vector<int> dp(n+1);
    dp[2]=abs(v[2]-v[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n];
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var ss = S.Split('T').ToArray();
		List<int> xa = new List<int>();
		List<int> ya = new List<int>();
		for(int i=0;i<ss.Length;i++){
			if(i % 2 == 0) xa.Add(ss[i].Length);
			if(i % 2 == 1) ya.Add(ss[i].Length);
		}
		
		var H = new HashSet<int>();
		H.Add(xa[0]);
		for(int i=1;i<xa.Count;i++){
			var nxt = new HashSet<int>();
			foreach(var k in H){
				nxt.Add(k + xa[i]);
				nxt.Add(k - xa[i]);
			}
			H = nxt;
		}
		if(!H.Contains(X)){
			Console.WriteLine("No");
			return;
		}
		
		H = new HashSet<int>();
		H.Add(0);
		for(int i=0;i<ya.Count;i++){
			var nxt = new HashSet<int>();
			foreach(var k in H){
				nxt.Add(k + ya[i]);
				nxt.Add(k - ya[i]);
			}
			H = nxt;
		}
		if(!H.Contains(Y)){
			Console.WriteLine("No");
			return;
		}
		
		Console.WriteLine("Yes");
		
		
		
	}
	String S;
	int X,Y;
	public Sol(){
		S = rs();
		var d = ria();
		X = d[0]; Y = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main() {
  int a,b,ans;
  cin >> a >> b;
  if(a > b){
    ans = a;
    a--;
  }else{
	ans = b;
    b--;
  }
  if(a > b){
    ans += a;
    a--;
  }else{
	ans += b;
    b--;
  }
  cout <<ans;
  
    
}

   


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

typedef long long ll;

vector<int> a(1111);

void swap(int x,int y){
  int tmp = a[x];
  a[x] = a[y];
  a[y] = tmp;
}

int main() {
  int n; cin >> n;
  for(int i=0; i<n; i++) cin >> a[i];
  int q; cin >> q;
  for(int i=0; i<q; i++){
    int b,e,t;
    cin >> b >> e >> t;

    for(int k=0; k<(e-b); k++){
      //cout << j <<" "<< j+t << endl;
      swap(b+k,t+k);
    }

  }
  for(int i=0; i<n; i++){
    if(i!=0) cout <<" ";
    cout << a[i];
  }
  cout << endl;
}


Measured memory_bytes: 3128
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	int n,m,i,j,a,b,good,f=1,ans=0;
	cin>>n>>m;
	int h[n+1];
	vector<int> ar[n+1];
	for(i=1;i<=n;i++)
		cin>>h[i];
	for(i=0;i<m;i++)
	{
		cin>>a>>b;
		ar[a].pb(b);
		ar[b].pb(a);
	}
//	for(i=1;i<=n;i++)
//	{
//		cout<<i<<" : ";
//		for(j=0;j<ar[i].size();j++)
//			cout<<ar[i][j]<<" ";
//		cout<<endl;
//	}
	for(i=1;i<=n;i++)
	{
		if(ar[i].size()==0)
		{
//			cout<<i<<endl;
			ans++;
		}
		else
		{
			f=0;
			for(j=0;j<ar[i].size();j++)
			{
				if(h[i]<=h[ar[i][j]])
				{
					f=1;
					break;
				}
			}
			if(f==0)
			{
//				cout<<i<<endl;
				ans++;
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    
    int arr[n];
    for(int i=0;i<n;i++){cin>>arr[i];}
    
    sort(arr,arr+n);
    
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=arr[i];
        cout<<sum;
}

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

int main()
{
  bool yes = false;
  int ROW, COL, K;
  cin >> ROW >> COL >> K;
  if (K % ROW == 0 || K % COL == 0)
  {
    yes = true;
  }
  else
  {
    for (int row = 1; row <= ROW; row++)
    {
      for (int col = 1; col <= COL; col++)
      {
        int k = COL * row + (ROW - 2 * row) * col;
        if (k == K)
        {
          yes = true;
          break;
        }
      }
    }
  }
  cout << (yes ? "Yes" : "No") << endl;
}


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

int main(void)
{
 int set_time,times,a,b;
  while(1){
    cin >> set_time;
    int c=0,d=0;
    if(set_time == 0){
      break;
    }else{
      cin >> times;
      while( times !=  0){
        cin >> a  >> b ;
        c = b -a;
        d += c;
        times -= 1;
      }
      if(d >= set_time){
        cout << "OK" << endl;
      }else{
        set_time -= d;
        cout << set_time << endl;
      }
    }

  }
}

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

int main(){

    int w,a,b;
    cin >> w >> a >> b;

    if((a<b&&a+w>=b)||(a>b&&b+w>=a)||a==b){
        cout << 0 << endl;
        return 0;
    }

    if(a>b){
        cout << abs(b+w-a) << endl;
    }else{
        cout << abs(a+w-b) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

N,Y = cin.mapInt()
for x in range(N + 1):
    for y in range(N + 1):
        z = N - x - y
        if(z < 0):
            continue
        yen = 10000 * x + 5000 * y + 1000 * z
        if yen == Y:
            print("{} {} {}".format(x,y,z))
            sys.exit()

print("{} {} {}".format(-1,-1,-1))


Measured memory_bytes: 40684
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e6+10,M=21,mod=1e9+7;
ll a[N];
int32_t main(){
    ll n;
    cin >> n;
    ll ans=0;
    for (int i=0;i<n;i++){
        cin >> a[i];
    }
    for (int i=0;i<n;i++){
        ans+=a[i]/2;
        if (a[i]%2==1 && a[i+1]>0){
            a[i+1]--;
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 4384