akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#define NUM 1000001 * 100
typedef struct process {
    char name[11];
    int time;
} Process;


Process queue[NUM];
int head=0, tail = 0;
void enqueue(Process process) {
    queue[tail] = process;
    tail++;
}

Process dequeue() {
    Process h = queue[head];
    head++;
    return h;
}

int size() {
    return tail - head;
}

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    for (int i=0; i<n; i++) {
        Process process;
        scanf("%s %d", process.name, &process.time);
        enqueue(process);
    }
    unsigned long sum_time = 0;
    while (1 < size()) {
        Process tgt = dequeue();
        if (tgt.time <= q) {
            sum_time += (unsigned long)tgt.time;
            printf("%s %lu\n", tgt.name, sum_time);
        } else {
            sum_time += q;
            tgt.time -= q;
            enqueue(tgt);
        }
    }
    Process tgt = dequeue();
    sum_time += (unsigned long)tgt.time;
    printf("%s %lu\n", tgt.name, sum_time);
}

Measured memory_bytes: 5120
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

int main(void) {
	int i, j, a, b, c, d, e, f, aa, ab = 0, x = 0;
	cin >> a >> b >> c >> d >> e >> f;
	priority_queue<int, vector<int>, greater<int>> w, s;
	for (i = 0; i * 100 < f; i += a) {
		for (j = 0; (i + j) * 100 < f; j += b) {
			w.push(i + j);
		}
	}
	for (i = 0; i <= f; i += c) {
		for (j = 0; i + j <= f; j += d) {
			s.push(i + j);
		}
	}
	b = 0;
	aa = a * 100;
	w.pop();
	while (!w.empty()) {
		a = w.top();
		w.pop();
		while (b <= a * e && a * 100 + b <= f) {
			if (b * 300000 / (a * 100 + b) > x) {
				x = b * 300000 / (a * 100 + b);
				aa = a * 100 + b;
				ab = b;
			}
			b = s.top();
			s.pop();
		}
	}
	printf("%d %d\n", aa, ab);
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int n;
cin>>n;
int x=(n+1)/2;
cout<<x*1.0/n<<endl;
}


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

string a[105], b[105];
int c[105];

int cmp(int x, int y){
	return x > y;
}

int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int m;
	cin >> m;
	for(int i = 1; i <= m; i++){
		cin >> b[i];
	}
	memset(c, 0, sizeof(c));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++)
			if(a[i] == a[j]) c[i]++;
		for(int j = 1; j <= m; j++)
			if(a[i] == b[j]) c[i]--;
	}
	sort(c, c + n, cmp);
	cout << c[0] << endl;
	return 0;
}

Measured memory_bytes: 256
int main()
{
     char a[4];
     int i,c;
     while(~scanf("%s",a))
     {
         c=0;
         for(i=0;i<4;i++)
         {
             if(a[i]=='+')
                c=c+1;
             if(a[i]=='-')
                c=c-1;
         }
         printf("%d\n",c);
     }
    return 0;
}

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a > b) cout << "a > b" << endl;
	if (a < b) cout << "a < b" << endl;
	if (a == b) cout << "a == b" << endl;
}


Measured memory_bytes: 3112
N = int(input())
A = list(enumerate(list(map(int, input().split()))))
A = sorted(A, key=lambda x:x[1], reverse=True)

before_idx = list(range(-1, N-1)) + [-1]
next_idx = list(range(1, N+1)) + [N]

ans = 0
for i, a in A:
  il = before_idx[i]
  ir = next_idx[i]
  ans += (i - il) * (ir - i) * a
  before_idx[ir] = il
  next_idx[il] = ir

print (ans)

Measured memory_bytes: 48368
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    long long x;
    mint(long long x=0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    map<char, int> mp;
    rep(i, n) mp[s[i]]++;
    mint ans = 1;
    for (auto p : mp) {
        ans *= p.second + 1;
    }
    ans -= 1;
    cout << ans << endl;
}

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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , k;
   cin >> n >> k;
   map <int , int> mp;
   ll ans = 0;
   int cur = 0;
   mp[0] = 1;
   int sum[n];
   sum[0] = 0;
   for(int i = 1 ; i <= n ; i++){
      int x;
      cin >> x;
      x--;
      x %= k;
      cur = (cur + x) % k;
      sum[i] = cur;
      if(i >= k)
         mp[sum[i - k]]--;
      ans += mp[cur];
      mp[cur]++;
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 13780
import java.util.*;
 
import java.io.*;
 
public class Main{
 
    public static long Combination(long n, long r){
        long A = 1;
        long B = 1;
        for(long i = 0; i < r; i++){
            A = A*(n-i);
            B = B*(r-i);
        }
        if(A == 0) return 0;
        return A/B;
    }
 
    public static long solve(int i, int j, boolean check, int N, String S){
        if(i == N){
            if(j == 0){
                return 1;
            }else{
                return 0;
            }
        }
 
        if(j == 0) return 1;
 
        if(check){
            return Combination(N-i, j)*(long)Math.pow(9, j);
        }else{
            if(S.charAt(i) == '0') return solve(i+1, j, false, N, S);
            long Z = solve(i+1, j, true, N, S);
            long A = solve(i+1, j-1, true, N, S)*(S.charAt(i)-'1');
            long P = solve(i+1, j-1, false, N, S);
            return Z+A+P;
        }
 
 
    }
    
    public static long Dflag(long a){
        if(a == 1) return 1;
        long h = Dflag(a/2);
        return h + h + 1;
    }
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        int A = s.nextInt();
        int B = s.nextInt();
        int C = s.nextInt();
        int K = s.nextInt();
        

        
        
        if(K <= A){
            System.out.println(K);
        }else if(K > A && K <= A+B){
            System.out.println(A);
        }else{
            System.out.println(A-(K-A-B));
        }
        
	}
} 

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

