akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 998244353;
using ll = long long;
using P = pair<ll, ll>;
double PI = acos(-1);
int L,R;
int a[502][502];
signed main(){
    int n,m,q;
    cin >> n >> m >>q;
    int total = 502;
    rep(i,m) {
        cin >> L >> R;
        a[L][R]++;
//        cout << L<<R<<" "<<a[L][R]<<endl;
    }
    FOR(i,1,n+1) FOR(j,1,n+1) a[i][j] += a[i-1][j];
    FOR(i,1,n+1) FOR(j,1,n+1) a[i][j] += a[i][j-1];

    // rep(i,n+1) {
    //     rep(j,n+1) {
    //         cout << a[i][j] << flush;
    //     }
    //     cout << "" << endl;
    // }
    
    rep(i,q) {
        int x,y;
        cin >>x>>y;
        //cout << a[y][y]<<a[x-1][y]<<a[y][x-1]<<a[x-1][x-1] << endl;
        int ans = a[y][y]-a[x-1][y]-a[y][x-1]+a[x-1][x-1];
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 5496
#include <iostream>
using namespace std;
int main(){
    int a,b,c,d,n,count=0;
    while(cin>>n){ count=0;
    for(a=0;a<=9;a++){
        for(b=0;b<=9;b++){
            for(c=0;c<=9;c++){
                for(d=0;d<=9;d++){
                    if(a+b+c+d==n) count++;;
                }
            }
        }
    }
    cout<<count<<endl;
    }
}

Measured memory_bytes: 3004
// KMP法を試してみる

#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

vector<bool> check_eq(string s, string t) {
  int s_size = s.size();
  int t_size = t.size();
  vector<bool> result(s_size - t_size + 1);

  // まずtに対して部分マッチテーブル作成
  int a[t_size+1];
  a[0] = -1;
  for (int i = 0, j = -1; i < t_size; i++) {
    while (j >= 0 && t[i] != t[j]) {
      j = a[j];
    }

    j++;
    if (t[i+1] == t[j]) {
      a[i+1] = a[j]; // 同じ文字ならさらに前に。これがKMPのKとのこと。http://potetisensei.hatenablog.com/entry/2017/07/10/174908
    } else {
      a[i+1] = j;
    }
  }

  /*
  for (const auto& aa : a) {
    cout << aa << endl;
  }
  */

  // 照合
  int j = 0, i = 0;
  while (j < s_size) {
    // m,iで実装する方法わからないのでコピペ
    // http://www-igm.univ-mlv.fr/~lecroq/string/node8.html
    // cout << "i " << i << " j " << j <<endl;
    while (i > -1 && t[i] != s[j]) {
      i = a[i]; // 現在のs[j]と同じt[i]がないか、さかのぼって探す。ひとつ前は違う文字になっているので、ちょっと効率的？
      // cout << "i " << i << " j " << j <<endl;
    }

    i++;
    j++;

    if (i >= t_size) {
      result[j-i] = true;
      i = a[i];
    }
  }
  
  return result;
}

int main() {
  string s,t,s_origin;
  cin >> s >> t;
  s_origin = s;
  int s_origin_size = s_origin.size();
  int t_size = t.size();
  
  while(s.size() < t_size + s_origin_size) {
    s += s_origin;
  }
  
  vector<bool> eqs = check_eq(s,t);
  
  int max_length = 0;
  vector<int> length(s_origin_size, -1);

  for (int i = 0; i < s_origin_size; i++) {
    if (length[i] != -1) {
      continue;
    }

    if (!eqs[i]) {
      length[i] = 0;
      continue;
    }

    int current = i;
    int diff = 0;
    queue<int> q;
    while(eqs[current]) {
      if (!q.empty() && i == current) {
        // 無限に一致する
        max_length = -1;
        goto finish;
      }

      if (length[current] != -1) {
        diff = length[current]; // すでに到達済みの場合、計算済みの長さを加えて終了する
        break;
      }
      length[current] = 0; // 一旦到達マーク設定
      q.push(current);
      current = (current + t_size) % s_origin_size;
    }

    max_length = max(max_length, diff + (int)q.size());

    while(!q.empty()) {
      int len = q.size();
      int current = q.front();
      q.pop();
      length[current] = len + diff; // 正確な長さで上書き
    }
  }

finish:
  cout << max_length << endl;
  
  return 0;
}


Measured memory_bytes: 8824
package main

import (
  "fmt"
)

func main() {
  var s string
  fmt.Scanf("%s", &s)
  
  count := make(map[string]int, 4)
  for _, v := range s {
    count[string(v)]++
  }
  
  ans := "Yes"
  for _, v := range count {
    if v != 2{
      ans = "No"
    }
  }
  fmt.Printf("%s\n", ans)
}

Measured memory_bytes: 1836
#include<iostream>
using namespace std;
#include <string>
int main()
{
    // 整数の入力
    int a,b;
    cin >> a >> b;
	int x,y;
	
	int i,j;
	string c("A");
	string s;
	string s1 = "snuke";
	
	for(i=0;i<a;i++){
		for(j=0;j<b;j++){
			cin >> s;
			if(s=="snuke"){
				x=i;
				y=j;
			}
		}
	}
    // 出力
	c='A'+y;
	x+=1;
    cout << c << x << endl;
    return 0;
}

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

int main(){
    int ans=0,sum=0;
    int k,x;
    
    cin >>k>>x;
    int a=x-k+1;

    for (int i = 0; i < 2*k-1; i++){
        cout << a+i << " ";
    }
    


    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

class mod {
public:
    mod() {m_n = 0;}
    mod(ll n) {if (n >= 0) m_n = n % MOD; else m_n = n % MOD + MOD;}
    friend bool operator== (const mod& a, const mod& b) {return a.m_n == b.m_n;}
    friend bool operator!= (const mod& a, const mod& b) {return !(a == b);}
    friend mod operator+ (const mod& a, const mod& b) {return (a.m_n + b.m_n) % MOD;}
    friend mod& operator+= (mod& a, const mod& b) {return a = a + b;}
    friend mod operator- (const mod& a) {return -a.m_n;}
    friend mod operator- (const mod& a, const mod& b) {return (a.m_n + (-b.m_n)) % MOD;}
    friend mod& operator-= (mod& a, const mod& b) {return a = a - b;}
    friend mod operator* (const mod& a, const mod& b) {return (a.m_n * b.m_n) % MOD;}
    friend mod& operator*= (mod& a, const mod& b) {return a = a * b;}
    friend mod mod_pow(const mod& n, ll r) {
        if (r == 0) {
            return 1;
        } else if (r < 0) {
            return mod_pow(n, (MOD - 2) * (-r));
        } else if (r % 2 == 0) {
            mod tmp = mod_pow(n, r / 2);
            return tmp * tmp;
        } else {
            return n * mod_pow(n, r - 1);
        }
    }
    friend mod operator/ (const mod& a, const mod& b) {return a * mod_pow(b, -1);}
    friend mod& operator/= (mod& a, const mod& b) {return a = a / b;}
    friend ostream& operator<< (ostream& os, const mod& n) {os << n.m_n; return os;}
    friend istream& operator>> (istream& is, mod& n) {ll tmp; is >> tmp; n = mod(tmp); return is;}
private:
    ll m_n;
};
mod mod_pow(ll n, ll r) { return mod_pow(mod(n), r); }

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    string L;
    cin >> L;
    int N = L.size();
    mod p = 1, q = 0;
    for (int n = 1; n < N; ++n) {
        if (L[n] == '1') {
            q = p + 3 * q;
            p = 2 * p;
        } else {
            q = 3 * q;
        }
    }
    cout << mod_pow(3, N-1) + 2*(p+q) << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    private static java.util.Scanner scanner = new java.util.Scanner(System.in);

    public static void main(String[] args) {
        System.out.println(IntStream.range(0, scanner.nextInt())
                .boxed()
                .collect(Collectors.groupingBy(i -> scanner.nextInt(), Collectors.reducing(0, i -> 1, Integer::sum)))
                .entrySet().stream()
                .mapToInt(value -> value.getKey() > value.getValue() ? value.getValue() : value.getValue() - value.getKey())
                .sum());
    }
}

Measured memory_bytes: 65576
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class DFaceProducesUnhappiness {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,h=0,u,t=0;
        string s;
        in>>n>>k>>s;
        s='R'+s+'L';
        Fr(i,n){
            if(s[i]=='R'&&s[i+1]=='R') ++h;
            if(s[i]=='L'&&s[i-1]=='L') ++h;
        }
        u=n-1-h;
        while(u>1&&k>0) h+=2,u-=2,--k;
        if(u==1&&k>0) ++h;
        out<<h<<endl;
    }
};

int main() {
    DFaceProducesUnhappiness solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
          string[] input = Console.ReadLine().Split(' ');
          int A = int.Parse(input[0]);
          int B = int.Parse(input[1]);
                
 
                int[] ans = { A + B, A - B, A * B };
                int max = -100;
 
                for (int i = 0; i < ans.Length; i++)
                {
                    if (ans[i] > max)
                        max = ans[i];
                }
                Console.WriteLine(max);
            
        }
    }
}

