akhauriyash/Code-Regression huggingface dataset:
from math import sqrt
N = int(input())
M = int((sqrt(4*N+1)-1)/2)
ans = 0
a = 1
while a <= M:
  if N % a == 0:
    m = N // a - 1
    ans += m if m > 0 and N % m == a else 0
  a += 1
print(ans)

Measured memory_bytes: 40684
using System;

namespace C
{
	class Program
	{
		static void Main(string[] args)
		{
			long n = int.Parse(Console.ReadLine());
			long div = (long)1e9 + 7;
			long all = 1;
			long non0 = 1;
			long non9 = 1;
			long non0non9 = 1;

			for (int i = 0; i < n; i++)
			{
				all = all * 10 % div;
				non0 = non0 * 9 % div;
				non9 = non9 * 9 % div;
				non0non9 = non0non9 * 8 % div;
			}

			var ans = (all - non0 - non9 + non0non9) % div;
			if (ans < 0)
			{
				ans += div;
			}

			Console.WriteLine(ans);
		}
	}
}


Measured memory_bytes: 27516
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<math.h>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<set>
using namespace std;

signed main() {
	int a, b; cin >> a >> b;
	vector<string>V;
	V.push_back("");
	for (int c = 0; c < b + 2; c++)V[0] += "#";
	for (int c = 0; c < a; c++) {
		V.push_back("#");
		string d; cin >> d;
		V[c + 1] += d;
		V[c + 1] += "#";
	}
	V.push_back("");
	for (int c = 0; c < b + 2; c++)V[a+1] += "#";
	for (string T : V) {
		cout << T << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[100010],b[100010];
int main(void){
    scanf("%s",a+1);
    int cnt=0;
    for(int i=strlen(a+1);i>=1;i--){
        b[++cnt]=a[i];
    }
    for(int i=1;i<=strlen(a+1);i++){
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    for(int i=1;i<=strlen(a+1);i++){
        if(a[i]==b[i]) continue;
        else{
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 512
a1 = gets.split(" ").map(&:to_i)
a2 = gets.split(" ").map(&:to_i)
a3 = gets.split(" ").map(&:to_i)
c = [a1,a2,a3]
ans = "Yes"
 if c[0][0] - c[0][1] != c[1][0] - c[1][1] || c[2][0] - c[2][1] != c[1][0] - c[1][1] || c[2][0] - c[2][1] != c[0][0] - c[0][1]
     ans = "No"
 end
 if c[0][1] - c[0][2] != c[1][1] - c[1][2] || c[2][1] - c[2][2] != c[1][1] - c[1][2] || c[2][1] - c[2][2] != c[0][1] - c[0][2]
     ans = "No"
 end
if c[0][0] - c[1][0] != c[0][1] - c[1][1] || c[0][1] - c[1][1] != c[0][2] - c[1][2] || c[0][2] - c[1][2] != c[0][0] - c[1][0]
     ans = "No"
end
if c[2][0] - c[1][0] != c[2][1] - c[1][1] || c[2][1] - c[1][1] != c[2][2] - c[1][2] || c[2][2] - c[1][2] != c[2][0] - c[1][0]
     ans = "No"
end

puts ans

Measured memory_bytes: 1788
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    K = i_input()
    print("ACL" * K)

if __name__ == "__main__":
    main()


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n+1);
    vector<int> b(m+1);
    cin>>a[n];
  cin >> b[m];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++) cin >> b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(a[n]<b[0]) cout << "No War" << endl;
    else cout <<"War"<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>

const double EPS=1e-10;

#define equals(a, b) (fabs((a)-b(b))<EPS)
#define X real()
#define Y imag()

using namespace std;

typedef complex<double> Point;
typedef complex<double> Vector;

struct Segment {
    Point p1, p2;
};
typedef Segment Line;

struct Circle {
    Point c;
    double r;
    Circle(Point c=Point(), double r=0.0) :
        c(c),r(r){}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b) {
    return a.X*b.X + a.Y*b.Y;
}

double cross(Vector a,Vector b) {
    return a.X*b.Y - a.Y*b.X;
}

Point project(Segment s, Point p) {
    Vector base=s.p2-s.p1;
    double r=dot(p-s.p1,base) / norm(base);
    return s.p1+base*r;
}

int main() {
    Segment s;
    {
        double x1,y1;
        double x2,y2;
        cin>>x1>>y1>>x2>>y2;
        s=Segment({Point(x1,y1),Point(x2,y2)});

    }
    int q;
    cin>>q;
    while(q-->0) {
        double x1,y1;
        cin>>x1>>y1;
        Point p=Point(x1,y1);
        Point x=project(s,p);
        printf("%.10f %.10f\n",x.X,x.Y);
    }
    return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <regex>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    VI v(n + 1, 0);
    REP(i,n) {
        cin >> v[i + 1];
    }
    
    sort(v.begin(), v.end());
    REP(i,v.size()) {
        if (i % 2 == 0) {
            v[i] = 24 - v[i];
        }
    }
    
    long ans = 24;
    REP(i,v.size()) {
        REPI(j,i+1,v.size()) {
            long d = abs(v[j] - v[i]);
            ans = min(ans, min(d, 24 - d));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,m,l=map(int,input().split())
A=[[0 for c in range(m)]for d in range(n)]
B=[[0 for e in range(l)]for f in range(m)]
for a in range(n):
    A[a]=list(map(int,input().split()))
for b in range(m):
    B[b]=list(map(int,input().split()))
sum=[[0 for g in range(l)]for h in range(n)]
for i in range(n):
    for j in range(l):
        for k in range(m):
            sum[i][j]=sum[i][j]+A[i][k]*B[k][j]
        if j!=l-1:
            print(sum[i][j],end=' ')
        else:
            print(sum[i][j])


Measured memory_bytes: 7048
#include<iostream>
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  bool b[50];
  for(int i=1;i<=m;i++)b[i]=1;
  for(int i=0;i<n;i++){
    int k;cin>>k;
    bool b1[50];
    for(int i=1;i<=m;i++)b1[i]=0;
    for(int j=0;j<k;j++){
      int p;cin>>p;
      b1[p]=1;
    }
    for(int i=1;i<=m;i++)b[i]=b[i]*b1[i];
  }
  int ans=0;for(int i=1;i<=m;i++)if(b[i])ans++;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,x) for(int i=head[x];i+1;i=nxt[i])
#define rep2(i,a,b) for(int i=(a);i<(b);i++)
#define ff first
#define ss second
using namespace std;
const int N=200005;
const int inf=1e9+7;
typedef long long ll;
//------------------------------------------head---------------------------------------------------//
int main()
{
	ll a,b,c,d,n;scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&n);
	ll f1=min(4ll*a,min(2ll*b,c));
	ll f2=min(f1*2ll,d);
	ll ans=(n/2ll)*f2;
	if(n&1)ans+=f1;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <cctype>
#include <set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define INF 10000000007
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main(){
    int v,e; cin >> v >> e;
    vector<unordered_map<int, ll>> edges(v);
    queue<int> q;
    set<int> se;
    vector<vector<ll>> table(v, vector<ll>(v, INF));
    rep(i, e) {
        ll s, t, d; cin >> s >> t >> d;
        edges[s][t] = d;
        table[s][t] = d;
        if(se.find(s) == se.end()) {
            se.insert(s);
            q.push(s);
        }
    }

    rep(i, v) {
        table[i][i] = 0;
    }
    int itr = 0;
    while(!q.empty()) {
        if(itr > 1000000) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
        itr++;
        int popped = q.front();
        q.pop();
        for(auto it = edges[popped].begin(); it != edges[popped].end(); it++) {
            for(int i = 0; i < v; i++) {
                if(table[i][popped] == INF)
                    continue;
                if(table[i][popped] + it->second < table[i][it->first]) {
                    table[i][it->first] = table[i][popped] + it->second;
                    q.push(it->first);
                }
            }
        }
    }
    rep(i, v) {
        rep(j, v) {
            if(table[i][j] == INF) {
                cout << "INF";
            } else {
                cout << table[i][j];
            }
            if(j != v-1)
                cout << ' ';
        }
        cout << endl;
    }
}




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

string a,b;
int dp[3005][3005];
int mp[3005][3005];

void func( ){


    for(int i=0;i<=a.size();i++){
        for(int j=0;j<=b.size();j++){
             if(i==0 || j==0)
                dp[i][j]=0;

             else{
                if(a[i-1]==b[j-1]){
                    dp[i][j]=1+dp[i-1][j-1];
                    mp[i][j]=3;
                }

                else{
                   if(dp[i-1][j]>dp[i][j-1]){
                    dp[i][j]=dp[i-1][j];
                    mp[i][j]=2;
                   }

                   else{
                    dp[i][j]=dp[i][j-1];
                    mp[i][j]=1;
                   }


                }
             }
        }
    }




}


int main(){
    string s="";


    cin>>a>>b;

    func();


    if(a.size()==0 || b.size()==0){
        cout<<s<<endl;
        return 0;
    }





    int i,j=b.size(),e=0;
    for(i=a.size();i>=0;i--){
         for( ; j>=0; j--){
            if(mp[i][j]==3){
                s+=a[i-1];
                j--;
                break;
            }

            else if(mp[i][j]==2){
                break;
            }

            if(j==0)
                break;



         }

         if(j==0)
            break;


    }

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

    cout<<s<<endl;




}


Measured memory_bytes: 70784
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> h(n+1);
  vector<int> ok(n);
  long long max=1000000001;
  long long ans=0;
  int length=0;
  h[n]=1000000001;
  cin>>h[0];
  for(int i=1;i<n;i++){
    cin>>h[i];
    if(h[i]<=h[i-1]){
      //      max=h[i];
      length++;
      if(ans<length) ans=length;
    }
    else{
      max=1000000001;
      length=0;
    }
  }
    cout<<ans<<endl;
    return 0;
  }


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

int main() {
  int N;
  cin >> N;
  long long ans = 1;
  bool ngFlg = false;
  for(int i=0;i<N;i++) {
  	long long A;
 	cin >> A;
    if(A == 0) {
      cout << 0 << endl;
      return 0;
    }
    if(ngFlg || 1000000000000000000/ans < A) {
	  ngFlg = true;
    }
  	ans*= A;
  }
  if(ngFlg){
    cout << -1 << endl;
  }
  else 
    cout << ans << endl;
}


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

int main(){
  int N;cin>>N;
  int A[N+10],B[N+10];for(int i=0;i<N;i++)cin>>A[i],B[i]=A[i];
  sort(B,B+N);
  int cnt=0;
  for(int i=0;i<N;i++){
    if(A[i]!=B[i]){
      cnt++;
    }
  }
  if(cnt<=2)cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int v[100000][2];
    int i = 0, j;
    int temp;

    do{
       scanf("%d %d", &v[i][0], &v[i][1]);
       if (v[i][0] > v[i][1])
       {
           temp = v[i][0];
           v[i][0] = v[i][1];
           v[i][1] = temp;
       }
       i++;
    }while(v[i - 1][0] != 0 || v[i - 1][1] != 0);

    for (j = 0; j < i - 1; j++)
    {
         printf("%d %d\n", v[j][0], v[j][1]);
    }

    return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin  >> s;
    ios::sync_with_stdio(false);
    int sum=0;
    for (int i=0;i<s.length();++i){
        sum += s[i]-'0';
    }
    if (sum %9 == 0){
        cout << "Yes";

    }else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3780
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    l = list(map(int, input().rstrip('\n').split()))
    l.sort()
    t = 0
    for i in range(len(l)-1):
        t += l[i]
    print("Yes" if t > l[-1] else "No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(void) {
    int count=0;
    char s[4096], p[4096];
    char u[12] = "END_OF_TEXT"; 
    scanf("%s", p);
    while(1){
    scanf("%s", s);
    if(strcmp(s,u) == 0){
    break;
    }
for(int i = 0; s[i] != '\0'; i++){
  s[i] = tolower(s[i]);
}

    if(strcmp(s, p) == 0) {
    count++;
    }
}
printf("%d\n",count);

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  cout << vec[N/2]-vec[N/2-1] << endl;
}

Measured memory_bytes: 640
x[3]={1,0,0};
main(t)
{
  char a,b;
  for(;~scanf(" %c,%c",&a,&b);)
    {
      a-=65;b-=65;
      t=x[a];
      x[a]=x[b];
      x[b]=t;
    }
  for(t=0;t<3;t++)
    x[t]&&printf("%c\n",65+t);
  exit(0);      
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  char op;
  cin >> a >> op >> b;
  while(op!='?'){
    int c;
    if(op=='+') c=a+b;
    if(op=='-') c=a-b;
    if(op=='*') c=a*b;
    if(op=='/') c=a/b;
    cout << c << endl;
    cin >> a >> op >> b;
  }
  return 0;
}


Measured memory_bytes: 3088
#include<stdio.h>

int MAX_X = 9;
int MAX_Y = 9;


int main ( int argc, char **argv )
{

    int x,y = 0;
    for ( x = 1; x <= MAX_X; x++ ) {
        for ( y = 1; y <= MAX_Y; y++ ) {
            printf("%dx%d=%d\n", x, y, ( x * y ));
        }
    }

    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int a, l;
    cin >> a >> l;
    if(l % 2 != 0)
        cout << "No";
    else if(l >= 2 * a && l <= 4 * a)
        cout << "Yes";
    else
        cout << "No";
}









Measured memory_bytes: 3612
#include <iostream>

using namespace std;

int main(){
	int e; cin >> e;
	while(e){
		int min = 1 << 21;
		for(int i = 0; i * i * i <= e; i++){
			for(int j = 0; j * j + i * i * i <= e; j++){
				if(e - (i * i * i + j * j) + j + i < min){
					min = e - (i * i * i + j * j) + j + i;
				}
			}
		}
		cout << min << endl;

		cin >> e;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

ll modpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}
ll modinv(ll a, ll m) {
    return modpow(a, m - 2, m);
}

int main() {
    init();

    string s; cin >> s;
    int n = s.length();
    ll p = 2019;
    ll fil = 1;
    ll ans = 0, now = 0;
    map<ll, ll> m;
    ++m[0];
    rFOR(i, 0, n) {
        now = (now + fil * (s[i] - '0')) % p;
        ans += m[now];
        ++m[now];
        fil = (fil * 10) % p;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define min_pq priority_queue<pll, vector<pll>, greater<pll> >
#define vpii vector<pair<int,int> >
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define modulo %
#define moduloe %=

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
ll add(ll a, ll b) {a+=b; while(a >= mod) a-= mod; while(a<0) a+= mod;}
ll mul(ll a, ll b) {return (a * 1LL *b % mod);}
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 500006;
const lf EPS = 0.000000001;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

ll a[nn], dp[nn];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        ll k;
        cin>>n>>k;
        rep(i,n)
            cin>>a[i];
        dp[0] = 0;
        for(i=1;i<n;i++)
        {
            dp[i] = 1e18;
            for(j=1;j<=k;j++)
            {
                if(i-j>=0)
                    dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
            }

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

    }
    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

int main() {
    int a, b, c = 0, p1, p2, p3, p4;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
        p4 = (i % 10);
        if (p4 == 0)
            continue;
        p1 = i / 10000 % 10;
        p2 = i / 1000 % 10;
        p3 = i / 10 % 10;
        if (p1 == p4 && p2 == p3)
            c++;
    }
    cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int a, b;
    cin >> a >> b;
    
    int diff = b-a;

    int a_ans = 0;

    REP(i, diff) {
        a_ans += i;
    }

    cout << a_ans-a << endl;


    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, y = map(int, input().split())
ans =[-1, -1, -1]
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        if i * 10 + j * 5 + k == y / 1000:
            ans = [i, j, k]
ans = [str(a) for a in ans]
print(' '.join(ans))

Measured memory_bytes: 40812
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)

	xs := make([]int, n)
	for i := 0; i < n; i++ {
		var tmp int
		fmt.Scan(&tmp)
		xs[i] = tmp
	}

	const minX = 1
	const maxX = 100
	min := 10000000
	for p := minX; p <= maxX; p++ {
		sum := 0
		for _, x := range xs {
			sum += int(math.Pow(float64(x-p), 2.0))
		}
		if sum < min {
			min = sum
		}
	}
	fmt.Println(min)
}


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

#define f(i, q) for(int i = 0; i < q; i++)  

typedef long long ll;

int main() {
    int n, l, ans;
    cin >> n >> l;

    int sum = 0;
    f(i, n) sum += l + i;

    if ( l <= 0 &&  0 <= n + l - 1) {
        //nothing;
    } else if (n + l - 1 < 0) {
        sum -= n + l - 1;
    } else if (l > 0) {
        sum -= l;
    } 

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

Measured memory_bytes: 256
#coding:utf-8

H,W=map(int,raw_input().split())
a=[]
for i in range(H):
    aa=map(int,raw_input().split())
    a.append(aa)

history=[]
for i in range(H):
    for j in range(W-1):
        if a[i][j]%2==1:
            a[i][j]-=1;a[i][j+1]+=1
            history.append((i,j,i,j+1))
for i in range(H-1):
    if a[i][W-1]%2==1:
        a[i][W-1]-=1
        a[i+1][W-1]+=1
        history.append((i,W-1,i+1,W-1))
print(len(history))
for h in history:
    print("%d %d %d %d"%(h[0]+1, h[1]+1, h[2]+1, h[3]+1))


        





Measured memory_bytes: 21252
K ,A, B = map(int,input().split())

if B - A <= 2 or K <= A: #交換しても増やせないorお金をビスケットに交換できない
    ans = K + 1
else:
    n = K - (A + 1)
    n_loop =  n // 2
    n_tataku = n % 2
    ans = B + n_loop * (B-A) + n_tataku
print(ans)


Measured memory_bytes: 2940
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	const p = args[1].map(arg => parseInt(arg, 10))
	let flg = false

	let t2 = true
	for (let k = 0; k < n; k++) {
		if ((k + 1) !== p[k]) t2 = false
	}
	if (t2) flg = true
	
	for (let i = 0; i < n; i++) {
		for (let j = (i + 1); j < n; j++) {
			const t1 = p.slice()
			t1[i] = p[j]
			t1[j] = p[i]
			let t2 = true
			for (let k = 0; k < n; k++) {
				if ((k + 1) !== t1[k]) t2 = false
			}
			if (t2) flg = true
		}
	}

	if (flg) console.log('YES')
	else console.log('NO')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
const ll M = 1e6 + 10;
vint table(M);
vint pf(int n)
{
    vint res;
    while (n > 1)
    {
        res.push_back(table[n]);
        int div=table[n];
        while (n % div == 0)
            n /= div;
    }
    return res;
}
int main()
{

    iota(all(table), 0);
    for (ll i = 2; i * i < M; i++)
    {
        if (table[i] < i)
            continue;
        for (ll j = i; i * j < M; j++)
        {
            if (table[i * j] == i * j)
                table[i * j] = i;
        }
    }

    int N;

    cin >> N;
    vint cnt(M);
    int g = 0;
    for (size_t i = 0; i < N; i++)
    {
        int a;
        cin >> a;
        auto p = pf(a);
        for (auto &&d : p)
        {
            cnt[d]++;
        }
        g = gcd(a, g);
    }
    bool pw = true;
    for (auto &&i : cnt)
    {
        if (i > 1)
            pw = false;
    }
    if (pw)
    {
        cout << "pairwise coprime";
    }
    else if (g == 1)
    {
        cout << "setwise coprime";
    }
    else
    {
        cout << "not coprime";
    }

    return 0;
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

int main() {
    string L;
    cin >> L;
    /*
    ll a0b0 = 1;
    ll a1b0 = 1;
    ll a0b1 = 1;
    */
    ll lax = 0;
    ll strict = 1;
    for (char c: L) {
        if (c == '0') {
            lax = 3 * lax % MOD;
            strict = strict;
        } else if (c == '1') {
            lax = (strict + 3 * lax) % MOD;
            strict = 2 * strict % MOD;
        }
        PRINT(lax);
        PRINT(strict);
    }
    ll result = (lax + strict) % MOD;
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main()
{
    long long x; cin >> x;
    long long y = 1;
    for (int i = 1; i <= x; i++) {
        y *= i;
        y %= 1000000007;
    }
    cout <<y;
    return 0;
}

Measured memory_bytes: 3572
(defun dfs (graph v n visited)
  (let ((all-visited-p t))
    (dotimes (i n)
      (if (null (aref visited i))
          (setf all-visited-p nil)))
    (if all-visited-p
        1
        (let ((res 0))
          (dotimes (i n)
            (if (and (aref graph v i)
                     (null (aref visited i)))
                (setf (aref visited i) t
                      res (+ res (dfs graph i n visited))
                      (aref visited i) nil)))
          res))))

(let* ((n (read))
       (m (read))
       (graph (make-array `(,n ,n) :initial-element nil))
       (visited (make-array n :initial-element nil)))
  (dotimes (i m)
    (let ((a (1- (read)))
          (b (1- (read))))
      (setf (aref graph a b) t
            (aref graph b a) t)))
  (setf (aref visited 0) t)
  (format t "~A~%" (dfs graph 0 n visited)))


Measured memory_bytes: 23136
n = int(input())
p = list(map(int, input().split()))
lst = list(range(1,n+1,1))
x = 0
for i in range(len(lst)):
  if lst[i]==p[i]:
    continue
  else:
    x+=1
if (x==0)|(x==2):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
 
const int MAXN = 256;
 
int maxi;
int n;
int d[MAXN];
bool vis[MAXN], vis2[MAXN];
 
int nextPos(int pos, int m) {
  int npos = min(pos + m, n-1);
  npos += d[npos];
  npos = min(npos, n-1);
  npos = max(npos, 0);
  return npos;
}
 
void rec(int pos) {
  vis[pos] = true;
  for(int m = 1; m <= maxi; ++m) {
    int npos = nextPos(pos, m);
    if(vis[npos]) continue;
    rec(npos);
  }
}
 
bool rec2(int pos) {
  vis2[pos] = true;
  if(pos == n-1) return true;
  for(int m = 1; m <= maxi; ++m) {
    int npos = nextPos(pos, m);
    if(vis2[npos]) continue;
    if(rec2(npos)) return true;
  }
  return false;
}
 
int main() {
  while(cin >> maxi && maxi) {
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> d[i+1];
    n += 2;
    d[0] = d[n-1] = 0;
    fill(vis, vis+n, false);
    rec(0);
    bool res = true;
    for(int i = 0; i < n; ++i) {
      if(vis[i]) {
    fill(vis2, vis2+n, false);
    if(!rec2(i)) {
      res = false;
      break;
    }
      }
    }
    if(res) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//素因数分解 (配列)
vector<vector<ll>> prime_fact(ll n) {
	auto is_prime = [] (ll n) {
		if (n == 1) return false;
		if (n == 2) return true;
		if (n % 2 == 0) return false;
		ll m = sqrt(n);
		for (ll i = 3; i <= m; i += 2) {
			if (n % i == 0) return false;
		}
		return true;
	};

	vector<vector<ll>> v(0);
	if (n % 2 == 0) {
		ll cnt = 0;
		while (n % 2 == 0) {
			n /= 2;
			cnt++;
		}
		v.push_back({2, cnt});
	}
	for (ll i = 3; i <= n; i += 2) {
		if (i % (ll)1e6 == 1) {
			if (is_prime(n)) {
				v.push_back({n, 1});
				break;
			}
		}
		if (n % i) continue;
		ll cnt = 0;
		while (n % i == 0) {
			n /= i;
			cnt++;
		}
		v.push_back({i, cnt});
	}
	return v;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;

	vector<vector<ll>> v = prime_fact(n);

	ll ans = 0;
	for (auto i : v) {
		ll x = i[1], y = 1;
		while (x >= y) {
			ans++;
			x -= y;
			y++;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	ll x;
	cin >> x;
	ll money = 100, count = 0;

	while (money < x) {
		money += money / 100;
		count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3576
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    else:
        s = 0
        l = []
        for _ in range(n):
            d, p = map(int, input().split())
            s += d * p
            l.append((p,d))

        l.sort()
        while m > 0 and l:
            a, b = l.pop()
            if m >= b:
                s -= a * b
                m -= b
            else:
                s -= a * m
                m = 0

        print(s)


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

int a, b, c;

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


Measured memory_bytes: 256
N = int(input())
xus = []
for _ in range(N):
    xus.append([e for e in input().split(" ")])

cum = 0.0
for x, u in xus:
    x = float(x)
    if u == "JPY":
        cum = cum + x
    else:
        cum = cum + 380000.0 * x
print(cum)



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

using namespace std;

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

int n,x,a,ans,mmin=0x7fffffff,vis[1005];

int main()
{
	x=read();n=read();
	for(int i=1;i<=n;++i)
		vis[read()]=1;
	for(int i=0;i<=500;++i)
		if(!vis[i])
			if(fabs(i-x)<mmin)
			{
				mmin=fabs(i-x);
				ans=i;
			}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using pii = pair<int, int>;

vector <int> arr;
vector <int> sorted_arr;
int main()
{
	usecppio
	int n;
	cin >> n;
	arr.resize(n);
	sorted_arr.resize(n);
	for (int i = 0; i<n; i++)
	{
		cin >> arr[i];
		sorted_arr[i] = arr[i];
	}
	sort(all(sorted_arr));
	for (int i = 0; i<n; i++)
	{
		cout << (sorted_arr[n-1]==arr[i]?sorted_arr[n-2]:sorted_arr[n-1]) << '\n';
	}
}

Measured memory_bytes: 3200
#include <iostream>
//#include <bits/stdc++.h>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define pb(x) push_back(x)
#define F first
#define S second
using namespace std;
const int N=101;
int arr[2*N];
int n;

void solve(){
	scanf("%d",&n);
	loop(i,0,2*n){
		scanf("%d",&arr[i]);
	}
	int sum=0;
	sort(arr,arr+2*n);
	for(int i=2*n-2;i>=0;i=i-2){
		sum+=arr[i];
	}
	cout<<sum;
}


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



	return 0;
}




Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<chrono>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;

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

	int n;
	cin>>n;
	int a[100005];
	a[0]=0;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	a[n+1]=0;

	int beg[100005];
	int end[100005];
	for(int i=1;i<=n;i++)
	{
		beg[i]=abs(a[i]-a[i-1])+beg[i-1];
		end[n-i+1]=abs(a[n-i+1]-a[n-i+2])+end[n-i+2];
	}

	for(int i=1;i<=n;i++)
	{
		cout<<beg[i-1]+end[i+1]+abs(a[i+1]-a[i-1])<<'\n';
	}
	return 0;
}

Measured memory_bytes: 2432
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M, X, Y = MAP()
x = LIST()
y = LIST()

max_x = max(x)
min_y = min(y)

for Z in range(X+1, Y+1):
	if max_x < Z <= min_y:
		print("No War")
		break
else:
	print("War")


Measured memory_bytes: 3900
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)(n);++i)
#define rep1(i, n) for (int i=1;i<=(int)(n);++i)
#define range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int counter[200010];

signed main()
{
	int N, K; cin >> N >> K;
	vi A(N);
	rep(i, N) {
		counter[read()]++;
	}
	vector<pii> data;
	rep(i, N + 1) {
		if (counter[i] > 0) {
			data.PB(counter[i], i);
		}
	}

	sort(all(data));

	int sz = data.size();

	if (sz <= K) {
		cout << 0 << endl;
	} else {
		int ans = 0;

		rep(i, sz - K) {
			ans += data[i].fst;
		}

		cout << ans << endl;
	}
}




Measured memory_bytes: 10552
#include <bits/stdc++.h>
#define MOD 1000000007
#define INT long long int
using namespace std;
INT n;

int main()
{
    ios::sync_with_stdio(false);
    scanf("%lld",&n);
    if( n%2 == 0 ) printf("%.10f\n", 0.5);
    else printf("%.10f\n", (double)(n/2+1)/n);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

void dfs(vector<int> &v, int now_n, int next, int &ans, vector<int> &a, vector<int> &b, vector<int> &c, vector<int> &d, int m, int n){
    int q = a.size();

    v.push_back(next);

    // for(int i = 0;i < v.size();++i){
    //     cout << v[i];
    // }
    // cout << endl;

    if(now_n == n-1){
        int tmp_ans = 0;
        for(int i = 0;i < q;++i){
            if(v[b[i]] - v[a[i]] == c[i]){
                tmp_ans += d[i];
            }
        }
        ans = max(ans, tmp_ans);

    }else{
        for(int i = next;i <= m;++i){
            dfs(v, now_n+1, i, ans, a, b, c, d, m, n);
        }
    }

    v.pop_back();

    return;

}

int main(void){
    int n, m, q;
    cin >> n >> m >> q;

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

    int ans = 0;
    for(int i = 1;i <= m;++i){
        vector<int> v;
        dfs(v, 0, i, ans, a, b, c, d, m, n);
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int main(){
  int N;cin>>N;
  vector<P> a_l(N),b_l(N);
  for (int i = 0; i < N; i++) {
    cin>>a_l[i].second>>a_l[i].first;
  }
  for (int i = 0; i < N; i++) {
    cin>>b_l[i].first>>b_l[i].second;
  }
  sort(b_l.begin(),b_l.end());
  sort(a_l.begin(),a_l.end(),greater<P>());
  vector<bool> check(N, false);
  int cnt=0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(a_l[j].second<b_l[i].first&&a_l[j].first<b_l[i].second&&!check[j]){
        check[j]=true;
        cnt++;
        break;
      }
    }
  }
  cout<< cnt  << "\n";
}

Measured memory_bytes: 256
n = int(input())
height = list(map(int, input().split()))

dis = [0] * n
dis[1] = abs(height[1] - height[0])
    
for i in range(2,n):
    dis[i] = min(dis[i-2] + abs(height[i] - height[i-2]), dis[i-1] + abs(height[i] - height[i-1]))

print(dis[-1])

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, W;
    cin >> N >> W;
    vector<vector<ll>> dp(N + 1, vector<ll>(110005, INF));
    dp[0][0] = 0;
    rep(i, N) {
        ll w, v;
        cin >> w >> v;
        rrep(j, 100000, 0) {
            dp[i + 1][j + v] = min(dp[i + 1][j + v], dp[i][j] + w);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    ll ans = 0;
    rrep(i, 100000, 0) {
        if (dp[N][i] <= W) {
            ans = i;
            break;
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

int H,W;
char A[1005][1005];

int dist[1005][1005];
bool visited[1005][1005];
int white_cnt=0;

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

class Node{
public:
    int x,y;
    Node(int a, int b):x(a),y(b){}
};

void input(){
    cin>>H>>W;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            cin>>A[i][j];
        }
    }
}

void init(){
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            dist[i][j]=-1;
        }
    }
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            visited[i][j]=false;
        }
    }
}

void bfs(){
    init();
    queue<Node> que;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(A[i][j]=='#'){
                Node temp(j,i);
                que.push(temp);
                visited[i][j]=true;
                dist[i][j]=0;
            }
        }
    }
    while(!que.empty()){
        Node cur=que.front();
        que.pop();
        int cur_x=cur.x;
        int cur_y=cur.y;
        for(int i=0;i<4;++i){
            int next_x=cur_x+dx[i];
            int next_y=cur_y+dy[i];
            bool b=0<=next_x&&next_x<W&&0<=next_y&&next_y<H;
            if(A[next_y][next_x]=='#'||visited[next_y][next_x]||!b) continue;
            visited[next_y][next_x]=true;
            dist[next_y][next_x]=dist[cur_y][cur_x]+1;
            Node next(next_x,next_y);
            que.push(next);
        }
    }   
}

int max_search(){
    int ans=0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            ans=ans<dist[i][j]?dist[i][j]:ans;
        }
    }
    return ans;
} 

void output(){
    cout<<max_search()<<endl;
}

int main(){
    input();
    bfs();
    output();
}

Measured memory_bytes: 17252
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long lint;
const int N=1005;
const int mod=1e9+7;
int h,w,cnt_v,cnt_row,cnt_col,con_row,con_col;
lint q;

template <class T> inline T nxi(){
	T x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

class mtrx{
	public:
		int n[3][3];
		friend inline mtrx operator * (const mtrx &a,const mtrx &b);
		inline void reset();
};

inline mtrx operator * (const mtrx &a,const mtrx &b){
	mtrx c;
	for(int i=0; i<3; ++i){
		for(int j=0; j<3; ++j){
			lint tp=0;
			for(int k=0; k<3; ++k){
				tp+=(lint)a.n[i][k]*b.n[k][j];
			}
			c.n[i][j]=tp%mod;
		}
	}
	return c;
}

inline void mtrx::reset(){
	memset(n,0,sizeof(n));
	for(int i=0; i<3; ++i) n[i][i]=1;
}

template <class T> inline int fpow(int x,T t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

inline void cal_row(char *ch){
	for(int i=1; i<w; ++i){
		if(ch[i]=='#'&&ch[i+1]=='#') ++cnt_row;
		if(ch[i]=='#') ++cnt_v;
	}
	if(ch[w]=='#') ++cnt_v;
	con_row+=ch[1]=='#'&&ch[w]=='#';
}

inline void cal_col(char *ch1,char *ch2){
	for(int i=1; i<=w; ++i){
		if(ch1[i]=='#'&&ch2[i]=='#') ++cnt_col;
	}
}

inline int solve(){
	mtrx ans,t;
	if(!con_col){
		std::swap(con_col,con_row);
		std::swap(cnt_col,cnt_row);
	}
	memset(t.n,0,sizeof(t.n));
	ans.reset();
	t.n[0][0]=t.n[1][1]=cnt_v;
	t.n[2][1]=1;
	t.n[2][2]=con_col;
	for(q-=1; q; q>>=1,t=t*t){
		if(q&1) ans=ans*t;
	}
	const int V=(lint)ans.n[0][0]*cnt_v%mod;
	const int E=((lint)ans.n[1][1]*(cnt_v-1)+(lint)cnt_col*ans.n[2][1])%mod;
	return (V+mod-E)%mod;
}

int main(){
	//static char ch[3][N];
	static char ch[N][N];
	h=nxi<int>(),w=nxi<int>(),q=nxi<lint>();
	if(q<=1){
		puts("1");
		return 0;
	}
	scanf("%s",ch[2]+1);
	for(int i=1; i<w; ++i){
		if(ch[2][i]=='#') ++cnt_v;
		if(ch[2][i]=='#'&&ch[2][i+1]=='#') ++cnt_row;
	}
	con_row+=ch[2][1]=='#'&&ch[2][w]=='#';
	if(ch[2][w]=='#') ++cnt_v;
	if(h>1){
		scanf("%s",ch[0]+1);
		cal_row(ch[0]);
		cal_col(ch[0],ch[2]);
	}
	for(int i=3; i<=h; ++i){
		scanf("%s",ch[i&1]+1);
		cal_row(ch[i&1]);
		cal_col(ch[i&1],ch[(i&1)^1]);
	}
	if(h>1){
		for(int i=1; i<=w; ++i){
			con_col+=ch[2][i]=='#'&&ch[h&1][i]=='#';
		}
	}
	else{
		for(int i=1; i<=w; ++i){
			con_col+=ch[2][i]=='#';
		}
	}
	if((con_col==0)==(con_row==0)){
		printf("%d\n",con_col?1:fpow(cnt_v,std::max(0ll,q-1)));
		return 0;
	}
	printf("%d\n",solve());
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<limits.h>

using namespace std;

int main()
{

    int n, maxv = INT_MIN, minv, tmp;
    
    cin >> n >> minv;
    
    for (int i = 1; i < n; i++)
    {
        cin >> tmp;
        maxv = max(maxv, tmp - minv);
        minv = min(minv, tmp); 
        
     
    }
    

    
    cout << maxv << endl;
    
    return 0;

}


Measured memory_bytes: 3116
#include <stdio.h>
 
int main()
{
 int x,y,i;
  
 i = 0;
  
 while( i < 3000)
 {
   i++;
   scanf("%d %d",&x,&y);
  if( x == 0 && y == 0)
   {
     break;
   }

   if( x < y )
   {
     printf("%d %d\n",x,y);
   }
   else
   {
    printf("%d %d\n",y,x);
   }
 }
return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector<int> ls(n);
  for(int i=0;i<n;i++) cin>>ls[i];

  sort(ls.rbegin(),ls.rend());
  int sum=0;
  for(int l:ls) sum+=l;

  const int INF = 1e9;
  int ans=INF;

  using BS = bitset<4040>;
  for(int i=1;i<n;i++){
    BS dp(0);

    dp[ls[i]]=1;
    for(int j=i+1;j<n;j++) dp|=dp<<ls[j];

    for(int j=0;j<=sum;j++){
      if(!dp[j]) continue;
      int k=sum-j;
      if(j-ls[i]<=ls[i]) continue;
      if(k-ls[0]<=ls[0]) continue;
      chmin(ans,abs(j-k));
    }
  }

  if(ans==INF) ans=-1;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3124
#include <stdio.h>
#include <string.h>
//#include <limits.h>

#define MAX  500002
#define HALF 250002

int S[MAX] = {0};
int L[HALF] = {0};
int R[HALF] = {0};
long cnt = 0;

void Merge(int A[], int left, int mid, int right) {
	int  n1, n2;
	int i, j, k;
//	memset(L, 0, sizeof(L));
//	memset(L, 0, sizeof(L));
	
	n1 = mid - left;
	n2 = right - mid;
	
	for (i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}

	for (i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}
	L[n1] = 1000000005;
	R[n2] = 1000000005;

	i = j = 0;
	for (k = left; k < right; ++k) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			++i;
		} else {
			A[k] = R[j];
			++j;
			cnt += (n1 -i);
		}
	}
	
	return;
}

void MergeSort(int A[], int left, int right) {
	int mid;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		MergeSort(A, left, mid);
		MergeSort(A, mid, right);
		Merge(A, left, mid, right);
	}
	return;
}

int main(void) {
	int n, i;

	scanf("%d", &n);

	for (i = 0; i < n; ++i) {
		scanf("%d", &S[i]);
	}
	MergeSort(S, 0, n);
	printf("%ld\n", cnt);
	
	return 0;
}

Measured memory_bytes: 2160