int main() {
    
    int A, B ,H ,M;
    cin >> A >> B >> H >> M;
    long double pi = acos(-1.0);
    long double mtheta = ((long double)M * 2.0 * pi) / 60.0;
    long double htheta = (((long double)H / 12.0) * 2.0 * pi)  +  ((long double)M/60.0) * (2.0 * pi / 12.0);
    long double theta = (htheta - mtheta);
    long double c = sqrtl(A*A + B*B  - 2 * A * B * cosl(theta));
    printf("%20.20Lf\n",c);
    
    
    return 0;
}

Measured memory_bytes: 4088
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)	cout<<"x";
	


}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 256
#include<stdio.h>


#define MAX 1000
#define VMAX 10000
#define N 2000000000

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

void merge(int A[], int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1];
    int R[n2];
    for(int i=0; i<n1; i++){
        L[i] = A[left+i];
    }
    for(int i=0; i<n2; i++){
        R[i] = A[mid+i];
    }
    L[n1]=N;
    R[n2]=N;
    int i=0;
    int j=0;

    for(int k=left; k<right; k++){
        
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}



int min(int a, int b){
    if(a>b){
        return b;
    }
    else{
        return a;
    }
}

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

int solve(){
    int ans=0;

    int V[MAX];
    for(int i=0; i<n; i++){
        B[i]=A[i];
        V[i]=0;
    }

    mergeSort(B, 0, n);
   
    for(int i=0; i<n; i++){
        T[B[i]]=i;

    }
    for(int i=0; i<n; i++){
       if(V[i]){
           continue;
       }
       int cur=i;
       int S=0;
       int m=VMAX;
       int an=0;
       while(1){
           V[cur]=1;
           an++;
           int v=A[cur];
           m=min(m,v);
           S+=v;
           cur=T[v];
           if(V[cur]){
               break;
           }
           

       }
       ans+=min(S+(an-2)*m, m+S+(an+1)*s);
       

    }
    return ans;



}

int main(void){
    scanf("%d", &n);
    s=VMAX;
    for(int i=0; i<n; i++){
        scanf("%d", &A[i]);
        s=min(s, A[i]);
    }
    int ans=solve();

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

    return 0;
}


Measured memory_bytes: 2108
#include <iostream>

