akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int cnt[1000000];

int main()
{
    int n, m;
    string s;
    while(cin >> n && n) {
        cin >> m >> s;
        
        fill(cnt, cnt + 1000000, 0);
        for(int i = m - 1; i > 1; i--) {
            if(s[i] == 'I' && s[i - 1] == 'O' && s[i - 2] == 'I') {
                cnt[i - 2] = cnt[i] + 1; 
            }
        }
        
        int ret = 0;
        for(int i = 0; i < m; i++) {
            if(cnt[i] >= n) {
                ret++;
            }
        }

        cout << ret << endl;
    }
}

Measured memory_bytes: 5936
import sys

sys.setrecursionlimit(500000)
def input():
    return sys.stdin.readline()[:-1]

def main():
    N,Q = list(map(int,input().split()))

    road = []
    x_list = []

    for i in range(N):
        s,t,x = list(map(int,input().split()))
        road.append([0,s-x,x])
        road.append([1,t-x,x])

    for i in range(Q):
        road.append([2,int(input()),i])

    from collections import defaultdict

    counter = defaultdict(int)
    counter[10**27] = 1
    ans = [0]*Q

    road.sort(key=lambda x:x[0])
    road.sort(key=lambda x:x[1])

    q = [10**27]

    from heapq import heappop,heappush

    for id,_,x in road:
        if id==0:
            heappush(q,x)
            counter[x]+=1
        elif id==1:
            counter[x]-=1
        else:
            while counter[q[0]]==0:
                heappop(q)
            #print(q)
            if q[0]<10**27:
                ans[x] = q[0]
            else:
                ans[x] = -1
    print("\n".join(map(str,ans)))

if __name__ == '__main__':
    main()



Measured memory_bytes: 130548
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

bool dp[11][11][11];

