akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<long long> L,
           std::vector<long long> R, std::vector<long long> D) {
  map<ll, map<ll, ll>> edges; // <from, <to, dist>>
  rep(m, M) {
    edges[L[m]][R[m]] = D[m];
    edges[R[m]][L[m]] = -D[m];
  }

  const ll INF = 1e12;
  vector<ll> dists(N + 1);
  dists.assign(N + 1, INF);
  for (ll i = 1; i <= N; i++) {
    if (dists[i] != INF) {
      continue;
    }

    queue<ll> que;
    que.push(i);
    dists[i] = 0;
    while (!que.empty()) {
      ll from = que.front();
      que.pop();

      map<ll, ll> toDists = edges[from];
      for (auto iter = toDists.begin(); iter != toDists.end(); iter++) {
        ll to = iter->fi;
        ll dist = iter->sc;

        if (dists[to] == INF) {
          dists[to] = dists[from] + dist;
          que.push(to);
        } else if (dists[to] != dists[from] + dist) {
          print(NO);
          return;
        }
      }
    }
  }

  print(YES);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> L(M);
  std::vector<long long> R(M);
  std::vector<long long> D(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &L[i]);
    scanf("%lld", &R[i]);
    scanf("%lld", &D[i]);
  }
  solve(N, M, std::move(L), std::move(R), std::move(D));
  return 0;
}


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

#define ll long long