int main(){
    int n;
    std::cin >> n;
    std::string str;
    double res = 0;
    double tmp;
    for(int i = 1;i <= n; i++){
        std::cin >> tmp >> str;
        if (str == "JPY") res += tmp;
        else if (str == "BTC") res += tmp * 380000.0;
    }
    std::cout << res;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

template<class T>
using vec = vector<T>;

template<class T>
using mat = vector<vec<T>>;

template<class T>
mat<T> mat_mul(mat<T> &A, mat<T> &B) {
    mat<T> C(A.size(), vec<T>(B[0].size()));
    rep(i, A.size()) {
        rep(k, B.size()) {
            rep(j, B[0].size()) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    return C;
}

template<class T>
mat<T> mat_pow(mat<T> A, ll n) {
    mat<T> B(A.size(), vec<T>(A.size()));
    rep(i, A.size()) B[i][i] = 1;
    while (n > 0) {
        if (n & 1) B = mat_mul(B, A);
        A = mat_mul(A, A);
        n >>= 1;
    }
    return B;
}

int main() {
    ll N, K;
    cin >> N >> K;
    mat<mint> A(N, vec<mint>(N, 0));
    rep(i, N) rep(j, N) cin >> A[i][j].x;

    auto B = mat_pow(A, K);
    mint ans = 0;
    rep(i, N) rep(j, N) ans += B[i][j];
    cout << ans.x << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll n;cin>>n;
  string ans="";
  while(n>0){
    char val=n%26;
    if(val==0){
      val=26;
      n-=26;
    }
    ans.push_back(val+'a'-1);
    n/=26;
  }
  reverse(all(ans));
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stack>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

#define rep(i,n) for(int i=0; i < n; i++)
using ll =  long long;
using namespace std;

map<int, bool> check;

int main()
{
    int s, i = 1;
    cin >> s;
    check[s] = true;
    i++;
    while (true)
    {
        if (s % 2 == 0)
        {
            s /= 2;
        }
        else
        {
            s = 3 * s + 1;
        }
        if (check[s] != true)
        {
            check[s] = true;
            i++;
        }
        else
        {
            break;
        }
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    table = [list(map(int, input().split())) for _ in range(2)]
    a1 = table[0][0]
    a2 = sum(table[1])
    res = a1 + a2
    for i in range(1, n):
        a1 += table[0][i]
        a2 -= table[1][i - 1]
        res = max(res, a1 + a2)
    print(res)


if __name__ == '__main__':
    main()


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

using namespace std;

void solve(vector<vector<char>>& maps, int x, int y, int h, int w, int &count) {

//    cout << x << "," << y << endl;

//    cout << count << endl;
//    for(int i=0; i<h; i++) {
//        for(int j=0; j<w; j++) {
//            cout << maps[i][j];
//        }
//        cout << endl;
//    }
    
    count++;
    maps[y][x] = '.';
//        if(y>0 && maps[y-1][x-1] == '#') solve(maps, x-1, y-1, w, h, count);
//        if((y<h-1) && maps[y+1][x-1] == '#') solve(maps, x-1, y+1, w, h, count);
//        if(y>0 && maps[y-1][x+1] == '#') solve(maps, x+1, y-1, w, h, count);
//        if((y<h-1) && maps[y+1][x+1] == '#') solve(maps, x+1, y+1, w, h, count);
    if(x>0 && maps[y][x-1] == '#')   solve(maps, x-1, y, h, w, count);
    if((x<w-1) && maps[y][x+1] == '#')   solve(maps, x+1, y, h, w, count);
    if(y>0 && maps[y-1][x] == '#') solve(maps, x, y-1, h, w, count);
    if((y<h-1) && maps[y+1][x] == '#') solve(maps, x, y+1, h, w, count);

    return;
}


int main(void){

    int h,w;
    cin >> h >> w;
    
    vector<vector<char>> maps;
    for(int i=0; i<h; i++) {
        vector<char> map;
        for(int j=0; j<w; j++) {
            char temp;
            cin >> temp;
            map.push_back(temp);
        }
        maps.push_back(map);
    }

    for(int i=0; i<h; i++) {
        for(int j=0; j<w; j++) {
            int count = 0;
            if(maps[i][j] == '#') solve(maps, j, i, h, w, count);
//            cout << count << endl;
            if(count == 1) {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
    
}


Measured memory_bytes: 512
#include <iostream>
#include<vector>
#include<numeric>
using namespace std;
int main(void){
    // Your code here!
    int a[100];
    int mergin[100];
    int N;
    cin>>N;
    vector<int> b;
    int c;
    for(int i=0;i<N;i++)
    {
        cin>>c;
        a[i]=++c;
        if(i){
            mergin[i]=a[i]-a[i-1];
        }else{
            b.push_back(a[0]);
        }
    }
    for(int i=1;i<N;i++)
    {
        if(b.back()*mergin[i]<0)
        {
            b.push_back(b.back()<0?a[i]:-a[i]);
        }else if(b.back()*mergin[i]>0){
            b.back()=b.back()>0?a[i]:-a[i];
        }else{}
    }
    int counter=accumulate(b.begin(),b.end(),0);
    if(b.back()<0) counter-=b.back();
    cout<<counter-1;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>
#include <set>
using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
ll BASE_NUM = 1000000007;


//https://scrapbox.io/pocala-kyopro/%E6%8B%A1%E5%BC%B5%E3%83%A6%E3%83%BC%E3%82%AF%E3%83%AA%E3%83%83%E3%83%89%E3%81%AE%E4%BA%92%E9%99%A4%E6%B3%95
vector<ll> inverse_array(ll n){
    vector<ll> inverse(n,-1);
    inverse[1] = 1;
    for(int i = 2;i<n;i++){
        inverse[i] = BASE_NUM - inverse[BASE_NUM % i] * (BASE_NUM/i) % BASE_NUM;
    }
    return inverse;
}

ll combination(vector<ll> &factorial, vector<ll> &inverse_factorial, ll n,ll m){
    ll value = factorial[n];
    value = value * inverse_factorial[m] % BASE_NUM;
    value = value * inverse_factorial[n - m] % BASE_NUM;
    return value;
}

int main()
{
    // 整数の入力
    ll N,K;
    vector<ll> X;
    cin >> N >> K;
    vector<ll> inverse = inverse_array(N);
    vector<ll> factorial;
    factorial.push_back(1);
    for(int i = 1;i<= N;i++){
        factorial.push_back(factorial[i-1] * i % BASE_NUM);
    }

    vector<ll> inverse_factorial;
    inverse_factorial.push_back(1);
    for(int i = 1;i<= N;i++){
        inverse_factorial.push_back(inverse_factorial[i-1] * inverse[i] % BASE_NUM);
    }
    for (int i = 0; i < N; i++)
    {
        ll x;
        cin >> x;
        X.push_back(x);
    }
    sort(X.begin(),X.end());
    ll max_sum = 0;
    ll min_sum = 0;
    for(int i = 1;N - i >= K - 1;i++){
        // cout << i << endl;
        ll current = (BASE_NUM + X[N - i]) % BASE_NUM;
        ll add = combination(factorial,inverse_factorial,N - i, K - 1) * current % BASE_NUM;
        max_sum = (max_sum + add) % BASE_NUM;
    }
    // cout << max_sum << endl;

    for(int i = 1;N - i >= K - 1;i++){
        ll current = (BASE_NUM + X[i - 1]) % BASE_NUM;
        ll add= combination(factorial,inverse_factorial,N - i, K - 1) * current % BASE_NUM;
        min_sum = (min_sum + add) % BASE_NUM;
    }
    // cout << min_sum << endl;
    // cout << combination(factorial, inverse_factorial,4,4) << endl;

    cout << ( BASE_NUM  + max_sum - min_sum) % BASE_NUM << endl;;
    return 0;
}

Measured memory_bytes: 4084
#include <stdio.h>

int main(void)
{
  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);

  if(a==b&&b==c)
    puts("1");
  else if(a==b||b==c||c==a)
    puts("2");
  else
    puts("3");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

int main()
{
	int w[101], n = 0, ans = 0,t=0;
	int d;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		if (i != 0) w[i] += w[i - 1];
	}
	int first, second;
	for (t = 0; t < n-1; t++) {
		first = w[t];
		second = w[n - 1] - w[t];
		if (t == 0) {
			d = abs(first - second);
		}
		else {
			if(d>abs(first - second))
				d = abs(first - second);
		}
	}

	cout << d << endl;
	return 0;
}

Measured memory_bytes: 256
#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 rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define lli long long int
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#define eb emplace_back
#define em emplace
#define all(v)  v.begin(),v.end()
#define mod 1000000007
#define vi vector<int>
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define pll pair<lli,lli>
#define vvi vector<vector<int>>
#define vvl vector<vector<lli>>
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define tk(args...) take(args);
#define posLSB(X) __builtin_ctz(X)
#define num1bit(X) __builtin_popcount(X)
#define numlead0(X) __builtin_clz(X)
#define umreserve(X) X.reserve(32768); X.max_load_factor(0.25);
void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << "\n"; err(++it, args...);}
void take() {} template<typename T, typename... Args> void take( T & a, Args & ... args ) { cin>>a; take(args...); }
template<class T>
void printvec(vector<T> &a){
	for(T &x:a){
		cout<<x<<" ";
	}
	cout<<endl;
}
template<class T>
void printarr(T a[],lli n){
	for(lli i=0;i<n;i++){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};

#define endl "\n"

lli add(lli a, lli b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

lli mul(lli a, lli b) {
	return a * 1ll * b % mod;
}

inline bool setmin(lli &x, lli y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(lli &x, lli y) { return (y > x) ? x = y, 1 : 0; }

lli power_mod(lli a,lli x){if(x==0) return 1;lli y=power_mod(a,x/2);lli ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
lli inv(lli a){return power_mod(a,mod-2);}
lli power(lli a, lli x){ if(x==0) return 1; lli y= power(a,x/2); lli ans=(y*y); if(x%2) ans*=a; return ans;}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<bool> dp(k+1);
	sort(all(a));
	dp[0]=false;
	for(int i=1;i<=k;i++){
		bool ans=false;
		for(int j=0;j<n;j++){
			if(a[j]>i)break;
			ans=ans|(!dp[i-a[j]]);
			if(ans)break;
		}
		dp[i]=ans;
	}
	cout<<(dp[k]?"First":"Second")<<endl;
}


Measured memory_bytes: 384
#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;

#ifdef LOCAL
	#define debug(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define debug(...) 42
#endif

#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
typedef long long ll;

const int S=100100;
int main()
{
	int n,m;
	while(~sf("%d %d",&n,&m))
	{
		vector<int>g[m+5];
		for(int i=0;i<m;i++)
		{
			int k;
			sf("%d",&k);
			for(int j=0;j<k;j++)
			{
				int x;
				sf("%d",&x);
				x--;
				g[i].push_back(x);
			}
		}

		int p[m+5];
		for(int i=0;i<m;i++)sf("%d",&p[i]);

		int ans=0;
		for(int i=0;i<(1<<n);i++)
		{
			bool all=true;
			for(int j=0;j<m;j++)
			{
				int cnt=0;
				for(int light:g[j])
				{
					if((i & (1<<light))!=0)cnt++;
				}
				if(cnt%2!=p[j]%2)
				{
					all=false;
					break;
				}
			}
			if(all)ans++;
		}
		pf("%d\n",ans);
	}
    return 0;
}



































Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>

using namespace std;

void solve() {
    long long ans = 1;
    int n;
    long long mod = 1e9+7;
    cin >> n;
    for (int i = 1; i < n + 1; ++i)
        (ans *= i) %= mod;
    cout << ans;

}

int main() {

    solve();
    return 0;
}



Measured memory_bytes: 3112
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> myds;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long int
#define F first
#define S second
#define vec(x) vector<x> 
#define pi(x,y) pair<x,y>
#define pqq(x) priority_queue<x> 
#define min_heap(x) priority_queue<x, vector<x>, greater<x> >
#define all(x) x.begin(),x.end()
#define rep(i,x,y) for(int i=x;i<y;i++)
#define repd(i,x,y,k) for(int i=x;i<y;i+=k)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define rev(x) reverse(all(x))
#define uniq(x) x.resize(distance(x.begin(),unique(all(x))))
#define full(x,a) memset(x,a,sizeof(x))
#define lcm(x,y) ((x*y)/__gcd(x,y))
#define mod 1000000007
#define bitcount __builtin_popcountll
#define pb push_back
#define pf push_front
#define indexof order_of_key
#define valueat find_by_order

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

int gcdextended(int a,int b,int &x,int &y){if(!a){x=0,y=1;return b;}int x1,y1;int ans=gcdextended(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return ans;}
int inv(int a){int x,y;int ans=gcdextended(a,mod,x,y);return(x%mod+mod)%mod;}
int nCr(int n,int k){int res=1;k=(k>n-k)?n-k:k;rep(i,0,k){res*=(n-i);res/=(i+1);}return res;}
int POW(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res%mod*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
//void seive(){prime[0]=0;prime[1]=0;rep(i,2,10002)prime[i]=1;for(int i=2;i*i<=10000;i++){if(prime[i]){for(int j=i*i;j<=10000;j+=i)prime[j]=0;}}} 

int t;
int n;
string s;

void input(){
    cin>>n>>s;
}

void solve(){
    int count=0;
    rep(i,0,n){
        int j=i;
        while(j<n&& s[i]==s[j])
            j++;
        count++;
        i=j-1;
    }
    cout<<count<<endl;
}

main(){
    fastio;
    t=1;
    while(t--){
        input();
        solve();
    }
}

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

int main(){
    int n,memo;
    priority_queue<int,vector<int>,greater<int> > que;
    cin >> n;
    int a[n];
    
    rep(i,0,n){
        cin >> a[i];
    }
    
    sort(a,a+n);
    
    rep(i,1,sqrt(a[n-1])+1){
        rep(j,0,n){
            if(a[j] % i)break;
            else if(j == n-1)que.push(i);
        }
        
        if(a[n-1]/i == i)continue;
        
        rep(j,0,n){
            if(a[j] % (a[n-1]/i))break;
            else if(j == n-1)que.push(a[n-1]/i);
        }
    }
    
    while(!que.empty()){
        if(que.top() == memo){
            que.pop();
            continue;
        }
        memo = que.top(); que.pop();
        
        cout << memo << endl;
    }
}


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

using namespace std;

int main() {

  int N, T[105], M,P[105], X[105];
  long long sum = 0;
  cin>>N;
  for(int i=0; i<N; i++) cin>>T[i], sum += T[i];
  cin>>M;
  for(int i=0; i<M; i++) cin>>P[i]>>X[i];

  for(int i=0; i<M; i++){
    cout<<sum - T[P[i]-1] + X[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

ll Q,H,S,D,N;
cin>>Q>>H>>S>>D>>N;

ll L=min({Q*4,H*2,S});
//!”Q=0.25L,so 4xQ means to 1L,and H=0.5L and so on”
ll d=min({2*L,D});
//!"D is for 2L , divide to as 1L"

ll ans=0, tea=0;
ans +=N/2*d;
tea +=(N/2)*2;

ans+=(N-tea)*L;
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
     int t,i,count=0,flag=0;
  cin>>t;
  string a;
 for(int i=0;i<t;i++)
 {
   cin>>a[i];
   
   
   if(a[i]=='R')
     count++;
   else
     flag++;
      
 }
 if(count>flag)
 {
     cout<<"Yes";
 }
 else if(count<=flag)
 {
     cout<<"No";
 }
 else
 {
     cout<<"No";
 }

 }
 



Measured memory_bytes: 256
import java.util.Scanner;

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

			for(;;) {

				int H = sc.nextInt();
				int W = sc.nextInt();

				if(H == 0 && W == 0) {
					break;
				}

				for(int j = 0; j < H; j++) {
					for(int k = 0; k < W; k++) {
						System.out.print("#");
					}
					System.out.print('\n');
				}
				System.out.println();
			}
	}
}

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

typedef long long s64;
int n;s64 a[55];
s64 check(const s64 &s)
{
	s64 ns=0;
	for(int i=1;i<=n;++i)ns+=(a[i]+s+1)/(n+1);
	return ns;
}

int main()
{
	cin>>n;
	s64 sum=0;
	for(int i=1;i<=n;++i){cin>>a[i];sum+=a[i];}
	s64 limit=sum-n*(n-1);
	s64 l=0,r=sum;
	if(check(l)<limit)
	{
		while(l+1!=r)
		{
			s64 mid=(l+r)/2;
			if(check(mid)<=limit)l=mid;
			else r=mid;
		}
	}
	s64 ans=check(l);
	for(int i=1;i<=n;++i)
	{
		s64 b=(a[i]+l+1)/(n+1);
		a[i]=a[i]-(n+1)*b+ans;
	}
	while(1)
	{
		s64 *it=max_element(a+1,a+n+1);
		if(*it<n)break;
		++ans;
		for(int i=1;i<=n;++i)++a[i];
		*it-=n+1;
	}
	cout<<ans;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
r = 0
ans = 0
s = 0
xor = 0

for i in range(n):
    while r < n:
        if xor ^ a[r] == s + a[r]:
            xor = xor ^ a[r]
            s += a[r]
            r += 1
            ans += (r-i)
        else:
            xor = xor ^ a[i]
            s -= a[i]
            break

print(ans)


Measured memory_bytes: 24424
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma -(big+1)
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000
#define mp make_pair
#define mt make_tuple
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define inv2 500000004
#define MOD 998244353 
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{

	ll n,x,y,i,j,d1,d2,d3,val;

	cin>>n>>x>>y;
	ll ans[n+1]={0};

	for(i=1;i<n;++i)
	{

		for(j=2;j<=n;++j)
		{
			//three ways to go to j from i take min of them
			d1 = j-i;
			d2 = abs(x-i) + 1 + abs(j-y);
			d3 = abs(y-i) + 1 + abs(j-x);

			val = min(d1,d2);
			val = min(d3,val);

			ans[val]++;

		}


	}

	for(i=1;i<=(n-1);++i)
			cout<<ans[i]<<"\n";



	return 0;
}

Measured memory_bytes: 256
N = int(input())
T = list(map(int, input().split()))
M = int(input())
drinks = [list(map(int, input().split())) for i in range(M)]

total = sum(T)

ans = []
for i in range(M):
    ans.append(total - T[drinks[i][0]-1] + drinks[i][1])

print(*ans, sep='\n')


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

int main() {
    double l; cin >> l;
    cout << setprecision(10) << (l * l * l)/27.0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

template <size_t T>
bool prevSubset(bitset<T>& bs, const bitset<T>& mask)
{
    if(bs.none())
        return false;
    bs = bs.to_ulong() - 1ull;
    bs &= mask;
    return true;
}

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> a(n), b(n);
        for(int i=0; i<n; ++i)
            cin >> a[i] >> b[i];

        vector<int> use(1<<n, 0);
        for(int i=0; i<(1<<n); ++i){
            bitset<14> bs(i);
            for(int j=0; j<n; ++j){
                if(bs[j])
                    use[i] += b[j];
            }
        }

        vector<int> dp(1<<n, INF);
        dp[(1<<n)-1] = 0;
        for(int i=(1<<n)-1; i>=0; --i){
            bitset<14> mask(i);
            int space = m;
            for(int j=0; j<n; ++j){
                if(!mask[j])
                    space += a[j] - b[j];
            }

            bitset<14> bs(i);
            do{
                if(use[bs.to_ulong()] <= space){
                    bitset<14> bs2 = mask & ~bs;
                    dp[bs2.to_ulong()] = min(dp[bs2.to_ulong()], dp[i] + 1);
                }
            }while(prevSubset(bs, mask));
        }

        if(dp[0] == INF)
            cout << "Impossible" << endl;
        else
            cout << dp[0] << endl;
    }
}

Measured memory_bytes: 1328
#include <stdio.h>

char s[105];

int main(){
    scanf("%s", s);
    int n;
    for(n=0; s[n]; n++);
    int res = 1e9;
    for(char ch='a'; ch<='z'; ch++){
        int cons = 0, mx = 0;
        for(int i=0; i<n; i++){
            if(s[i] == ch){
                if(cons > mx) mx = cons;
                cons = 0;
            } else{
                cons++;
            }
        }
        if(cons > mx) mx = cons;
        if(mx < res) res = mx;
    }
    printf("%d", res);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	rep(i, 26)rep(j, 15) {
		int ans = i * 4 + j * 7;
		if (ans == n) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int n = int.Parse(ReadLine());
	int[] b = ReadIntArray();
	int[] a = new int[n];
	a[0] = b[0];
	a[n-1] = b[n-2];

	for (int i = 1; i <= n-2; i++)
	{
	    a[i] = Math.Min(b[i], b[i-1]);
	}

	WriteLine(a.Sum());
    }
}


Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main()
{
	int n;
	int y;
	string a;
	int x=0;
	int max=0;
	cin>>n>>a;
	for(y=0;y<n;y++)
	{
		if(a[y]=='I')
		{
			x++;
		}
		else if(a[y]=='D')
		{
			x--;
		}
		if(x>max)
		{
			max=x;
		}
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll function1(ll h)
{
 	if(h==1)
 	{
 		return 1;
 	}
 	else
 	{
 		return 1+2*function1(h/2);
 	}
}
int main()
{
	ll h, sum =0;
	cin >> h;
	cout << function1(h);
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)


int main() {

	char S[212345], T[212345];

	scanf("%s%s", S, T);

	map<char, char> s, t;

	int len = strlen(S);

	char cs = 1, ct = 1;
	rep(i, len) {
		if (s[S[i]] == 0) {
			s[S[i]] = cs;
			S[i] = cs;
			++cs;
		}
		else S[i] = s[S[i]];
		if (t[T[i]] == 0) {
			t[T[i]] = ct;
			T[i] = ct;
			++ct;
		}
		else T[i] = t[T[i]];
	}

	bool yn = true;
	
	rep(i, len) if (S[i] != T[i]) yn = false;

	printf("%s\n", yn ? "Yes" : "No");

	return 0;
}


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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main()
{
	ll N;
	cin >> N;
	vector<ll> vec(N);
	for( ll i = 0; i < N; ++ i ){
		cin >> vec[i];
	}

	vector<ll> dp(N+2, INF);
	dp[0] = 0;
	for( ll i = 1 ; i < N; ++ i ){
		chmin(dp[i], dp[i-1] + abs(vec[i-1]-vec[i]));
		if ( i > 1 ){
			chmin(dp[i], dp[i-2] + abs(vec[i-2]-vec[i]));
		}
	}

	cout << dp[N-1] << endl;
	return 0;
}

Measured memory_bytes: 4720
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Console;

namespace AtCoder_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = CinTAr();
            int res = 0;
            for(int i = a[0];i <= a[2] + 0.5;i += a[0])
            {
                res += a[1];
            }
            Cout(res);
            Cin();

        }



        static readonly int MOD1E9 = 10000007;
        static bool isInt(double d) { return (int)d == d; }
        static string Cin() { return ReadLine(); }
        static string[] CinAr() { return ReadLine().Split(' '); }
        static int CinT() { return S2i(Cin()); }
        static int[] CinTAr() { return CinAr().Select((x, i) => { return S2i(x); }).ToArray(); }
        static long CinL() { return S2L(Cin()); }
        static long[] CinLAr() { return CinAr().Select((x, i) => { return S2L(x); }).ToArray(); }
        static double CinD() { return S2D(Cin()); }
        static double[] CinDAr() { return CinAr().Select((x, i) => { return S2D(x); }).ToArray(); }
        static int S2i(string s) { return int.Parse(s); }
        static long S2L(string s) { return long.Parse(s); }
        static double S2D(string s) { return double.Parse(s); }
        static void Cout(object s) { WriteLine(s); }
        static int[] yakusuu(int n)
        {
            if (n == 1) { return new int[] { 1 }; }
            HashSet<int> res = new HashSet<int>();
            for (int i = 1; i < Math.Ceiling(n / 2.0); i++)
            {
                if (n % i == 0)
                {
                    res.Add(i);
                    res.Add(n / i);
                }
            }
            return res.ToArray();
        }
        /// <summary>
        /// Debug時のみの使用を推奨
        /// </summary>
        /// <typeparam name="Type"></typeparam>
        /// <param name="types"></param>
        static void CoutAr<Type>(IEnumerable<Type> types)
        {
            string text = "";
            foreach (var i in types)
            {
                text += " " + i;
            }
            WriteLine(text.Substring(1));
        }

        public static long nCr(int n, int r)
        {
            // naive: return Factorial(n) / (Factorial(r) * Factorial(n - r));
            return nPr(n, r) / Factorial(r);
        }

        public static long nPr(int n, int r)
        {
            // naive: return Factorial(n) / Factorial(n - r);
            return FactorialDivision(n, n - r);
        }

        private static long FactorialDivision(int topFactorial, int divisorFactorial)
        {
            long result = 1;
            for (int i = topFactorial; i > divisorFactorial; i--)
                result *= i;
            return result;
        }

        private static long Factorial(int i)
        {
            if (i <= 1)
                return 1;
            return i * Factorial(i - 1);
        }
    }
}


Measured memory_bytes: 11220
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
BC = [list(map(int, input().split())) for i in range(m)]
BC.sort(key=lambda x: x[1], reverse=True)
ans = 0
cmax = BC[0][1]
cnt = 0
j = 0
for i in range(n):
    if A[i] < cmax:
        ans += cmax
        cnt += 1
    else:
        ans += A[i]

    if cnt == BC[j][0]:
        if j == m - 1:
            cmax = -1
            continue
        else:
            j += 1
            cmax = BC[j][1]
            cnt = 0
    else:
        continue
print(ans)


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

using namespace std;

int gcd(int a, int b) {
  return a ? gcd(b % a, a) : b;
}

const int N = 1e6 + 6;
char s[N], t[N];

int main() {
  int n, m;
  scanf("%d %d %s %s", &n, &m, s, t);
  long long kpk = 1LL * n * (m / gcd(n, m));
  long long step = kpk / m;
  for (int i = 0; i < n; ++i) {
    long long now = (kpk/n) * i;
    // cerr << i << " " << now << endl;
    if (now % step) continue;
    int cur = now / step;
    if (s[i] != t[cur]) {
      kpk = -1;
      break;
    }
  }
  printf("%lld\n", kpk);
  return 0;
}

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



int main() {
  int x; 
  cin >> x;
  if(x >= 30){ 
    puts("Yes");
  }else{
    puts("No");
  }
}

Measured memory_bytes: 3536
/**


文字列 str  に対して、与えられた命令の列を実行するプログラムを作成してください。命令は以下の操作のいずれかです：
?print a b: str  の a 文字目から b 文字目までを出力する。
?reverse a b: str  の a 文字目から b 文字目までを逆順にする。
?replace a b p: str  の a 文字目から b 文字目までを p に置き換える。

ここでは、文字列 str  の最初の文字を 0 文字目とします。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);

		// 文字列str,命令の数を受け取る
		String str = sc.nextLine();
		int intMeirei = sc.nextInt();
		String strMeirei;
		int intSaisyo;
		int intSaigo;
		String strKekka ;
		//intMeireiの数だけ処理を繰り返す
		for (int i = 0; i < intMeirei; i++) {
			//命令の内容を受け取る
			strMeirei = sc.next();
			//命令の最初の文字と最後の文字設定
			intSaisyo = sc.nextInt();
			intSaigo = sc.nextInt();
			//受け取った文字がreplace
			if (strMeirei.equals("replace")) {
				//指定された場所の文字と受け取った文字列を入れ替え
				String strOkikae = sc.next();
				String a = str.substring(0,intSaisyo);
				String b =  str.substring(intSaigo+1,str.length());
				str = a + strOkikae + b ;

				//System.out.println(str);
			//受け取った文字がreverse
			} else if (strMeirei.equals("reverse")) {


				StringBuffer b = new StringBuffer(str.substring(intSaisyo,intSaigo + 1));
		        String strGyaku = b.reverse().toString();
		        String c = str.substring(0,intSaisyo);
		        String d = str.substring(intSaigo+1,str.length());
		        str =  c + strGyaku + d;


		        //System.out.println(str);

			//受け取った文字がprint
			} else if (strMeirei.equals("print")) {
				strKekka= str.substring(intSaisyo,intSaigo+1);
				System.out.println(strKekka);

			}

		}
	}
}

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

int H, W;
string S[2000];
int L[2000][2000], R[2000][2000], U[2000][2000], D[2000][2000];

int main(void){
    // Your code here!
    cin >> H >> W;
    for(int i=0;i<H;i++)    cin >> S[i];
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if( S[i][j] == '#' ){
                L[i][j] = 0;
                U[i][j] = 0;
            } else {
                L[i][j] = ( ( 0 <= j-1 )? L[i][j-1] + 1 : 1 );
                U[i][j] = ( ( 0 <= i-1 )? U[i-1][j] + 1 : 1 );
            }
        }
    }
    
    for(int i=H-1;i>=0;i--){
        for(int j=W-1;j>=0;j--){
            if( S[i][j] == '#' ){
                R[i][j] = 0;
                D[i][j] = 0;
            } else {
                R[i][j] = ( ( j+1 < W )? R[i][j+1] + 1 : 1 );
                D[i][j] = ( ( i+1 < H )? D[i+1][j] + 1 : 1 );
            }
        }
    }
    
    int ans = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int res = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3;
            ans = max(ans, res);
        }
    }
    
    cout << ans << endl;
}


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

int main(){
  int dp[50001];
  int c[20];
  int n;
  int m;

  cin >> n >>m;
  for(int i=0;i<m;i++) cin>> c[i];
  sort(c,c+m);
  for(int j=0;j<=n;j++) dp[j] = j;

  for(int i=1;i<m;i++)
    for(int j=1;j<=n;j++)
      if(j>=c[i]) dp[j] = min(dp[j],dp[j-c[i]]+1);

  cout << dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 1372