int main() {
	int n; string s;
	cin >> n >> s;
	
	dp[10][10][10] = true;
	inc(i, n) {
		int c = s[i] - '0';
		inc(x, 10) {
		inc(y, 10) {
			dp[x][y][c] |= dp[x][y][10];
		}
		}
		inc(x, 10) {
			dp[x][c][10] |= dp[x][10][10];
		}
		dp[c][10][10] |= dp[10][10][10];
	}
	
	LL ans = 0;
	inc(x, 10) {
	inc(y, 10) {
	inc(z, 10) {
		ans += (dp[x][y][z] ? 1 : 0);
	}
	}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
ans={k:0 for k in range(1,N+1)}
for i in range(1,K+1):
    d=int(input())
    l=list(map(int,input().split()))
    for item in l:
        ans[item]=ans[item]+1 
count=0
for i in ans:
    if ans[i]==0:
        count+=1
print(count)

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

typedef long long ll;

int ModPow(int a,int r,int m)
{
	int x=1;
	for(;r;r>>=1){
		if(r&1) x=(ll)x*a%m;
		a=(ll)a*a%m;
	}
	return x;
}

int main()
{
	constexpr int MOD=1e9+7;
	for(int m,n;cin>>m>>n && m|n;){
		cout<<ModPow(m,n,MOD)<<endl;;
	}
}

Measured memory_bytes: 1164
n=int(input())
a=list(map(int,input().split(' ')))
sw=0
for i in range(n-1):
    minj=i
    for j in range(i,n):
        if a[j]<a[minj]:
            minj=j
    a[i],a[minj]=a[minj],a[i]
    if i != minj:
        sw=sw+1
print(" ".join(map(str,a)))
print(str(sw))

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

int main()
{
  string S;
  cin >> S;
  int D = S.size();
  int N = stoi(S);
  int cnt = 0;
  if (D % 2 == 1)
  {
    // Dが奇数の時
    // N以下のD桁の整数の個数をカウントする
    cnt += (N - pow(10, D - 1) + 1);
  }
  for (int i = 0; i < D / 2; i++)
  {
    // Dより小さい奇数の桁数の整数の個数をカウントする
    cnt += 9 * pow(100, i);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
using namespace std;

int H,W;
int solve(const int& a_term, const int& b_term) {
  int ret = 0;
  if (a_term < H || b_term < W) {
    ret = 0;
  } else if (a_term >= H && b_term >= W) {
    int a_remain = a_term - H;
    int b_remain = b_term - W;
    ret = 1 + solve(a_remain, b_remain);
  }
  return ret;
}

int main() {
  int N;
  cin >> N >> H >> W;

  vector<int> A(N);
  vector<int> B(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  int cnt = 0;
  for(int i = 0; i < N; i++) {
    cnt += solve(A[i], B[i]);
  }

  cout << cnt << endl;
}


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

#define ll long long
#define db double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ino freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

#define fr(i,n) for(i=0;i<n;i++)
#define frs(i,a,n) for(i=a;i<n;i++)
#define frv(i,n) for(i=n-1;i>=0;i--)

#define ne cout<<"\n";
#define cas(i) cout<<"Case #"<<i<<": "

#define vi vector <int>
#define vpi vector <pair <int,int> >
#define vpin(v,a,b) v.push_back(make_pair(a,b))
#define vsort(v) sort(v.begin(),v.end());
#define all(v) ((v).begin()),((v).end())
#define sz(v) ((int)((v).size()))

#define todegree(rad) rad*(180.0/pi)
#define isnttriangle(a,b,c) (a+b<c||a+c<b||b+c<a)
#define pi acos(-1)
#define siz 1000


int main()
{
    ll n,i,j,k;
    ll x[siz];
    cin>>n;
    fr(i,n) cin>>x[i];

    ll mini=100000000;
    ll sum=0;
    frs(i,1,101)
    {
        sum=0;
        fr(j,n)
        {
            sum+=((x[j]-i)*(x[j]-i));
        }
        if(sum<mini) mini=sum;
    }

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




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

using namespace std;

int main () {
	long long a, b, c;
	cin >> a >> b >> c;
	long long x = min ({a % 2, b % 2, c % 2});
	long long ans = 1e18 + 7;
	ans = ans * x;
	ans = min (ans, min ({a * b, b * c, c * a}));
	cout << ans;	
	return 0;
}

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

#define M 1046257
#define NIL (-1)
#define L 14

char H[M][L];


int getChar(char ch) {
  if ( ch == 'A' ) return 1;
  else if ( ch == 'C' ) return 2;
  else if ( ch == 'G' ) return 3;
  else if ( ch == 'T' ) return 4;
  return 0;
}
long long getKey(char str[]) {
  long long sum =0, p = 1, i;
  for(i=0;i<strlen(str);i++) {
    sum += p*(getChar(str[i]));
    p*= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ;i++) {
    h = (h1(key) + i*h2(key)) %M;
    if( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str); 
  for(i=0; ; i++) {
    h = (h1(key) + i * h2(key)) %M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(void) {
  int i, n;
  char str[L], com[9];
  for(i=0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i=0;i<n;i++) {
    scanf("%s %s",com,str); 
    if(com[0] == 'i') {
      insert(str);
    } else {
      if(find(str)){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N; cin >> N;
  
  int ans = 1;
  rep(i,100) {
     if (N < ans) {
       cout << ans/2 << endl;
       break;
     }
    ans *= 2;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
struct segtree{
  ll M=1, INF = 1000000000000000000;
  vector<vll> dat;
  segtree(ll N, ll num){
    while(M<N) M*=2;
    for(ll i=0;i<M*2-1;i++)  dat.push_back(vll{num, -1});
  }
  void update(ll x, ll k, ll l=0, ll r=-1){
    if(r==-1) r = M;
    k+=M-1;
    dat[k] = vll{x, k-(M-1)};
    while(k>0) {
      k = (k-1)/2;
      dat[k] = min(dat[k*2+1], dat[k*2+2]);
    }
  }
  vll query(ll a, ll b=-1, ll k=0, ll l=0, ll r=-1){
    if(r==-1) r = M;
    if(b==-1) b = M;
    if(r<=a || b<=l) return vll{INF, -1};
    if(a<=l && r<=b) return dat[k];
    vll A = query(a, b, k*2+1, l, (l+r)/2);
    vll B = query(a, b, k*2+2, (l+r)/2, r);
    return min(A, B);
  }
};
//-------------------------------------------------------------------

int main(int argc, char const *argv[]) {
  ll t,n;std::cin >> n;
  segtree seg(n+1, 1000000000000000000);
  ll ans = 0;
  re(i, n){
    std::cin >> t;
    vll q = seg.query(0, i);
    if(i==0||q[0]>=t) ans++;
    seg.update(t, i);
  }
  std::cout << ans << '\n';
  return 0;
}


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

typedef vector<int> vec;
typedef vector<vec> mat;

vec times(mat& a,vec& b){
  int n = a.size(), m = b.size();
  vec ans(n,0);
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      ans[i] += a[i][j] * b[j];
    }
  }
  return ans;
}

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

  vec b(m);
  mat a(n,vec(m));
  for(int i=0; i<n; i++)
    for(int j=0; j<m; j++)  cin >> a[i][j];
  for(int j=0; j<m; j++)  cin >> b[j];

  vec ans = times(a,b);
  for(int i=0; i<n; i++){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 1256
#include<stdio.h>

int main(){
    char text[4];
    char word[2];
    int counter[2]={1,1};
    int judge=0;
    scanf("%s", text);
    word[0]=text[0];
    for(int i=1; i<4; ++i){
        if(judge==0){
            if(text[i]==word[0]){
                counter[0]+=1;
            }else{
                word[1]=text[i];
                judge=1;
            }
        }else{
            if(text[i]==word[0]){
                counter[0]+=1;
            }else if(text[i]==word[1]){
                counter[1]+=1;
            }else{
                printf("No\n");
                return 0;
            }
        }
        if(counter[0]>2 | counter[1]>2){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<bits/stdc++.h>
#include<cctype>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include <string> 
#define ll long long
#define charToInt(c) (c-'0')
using namespace std;

main(){
ll a,b,c;
cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b<<endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s[3];
  cin >> s[0] >> s[1] >> s[2];
  cout << "A" << s[1][0] << "C\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <numeric>
#include <tuple>

using namespace std;

using lint = long long;
using ldouble = long double;

bool solve() {
    int N, D;
    cin >> N >> D;
    if (N == 0) return false;

    vector<vector<int>> C(N);
    for (auto& v : C) {
        int m;
        cin >> m;
        v.resize(m);
        for (auto& c : v) cin >> c;
        reverse(v.begin(), v.end());
    }

    if (N == 1) {
        cout << "Yes" << endl;
        return true;
    }

    vector<int> sum(N);
    for (int i = 0; i < N; ++i) {
        sum[i] = accumulate(C[i].begin(), C[i].end(), 0);
    }

    vector<int> itr(N, 0);
    while (true) {
        int minsum = *min_element(sum.begin(), sum.end());

        for (int i = 0; i < N; ++i) {
            while (itr[i] < C[i].size() && sum[i] - C[i][itr[i]] >= minsum) {
                sum[i] -= C[i][itr[i]++];
            }
        }

        if (*max_element(sum.begin(), sum.end()) == 0) break;

        auto sums = sum;
        sort(sums.rbegin(), sums.rend());

        int nxt = -1, minminsum = 1 << 30;
        for (int i = 0; i < N; ++i) {
            int ma = (sum[i] == sums[0] ? sums[1] : sums[0]);
            if (itr[i] == C[i].size() || ma - (sum[i] - C[i][itr[i]]) > D) continue;
            if (sum[i] - C[i][itr[i]] < minminsum) {
                nxt = i;
                minminsum = sum[i] - C[i][itr[i]];
            }
        }

        if (nxt < 0) {
            cout << "No" << endl;
            return true;
        }

        sum[nxt] -= C[nxt][itr[nxt]++];
    }

    cout << "Yes" << endl;
    return true;
}

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



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

int main() {
  ll h, w, c;
  cin >> h >> w;

  if (h == 1 || w == 1) {
    c = 1;
  } else {
    c = ((h + 1) / 2) * ((w + 1) / 2) + (h / 2) * (w / 2);
  }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools

N,X,Y = list(map(int , input().split()))

combi = list(itertools.combinations(range(1,N+1),2))

ansList = [0 for _ in range(N)]

for i,j in combi:
    kyori = min(j-i, abs(j-Y) + abs(X-i) + 1)
    ansList[kyori] += 1
#    print(i,j,ansList)

for ans in ansList[1:]:
    print(ans)



Measured memory_bytes: 146084
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <queue>
#include <numeric>

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int N, M;
  cin >> N >> M;
  vector<long> xs(N), ys(N), zs(N);
  rep (i, N) {
    cin >> xs[i] >> ys[i] >> zs[i];
  }

  long ans = 0;
  rep (xx, 2) {
    int sx = xx==0 ? -1 : 1;
    rep (yy, 2) {
      int sy = yy==0 ? -1 : 1;
      rep (zz, 2) {
	int sz = zz==0 ? -1 : 1;
	vector<long> ss(N);
	rep (i, N) {
	  ss[i] = sx*xs[i] + sy*ys[i] + sz*zs[i];
	}
	sort(ss.begin(), ss.end());
	long sub = accumulate(ss.end()-M, ss.end(), 0l);
	ans = max(ans, sub);
      }
    }
  }

  cout << ans << endl;

  return 0;
}








Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] arr = new int[r+1][c+1];
		for(int i=0;i<r;i++) {
			int sumX = 0;
			for(int j=0;j<c;j++) {
				arr[i][j] = scanner.nextInt();
				sumX += arr[i][j];
			}
			arr[i][c] = sumX;
		}
		for(int i=0;i<c+1;i++) {
			int sumY = 0;
			for(int j=0;j<r+1;j++) {
				sumY += arr[j][i];
			}
			arr[r][i] = sumY;
		}
		
		for(int i=0;i<r+1;i++) {
			for(int j=0;j<c+1;j++) {
				if (j!=c) {
					System.out.print(arr[i][j] + " ");
				}else {
					System.out.print(arr[i][j]);
				}
			}
			System.out.println();
		}
		scanner.close();
	}
}


Measured memory_bytes: 41268
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
int cnt[213456];
signed main() {
	int n, a = 0, b; string s; cin >> s;
	for (int h = 0; h < s.size(); h++) {
		if (s[h] == 'R') { a++; }
		else {
			cnt[h - 1] += (a + 1) / 2; cnt[h] += a / 2; a = 0;
		}
	}
	a = 0;
	for (int h = s.size() - 1; h >= 0; h--) {
		if (s[h] == 'L') { a++; }
		else {
			cnt[h + 1] += (a + 1) / 2; cnt[h] += a / 2; a = 0;
		}
	}
	for (int h = 0; h < s.size(); h++) {
		if (h == 0) { cout << cnt[h]; }
		else { cout << ' ' << cnt[h]; }
	}
	cout << endl;
	return 0;
}

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

int main()
{
	long long N, P;
	cin >> N >> P;

	map<long long, long long> mp;
	for( long long i = 2; i * i <= P; i++ ) {
		while( P % i == 0 ) {
			mp[i]++;
			P /= i;
		}
	}
	if( P != 1 ) mp[P]++;
	long long ans = 1;
	for( auto it = mp.begin(); it != mp.end(); it++ ) {
		while( it->second >= N ) {
			it->second -= N;
			ans *= it->first;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3620
package main

import "fmt"

var (
	a int
	b int
	c int
)

func main() {
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	if b-a == c-b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define per(i,n) for(int i=n-1;i>=0;++i)
#define rep1(i,n) for(int i=1; i<=n; ++i)
#define per1(i,n) for(int i=n; i>=1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------

int sum_object(int n){
  int sum = 0;
  while (n > 0) {
    sum += n%10;
    n /= 10;
    }
    return sum;
  }

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

  int A,B,N,B_sum,A_sum;
  cin >> N;
  int sum_min;
  rep1(k,N-1){
    B=k;
    A=N-B;
    B_sum = sum_object(B);
    A_sum = sum_object(A);
    if(k==1) sum_min = B_sum + A_sum;
    else sum_min = min(sum_min,B_sum + A_sum);
  }

  cout << sum_min << endl;

  return 0;
}


Measured memory_bytes: 256
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int max(a, b)
{
    return a < b ? b : a;
}

int main(int argc, char **argv)
{
    int n;
    scanf("%d", &n);
    int hpy[n][3];
    for (int i = 0; i< n; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        if (i == 0) {
            hpy[i][0] = a;
            hpy[i][1] = b;
            hpy[i][2] = c;
            continue;
        }
        hpy[i][0] = max(hpy[i - 1][1], hpy[i - 1][2]) + a;
        hpy[i][1] = max(hpy[i - 1][2], hpy[i - 1][0]) + b;
        hpy[i][2] = max(hpy[i - 1][0], hpy[i - 1][1]) + c;
    }
    printf("%d\n", max(max(hpy[n - 1][0], hpy[n - 1][1]), hpy[n - 1][2]));
    return EXIT_SUCCESS;
}


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

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

int main(){

    int n, x;

    while ( true ) {

        std::cin >> n >> x;

        if ( n == 0 && x == 0 ) break;

        int sum = 0;

        REP(i, n) REP(j, i) REP(k, j) {
            if ( i + j + k == x - 3 ) sum++;
        }

        std::cout << sum << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    int n,q;cin >> n >> q;
    vector<int> G[n+1];
    for(int i=0; i<n-1; i++){
        int a,b;cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> ans(n+1);
    for(int i=0; i<q; i++){
        int p,x;cin >> p >> x;
        ans[p]+=x;
    }
    stack<int> st;
    vector<bool> used(n+1,false);
    st.push(1);
    used[1]=true;
    while(!st.empty()){
        int now=st.top();st.pop();
        for(auto next: G[now]){
            if(used[next]) continue;
            used[next]=true;
            st.push(next);
            ans[next]+=ans[now];
        }
    }
    for(int i=1; i<=n; i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 15604
# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n = int(input())

ans = 0

for i in range(1,n+1,2):
    if len(make_divisors(i)) == 8:
        ans += 1
        
print(ans)

Measured memory_bytes: 3060
h,w = map(int,input().split())
block = [input() for _ in range(h)]

allcnt = 0
for i in range(w):
    for j in range(h):
        if block[j][i] == '.':
            allcnt += 1
import sys
sys.setrecursionlimit(10**6)
# BFSで最短経路を求める。allcnt - (cnt + 1)
INF = float('inf')
AR = [[INF] * w for _ in range(h)]
from collections import deque
# cnt = 0
dy = [1,0,0,-1]
dx = [0,-1,1,0]
def bfs():
    d = deque()
    d.append([0,0])
    while d:
        y,x = d.popleft()
        if y == 0 and x == 0:
            AR[y][x] = 0
        for i in range(4):
            ny = y + dy[i]
            nx = x + dx[i]
            if (not 0 <= ny < h) or (not 0 <= nx < w):
                continue
            if AR[ny][nx] == INF and block[ny][nx] != '#':
                AR[ny][nx] = AR[y][x] + 1
                d.append([ny,nx])
bfs()
if AR[h-1][w-1] == INF:
    print(-1)
else:
    print(allcnt - (AR[h-1][w-1]+1))


Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int main() {
    ll n, m; cin >> n >> m;
    if (n > m) swap(n, m);

    ll ans;
    if (n == 1) {
        if (m == 1) ans = 1;
        else ans = m - 2;
    } else {
        ans = (n - 2) * (m - 2);
    }
    cout << ans << endl;
}


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

int main(){
  ll n,m; cin>>n>>m;
  vector<pair<ll, ll>> v(n);
  
  rep(i,n){
   cin>>v.at(i).first>>v.at(i).second;
  }
  sort(v.begin(),v.end());
  ll i=0,ans=0;
  while(true){
    
    if(m>v.at(i).second){
      m-=v.at(i).second;
      ans+=v.at(i).first*v.at(i).second;
      i++;
    }
    else{
      ans+=m*v.at(i).first;
      m=0;
    }
    if(m==0){break;}
  
  }
  cout<<ans;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
typedef vector<set<int>> VSI;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
struct UnionFind {
    VI d;
    UnionFind(int n = 0): d(n,-1) {}
    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x,int y) {
        x = find(x); y = find(y);
        if(x == y) return false;
        if(d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x,int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};
int deg[100005];
VI to[100005];

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

mint f(int n) {
    if(n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if(n%2 == 1) x *= 2;
    return x;
}

mint choose(int n,int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main() {
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    if(s == "ARC") cout << "ABC" << endl;
}


Measured memory_bytes: 5944
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

int main(void) {
    string s;
    cin>>s;
    bool odd,even;
    odd = even = true;
    for(int i = 1;i <= s.size();i++) {
        if(i%2==1) {
            if(s[i-1] == 'L')
                odd = false;
        } else {
            if(s[i-1] == 'R')
                even = false;
        }
    }

    if(odd&&even) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  cout << fixed << setprecision(30) ;

  ld a, b, h, m, pi=2*acos(0);
  cin >> a >> b >> h >> m;
  
  ld l = m*pi/30, s = (60*h+m)*pi/360;
  cout << sqrt(a*a+b*b-2*a*b*cos(s-l)) << newl;
  return 0;
}

Measured memory_bytes: 4184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
using namespace std;

int main()
{
    string S;
    cin >> S;
    int tmp = 0;
    int ans = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if ((S[i] == 'A') || (S[i] == 'T') || (S[i] == 'C') || (S[i] == 'G'))
        {
            tmp++;
        }
        else
        {
            if (ans < tmp)
            {
                ans = tmp;
            }
            tmp = 0;
        }
    }
    if (ans < tmp)
    {
        ans = tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n:u64 = s.split_whitespace().next().unwrap().parse().unwrap();

    match (0..(n/4+1)).filter(|x|{let y=(n-4*x)/7; 4*x+7*y==n}).next() {
        Some(_) => println!("Yes"),
        None => println!("No"),
    }
}


Measured memory_bytes: 4352
n = gets.to_i
as = gets.chomp.split.map(&:to_i).sort
num_lcm = 1
as.each do |a|
  num_lcm = a.lcm(num_lcm)
end
ans = 0
as.each do|a|
  ans += (num_lcm - 1) % a
end
puts ans

Measured memory_bytes: 16248
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;



int main() {
	ll n; cin >> n;
	for (ll h = 3500; h >= 1; h--) {
		for (ll k = 3500; k >=1; k--) {
			if ((double)1.0*n*h*k/(4.0*h*k-n*h-n*k) < 0)continue;
			if ((double)(1.0*n*h*k / (4.0*h*k - n * h - n * k)) == floor((double)1.0*n*h*k / (4.0*h*k - n * h - n * k))) {
				cout << h << " " << k << " " << (ll)n*h*k / (4*h*k - n * h - n * k) << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {   
    long double sr = sqrt(x); 
    return ((sr - floor(sr)) == 0); 
} 
int32_t main(){
    SPEED;
    int n;
    cin >> n;
    int arr[n + 1];
    for(int i = 1; i <= n; ++i){
        cin >> arr[i];
    }
    int ans = 0;
    int j = 1;
    for(int i = 0; i <= 1000000; ++i){
        ans++;
        int temp = arr[j];
        //cout << temp << " ";
        if(temp == 2){
            j = -1;
            break;
        }
        j = temp;
    }
    if(j == -1) cout << ans;
    else cout << -1;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int loop=0; loop<n; ++loop){
        int gx, gy, p;
        int x1, y1, x2, y2;
        int dp[16][16];
        int row[16][16];
        int col[16][16];
        for(int i=0; i<16; ++i){
            for(int j=0; j<16; ++j){
                dp[i][j] = row[i][j] = col[i][j] = 0;
            }
        }

        cin >> gx >> gy >> p;
        for(int i=0; i<p; ++i){
            cin >> x1 >> y1 >> x2 >> y2;
            if(x1==x2) col[x1][min(y1,y2)] = 1;
            else if(y1==y2) row[min(x1,x2)][y1] = 1;
        }
        dp[0][0] = 1;
        for(int y=0; y<=gy; ++y){
            for(int x=0; x<=gx; ++x){
                if(row[x][y]==0) dp[x+1][y] += dp[x][y];
                if(col[x][y]==0) dp[x][y+1] += dp[x][y];
            }
        }
        if(dp[gx][gy]==0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[gx][gy] << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main()
{
    int n, m, x;
    std::cin >> n >> m >> x;
  
    std::vector<int> g_yens(n);
    std::vector<vector<int>> g_books(n, std::vector<int>(m));
    for (int i = 0; i < n; ++i)
    {
        std::cin >> g_yens[i];
      	for (auto& item : g_books[i])
            std::cin >> item;
    }
  
    unsigned int Min = -1;
  	for(int i = 0; i < (1 << n); ++ i)
    {
      std::vector<int> skill(m, 0);
      unsigned int yen = 0;
      for(int j = 0; j < n; ++j)
      {
        if(i & (1 << j))
        {
          for(int k = 0; k < m; ++k)
            skill[k] += g_books[j][k];
          yen += g_yens[j];
        }
      }
      
      bool isAchieve = true;
      for(const auto& item : skill)
      {
        if(item < x)
        {
          isAchieve = false;
          break;
        }
      }
      
      if(!isAchieve)
        continue;
      
      Min = std::min(Min, yen);
    }
	std::cout << (int)Min << std::endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>


int main(void) {

    int x, y;
    scanf("%d %d", &x, &y);

    char *ans = "No";
    for (int i = 0; i <= x; i ++) {

        int kame = i;
        int tsuru = x - i;

        if (kame * 4 + tsuru * 2 == y) {
            ans = "Yes";
            break;
        }

    }

    printf("%s", ans);


    return 0;
}

Measured memory_bytes: 1724
#include <iostream>

using namespace std;

int N, counter;

void check(int a, int b){
	if(a + b == N){
		counter++;
	} else if(a + b < N){
		check(a + b, b + 1);
	}
}

int main(){
	while(1){
		counter = 0;
		cin >> N;

		if(N == 0) break;

		for(int i = 1;i < N;i++){
			check(i, i + 1);
		}

		cout << counter << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll a, b, c;

int main(){
  cin >> a >> b >> c;
  if(a * b * c % 2 == 0) {
    cout << 0 << endl;
  } else {
    cout <<  min(a * b, min(b * c, c * a)) << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>

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

using namespace std;

int min_u, max_d, min_l, max_r;
int u, d, l, r;

void Renew(char c, bool is_a){
    if (c == 'U'){
        if (is_a)
            u++;
        else
            d++;
    }
    else{
        if (c == 'D'){
            if (is_a)
                d--;
            else
                u--;
        }
        else{
            if (c == 'L'){
                if (is_a)
                    l++;
                else
                    r++;
            }
            else{
                if (is_a)
                    r--;
                else
                    l--;
            }
        }
    }
    u = max(u, min_u);
    d = min(d, max_d);
    l = max(l, min_l);
    r = min(r, max_r);
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
//    ifstream cin("B.in");
    int rrr, ccc, n;
    cin >> rrr >> ccc >> n;
    int ii, jj;
    cin >> ii >> jj;
    string a, b;
    cin >> a >> b;
    min_u = 0, max_d = rrr + 1, min_l = 0, max_r = ccc + 1;
    u = min_u, d = max_d, l = min_l, r = max_r;
//    cout << u << ' ' << d << ' ' << l << ' ' << r << endl;
    Renew(a[n - 1], true);
//    cout << u << ' ' << d << ' ' << l << ' ' << r << endl;
    for (int i = n - 2; i >= 0; i--){
        if (u + 1 >= d || l + 1 >= r){
            cout << "NO" << endl;
            return 0;
        }
        Renew(b[i], false);
        Renew(a[i], true);
//        cout << u << ' ' << d << ' ' << l << ' ' << r << endl;
    }
    if (u + 1 >= d || l + 1 >= r){
        cout << "NO" << endl;
        return 0;
    }
    if (ii <= u || ii >= d || jj <= l || jj >= r){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    //    if (a[n - 1] == 'U')
//        u++;
//    else{
//        if (a[n - 1] == 'D')
//            d--;
//        else{
//            if (a[n - 1 == 'L')
//                l++;
//            else
//                r--;
//        }
//    }
}


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

int main() {
    int a,b; 
    cin >> a >> b;
    int price = 0;
    bool check= false;
    while(!check){
        price++;
        float tax_one = (float)floor(price * 0.08);
        float tax_two = (float)floor(price * 0.1);
        int f = (int)floor(tax_one);
        int s = (int)floor(tax_two);
        if( (f == a) && (s == b)) {
            cout << price << "\n";
            check = true;
        }
        if(f > a || s > b){
            cout << -1 << "\n";
            check = true;
        }
    }
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  if(a != 1){
    if(b != 1){
      if(a > b) printf("Alice");
      else if(a < b) printf("Bob");
      else printf("Draw");
    }else if(a == 1) printf("Draw");
    else printf("Bob");
  }else if(b == 1) printf("Draw");
  else printf("Alice");
  return 0;
}


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

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

 public:
  segtree(int n_) {
    n = pow(2, ceil(log2(n_)));
    data.resize(n);
    lazy.resize(n);
    auto __x = data[0];
    repi(n) {
      data[i] = __vmin(__x);
      lazy[i] = 0;
    }
  }
};

typedef pair<int, ll> pil;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pil> w;
  w.resize(n);
  repi(n) cin >> w[i].first >> w[i].second;
  sort(w.begin(), w.end(), [](pil a, pil b) { return a.first < b.first; });
  auto qcomp = [](pil a, pil b) { return a.second < b.second; };
  priority_queue<pil, vector<pil>, decltype(qcomp)> q(qcomp);
  ll re = 0;
  int wi = 0;
  repi(m) {
    while (wi < n && w[wi].first <= i + 1) q.push(w[wi++]);
    if (q.empty()) continue;
    re += q.top().second;
    q.pop();
  }
  cout << re << endl;
}


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

int main(){
    int n; cin >> n;
    set<string> said; vector<char> w; bool flag = true;
    rep(i, n){
        string x; cin >> x; int length = x.size();
        if (i == 0){
            w.push_back(x[length-1]);
            said.insert(x);
        }
        else{
            if (x[0] != w[i-1] || said.count(x)){
                flag = false;
            }
            w.push_back(x[length-1]);
            said.insert(x);
     
        } 
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}   

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+9;
int x,y,a,b,c,r[N],g[N],l[N],cnt,p[N*3],ans;
signed main(){
	ios::sync_with_stdio(0);
	cin>>x>>y>>a>>b>>c;
	for(register int i=1;i<=a;i++) cin>>r[i];
	for(register int i=1;i<=b;i++) cin>>g[i];
	for(register int i=1;i<=c;i++) cin>>l[i];
	sort(r+1,r+a+1); reverse(r+1,r+a+1);
	sort(g+1,g+b+1); reverse(g+1,g+b+1);
	for(int i=1;i<=x;i++) p[i]=r[i];
	for(int i=x+1;i<=x+y;i++) p[i]=g[i-x];
	for(int i=x+y+1;i<=x+y+c;i++) p[i]=l[i-x-y];
	cnt=x+y+c;sort(p+1,p+cnt+1); reverse(p+1,p+cnt+1);
	for(int i=1;i<=x+y;i++) ans+=p[i];
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 4992
# import sys; input = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	S = input()
	T = input()
	ans = INF
	N = len(S)
	M = len(T)
	for i in range(N - M + 1):
		text = S[i:i + M]
		val = 0
		for j in range(M):
			if text[j] != T[j]:
				val += 1

		ans = min(ans, val)

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}

#define N 	1000*100+5
int A[N], cost[N];
void solve(){
	int n;
	cin>>n;
	rep(i,1,n+1) cin>>A[i];
	cost[1] = 0;
	cost[2] = abs(A[2]-A[1]);
	rep(i,3,n+1) cost[i] = min(cost[i-1] + abs(A[i]-A[i-1]), cost[i-2]+ abs(A[i]-A[i-2]));
	cout<<cost[n]<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
     t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
long long N, M, K;
long long As[200005];
long long Bs[200005];
long long aim[200005];
int main(){
    scanf("%lld%lld%lld",&N,&M,&K);
    long long s = 0;
    int length = 1;
    aim[0] = K;
    for(int i = 1; i <= N; ++i){
        scanf("%lld",&As[i]);
        s+=As[i];
        if(s > K)
            continue;
        
        length++;
        aim[i] = K - s;
            
    }
    if(length == -1)
        length = N+1;

    s = 0;
    int maxN = length-1;
    int ptr = length -1;
    for(int i = 1; i <= M; ++i){
        scanf("%d",&Bs[i]);
        
        if(s > K)
            continue;

        s += Bs[i];

        while(ptr >= 0 && s > aim[ptr] )
            ptr--;
        
        if (ptr >= 0)
            maxN = max(maxN,ptr+i);
    }

    printf("%d\n",maxN);
}

Measured memory_bytes: 7912