int main()
{
    int n,p;
    cin>>n;

    float x=1,k;
    while(x<=n)
    {
        k = x*1.08;
        p = int(k);

        if(p==n)
        {
            cout<<x<<endl;
            goto end;
        }
        x=x+1;
    }
    cout<<":("<<endl;
    end:;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  scanf("%d", &n);
  if(n<105) printf("%d\n",0);
  if(105<=n&&n<135) printf("%d\n",1); 
  if(135<=n&&n<165) printf("%d\n",2);
  if(165<=n&&n<189) printf("%d\n",3);
  if(189<=n&&n<195) printf("%d\n",4);
  if(195<=n) printf("%d\n",5);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<math.h> 
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<climits>
using namespace std;
typedef long long int lli;
lli mod=1000000007;
vector < lli> primes;

void Sieve(lli n) 
{ 
    bool prime[n+1];
	for(lli i=0;i<n+1;++i)
		prime[i]=true;
    for (lli p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (lli i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(lli p=2; p<=n; p++) 
       if (prime[p]) 
		primes.push_back(p);  
}
lli gcd(lli a,lli b)  
 {
    if(b>a)
        swap(a,b);
    if (a%b==0)  
        return b;  
    else 
        return gcd(a%b,b);  
 }
lli power(lli x,lli y,lli m)   
{ 
    lli res = 1; 
    x=x%m;   
    while (y > 0) 
    {  
        if (y%2==1) 
            res =(res*x)%m;  
        y=y/2; 
        x=(x*x)%m; 
    } 
    return res; 
}

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	lli n;
	cin>>n;
	lli a[n],b[n-1];
	for(lli i=0;i<n-1;++i)
		cin>>b[i];
	a[0]=b[0];
	a[n-1]=b[n-2];
	lli s=a[0]+a[n-1];
	
	for(lli i=0;i<n-2;++i)
	{
		a[i+1]=min(b[i],b[i+1]);
		s+=a[i+1];
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include <stdlib.h>
using namespace std;

int main(){

string a;
    cin >> a;
    string b = "CODEFESTIVAL2016";
    int ans = 0;
    for(int i = 0; i < a.length(); i++){
        if(a[i] != b[i]) ans++;
    }
    cout << ans << endl;
    return 0;
    
}


Measured memory_bytes: 256
n = int(input())
s = input()

lst = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            moji1 = lst[i]
            moji2 = lst[j]
            moji3 = lst[k]
            cnt = 0
            kuraberu = [moji1, moji2, moji3]
            for moji in s:
                if moji == kuraberu[cnt]:
                    cnt += 1
                if cnt == 3:
                    ans += 1
                    break

print(ans)

Measured memory_bytes: 42204
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  string s;
  cin >> s;
  i64 ans = 0, cnt = 0, size = s.size();
  for (i64 i = 0; i < size - 1; i++)
    if (s[i] == 'B' && s[i + 1] == 'C')
    {
      ans += cnt;
      i++;
    }
    else if (s[i] == 'A')
      cnt++;
    else
      cnt = 0;
  cout << ans << endl;
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll r,c;
    cin>>r>>c;
    vector<string> arr(r);
    fr(i,0,r)
        cin>>arr[i];
    vector<VL> dp(r,VL(c,inf));
    fr(i,0,r)
    {
        fr(j,0,c)
        {
            if(i+j==0)
            {
                dp[i][j]=(arr[i][j]=='#');
            }
            else
            {
                if(i>0)
                {
                    dp[i][j]=min(dp[i][j],dp[i-1][j]+(arr[i-1][j]=='.'&&arr[i][j]=='#'));
                }
                if(j>0)
                {
                    dp[i][j]=min(dp[i][j],dp[i][j-1]+(arr[i][j-1]=='.'&&arr[i][j]=='#'));
                }
            }
        }
    }
    cout<<dp[r-1][c-1];
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<":\n";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main() {
    int number, queries, quantifier, numb1, numb2;
    cin >> number >> queries;
    int parents[number] = {};
    for (int i = 0; i < number; i++) parents[i] = i;
    for (int i = 0; i < queries; i++) {
        cin >> quantifier >> numb1 >> numb2;
        if (quantifier == 0) {
            int pickles = parents[numb2];
            for (int i = 0; i < number; i++) if (parents[i] == pickles) parents[i] = parents[numb1];
        } else {
            if (parents[numb1] == parents[numb2]) cout << "1" << endl;
            else cout << "0" << endl;
        }
    }
}


Measured memory_bytes: 3144
import java.util.Scanner;

public class Main {

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

		char[] array = new char[S.length()];
		for(int i=0;i<S.length();i+=2) {
			System.out.print(S.charAt(i));
		}
		//System.out.println(Math.pow(4, 8));

	}
	public static int sample() {
		return 1;
	}

}


Measured memory_bytes: 27756
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
using namespace std;

string S;
char T[17] = "0123456789abcdef";
int Q;
int U[32];
int power[4] = { 1,2,4,8 };

void Bit(string W) {
	int c[8], v[32];
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 16; j++) {
			if (W[i] == T[j]) {
				c[i] = j;
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i < 8; i++) {
		for (int j = 3; j >= 0; j--) {
			v[cnt] = (c[i] / power[j]) % 2;
			cnt++;
		}
	}
	for (int i = 0; i < 32; i++) {
		U[i] = v[31 - i];
	}
}

int Seisu() {
	int res2 = 0;
	for (int i = 8; i < 31; i++) {
		res2 += (1 << (i - 8))*U[i];
	}
	return res2;
}

int Shosu() {
	int res3 = 0;
	for (int i = 0; i < 8; i++) {
		res3 += (1 << i)*U[i];
	}
	return res3;
}

long double solve(string V) {
	Bit(V);
	int seisu = Seisu();
	int shosu = Shosu();
	long double ans = 1.0*seisu;
	long double ans2 = 1.0*shosu;
	ans += ans2 / 256.0;
	return ans;
}

int main() {
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> S;
		long double f = solve(S);
		long long g = f * 200000000;
		bool ok = false;
		if (U[31] == 1) { cout << '-'; }
		for (int i = 18; i >= 9; i--) {
			long long h = (g / (long long)pow(10, i)) % 10;
			if (h >= 1) { ok = true; }
			if (ok == true) { cout << h; }
		}
		cout << (g / (long long)pow(10, 8)) % 10;
		cout << '.';
		ok = true;
		for (int i = 7; i >= 0; i--) {
			int h = (g / (long long)pow(10, i)) % 10;
			if (ok == true || i == 7) {
				cout << h;
			}
			if (g % (long long)(pow(10, i)) == 0) {
				ok = false;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
dataset = []
op = ""
while op is not "?":
    a, op, b = map(str, input().split())
    a = int(a)
    b = int(b)
    if (a >= 0 and a <= 20000) and (b >= 0 and b <= 20000):
        listed = []
        listed.append(a)
        listed.append(op)
        listed.append(b)
        dataset.append(listed)
    elif op is "?":
        break
    else:
        break

for i in dataset:
    if i[1] is "+":
        print("{0}".format(i[0] + i[2]))
    elif i[1] is "-":
        print("{0}".format(i[0] - i[2]))
    elif i[1] is "*":
        print("{0}".format(i[0] * i[2]))
    elif i[1] is "/":
        print("{0}".format(int(i[0] / i[2])))
    else:
        pass

Measured memory_bytes: 7724
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    while(true){
        int n, x; cin >> n >> x;
        if(n == 0 and x == 0) break;

        int cnt = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++){
                for(int k = j + 1; k <= n; k++){
                    if(i + j + k == x){
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int main(void) {
  string s_str;
  cin >> s_str;

  int s= stoi(s_str);

  int hour, minute, second;

  hour = s / 3600;
  s -= (hour * 3600);

  minute = s / 60;
  s -= (minute * 60);

  second = s;

  cout << hour << ':' << minute << ':' << second << endl;

  return 0;
}


Measured memory_bytes: 3176
#include <iostream>
using namespace std;
int main(void){
    
    int a, b;
    cin >> a >> b;
    
    double amari = (a + b) / 2.0 - (a + b) / 2;    

    if(amari > 0){
        cout << (a + b) / 2 + 1 << endl;
    }
    else{
        cout <<  (a + b) / 2 << endl;
    }
    
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
  	int N;
  	string S;
  	cin >> N >> S;
  
  	int dp[N];
  	dp[0] = 0;
  	for (int i = 1; i < N; i++) if (S[i] == 'E') dp[0]++;
  
  	for (int i = 1; i < N; i++){
      	dp[i] = dp[i - 1];
      	if (S[i - 1] == 'W') dp[i]++;
      	if (S[i] == 'E') dp[i]--;
    }
  
  	int min = dp[0];
  	for (int i = 1; i < N; i++) if (min > dp[i]) min = dp[i];
  
  	cout << min << endl;
}

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

int main() {
  int N;
  int count = 0;
  cin >> N;
  for (int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    count += r - l + 1;
  }
    cout << count << endl;
}


Measured memory_bytes: 256
A, B, C = [int(i) for i in input().split()]

if A == B == C:
    if A % 2 == 0:
        print(-1)
    else:
        print(0)
else:
    count = 0
    while all(d % 2 == 0 for d in [A, B, C]):
        A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
        count += 1
    print(count)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int main(){
  long long int yon;
  cin >> yon;
  long long int count = 0;
  for(long long int i = 100;i<yon;i+=i/100){
     count++;
     if(i==yon){
       break;
     }
  }
  cout << count << endl;
 return 0;
}

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

int64_t factorial( int64_t n, int64_t m ) {
	int64_t x = 1;
	for( int64_t i = 2; i <= n; ++i ) {
		x = x*i % m;
	}
	return x;
}

int main() {
	ios_base::sync_with_stdio( false );

	int N, M;
	cin >> N >> M;

	if( abs( N-M ) > 1 ) {
		cout << "0\n";
	}
	else {
		const int64_t mod = 1000000007;

		int64_t result = 2 - abs( N-M );
		result = result * factorial( N, mod ) % mod;
		result = result * factorial( M, mod ) % mod;

		cout << result << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

int main() {
	optimizar_io
	int n, a[200010];
	map<int,ll> cnt;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	ll total = 0;
	for (auto c : cnt) {
		total += (c.second * (c.second - 1)) / 2; 
	}
	for (int i = 0; i < n; i++) {
		cout << total - (cnt[a[i]] - 1) << "\n";
	}
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define Rep(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define Repr(i, b, e) for(int (i) = (b) - 1; (i) >= (e); --(i))
#define Print(x) cout << (x) << endl 
#define Min2(a, b) ((a) < (b)) ? (a) : (b)
#define Max2(a, b) ((a) > (b)) ? (a) : (b)

typedef long long ll;

using namespace std;

int N;
int color[100000];
bool visited[100000];
vector<pair<int, int> > adj[100000];

void dfs(int node, int weight, int c){
    if(visited[node]) return;
    visited[node] = true;
    if(weight % 2 == 1) color[node] = 1 - c;
    else color[node] = c;
    for(auto edge : adj[node]){
        dfs(edge.first, edge.second, color[node]);
    }
}

int main(){
    int u, v, w;
    cin >> N;
    Rep(i, 0, N - 1){
        cin >> u >> v >> w;
        u--; v--;
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
        visited[i] = false;
    }
    Rep(i, 0, N) dfs(i, 0, 0);
    Rep(i, 0, N){
        Print(color[i]);
    }
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<int> cnt(n);
	vector<bool> solved(n);
	rep (i, m) {
	  int p;
	  string s;
	  cin >> p >> s;
	  if (solved[p - 1]) continue;
	  if (s == "AC") solved[p - 1] = true;	
	  else cnt[p - 1]++;
	}
	int ac = 0, wa = 0;
	rep (i, n) {
	  if (!solved[i]) continue;
	  ac++;
	  wa += cnt[i];
	}
	cout << ac << " " << wa << endl;
    
    return 0;
}



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

int main(){
    int q;
    cin >> q;
    deque<int> v;
    for(int i=0; i<q; i++){
        int x;
        cin >> x;
        if(x == 0){
            int d, x;
            cin >> d >> x;
            if(d == 0){
                v.push_front(x);
            }else{
                v.push_back(x);
            }
        }else{
            int y;
            cin >> y;
            if(x == 1){
                cout << v[y] << endl;
            }else{
                if(y == 0){
                    v.pop_front();
                }else{
                    v.pop_back();
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 200005;
const ll inf = 1e18;
int n, a[max_n];
ll dp[max_n][3];
ll solve(int n, int k) {
    if(k > (n + 1) / 2) return -inf;
    if(k <= 0) return 0;
    int x = k - n/2 - 1;
    if(~ dp[n][x]) return dp[n][x];
    return dp[n][x] = max(solve(n - 1, k), solve(n - 2, k - 1) + a[n]);
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a+i);
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j < 3; j++) dp[i][j] = -1;
    }
    printf("%lld\n", solve(n, n/2));
    return 0;
}

Measured memory_bytes: 15536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

#include <atcoder/fenwicktree>
using namespace atcoder;

int main() {
  int n, q; cin >> n >> q;
  fenwick_tree<long long> a(n);
  REP(i, n) {
    int ai; cin >> ai;
    a.add(i, ai);
  }
  while (q--) {
    int type; cin >> type;
    if (type == 0) {
      int p, x; cin >> p >> x;
      a.add(p, x);
    } else if (type == 1) {
      int l, r; cin >> l >> r;
      cout << a.sum(l, r) << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 8248
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

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

    ll A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;

    ll ans = 0;
    int maximum, others;
    if (A > B) {
        if (A > C) {
            maximum = A;
            others = B + C;
        } else {
            maximum = C;
            others = A + B;
        }
    } else {  // A<B
        if (B > C) {
            maximum = B;
            others = A + C;
        } else {
            maximum = C;
            others = A + B;
        }
    }
    rep(i, K){
        maximum = maximum*2;
    }
    ans = others + maximum;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,m;
int a[100][10010];
int maxn=0;
void dfs(int x)
{
	if(x==n+1)
	{
		int t=0;
		for(int i=0;i<m;i++)
		{
			int s=0;
			for(int j=0;j<n;j++)
			if(a[j][i]==1)
			s++;
	    	t+=max(s,n-s);
		}
		maxn=max(maxn,t);
		return ;
	}
	dfs(x+1);
	for(int j=0;j<m;j++)
	{
		a[x][j]=!a[x][j];
	}
	dfs(x+1);
}
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF&&(n+m))
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			scanf("%d",&a[i][j]);
		}
		dfs(0);
    	printf("%d\n",maxn);
	}
	
    return 0;
}



Measured memory_bytes: 3588
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    var ary = Array<Long>(k){0}.toMutableList()
    var ans = 0L
    (1..n).forEach {i ->  ary[(i%k)] += 1}
    (0 until k).forEach { a ->
        var b = (k-a) % k
        var c = (k-a) % k
        if ((b+c) % k != 0) return@forEach
        ans += ary[a] * ary[b] * ary[c]
    }
    println(ans)
}

Measured memory_bytes: 40628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

// doubling[k][i] := a[i] から始めて 2^k 回操作を行った時の長さ
ll doubling[70][200005];

int main(void){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> a(N);
    vector<vector<int>> pos(2e+5 + 1);  // 要素の位置を表すテーブル
    for(int i = 0; i < N; ++i){
        cin >> a[i];
        pos[a[i]].push_back(i);
    }

    for(int i = 0; i < N; ++i){
        int it = upper_bound(pos[a[i]].begin(), pos[a[i]].end(), i) - pos[a[i]].begin();

        if(it != (int)pos[a[i]].size()){    // (i,N) に同じ要素があるとき
            doubling[0][i] = pos[a[i]][it] - i + 1;
        }
        else{   // (i,N) に同じ要素がないとき
            doubling[0][i] = (N + pos[a[i]][0]) - i + 1;
        }
    }

    for(int k = 1; k < 60; ++k){
        for(int i = 0; i < N; ++i){
            doubling[k][i] = doubling[k-1][i] + doubling[k-1][(i + doubling[k-1][i]) % N];
        }
    }

    // a[0] から操作を行って、K*N を超えない最大値を調べる。
    ll len = 0;
    bool flag = true;   // 更新フラグ　更新がない時にループを抜けられる
    while(flag){
        ll tmp = 0;
        int p = len % N;    // 現在の位置 (modN)
        flag = false;
        for(int i = 0; i < 60; ++i){
            if(len + doubling[i][p] >= K * N)   break;

            tmp = doubling[i][p];
            flag = true;
        }

        if(flag){
            len += tmp;
        }
    }
    int start = len % N;

    deque<int> deq;
    set<int> s;
    for(int i = start; i < N; ++i){
        if(s.find(a[i]) == s.end()){    // deq 内に a[i] がない場合
            deq.push_back(a[i]);
            s.insert(a[i]);
        }
        else{   // deq 内に a[i] がある場合
            while(!deq.empty()){
                int tmp = deq.back();
                deq.pop_back();
                s.erase(tmp);
                if(tmp == a[i])     break;
            }
        }
    }

    while(!deq.empty()){
        cout << deq.front() << " ";
        deq.pop_front();
    }
    cout << "\n";
}

Measured memory_bytes: 117632
#include<iostream>
using namespace std;
int main(){
    int n,l,a[100009],tmp, mxl=0;
    cin >> n >> l;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=1;i<n;i++){
        if(a[i-1]+a[i] > mxl){
            tmp=i-1;
            mxl=a[i-1]+a[i];
        }
    }
    if(mxl<l)cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        for(int i=0;i<tmp;i++){
            cout << i+1 << endl;
        }
        for(int i=n-2;i>tmp;i--){
            cout << i+1 << endl;
        }
        cout << tmp+1 <<endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

class Problem
{
private:
	// Variables
	int r, g;
	
public:
	// Methods
	void input ()
	{
		cin >> r >> g;	
	}
	
	void process ()
	{
		
	}
	
	void output ()
	{
		cout << (g << 1) - r << endl;
	}
};

int main ()
{
	Problem problem;
	problem.input();
	problem.process();
	problem.output();
	return 0;
}

Measured memory_bytes: 256
Imports System

Module Program
    Sub Main(args As String())

        Dim Str As String = Console.ReadLine()

        Dim A As Long = Long.Parse(Str.Substring(0, Str.IndexOf(" ")))
        Dim B As Long = Long.Parse(Str.Substring(Str.IndexOf(" ") + 1, Str.Length - Str.IndexOf(" ") - 1))

        Console.WriteLine(flcm(A, B))

    End Sub


    '最大公約数
    Function fgcm(A As Long, B As Long)
        Dim r As Long, tmp As Long, z As Long
        If A < B Then
            tmp = A : A = B : B = tmp
        End If
        r = A Mod B
        If r = 0 Then z = B Else z = fgcm(B, r)
        fgcm = z
    End Function


    '最小公倍数
    Function flcm(x As Long, y As Long) As Long
        Dim G As Long
        G = fgcm(x, y)
        flcm = x * y \ G
    End Function

End Module


Measured memory_bytes: 13524
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 == 0) {
        int n = (2 * x - y) / 3;
        int m = (2 * y - x) / 3;

        if (n >= 0 && m >= 0) {
            long long mod = 1000000007;

            vector<long long> inv(n + m, 0), frac(n + m + 1, 0), frac_inv(n + m + 1, 0);
            inv[1] = 1;
            frac[0] = frac[1] = 1;
            frac_inv[0] = frac_inv[1] = 1;
            for (int i = 2; i <= n + m; i++) {
                inv[i] = mod - (inv[mod % i] * (mod / i)) % mod;
                frac[i] = (frac[i - 1] * i) % mod;
                frac_inv[i] = (frac_inv[i - 1] * inv[i]) % mod;
            }

            cout << (((frac[n + m] * frac_inv[n]) % mod) * frac_inv[m]) % mod << endl;
        } else {
            cout << "0" << endl;
        }
    } else {
        cout << "0" << endl;
    }
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}

int n;
vector<pair<ll, int>> a;
auto memo = make_vec<ll>(2200, 2200);
ll dp(int l, int r) {
    if (l < 0 || r < 0) return -LINF;
    if (l == 0 && r == 0) return 0;
    if (memo[l][r] != -1) return memo[l][r];
    int i = l + r - 1;
    ll left = dp(l - 1, r) + a[i].first * (a[i].second - (l - 1));
    ll right = dp(l, r - 1) + a[i].first * (n - r - a[i].second);
    return memo[l][r] = max(left, right);
}
int main() {
    cin >> n;
    a.resize(n);
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(all(a));
    reverse(all(a));
    rep(i, 2200) rep(j, 2200) memo[i][j] = -1;
    ll ans = 0;
    rep(i, n + 1) {
        chmax(ans, dp(i, n - i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 41084
#include <stdio.h>

int sort(int *A,int n){
  int i,j,min,ans=0,t;

  for(i=0;i<n-1;i++){
    min=i;
    for(j=i;j<n;j++){
      if(A[j]<A[min])min=j;
    }
    t=A[i];
    A[i]=A[min];
    A[min]=t;
    if(i!=min)ans++;
  }
  return ans;
}

int main(){
  int i,n,ans;
  int A[100];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  ans=sort(A,n);

  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 604
#include <iostream>

using namespace std;

int main(){
    int N,W;
    cin >> N >> W;
    int w[N],v[N];
    for(int i=0;i<N;++i) cin >> v[i] >> w[i];

    int dp[110][10010];
    for(int i=0;i<=W;++i) dp[0][i] = 0;

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

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7064
#include <bits/stdc++.h>
int main(void)
{
  int n, m, x[100000], y[100000] = {}, ans;
  std::cin >> n >> m;
  for(int i = 0; i != m; i++) std::cin >> x[i];
  std::sort(x, x + m);
  for(int i = 0; i != m - 1; i++) y[i] = x[i + 1] - x[i];
  std::sort(y, y + m - 1, std::greater<int>());
  ans = x[m - 1] - x[0];
  for(int i = 0; i != n - 1; i++) ans -= y[i];
  std::cout << ans << std::endl;
  return 0;
}

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

int main() {

  int N,M;
  int ans = 0;

  cin >> N >> M;
  vector<int> vec(M,0);
  for(int i=0;i<N;++i){
    int K; cin >> K;
    for(int j=0;j<K;++j){
      int a; cin >> a;
      vec.at(a-1) += 1;
    }
  }

  for(int i=0;i<M;++i){
    if(vec.at(i) == N) ans += 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  if (tail + 1 == LEN)
    tail = 0;
  else
    tail = tail + 1;
}

P dequeue(){
  P x;
  x = Q[head];
  if(head + 1 == LEN)
    head = 0;
  else
    head = head + 1;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);


  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    if(Q[head].t <= q){
      elaps += Q[head].t;
      printf("%s %d\n",Q[head].name,elaps);
      dequeue();
    }
    
    else {
      elaps += q;
      Q[head].t -= q;
      enqueue(dequeue());
    }
  }

  return 0;
}

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

int main(){
    long long waru = 998244353;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    if(a[0] != 0){
        cout << "0" << endl;
        return 0;
    }
    vector<long long> karisum(n,0);
    int x;
    for(int i = 1; i < n; i++){
        x = a[i];
        if(x == 0){
            cout << "0" << endl;
            return 0;
        }
        karisum[x]++;
    }
    long long ans = 1;
    karisum[0] = 1;
    bool check = false;
    for(int i = 1; i < n; i++){
        if(karisum[i] == 0){
            check = true;
            continue;
        }
        if(check){
            cout << "0" << endl;
            return 0;
        }
        int temp = karisum[i];
        while(temp != 0){
            ans = ans * karisum[i-1] % waru;
            temp-=1;
        }
    }
    cout << ans << endl;
}


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

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
// #endif
    int n;
    cin>>n;
    double sum = 0 ;
    double tmp = 0.0;
    for(int i = 0 ;i<n ;i++)
    {
        cin>>tmp;
        sum+=1/tmp;
    }
    cout<<1/sum<<endl;
    return 0 ;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;
char C[111][111];
signed main(){
    cin>>H>>W;
    rep(i,H)cin>>C[i];

    for(int i=1;i<=2*H;i++){
        cout<<C[(i+1)/2-1]<<endl;
    }
    return 0;
}


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


int N;
vector<int> P, Q;


void input() {
    cin >> N;
    P = Q = vector<int>(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
}


int main() {
    input();
    vector<int> f(9);
    f[0] = 1;
    rep(i, 8) f[i+1] = f[i] * (i+1);
    int a, b;
    a = b = 1;
    set<int> s1, s2;
    rep(i, 9) {
        s1.insert(i+1);
        s2.insert(i+1);
    }
    rep(i, N) {
        a += distance(s1.begin(), lower_bound(s1.begin(), s1.end(), P[i])) * f[N-i-1];
        b += distance(s2.begin(), lower_bound(s2.begin(), s2.end(), Q[i])) * f[N-i-1];
        s1.erase(P[i]);
        s2.erase(Q[i]);
    }
    int ans = max(a - b, b - a);
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class  Main{
	static char[]in;
	static int k;
	static int[][][]memo;
	static int dp(int i,int nonzero,int isSmall) {
		if(nonzero>k)return 0;
		if(i>=in.length)return nonzero==k?1:0;
		if(memo[i][nonzero][isSmall]!=-1)return memo[i][nonzero][isSmall];
		int ans=0;
		if(isSmall==1) {
			ans=dp(i+1,nonzero,isSmall)+dp(i+1,nonzero+1,isSmall)*9;
		}
		else {
			for(int d=0;d<=(in[i]-'0');d++) {
				ans+=dp(i+1,nonzero + ((d!=0)?1:0) ,d<(in[i]-'0')?1:0);
			}
		}
		return memo[i][nonzero][isSmall]=ans;
	}
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		in=sc.nextLine().toCharArray();
		k=sc.nextInt();
		memo=new int[in.length][k+1][2];
		for(int i[][]:memo) {
			for(int j[]:i) {
				j[0]=-1;j[1]=-1;
			}
		}
		pw.println(dp(0,0,0));
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 22484
N = int(input())
R = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x: x[1],reverse = True)
B = sorted([list(map(int,input().split())) for i in range(N)])
count = 0
l = []
for i in range(N):
    Bx = B[i][0]
    By = B[i][1]
    for j in range(N):
        if Bx > R[j][0] and By > R[j][1] and R[j][0] not in l:
            count += 1
            l.append(R[j][0])
            break
print(count)

Measured memory_bytes: 3064
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, H, W = map(int, readline().split())

    ans = 0
    for _ in range(N):
        a, b = map(int, readline().split())
        if H <= a and W <= b:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64012
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int H,W,D;cin >> H >> W >> D;
    int A[H][W];
    vector<pair<int,int>> table(H*W);
    vector<int> cost(H*W);
    REP(i,H){
        REP(j,W){
            cin >> A[i][j];--A[i][j];
            table[A[i][j]] = {i,j};
        }
    }
    REP(i,D){
        cost[i] = 0;
        for(int j = i+D; j < H*W; j += D){
            cost[j] = cost[j-D] + abs(table[j].first - table[j-D].first) + abs(table[j].second - table[j-D].second);
        }
    }
    int Q,L,R;
    cin >> Q;
    REP(i,Q){
        cin >> L >> R;
        --L;--R;
        cout << cost[R] - cost[L] << endl;
    }
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
# define MAX_N 1000010
/* ACはうれCすぎてうれD */

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

int main(void){ 
    int n, x;
    cin >> n >> x;

    vector<int> XX;
    XX.push_back(x);
    for(int i=0; i<n; i++){
        int tmp_x;
        cin >> tmp_x;
        XX.push_back(tmp_x);

    }
    sort(XX.begin(), XX.end());
    vector<int> diff;
    for(int i=0; i<n; i++){
        int d = XX[i+1] - XX[i];
        diff.push_back(d);
    }

    int ans = diff[0];
    for(int i=1; i<n; i++){
        ans = gcd(ans, diff[i]);
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FASTIO \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr); \
    cout.tie(nullptr);

ll dp[100001];

ll min_cost(ll h[], int index, int n) {
    if(index >= n-1) {
        return 0;
    }

    if(dp[index]) return dp[index];

    ll cost1, cost2;
    cost1 = cost2 = INT_MAX;

    
    if(index+1 < n)
        cost1 = min_cost(h, index+1, n)+abs(h[index]-h[index+1]);
    if(index+2 < n)
        cost2 = min_cost(h, index+2, n)+abs(h[index]-h[index+2]);
    
    return dp[index] = min(cost1, cost2);
}

ll min_cost_bu(ll h[], int n) {
    
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = min(abs(h[i] - h[i-1]) + dp[i-1], abs(h[i] - h[i-2]) + dp[i-2]);
    }

    // for (int i = 0; i < n; i++) {
    //     cout<<dp[i]<<" ";
    // }
    return dp[n-1];
}

void solve() {
    ll n;
    cin>>n;
    
    ll h[n];
    for (int i = 0; i < n; i++) {
        cin>>h[i];
    }

    // dp = {0};
    memset(dp, 0, sizeof(dp[0])*100001);

    cout<<min_cost_bu(h, n)<<"\n";
    
}

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

Measured memory_bytes: 5212
#include<iostream>
#include <string.h>
#include<string>

using namespace std;

int main()
{
	/*long long h, a, attacks = 0;
	cin >> h >> a;
	while (h > 0)
	{
		attacks++;
		h -= a;
	}
	cout << attacks << endl;*/
	long long n;
	string s;
	cin >> n;
	getline(cin, s);
	getline(cin, s);
	char currentchar = s[0];
	int cnt = 1;

	for (int i = 1; i < s.size(); i++)
	{
		if (s[i] != currentchar)
		{
			currentchar = s[i];
			cnt++;
		}
	}

	cout << cnt << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>

using ll = long long;

int main() {
    ll r, D, x;
    std::cin >> r >> D >> x;
    ll now = x;
    for (int i = 0; i < 10; i++) {
        now = now * r - D;
        std::cout << now << std::endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define pw(x) (1ll << x)
#define sz(x) (int)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
using namespace std;
ld eps = (ld)1 / 1e15;
ll inf = 1e18, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const ll to[5]={0,4,6,7,9};
const ll N=1e3+1e2;
const ll R=1e4;
//ll columns[N][26];
//ll str[N][26];
//pll cool[N][N];
signed main(){
    fast_io;
    ll n;
    cin>>n;
    vector<ll>a(n);
    unordered_map<ll,ll>mp;
    for(auto &z : a) {
        cin>>z;
        mp[z]++;
    }
    ll ans=0;
    for(auto z : mp){
        ans+=(z.s)*(z.s-1)/2;
    }
    for(ll i=0;i<n;i++){
        cout<<ans-(mp[a[i]]*(mp[a[i]]-1)/2)+((mp[a[i]]-1)*(mp[a[i]]-2)/2)<<endl;
    }
    return 0;
}


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
#define vec vector

/*  <<bit全探索>>
 
    for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
        bitset<ビット数> s(tmp);
    }
*/
 
/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>
 
    string str;
    int N[桁数];
 
    cin >> str;
 
    for (int i = 0; i < 桁数; ++i) {
 
        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
 
        //cout << N[i] << endl;  //確認のため表示
    }
*/
 
typedef long long ll;

///////////////////////////////////////////////////////////////////////////


int main() {

   ll A, B, C, K;
   cin >> A >> B >> C >> K;

   if(A >= K){
       cout << K << endl;
   }

   else if(A + B >= K){
       cout << A << endl;
   }

   else{
       cout << A - K + (A + B) << endl;
   }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    for(int i=k;i < n;i++){
        if(a[i-k] < a[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4792
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
int deco[1000];

int c[30];
int st[30][100000];
ll dp[52][2510];
ll a[101];
void Solve() {
	int n, l;
	cin >> n >> l;
	string sa[101];
	for (size_t i = 0; i < n; i++)
	{
		cin >> sa[i];
	}
	sort(sa, sa + n);
	for (size_t i = 0; i < n; i++)
	{
		cout << sa[i];
	}
	cout << endl;
}
int main() {
	Solve();
	return 0;
}



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

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

using namespace std;

int main(){
	int w,a,b; cin>>w>>a>>b;
	if(a+w<b) cout<<b-(a+w)<<'\n';
	else if(b+w<a) cout<<a-(b+w)<<'\n';
	else cout<<0<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	char c[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}
	cout << c[0][0] << c[1][1] << c[2][2] << endl;

	return 0;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<int> X(N), a(100001, 0), b(M, 0), c(M, 0);
    /*
    a[i]: iが何枚あるか
    b[i % M]: i % Mが何枚あるか.
    c[i % M]: iのペアの数
    */
    rep(i, N) {
        cin >> X[i];
        a[X[i]]++;
        b[X[i] % M]++;
    }
    rep(i, 100001) {
        c[i % M] += a[i] / 2;
    }
    /*
    rep(i, M) {
        cout << b[i] << " " << c[i] << endl;
    }
    */
    rep(i, M / 2 + 1) {
        if ((i * 2) % M == 0) {
            ans += b[i] / 2;
        } else {
            int d = min(b[i], b[M - i]);
            ans += d;
            ans += min(c[i], (b[i] - d) / 2);
            ans += min(c[M - i], (b[M - i] - d) / 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792