Measured memory_bytes: 13140
N = int(input())
A = sorted(list(map(int, input().split())))

cnt = 1
tmp = A[0]
for i in range(1, N):
    if tmp * 2 >= A[i]:
        tmp += A[i]
        cnt += 1
    else:
        tmp += A[i]
        cnt = 1
print(cnt)


Measured memory_bytes: 14276
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main(){
  string s;
  cin>>s;
  int hold, ma=1000,ans;
  rep(i, s.size()-2){
  hold=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
    if(abs(753-hold)<ma)
    {ans=hold;
     ma=abs(753-hold);
    }
  }
  cout << ma << endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n;
	vector<ll> v;
	ll ans = 0;

	cin >> n;

	REP(i, n) {
		ll a;
		cin >> a;
		v.push_back(a);
	}

	if (v[0] != 0) {
		cout << -1 << endl;
		return 0;
	}

	FOR(i, 1, n) {
		if (v[i] - v[i - 1] <= 0) {
			ans += v[i];
		}
		else if (v[i] - v[i - 1] == 1) {
			ans++;
		}
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    long long int a=1,b,n,i;
    string s;
    cin>>n>>s;
    for(int i=1;i<n;i++)
    {
        if(s[i]!=s[i-1])
            a++;
    }
    cout<<a;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <cstring>
#include <vector>

using namespace std;

typedef long long LL;

const int MAXN = 100010;
const int MOD = 1000000007;

int A[MAXN], h[MAXN];
int N;

int main() {
	scanf("%d", &N);
	int max_left = 0, max_h = 0, t;
	for (int i = 1; i <= N; ++i) {
		scanf("%d", &t);
		if (t > max_h) {
			h[i] = t;
			max_h = t;
			max_left = i;
		}
	}
	for (int i = 1; i <= N; ++i)
		scanf("%d", &A[i]);
	int max_right = N + 1;
	max_h = 0;
	for (int i = N; i >= 1; --i) {
		if (A[i] > max_h) {
			if (i == max_left && A[i] != h[i]) {
				printf("0\n");
				return 0;
			}
			h[i] = A[i];
			max_h = A[i];
			max_right = i;
		}
	}
	if (max_left > max_right || max_h != h[max_left]) {
		printf("0\n");
		return 0;
	}
	LL ans = 1;
	max_h = 0;
	for (int i = 1; i < max_right; ++i) {
		if (h[i] == 0)
			ans = (ans * max_h) % MOD;
		else
			max_h = h[i];
	}
	max_h = 0;
	for (int i = N; i > max_right; --i) {
		if (h[i] == 0)
			ans = (ans * max_h) % MOD;
		else
			max_h = h[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

signed main() {
    int N;
    cin >> N;
    int ret = 0;

    for (int m = 1; m <= sqrt(N); m++) {
        if (N / m == N % m) ret += m;
    }

    for (int r = 1; r < sqrt(N); r++) {
        if ((N - r) % r != 0) continue;
        int m = (N - r) / r;
        if (m > sqrt(N)) ret += m;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
ll n, a, b, res;
int main() {
	cin >> n;
	vector<ll> s(n);
	REP(i, n) {
		cin >> a >> b;
		s[i] = a + b;
		res -= b;
	}
	sort(s.rbegin(), s.rend());
	REP(i, n) res += s[i++];
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 4048
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
dpa=[0]*n
dpb=[0]*n
dpc=[0]*n
dpa[0]=a[0][0]
dpb[0]=a[0][1]
dpc[0]=a[0][2]
for i in range(1,n):
    dpa[i]=max(dpb[i-1]+a[i][0],dpc[i-1]+a[i][0])
    dpb[i]=max(dpa[i-1]+a[i][1],dpc[i-1]+a[i][1])
    dpc[i]=max(dpb[i-1]+a[i][2],dpa[i-1]+a[i][2])
#print(dpa,dpb,dpc)
print(max(dpa[-1],dpb[-1],dpc[-1]))

Measured memory_bytes: 66008
/* AtCoder コピペ */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repEq(i, n) for (int i = 0; i <= (int)(n); i++)
#define repVector(i, v) for (auto i = v.begin(); i != v.end(); ++i)

#define ifBetween(n, a, b) if (n > a && n < b)
#define ifBetweenEq(n, a, b) if (n >= a && n <= b)

int main() {
  	int N;
    cin >> N;
  
  	int taco[N];
  	rep(i, N) {
    	cin >> taco[i];
    }
  
  	int total = 0;
  	for(int i = 0; i < N; i++) {
    	for(int j = i + 1; j < N; j++) {
          total += taco[i] * taco[j];
        }
    }

  	cout << total << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define modn 1000000007
using namespace std;
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int tc;
    //cin>>tc;
    tc = 1;
    while(tc--)
    {
        int n=3;
        int arr[4][4];
        for(int i=1; i<=3 ; i++)
            for(int j=1; j<=3; j++) cin>>arr[i][j];

        if(arr[1][1] - arr[1][2] == arr[3][1] - arr[3][2] && arr[3][1] - arr[3][2] == arr[2][1] - arr[2][2] &&
           arr[1][1] - arr[1][3] == arr[2][1] - arr[2][3] && arr[2][1] - arr[2][3] == arr[3][1] - arr[3][3] &&
           arr[1][2] - arr[1][3] == arr[2][2] - arr[2][3] && arr[2][2] - arr[2][3] == arr[3][2] - arr[3][3]
           )
           cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

    }
    return 0;
}


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

using namespace std;
typedef long long ll;

#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--)

int main(){
  
int A=0,B=0,K=0,C=0;
int flag0=0;
  
 cin >> K;
 cin >> A >> B;
 
  For(i,A,B){   
    C=i%K;
     if(C == 0){
      flag0 = 1;
     }
  }

 if(flag0==1){
   cout<<"OK";
 }
 else {
   cout<<"NG";
 }
  
}

Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int n,a[201],i,c,flg;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	c=0;
	flg=0;
	while(1){
		for(i=0;i<n;i++){
			if(a[i]%2!=0)	flg=1;
			a[i]=a[i]/2;
		}
		if(flg==0)	c++;
		else	break;
	}
	printf("%d\n",c);
}
	
		

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair

int read()
{
    int v = 0, f = 1;
    char c = getchar();
    while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();}
    while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
    return v * f;
}

const int N = 1e5 + 10;

int f[N], g[N], head[N], en, n;

struct Edge
{
    int nxt, to;
} eg[N << 1];

void setEdge(int u, int v)
{
    eg[++en] = (Edge) {head[u], v};
    head[u] = en;
}

void dfs(int u, int fa)
{
    int t = 0;
    for (int e = head[u]; e; e = eg[e].nxt)
    {
        int v = eg[e].to;
        if (v == fa) continue;
        dfs(v, u);
        if (f[v]) continue;
        if (!g[v])
        {
            f[u] = g[u] = 0;
            return ;
        }
        t++;
    }
    if (t > 1)
        f[u] = g[u] = 0;
    if (t == 1)
        f[u] = 1, g[u] = 0;
    if (t == 0)
        f[u] = 0, g[u] = 1;
}

int main()
{
    n = read();
    for (int i = 1; i < n; i++)
    {
        int u = read(), v = read();
        setEdge(u, v);
        setEdge(v, u);
    }
    dfs(1, 0);
    if (f[1])
        puts("Second");
    else
        puts("First");
}


Measured memory_bytes: 2944
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
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);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);

    ll ans = 0;
    for(ll i=1; i*i<=N; i++) {
        ans += i*i;
        ll ub = N / i, lb = i;
        if(ub - lb >= 0) {
            ll add = 0;
            add += ub*(ub+1) / 2 * i * 2;
            add -= lb*(lb+1) / 2 * i * 2;
            ans += add;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


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

// Macros and Constants
#define ll long long
const ll mod=1000000007LL;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     ifstream cin("practice/input.txt");
    //     ofstream cout("practice/output.txt");
    // #endif
    
    ll N, A, B;
    cin >> N >> A >> B;

    ll blueballs = N/(A + B);
    ll remainder = N%(A + B);
    blueballs = blueballs*A + ((remainder < A) ? remainder : A);

    cout << blueballs;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int x,y;
  cin >> x >> y;
  
  int res=0;
  if(x==1){
    res+=300000;
  }
  else if(x==2){
    res+=200000;
  }
  else if(x==3){
    res+=100000;
  }

  if(y==1){
    res+=300000;
  }
  else if(y==2){
    res+=200000;
  }
  else if(y==3){
    res+=100000;
  }

  if(x==1&&y==1) res+=400000;

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>

int main(void) {
    int h, w;
    char a[100 + 10][100 + 10] = {'\0'};
    int i, j;
    bool del_row[100 + 10] = {false};
    bool del_col[100 + 10] = {false};
    bool del;

    scanf("%d%d", &h, &w);
    for(i = 0; i < h; i++) scanf("%s", a[i]);

    for(i = 0; i < h; i++) {
        del = true;
        for(j = 0; j < w; j++) {
            if(a[i][j] == '#') {
                del = false;
                break;
            }
        }
        del_row[i] = del;
    }
    for(j = 0; j < w; j++) {
        del = true;
        for(i = 0; i < h; i++) {
            if(a[i][j] == '#') {
                del = false;
                break;
            }
        }
        del_col[j] = del;
    }

    for(i = 0; i < h; i++) {
        if(del_row[i]) continue;
        for(j = 0; j < w; j++) {
            if(del_col[j]) continue;
            printf("%c", a[i][j]);
        }
        printf("\n");
    }

    return 0;
}


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

#define MAX_N 100000

using namespace std;

int dp[MAX_N + 2];
int field[MAX_N + 2];

int ans;

int N;
int L;

bool shape(int i){
	if(field[i] > field[i - 1] && field[i] > field[i + 1]){
		return true;
	}
	return false;
}

void search(int now,int cost,int mode){
	int ncost = cost + L - field[now];
	dp[now] = max(dp[now],ncost);
	if(mode != 2){
		if(field[now - 1] == 0);
		else if(field[now] > field[now - 1]){
			search(now - 1,ncost,1);
		}
	}
	if(mode != 1){
		if(field[now + 1] == 0);
		else if(field[now] > field[now + 1]){
			search(now + 1,ncost,2);
		}
	}

	return ;

}

void solve(){

	for(int i = 1;i <= N;i++){
		if(shape(i)){
			search(i,0,0);
		}
	}

	ans = 0;
	for(int i = 1;i <= N;i++){
		ans = max(ans,dp[i]);
	}

	return ;
}


int main(){

	scanf("%d%d",&N,&L);
	for(int i = 1;i <= N;i++){
		scanf("%d",field + i);
	}

	solve();

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

	return 0;
}

Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N, A, B;
    cin >> N >> A >> B;

    int res = 0;
    FOR(i, 1, N+1) {
        string s = to_string(i);
        int sum = 0;
        rep(j, s.size()) {
            int t = s[j]-'0';
            sum += t;
        }
        if(sum >= A && sum <= B) res += i;
    }

    cout << res << endl;
    
    return 0;
}

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

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

	ll N, M;
	cin >> N >> M;

	if(N > M) swap(N, M);
	if(N == 1 && M == 1){
		cout << 1 << endl;
		return 0;
	}
	if(N == 1){
		cout << M - 2 << endl;
		return 0;
	}
	cout << N * M - (N - 1) * 2 - (M - 1) * 2 << endl;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second

typedef long long ll;
typedef pair<ll,int> P;
typedef pair<P,P> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

//-----------------------------------------------------------------------------

int n;

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

	cin>>n;
	ll prv=2,crt=1,ans=1;
	REP(i,n-1) {
		ans=prv+crt;
		prv=crt,crt=ans;
	}
	cout<<ans<<endl;

	return 0;
}


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

int main() {
  long n, max = 0, sum = 0;
  cin >> n;
  long a[n];
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > max) max = a[i];
    else sum += max - a[i];
  }
  
  cout << sum;
  
  return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int max_num = min(b, c / 2);
    int num_of_divisors;
    for (int i = a; i <= b; ++i)
    {
        if (c % i == 0)
        {
            num_of_divisors++;
        }
    }
    cout << num_of_divisors << endl;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.next();
		if(str.charAt(4) == (str.charAt(5))) {
			if(str.charAt(2) == (str.charAt(3))) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26576
#include <stdio.h>

int main() {
	int N,sum=0,dig;
	scanf("%d", &N);
	int N2 = N;
	while (N) {
		dig = N % 10;
		sum = sum + dig;
		N = N / 10;
	}
	if (N2%sum == 0) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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

int n;
int x[110];
int y[110];
int h[110];
int resx = -1;
int resy = -1;

int main(){
    scanf("%d",&n);
    int maxv = 0;
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
        maxv = max(maxv,h[i]);
    }
        for(int i=0;i<=100;i++){
            int ress = 0;
            for(int j=0;j<=100;j++){
                int flag = 0;
                int now = -1;
                for(int k=0;k<n;k++){
                  if(h[k]){
                    now =  abs(x[k]-i)+abs(y[k]-j)+h[k];
                    break;
                  }
                }
                if(now==-1)continue;
                for(int k=0;k<n;k++){ 
                        if(max(0,now-abs(i-x[k])-abs(j-y[k]))==h[k])continue;
                        flag = 1;
                        break;
                }
                if(flag)continue;
                else{
                    resx = i;
                    resy = j;
                    ress = 1;
                    break;
                }
            }
            if(ress)break;
        }
        int ans = 0;
        for(int i=0;i<n;i++){
            if(h[i]){
                ans = abs(x[i]-resx)+abs(y[i]-resy)+h[i];
                break;
            }
        }
        if(!ans)ans = 1;
        printf("%d %d %d\n",resx,resy,ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,s=0;
  cin>>n;
  for(long long i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
      s+=i;
    }
  }
  cout<<s<<endl;
}  

Measured memory_bytes: 3636
#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, Q;
	ll K;
	cin >> N >> K >> Q;
	vector<int> B(N);
	REP(i, Q) {
		int A;
		cin >> A;
		B[--A]++;
	}
	REP(i, N) {
		string res = "Yes";
		if (Q - B[i] >= K) res = "No";
		cout << res << endl;
	}


	return 0;
}


Measured memory_bytes: 1024
IDENTIFICATION DIVISION.
       PROGRAM-ID. ATCODER.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  indata PIC X(100).
       01  k PIC 9(08).
       01  x PIC 9(08).
       01  r PIC 9(08).
       PROCEDURE DIVISION.
        ACCEPT indata

        UNSTRING indata DELIMITED BY SPACE INTO k x.

        MULTIPLY 500 BY k GIVING r
        IF r >= x THEN
          DISPLAY "Yes"
        ELSE
          DISPLAY "No"
        END-IF

       STOP RUN.


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
  cin.sync_with_stdio(false);
  string s;
  while(cin >> s, s[0] != '0') {
    int dp[s.length() + 1][11] = {};
    int ans = 0;
    rep(i, s.length()) {
      int num = s[i] - '0', a = (i % 2) ? -1 : 1;
      if (num > 0) dp[i + 1][(num * a + 11) % 11]++;
      rep(j, 11) {
        dp[i + 1][(j + num * a + 11) % 11] += dp[i][j];
      }
      ans += dp[i + 1][0];
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 6740
a,b,k = map(int,input().split())
def solve_b(a,b,k):
    if b - a >= 2 * k:
        for i in range(a,a+k):
            print(i)
        for j in range(b-k+1,b+1):
            print(j)
    else:
        for i in range(a,b+1):
            print(i)
solve_b(a,b,k)


Measured memory_bytes: 3060
#include <stdio.h>
 
int main()
{
    int a, b, c, tmp;
    scanf("%d %d %d", &a, &b, &c);
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    if (b > c) {
        tmp = b;
        b = c;
        c = tmp;
    }
    if (a > b) {
        tmp = a;
        a = b;
        b = tmp;
    }
    printf("%d %d %d\n", a, b, c);
    return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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



int main(void)
{
  string e, o;
  cin >> o >> e;
  REP(i, e.size()) {
    cout << o[i] << e[i];
  }
  if(o.size()>e.size()) {
    cout << o[o.size()-1] ;
  }
  cout << endl;
}


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

int main(void) {
    string s;
    cin >>s;
    map<char, bool> p;
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    for (char c: alpha) {
        p.insert(pair<char,bool>(c,true));
    }
    for (char& c: s) {
        p[c] = false;
    }
    string ret = "None";
    for (char c: alpha) {
        if (p[c]) {
            ret = c;
            break;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define llt long long int
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
	speed;
	llt n;
	cin >> n;
	llt a[n];
	llt i,m = INT_MIN;
	map <llt,llt> mpo;
	for(i =0; i < n; i++)
	{
		cin >> a[i];
		mpo[a[i]]+=1;
		m = max(a[i],m);
	}
	llt sum =0;
	for( i =1; i <= m; i++)
	{
		sum+=mpo[i]*(mpo[i]-1)/2;
	}
	for(i =0; i < n; i++)
	{
		llt z = mpo[a[i]]-1;
		cout << sum - z << endl;
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int count=0,sum=0,m;
    vector<int> vec(10001);
    m = sqrt(n);
    for(int a=1; a<=m; a++){
        for (int b=a; b<=m; b++){
            for (int c=b; c<=m; c++){
                sum = (a+b+c)*(a+b+c) -(a*b+b*c+a*c);
                if (sum < 10001){
                    set<int> sets={a,b,c};
                    if (sets.size()==3)count = 6;
                    else if (sets.size()==2)count =3;
                    else count = 1;
                    vec.at(sum) += count;
                
                }
            }
        }
    }

    rep(i,n){
        cout << vec.at(i+1) << endl;
    }    
    return 0;
}

Measured memory_bytes: 3512
#include<stdio.h>

int main(void)
{
    int p, q, r;
    int temp=0;
    scanf("%d %d %d", &p, &q, &r);
    if(p > q){
        temp = p;
        p = q;
        q = temp;
    }
    if(q > r){
        temp = q;
        q = r;
        r = temp;
    }
    printf("%d\n", p+q);
    return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	for j in range(1, min(K + 1, N - i)):
		dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[N - 1])

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll y1, m1, d1, y2, m2, d2;
  ll ch[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  ll ch2[2] = {28, 29};
  while(cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2) {
    if(y1 == (-1)) break;
    ll cnt = 0;
    if(y1 == y2 && m1 == m2 && d1 == d2) {
      cout << cnt << endl;
      continue;
    }
    ll ye = 0, webch = 0;
    bool che = false;
    while(1) {
      while(1) {
        if(che) break;
        if(m1 == 2) break;
        d1++;
        cnt++;
        if(d1 > ch[m1]) {
          m1++;
          d1 = 1;
          if(m1 > 12) {
            y1++;
            m1 = 1;
          }
        }
        if(y1 == y2 && m1 == m2 && d1 == d2) {
          che = true;
          break;
        }
      }
      ye = webch = 0;
      if(y1 % 4 == 0) {
        if(y1 % 100 != 0) ye = 1;
        if(y1 % 400 == 0) ye = 1;
      }
      while(1) {
        if(che) break;
        d1++;
        cnt++;
        if(d1 > ch2[ye]) {
          m1++;
          d1 = 1;
          webch = 1;
          break;
        }
        if(webch) break;
        if(y1 == y2 && m1 == m2 && d1 == d2) {
          che = true;
          break;
        }
      }
      if(che) break;
    }
    cout << cnt << endl;
  }
	return 0;
}


Measured memory_bytes: 3124
fun main() {
    val x = nextLong()
    if (x == 0L) {
        return println("0 0")
    }
    for (i in 1..x / 2) {
        if (x % i == 0L) {
            var a = i / 2
            var b = a - i
            while (a * a * a * a * a - b * b * b * b * b < x) {
                a++
                b++
            }
            if (a * a * a * a * a - b * b * b * b * b == x) {
                return println("$a $b")
            }
        }
    }
    var a = x / 2
    var b = a - x
    while (a * a * a * a * a - b * b * b * b * b < x) {
        a++
        b++
    }
    if (a * a * a * a * a - b * b * b * b * b == x) {
        return println("$a $b")
    }
}

val sc = java.util.Scanner(System.`in`)
fun next(): String = sc.next()
fun nextInt() = sc.nextInt()
fun next2Int() = Pair(nextInt(), nextInt())
fun next3Int() = Triple(nextInt(), nextInt(), nextInt())
fun nextIntArray(size: Int) = IntArray(size) { nextInt() }
fun nextLong() = sc.nextLong()
fun nextLine(): String = sc.nextLine()
fun nextList() = nextLine().split(" ")
fun printYesNo(isYes: Boolean) = println(if (isYes) "Yes" else "No")
fun printString(action: StringBuilder.() -> Unit) = println(buildString(action))


Measured memory_bytes: 36320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static string S;
    static void INPUT()
    {
        NextInt();
        S = NextString();
    }

    static void OUT()
    {
        var wc = S.Where(__ => __ == 'W').Count();
        var c = 0;
        for (int i = S.Length - 1; i >= S.Length - wc ; i--)
        {
            if (S[i] == 'R') c++;
        }
        Console.WriteLine(c);
    }

    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}


Measured memory_bytes: 19644
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a,b; cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
lis = [[] for _ in range(n)]
for i in range(m):
  p, y = map(int, input().split())
  lis[p-1].append([i, y])

lis2 = []
for j in range(len(lis)):
  l = lis[j]
  if l:
    l.sort(key=lambda x: x[1])
    cnt = 1
    for city in l:
      city.append("{:06}{:06}".format(j+1, cnt))
      cnt += 1
      lis2.append(city)

lis2.sort(key=lambda x: x[0])
for l2 in lis2:
  print(l2[2])

Measured memory_bytes: 45464
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<long long>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	vector<long long>DP(N);
	DP.at(0) = 0;
	for (long long i = 1; i < N; i++) {
		if (i == 1) {
			DP.at(i) = DP.at(i - 1) + abs(A.at(i) - A.at(i - 1));
		}
		else {
			DP.at(i) = min(DP.at(i - 1) + abs(A.at(i) - A.at(i - 1)), DP.at(i - 2) + abs(A.at(i) - A.at(i - 2)));
		}
	}
	cout << DP.at(N - 1) << endl;
}


Measured memory_bytes: 1792
import scala.io.StdIn

object Main extends App {
  val k = StdIn.readInt()
  val (a, b) = readIntPair
  val res = (a to b).exists(_ % k == 0)
  println(if (res) "OK" else "NG")

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}

Measured memory_bytes: 54736
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

vector<int>in[1010];
int x[5050];

void pr(int ok) {
	if (ok)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	exit(0);
}

pair<int,int> dfs(int now) {
	vector<pair<int, int>>xy;
	if (in[now].size() == 0) {
		if (now == 0)pr(1);
		return { x[now],0 };
	}
	fore(p, in[now])xy.pb(dfs(p));
	bitset<5050>dp;
	bitset<5050>dp2;
	dp[0] = 1;
	dp2[0] = 1;

	int sum = 0;
	for (int i = 0; i < xy.size(); i++) {
		sum += xy[i].first;
		sum += xy[i].second;
		dp2 = dp << xy[i].second;
		dp = dp << xy[i].first;
		dp |= dp2;
		dp2 = dp;
	}

	int rec = -1;
	for (int i = x[now]; i >= 0; i--) {
		if (dp[i]) {
			rec = i;
			break;
		}
	}
	if (rec == -1)pr(0);
	else if (now == 0)pr(1);
	return { x[now],sum - rec };
}

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

	int N;
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int P;
		cin >> P;
		P--;
		in[P].pb(i+1);
	}
	for (int i = 0; i < N; i++)cin >> x[i];
	dfs(0);

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll INF = 1000000000000000000LL;
using namespace std;

const int MOD = 1000000007;


//繰り返し二乗法
ll beki(ll a, ll b)
{
    a %= MOD;
    if(b == 0)return 1;
    ll res = beki(a, b / 2);
    res = res * res % MOD;
    if(b % 2 == 1)
    {
        res = res * a % MOD;
    }
    return res;
}

//aCbを返します
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ret = 1;
    for(ll i = 0; i < b; i++) {
        ret *= (a - i);
        ret %= MOD;
        //逆元 a*a^-1 ≡ 1 (mod MOD)
        //フェルマーの小定理より
        // a ^(MOD-1) (mod MOD) = 1
        // a * a ^(MOD-2)
        ret *= beki(i + 1, MOD - 2);
        ret %= MOD;
    }
    return ret;
}


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    //init_combination();
    ll n, a, b;
    cin >> n >> a >> b;
    ll res = beki(2, n) - 1;
    res -= combination(n, a);
    res -= combination(n, b);
    res += 2 * MOD;
    res %= MOD;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  int n, x, t; cin >> n >> x >> t;
  int ans = (n + x - 1) / x;
  ans *= t;
  cout << ans << endl;

  return 0;
}


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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))]

//char型のポインタ(=配列と意味は同じ)をString型と定義([0]から数える)
typedef char* String;

//S[0]から始まる文字列の長さを求める関数
int string_len(String str){
    int len=0;
    while(str[len]!=0){
        len++;
    }
    return len;
}

//文字列を標準入力から読み込み、それをString型のメモリを確保し直してくれる関数
//S[0]~S[n-1]までが入力で、S[n]は0になる
//文字列長さの上限は1000まで
String string_input(void){
    int i,len;
    char buf[200001];
    String str;
    scanf("%s",buf);//buf=入力した文字列が入るchar型の配列
    
    len=string_len(buf);//len=文字列の長さを表すint型変数
    NEW(str,len+1);//strはただのポインタだから、ここでNEWを使ってメモリを確保しなくちゃいけない
    for(i=0;i<len;i++){
        str[i]=buf[i];
    }
    str[len]=0;
    
    return str;
}


int main(void){
    String S,T;
    S=string_input();
    T=string_input();

    int N=string_len(S);

    int trans1[26];
    int trans2[26];
    for(int i=0;i<26;i++){
        trans1[i]=-1;
        trans2[i]=-1;
    }

    for(int i=0;i<N;i++){
        int s=S[i]-'a';
        int t=T[i]-'a';
        if(trans1[s]>=0 || trans2[t]>=0){
            if(trans1[s]!=T[i]-'a' || trans2[t]!=S[i]-'a'){
                printf("No\n");
                return 0;
            }
        }
        else{
            trans1[s]=T[i]-'a';
            trans2[t]=S[i]-'a';
        }
    }

    //for(int i=0;i<26;i++) printf("%c ",trans[i]);

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#define REP(i, a, n) for(int a = 0; i < n; i++)
using namespace std;


int n, d, cnt;

int main(void) {
  while(cin >> n, n != 0) {
    d = 1000 - n;

    cnt = 0;
    while(d >= 500) d -= 500, cnt++;
    while(d >= 100) d -= 100, cnt++;
    while(d >=  50) d -=  50, cnt++;
    while(d >=  10) d -=  10, cnt++;
    while(d >=   5) d -=   5, cnt++;
    while(d >=   1) d -=   1, cnt++;

    cout << cnt << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#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 FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = x;
  rep(i, n) {
    rep(j, d) {
      if (j * a[i] + 1 > d) break;
      ans++;
    }
  }
  cout << ans << endl;
  


  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int Y[]={0,1,0,-1};
int X[]={1,0,-1,0};
int main(){
  int i,j,k,l,h,w,ans=0,r[30]={0};
  int y[30][2],x[30][2],t[30]={0};
  char d[510][510]={0};
  scanf("%d %d",&h,&w);
  for(i=1;i<=h;i++){
    for(j=1;j<=w;j++){
      scanf(" %c",&d[i][j]);
      if(d[i][j]-'.'){
	k=d[i][j]-'A';
	y[k][r[k]  ]=i;
	x[k][r[k]++]=j;
	t[k]=1;
      }
    }
  }
  for(i=0;i<26;i++){
  FRONT:
    if(t[i]==0)continue;
    int f[510][510]={0};
    for(j=0;j<2;j++){
      for(k=0;k<4;k++){
	for(l=1;d[y[i][j]+Y[k]*l][x[i][j]+X[k]*l]=='.';l++){
	  f[y[i][j]+Y[k]*l][x[i][j]+X[k]*l]++;
	  if(f[y[i][j]+Y[k]*l][x[i][j]+X[k]*l]==2){
	    ans+=2;
	    d[y[i][0]][x[i][0]]=d[y[i][1]][x[i][1]]='.';
	    i=t[i]=0;
	    goto FRONT;
	  }
	}
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1876