akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> a(N+1);
    for (int i = 1; i <= N; i++) cin >> a[i];
    vector<vector<bool>> dp1(N+2, vector<bool>(K+1, false)), dp2(N+2, vector<bool>(K+1, false));
    dp1[0][0] = true;
    dp2[N+1][0] = true;
    for (int i = 1; i <= N; i++) {
        for (int j = 0; j <= K; j++) {
            if (dp1[i-1][j]) {
                dp1[i][j] = true;
                dp1[i][min(K, j+a[i])] = true;
            }
        }
    }
    for (int i = N; i >= 1; i--) {
        for (int j = 0; j <= K; j++) {
            if (dp2[i+1][j]) {
                dp2[i][j] = true;
                dp2[i][min(K, j+a[i])] = true;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        set<int> s;
        for (int j = 0; j <= K; j++) {
            if (dp1[i-1][j]) s.insert(j);
        }
        bool check = true;
        for (int j = 0; j <= K; j++) {
            if (!dp2[i+1][j]) continue;
            auto it = s.lower_bound(K-j-a[i]);
            if (it != s.end() && (*it) < K-j) {
                check = false;
                break;
            }
        }
        if (check) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int i, n;
    cin >> n;
    int arr[200000];
    for(i=0;i<n;i++)
      cin >> arr[i];

    sort(arr,arr+n);
    reverse(arr, arr+n);

    long long ans = arr[0];
    int rem=n-2;
    for(i=1;i<n;i++)
    {
      //cout<<arr[i]<< " ";
      if(rem>=2){
        ans = ans + 2LL*arr[i];
        rem -=2;
      }
      else if(rem==1){
        ans = ans+arr[i];
        rem--;
      }
      else break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    string S;
    cin>>S;
    int N=sz(S);
    int from=0,to,chr,chl;
    vector<int> ans(N);
    S.pb('R');
    rep(i,N){
        if(S.at(i)=='R' && S.at(i+1)=='L'){
            chr=i;chl=i+1;
        }
        if(S.at(i)=='L' && S.at(i+1)=='R'){
            to=i;
            int even,odd,a,b,c=0,d=0;
            a=to/2+1;b=to-a+1;
            if(from!=0){c=(from-1)/2+1;d=(from-1)-c+1;}
            even=a-c;odd=b-d;
            if(chr%2==0){ans.at(chr)=even;ans.at(chl)=odd;}
            else{ans.at(chr)=odd;ans.at(chl)=even;}
            from=i+1;
        }
    }
    rep(i,N)cout<<ans.at(i)<<endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;

bool kaibun(string S){
  int len = S.size();
  bool ok = true;
  //cout << S << endl;
  rep(i, len/2){
    if(S[i] != S[len-i-1]) ok = false;
  }
  return ok;
}

int main(){
  string S;
  cin >> S;
  int N = S.size();
  bool ans=true;
  if(!kaibun(S)) cout << "No" << endl;
  else if(!kaibun(S.substr(0,(N-1)/2))){
    //cout << 1 << endl;
    cout << "No" << endl;
  }else if(!kaibun(S.substr(N+3/2-1, N-1))){
    //cout << 2 << endl;
    cout << "No" << endl;
  } else{
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<int> a(n),s(n);
  rep(i,n){
    cin >> a[i];
    s[i] = a[i];
  }
  sort(s.begin(), s.end());
  for(int i = 0; i < n; i++){
    if(a[i] == s[n-1]) cout << s[n-2] << endl;
    else cout << s[n-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 3200
def conv(a,b)
  if b > a/2
    b = a - b
  end
  ans = 1
  div = 1
  b.times do |i|
    ans *= a - i
    div *= (i+1)
  end
  ans / div
end

n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
hash = Hash.new(0)
sum = 0
n.times do |i|
  sum += a[i]
  hash[sum] += 1
end
cnt = hash[0] == 0 ? 0 : conv(hash[0]+1,2)
hash[0] = 0
hash.each_value do |x|
  if x >= 2
    cnt += conv(x,2)
  end
end
puts cnt

Measured memory_bytes: 39608
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int H = nint();
        int W = nint();
        int[][] count = new int[H+2][W+2];
        char[][] a = nchars2(H, W, 1);
        count[0][1] = 1;
        
        for (int h = 1; h <= H; h++) {
            for (int w = 1; w <= W; w++) {
                if (a[h][w] == '#') continue;
                count[h][w] += count[h-1][w] + count[h][w-1];
                count[h][w] %= MOD;
            }
        }
        System.out.println(count[H][W]);
    }
    
    static long max(long... longs) {
        return Arrays.stream(longs).max().getAsLong();
    }
    
    static long min(long... longs) {
        return Arrays.stream(longs).min().getAsLong();
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static int nint() {
        return sc.nextInt();
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0);
    }

    private static char[][] nchars2(int h, int w, int pad) {
        char[][] a2 = new char[h + pad * 2][w + pad * 2];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[pad + i], pad, w);
        return a2;
    }
}


Measured memory_bytes: 37804
n=int(input())
P=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
D=dict()
for p in P:
  count=0
  order=1
  while p**order<=n:
    count+=n//(p**order)
    order+=1
  D[p]=count
List=[0 for i in range(5)]
for p in P:
  if D[p]>=74:
    List[4]+=1
  elif D[p]>=24:
    List[3]+=1
  elif D[p]>=14:
    List[2]+=1
  elif D[p]>=4:
    List[1]+=1
  elif D[p]>=2:
    List[0]+=1
for i in range(4):
  List[3-i]+=List[4-i]
print(List[4]+(List[0]-1)*List[3]+(List[1]-1)*List[2]+(List[0]-2)*List[1]*(List[1]-1)//2)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
    int n;
    scanf("%d", &n);

    int cnt = 0;
    while (n > 0)
    {
        if (n % 10 == 2)
            cnt++;
        n /= 10;
    }
    printf("%d\n", cnt);
    return 0;
}


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

int main() {
	int n,c,m;
	cin>>n>>m;
	for(int a=0;a<=n;a++){
		for(int b=0;b<=n;b++){
		c=n-a-b;
		if(c<0)break;
		if(m==a*10000+b*5000+c*1000){
			cout<<a<<' '<<b<<' '<<c;
			return 0;
		}
		}
	}
	cout<<-1<<' '<<-1<<' '<<-1;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void resolve() {
    LL h,w;
    cin >> h >> w;
    LL c[10][10];
    REP(i,0,10) REP(j,0,10) cin >> c[i][j];
    REP(k,0,10) REP(i,0,10) REP(j,0,10) {
        if (c[i][j] > c[i][k] + c[k][j]) c[i][j] = c[i][k] + c[k][j];
    }
    LL cnt = 0, in;
    REP(i,0,h) REP(j,0,w) {
        cin >> in;
        if (in > -1) cnt += c[in][1];
    }
    cout << cnt << endl;
}

int main() {
    resolve();
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << "$ " << #x << " => " << x << endl
using namespace std;
typedef long long ll;

#define pb push_back
typedef vector<int> vi;
typedef vector<int>::iterator it_vi;

const int MAX_N = 7 + 2000;
vi G[MAX_N];
///----------------------------------------------
bool vis[MAX_N];
int dfs(int u,int can) {
    if (can<0) return 0; else {
        vis[u]=true;
        int ret=1, v;
        rep(i,0,sz(G[u])) if (!vis[v=G[u][i]]) {
            ret+=dfs(v,can-1);
        }
        return ret;
    }
}
int main( ) {

    ///freopen ( "xx.in"  , "r" , stdin  );

    ///init
    int n,k; cin>>n>>k;
    rep(i,1,n) {
        int a,b; scanf("%d%d",&a,&b);
        G[a].pb(b);
        G[b].pb(a);
    }

    ///work
    int ans=n-1;
    if (k&1) {
        rep(i,1,n+1) rep(j,0,sz(G[i])) {
            memset(vis,false,sizeof(vis));
            vis[i]=true; vis[G[i][j]]=true;
            int can = dfs(i,k/2) + dfs(G[i][j],k/2);
            ans = min(ans, n-can);
        }
    }
    else {
        rep(i,1,n+1) {
            memset(vis,false,sizeof(vis));
            ans=min(ans,n-dfs(i,k/2));
        }
    }
    cout << ans << endl;

}


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

int main() {
  int N;
  cin >> N;
  int j = 0;
  int count = 0;
  
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    for (j = 0; A % 2 == 0; A /= 2) {
      j++;
    }
    if (i == 0) {
      count = j;
    }
    else if (count > j) {
      count = j;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 303+5;
int a[N][N];
int px[N*N];
int py[N*N];
int dis[N*N];
void solve(){
	int n,m,d; 
	cin>>n>>m>>d;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
			px[a[i][j]]=i;
			py[a[i][j]]=j;
		}
	}
	for(int i=0;i<d;i++){
		dis[i] = 0;
	}
	for(int i=d;i<=n*m;i++){
		dis[i] = 1e9;
	}
	for(int i=d;i<=n*m;i++){
		dis[i] = dis[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
	}
	int q;
	cin>>q;
	while(q--){
		int l,r; 
		cin>>l>>r;
		cout<<dis[r]-dis[l]<<endl;
	}
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ve vector
#define chmin(x,y) x = min(x,y)

int main(){
    string s;
    ll k;
    cin >> s >> k;
    k--;
    int n = (int)s.size();
    int n1 = n-1;
    char c = '1';
    rep(i,n){
        if(s[i] == '1') continue;
        else{
            c = s[i];
            n1 = (int)i-1;
            break;
        }
    }
    if(k <= n1) cout << 1 << endl;
    else cout << c << endl;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int a,b,c;
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&a,&b,&c);
        if(a*a+b*b==c*c)printf("YES");
        else if(b*b+c*c==a*a)printf("YES");
        else if(c*c+a*a==b*b)printf("YES");
        else printf("NO");
        printf("\n");
    }
    return 0;
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long n,num[5],ii;
  long min = LONG_MAX;
  cin  >> n;

  for(ii=0;ii<5;ii++){
    cin >> num[ii];
    if(num[ii] < min){
      min = num[ii];
    }
  }
  
  long res = (n/min) + 5;

  if(n == min){
    res = 5;
  }
  else if(min == 1){
    res = n + 5 -1;
  }
  else{
    res = (n/min) + 5;
  }
  
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
import math
def main():
    N = int(input())
    P = list(map(int, input().split()))
    if N == 0 and P[0] == 1:
        return 1
    if P[0] >= 1:
        return -1
    ul = [1]
    ll = [1]
    for i, v in enumerate(P[1:]):
        u = (ul[-1] - P[i]) * 2
        l = v
        ul.append(u)
        ll.append(l)
    ul2 = [P[-1]]
    ll2 = [P[-1]]
    for i, v in enumerate(reversed(P[:-1])):
        u = min(ul2[-1] + v, pow(2, N-i-1))
        l = min(math.ceil(ll2[-1]/2) + v, pow(2, N-i-1))
        ul2.append(u)
        ll2.append(l)
    ul2.reverse()
    ll2.reverse()
    r = 0
    for i in range(N+1):
        a = ul[i]
        b = ll[i]
        c = ul2[i]
        d = ll2[i]
        if d > a or b > c:
            return -1
        if max(b, d) > pow(2, i):
            return -1
        r += min(a, c)
    return r
print(main())


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

int main(){
  string S;
  cin >> S;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='o'){
      count++;
    }
  }
  if(8-count<=15-S.size()){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

#define INF 1000000007ll
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define Min(a,b) (((a) < (b))?(a):(b))
#define Max(a,b) (((a) > (b))?(a):(b))
#define Abs(a) (((a) > 0)?(a):(-1)*(a))
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define SIZE 0

int main() {
   int n, mn = INF, mx = 0, a;
   cin >> n;
   for (int i = 0 ; i < n ; ++i) {
      cin >> a;
      mn = Min (mn, a);
      mx = Max(mx, a);
   }
   cout << mx - mn << endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)((x).size())
#define debug(x) cout << #x << ":" << x << ' ';
#define debugg(x) cout << #x << ":" << x << ' ' << "\n";
#define endl "\n"
#define L(X) ((X)<<1)
#define R(X) (((X)<<1)|1)
#define M(X,Y) (((X)+(Y))>>1)

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

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const long long int LLINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = acos(-1);

template<typename T>   T max_self(T& a, T b) { if (a < b) a = b; return a; }
template<typename T>   T min_self(T& a, T b) { if (a > b) a = b; return a; }
template<typename T>   T add(T x, T y) { return ((x % MOD)  + (y % MOD)) % MOD;}
template<typename T>   T mul(T x, T y) { return ((x % MOD) * (long long)(y % MOD)) % MOD;}
template<typename T>   T sub(T x, T y) { return add(x, -y + MOD);}
template<typename T>   T gcd(T a, T b) { return b ? gcd(b, a % b) : a;}
template<typename T>   T lcm(T a, T b) { return a / gcd(a, b) * b;}
template<typename T>   vector<T> read(vector<T>& v, int n) {v.resize(n); for (auto &x : v)cin >> x;}
template<typename T>   void trav(vector<T> &v) {for (int i = 0 ; i < (int)v.size() ; ++i) {cout << v[i]; if (i != (int)v.size() - 1) cout << ' ';}}
int lg2(long long x)   {   return 64 - __builtin_clzll(x) - 1;	}
int lg2(int x)   {   return 32 - __builtin_clz(x) - 1;	}


//Variables Declaration


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ull count = 0 ;
	for(int i=1 ; i<=n ; ++i){
		if(i%3 && i%5) count+=i;
	}
	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 3652
#include<iostream>

using namespace std;

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

	int n,m;
	cin >> n >> m;
	for(int i=0; i<m; i++){
		int a;
		cin >> a;
		n -= a;
	}
	if(n<0) cout << -1;
	else cout << n;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  s='0'+s;
  if(s==string(s.rbegin(),s.rend())&&s[1]=='1') {
    ll r=1;
    for(ll i=2;i<s.size();i++) {
      cout << r << " " << i << endl;
      if(s[i-1]=='1') r=i;
    }
  }
  else {
    cout << -1 << endl;
  }
}

Measured memory_bytes: 1660
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void printArray(String[] cardSort) {
		for (int i = 0; i < cardSort.length; i++) {
			System.out.print(cardSort[i]);

			if (i == cardSort.length - 1) {
				break;
			}
			System.out.print(" ");
		}
		System.out.println();
	}

	public static boolean isStable(String in[], String out[]) {
		int N = in.length;
		for(int i = 0; i < N; i++) {
			for(int j = i + 1; j < N; j++) {
				for(int a = 0; a < N; a++) {
					for(int b = a + 1; b < N; b++) {
						if(in[i].charAt(1) == in[j].charAt(1) && in[i].equals(out[b]) && in[j].equals(out[a])) {
							return false;
						}
					}
				}
			}
		}
		return true;
	}

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int progCardNumOfSheets = Integer.parseInt(br.readLine());

		String[] card = br.readLine().split(" ");

		String[] cardNumBubbleSort = new String[progCardNumOfSheets];
		String[] cardNumSelectionSort = new String[progCardNumOfSheets];


		for(int i = 0; i < progCardNumOfSheets; i++) {
			cardNumBubbleSort[i] = card[i];
			cardNumSelectionSort[i] = card[i];
		}

		int compareNumResult = 0;
		String compareNum1 = "";
		String compareNum2 = "";

		boolean isSortFlag = true;

		while(isSortFlag) {
			isSortFlag = false;

			for(int i = progCardNumOfSheets - 1; i > 0; i-- ) {
				compareNum1 = cardNumBubbleSort[i].substring(1);
				compareNum2 = cardNumBubbleSort[i - 1].substring(1);
				compareNumResult = compareNum1.compareTo(compareNum2);
				if(compareNumResult < 0) {
					String tmp = cardNumBubbleSort[i - 1];
					cardNumBubbleSort[i - 1] = cardNumBubbleSort[i];
					cardNumBubbleSort[i] = tmp;
					isSortFlag = true;
				}
			}
		}

		printArray(cardNumBubbleSort);

		if(isStable(card, cardNumBubbleSort)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}

		int minNum = 0;
		for(int i = 0; i < progCardNumOfSheets; i++) {
			minNum = i;

			for(int j = i; j < progCardNumOfSheets; j++) {
				compareNum1 = cardNumSelectionSort[j].substring(1);
				compareNum2 = cardNumSelectionSort[minNum].substring(1);
				compareNumResult = compareNum1.compareTo(compareNum2);
				if(compareNumResult < 0) {
					minNum = j;
				}
			}
			if(i != minNum) {
				String tmp = cardNumSelectionSort[i];
				cardNumSelectionSort[i] = cardNumSelectionSort[minNum];
				cardNumSelectionSort[minNum] = tmp;
			}
		}

		printArray(cardNumSelectionSort);

		if(isStable(card, cardNumSelectionSort)) {
			System.out.println("Stable");
		} else {
			System.out.println("Not stable");
		}
	}
}

Measured memory_bytes: 25644
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<string>
#include<map>
#include<set>
#define INF 1000000001
using namespace std;
typedef long long ll;

typedef pair<int, int> p;

bool xxx(p x, p xx) {
	return x.second < xx.second;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n>>m;
	vector<p> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i].first >> a[i].second;

	}
	sort(a.begin(), a.end(),xxx);
	/*for (int i = 0; i < a.size(); i++) {
		cout << a[i].first << " " << a[i].second << endl;
	}*/
	int ans = 1;
	int hasi = a[0].second - 1;
	for (int i = 0; i < a.size(); i++) {
		if (hasi < a[i].first) {
			hasi = a[i].second - 1;
			ans++;
		}
	}
	cout << ans;
	return 0;
}

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


int A[1000];

int main(){
	int n,a,cnt=0;
	cin >> n;
	a=n+1;
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	
	for(int i=1;i<n;i++){
		if(A[i]==A[i-1]){
			cnt++;
			A[i]=a;
			a++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
import math
import itertools
L, R = tuple([int(x) for x in input().split(' ')])

x = L // 2019
y = R // 2019

if x != y:
    print(0)
else:
    xx = L % 2019
    yy = R % 2019
    ans = min([i*j%2019 for i, j in itertools.combinations(range(xx,yy+1), 2)])
    print(ans)

Measured memory_bytes: 75440
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=map(int,input().split())
p=list(map(int,input().split()))
uf=UnionFind(n)
for i in range(m):
  x,y=map(int,input().split())
  uf.union(x-1,y-1)
yes=[0]*n
for i in range(n):
  if uf.same(p[i]-1,i):
    yes[p[i]-1]=1
print(sum(yes))

Measured memory_bytes: 89580
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
const ll inf = 1e18;
const int nax = 2e6 + 7;
ll mod;
int n , q;
using namespace std;
ll exp(ll a , ll b){
	if(b == 0)	return 1;
	int x = b % 2 == 0 ?   ((exp(a , b/2)%mod)*(exp(a , b / 2)%mod))%mod :  (a%mod*exp(a , b - 1) % mod)%mod;
	return x;
}
ll tree[nax];
ll arr[nax];
int marked[nax];
void build(ll tl , ll tr , ll pos){
	if(tl == tr)
	{
		tree[pos] = arr[tl];
		return ;
	}
	ll mid = tl + (tr - tl)/2;
	build(tl , mid , 2 * pos);
	build(mid + 1 , tr , 2 * pos + 1);
}
void update(ll l , ll r , ll val , ll tl , ll tr , ll pos){
	if(l > r)
		return ;
	if(tl == l && tr == r){
		tree[pos] = val;
		marked[pos] = 1;
		return ;
	}
	ll mid = tl + (tr - tl)/2;
	if(marked[pos]){
		tree[2 * pos] = tree[pos];
		tree[2*pos + 1] = tree[pos];
		marked[pos*2] = marked[pos*2 + 1] = 1;
		marked[pos] = 0;
	}
	update(l , min(r , mid),val ,  tl , mid , 2 * pos );
	update(max(l , mid + 1), r , val , mid + 1 , tr , 2 * pos + 1);
	//tree[pos] = tree[2*pos] + tree[ 2* pos + 1];
}
ll query(ll ind, ll tl , ll tr , ll pos){
	if(tl == tr)
		return tree[pos];
	ll mid = tl + (tr - tl)/2;
	if(marked[pos]){
		tree[2 * pos] = tree[pos];
		tree[2*pos + 1] = tree[pos];
		marked[pos*2] = marked[pos*2 + 1] = 1;
		marked[pos] = 0;	
	}
	if(ind <= mid)
		return query(ind , tl , mid , 2*pos);
	else 
		return query(ind , mid + 1 , tr , 2*pos + 1);	
}
int main(int argc,char ** argv){
	dhoom;

	cin >> n >> q;
	ll x = pow(2LL , 31LL) - 1;
//	cout << "HEY" << endl;
	//cout << x << endl;
	for(int i = 1 ; i <= n ; i++)
		arr[i] = x;
	//cout << "building" << endl;
	build(1 , n , 1);
	//cout << " hi " << endl;
	for(int i = 0 ; i < q ; i++){
		ll a , b , c , d;
		cin >> a;
		if(a == 0){
				cin >> b >> c >> d;
				update(b+1 , c+1 , d , 1 , n , 1);
		}
		else
		{
				cin >> b;
				cout << query(b + 1, 1 , n , 1) << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 7104
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a, n, sum=0;
	cin>>a>>n;
	for(int i=0;i<n;i++){
	   int b;
	   cin>>b;
	   sum+=b;
	}
	if(sum>=a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
def A_win():
    print("Alice")
def B_win():
    print("Bob")
def Draw():
    print("Draw")
if c == -1 or d == -1:
    if a < b:
        A_win()
    elif a > b:
        B_win()
    else:
        Draw()
elif c > d:
    A_win()
elif c < d:
    B_win()
elif c == d:
    Draw()


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

/*
 * 全部A, B円で買って，減らしていく
 */

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int a = X, b = Y, c = 0;
    int price = a * A + b * B + c * C;
    if(A + B <= 2 * C){
        cout << price << endl;
        return 0;
    }else if(A + B > 2 * C){
        while(true) {
            int new_price = price;
            new_price += 2 * C;
            if (a != 0) {
                a -= 1;
                new_price -= A;

            }
            if (b != 0) {
                b -= 1;
                new_price -= B;
            }
            if(new_price >= price){
                break;
            }else{
                price = new_price;
            }
        }
    }else{
        cout << "error" <<endl;
        return 0;
    }
    // debug
    // cout << "a:" << a << " b:" << b << " c:" << c << endl;
    cout << price << endl;




}


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

int main() {
	int n, c;

	while (std::cin >> n) {
		std::vector<int> nums;
		++n;
		c = 0;
		for (int i = 0; i < n; ++i) {
			nums.push_back(i);
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) < 2) continue;
			for (int j = nums.at(i) * 2; j < n; j += nums.at(i)) {
				nums.at(j) = 0;
			}
		}
		for (int i = 0; i < n; ++i) {
			if (nums.at(i) > 1) {
				++c;
			}
		}
		std::cout << c << std::endl;
	}
	return 0;
}

Measured memory_bytes: 9324
import java.util.*;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        for(int i=1;true;i++){
            int x = sc.nextInt();
            if(x!=0){    
                System.out.println("Case "+i+": "+x);
            }else{
               break;
            }
                
        }


    }
}


Measured memory_bytes: 42456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, k;
    cin >> n >> k;

    int m = n / 2;
    int d[5] = { 0, m, 0, n - m, 0 };
    for (int i = 0; i < 5; i++) {
        d[i] += k + (i / 2) * n;
    }
    if (d[1] + d[2] > d[4]) {
        cout << -1 << endl;
        exit(0);
    }

    for (int i = 0; i < n - m; i++) {
        cout << d[1] + i << ' ' << d[2] + i << ' ' << d[4] + i * 2 << '\n';
    }
    for (int i = 0; i < m; i++) {
        cout << d[0] + i << ' ' << d[3] + i << ' ' << d[4] + i * 2 + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define int long long
using namespace std;
int num[100005];
signed main() {
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		num[a]++;
		sum+=a;
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++){
		int b,c;
		cin>>b>>c;
		sum+=((c-b)*num[b]);
		cout<<sum<<endl;
		num[c]+=num[b];
		num[b]=0; 
	}
	return 0;
}


Measured memory_bytes: 4412
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

INF = 10**9+7
N = II()
pow = 1
for i in range(1, N+1):
    pow = pow*i%INF
print(pow)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#define MAXN 10000
using namespace std;
typedef long long ll;

int N;
string s[MAXN];
int ans;
int a, b ,ba, ab;

int main() {
	ans = 0;
	a = 0; b = 0;

	cin >> N;
	for (int i = 0; i<N; i++) {
		cin >> s[i];

		for (int j = 0; j < s[i].length(); j++) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
				ab ++;
			}
		}

		if (s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') ba++;
		 else if (s[i][0] == 'B') b++;
		 else if (s[i][s[i].length() - 1] == 'A') a++;

	}

	if (ba >= 2) {
		ab += ba - 1;
		if (a > 0) {
			b++;
		}
		if (b > 0) {
			a++;
		}
	}
	else if (ba == 1) {
		if(a > 0) {
			b++;
		}
		if (b > 0) {
			a++;
		}
	}

	if (a < b) {
		cout << ab + a << endl;
	}
	else {
		cout << ab + b << endl;
	}

	return 0;
}

Measured memory_bytes: 768
# -*- coding: utf-8 -*-
import sys

n= int(input())
#tmp= float(input())

s=[]
h=[]
c=[]
d=[]

for i in range(13):
    s.append(0)
    h.append(0)
    c.append(0)
    d.append(0)

for i in range(n):
    tmp = input().split()
    #suits,num = list(map(lambda a: int(a), tmp))
    suits=tmp[0]
    num=int(tmp[1])
    if(suits=="S"):
        s[num-1]+=1
    if(suits=="H"):
        h[num-1]+=1
    if(suits=="C"):
        c[num-1]+=1
    if(suits=="D"):
        d[num-1]+=1


for i in range(13):
    if s[i]==0 :
        print("S "+str(i+1))
for i in range(13):
    if h[i]==0 :
        print("H "+str(i+1))
for i in range(13):
    if c[i]==0 :
        print("C "+str(i+1))
for i in range(13):
    if d[i]==0 :
        print("D "+str(i+1))




Measured memory_bytes: 5620
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

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

  vector<bool> is_red(n, false);
  vector<int> cnt(n, 1);

  is_red[0] = true;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    cnt[x]--;
    cnt[y]++;
    if (is_red[x]) { is_red[y] = true; }
    if (cnt[x] == 0) { is_red[x] = false; }
  }

  int ans = 0;
  rep(i, n) {
    if ( is_red[i] && cnt[i] != 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def F(x):
    if x&1:
        return 3*x + 1
    else:
        return x // 2

S = ir()
se = set()
dp = S; se.add(dp)
count = 1
while True:
    count += 1
    dp = F(dp)
    if dp in se:
        break
    se.add(dp)

print(count)


Measured memory_bytes: 3060
import java.io.PrintWriter;
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int cnt = 0;

        String a = sc.next();
        String b = sc.next();

        int tmpA = Integer.parseInt(a);
        int tmpB = Integer.parseInt(b);

        for (int i=tmpA; i<=tmpB; i++) {
            String str = String.valueOf(i);
            StringBuffer sb = new StringBuffer(str);
            String afterS = sb.reverse().toString();
            if (str.equals(afterS)) cnt++;
        }

        out.print(cnt);
        out.flush();
    }
}

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

int main(void)
{
string a, b, ab;
cin >> a >> b;
ab = a + b;
int n = stoi(ab);

if(sqrt(n) == int(sqrt(n))){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

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

int main(int argc, const char * argv[]) {
    int K, X;
    cin >> K >> X;
    
    for (int i = X - K + 1; i < X + K; i++) {
        cout << i;
        if (i < X + K - 1) {
            cout << " ";
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
     public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(A == B)
			System.out.println("Draw");
		if((A > B && B != 1) || (A == 1 && A != B))
			System.out.println("Alice");
		if((A < B && A != 1) || (B == 1 && A != B))
			System.out.println("Bob");
     }
}

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

int main(){
int N,k,i,min,a=1;
  scanf("%d",&N);
  int *P=(int*)malloc(sizeof(int)*N);
  for(k=0;k<N;k++)scanf("%d ",&P[k]);
  min=P[0];
  for(i=1;i<N;i++){
  	if(min>=P[i]){
		min=P[i];
      	a++;
    }
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <iterator>
#include <utility>
#include <iomanip>
#include <stack>
#include<bitset>
#include <cmath>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
ll gcd(ll x,ll y){
	if(y==0)return x;
	return gcd(y,x%y);
}
priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >pq;
ll expo(ll b,ll n,ll m)
{
 ll r,p;
	p=1;
	 b=b%m;
	while(n>0)
	{ 
		r=n%2;
		if(r==1)
		   p=((p%m)*(b%m))%m;
		b=((b%m)*(b%m))%m; 
		n=n/2;		
	}
 return (p%m);
}
ll divide1(ll a,ll b,ll m)
	{ ll r,p,n;
			p=a%m;
				n=m-2;
				while(n>0){
						 r=n%2;
						if(r==1)
							p=((p%m)*(b%m))%m;
						b=((b%m)*(b%m))%m; 
						n=n/2;	
					}
	return (p%m); }
ll absol(ll x)
{
	if (x<0)
	{
		return -x;
	}
return x;
}
ll h[1000002];
ll dp[1000002];
int main(int argc, char const *argv[])
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	ll n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>h[i];
	}
	if(n-2>=0)
	{
		dp[n-2]=absol(h[n-1]-h[n-2]);
	}
	for(int i=n-3;i>=0;--i)
	{
		dp[i]=min(dp[i+1]+absol(h[i+1]-h[i]),dp[i+2]+absol(h[i+2]-h[i]));
	}
	cout<<dp[0]<<"\n";
	return 0;
}

Measured memory_bytes: 5120
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<string> s(n);
	map<string, int> m;
	rep(i, n) cin >> s[i], m[s[i]]++;
	vector<string> best;
	int ans = 0;
	for(pair<string, int> x : m){
		if(x.se == ans) best.pb(x.fi);
		if(x.se > ans){
			best.clear();
			best.pb(x.fi);
			ans = x.se;
		}
	}
	sort(all(best));
	rep(i, best.size()) cout << best[i] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 27120
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>

using namespace std;

#define dirmax 8

int l[2];
int dir[8][2] = { {0,1}, {1,0}, {-1,0}, {0,-1}, {1,1}, {-1,1}, {1,-1}, {-1,-1} };
string ans;

void search( set<string> *v, int pos[2] , char ch[10][20]){

	for(int i = 0; i < dirmax; i++) {
		string str;
		int cpos[] = { pos[0], pos[1] };

		str += ch[pos[0]][pos[1]];

		while( 1 ) {
			for(int j = 0; j < 2; j++) {
				cpos[j] += dir[i][j];
				if( cpos[j] < 0 ) cpos[j] = l[j] - 1;
				if( cpos[j] >= l[j] ) cpos[j] = 0;
			}
			if( cpos[0] == pos[0] && cpos[1] == pos[1] ) break;

			str += ch[cpos[0]][cpos[1]];
			
			if( v->find(str) != v->end() ) {
 				if( ( str.length() > ans.length() ) || ( str.length() == ans.length() && str < ans ) ) {
					ans = str;
				}
			} else 
				v->insert(str);
		}
	}
}

int main(void){
	while(1){
		cin >> l[0] >> l[1];
		if( l[0] == 0 && l[1] == 0 ) break;

		char donut[10][20];
		int pos[2];
		ans = "";

		set< string > strs;

		for(int i = 0; i < l[0]; i++)
			cin >> donut[i];
		
		for(pos[0] = 0; pos[0] < l[0]; pos[0]++)
			for(pos[1] = 0; pos[1] < l[1]; pos[1]++)
				search( &strs, pos, donut );

		if(ans == "") 
			cout << 0 << endl;
		else 
			cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 33764
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
typedef vector<vp> vvp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;
ll cut(string s,int a,int b){
  string t=s.substr(a,b-a);
  ll res=0,tmp=1;
  rep(i,0,t.size()){
    int x=t[t.size()-1-i]-'0';
    res+=x*tmp;
    tmp*=10;
  }
  return res;
}

int main(){
  string s;cin>>s;
  int n=s.size();
  ll ans=0;
  rep(i,0,1<<(n-1)){
    int l=0,r;
    rep(j,0,n-1){
      if(i>>j&1){
        r=j+1;
        ans+=cut(s,l,r);
        l=r;
      }
    }
    ans+=cut(s,l,n);
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;
int N, A;
ll x[55], dp[55][2510][55];

int main(void) {
    cin >> N >> A;
    rep(i, 1, N+1) cin >> x[i];

    dp[0][0][0] = 1;
    for (int i=1; i<=N; i++) for (int j=0; j<=2500; j++) for (int k=0; k<=N; k++) {
        dp[i][j][k] += dp[i-1][j][k];
        if (j-x[i]>=0) dp[i][j][k+1] += dp[i-1][j-x[i]][k];
    }

    for (int i=1; i<=50; i++) ans += dp[N][A*i][i];

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



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

int main() {
  int n;
  float x, sum = 0;
  string y;
  vector<pair<float,string>> gifts;
  
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> x >> y;
    gifts.push_back(make_pair(x,y));
  }
  for (auto i : gifts) {
    if (i.second=="JPY") sum+=i.first;
    else sum+=380000*i.first;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

//const ll MOD = 998244353;
const ll MOD = 1e9+7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n,m;
  std::cin>>n>>m;
  std::vector<P> work(n);
  rep(i,0,n){
    ll a,b;
    std::cin>>a>>b;
    work[i]=P(a,b);
  }
  std::sort(all(work));
  std::priority_queue<ll> que;
  ll now=0,ans=0;
  rep(i,1,m+1){
    while(work[now].first==i){
      que.push(work[now].second);
      now++;
    }
    if(que.size()){
      ans+=que.top();
      que.pop();
    }
  }

  std::cout<<ans;
  return 0;
}

Measured memory_bytes: 2936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int count = 0;
		int max = 0;

		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'A' || s.charAt(i) == 'C' || s.charAt(i) == 'G' || s.charAt(i) == 'T') {
				count++;

				if (count > max) {
					max = count;
				}
			} else {
				count = 0;
			}

		}

		System.out.println(max);

		sc.close();

	}
}

Measured memory_bytes: 35632
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int a[105];
int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		int sum = 0;
		n--;
		for (int i = 0; i < n; i++)	scanf("%d", a + i);
		for (int i = 0; i < n - 1; i++)	sum += min(a[i], a[i + 1]);
		sum += a[0] + a[n - 1];
		printf("%d\n", sum); 
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n > 0) {
	  n /= k;
	  ans++;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 _   ________   ___       __ ___   _           _  _
| | / /|  _  \ / _ \     / // _ \ | |         | |(_)
| |/ / | | | |/ /_\ \   / // /_\ \| | __ __ _ | | _
|    \ | | | ||  _  |  / / |  _  || |/ // _` || || |
| |\  \| |/ / | | | | / /  | | | ||   <| (_| || || |
\_| \_/|___/  \_| |_//_/   \_| |_/|_|\_\\__,_||_||_|
*/
#include<bits/stdc++.h>
using namespace std;
int n,a[205];
vector<int> ans;
int main(){
	cin >> n;
	for(int i=0;i<n;i++) cin >> a[i];
	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			ans.push_back(1);
			for(int i=1;i<n;i++) swap(a[i],a[i-1]);
			if(a[0]<a[n-1]){
				ans.push_back(n-1);
				swap(a[n-1],a[0]);
			}
		}
		ans.push_back(1);
		for(int i=1;i<n;i++) swap(a[i],a[i-1]);
	}
	cout << ans.size() << '\n';
	for(int i=0;i<ans.size();i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 1e5+6;
int a[N];
void solve(){
	int n; 
	cin>>n; 
	for(int i=0;i<n;i++)cin>>a[i];
	int dis = 0;
	int idx=-1,jdx = -1;
	sort(a,a+n);
	for(int i=1;i<n;i++){
		int x = (lower_bound(a,a+n,a[i]/2)-a);
		if(x!=i){

			if(dis <=min(a[i]-a[x],a[x])){
				dis = min(a[i]-a[x],a[x]);
				idx=  i;
				jdx = x;
			} 
		}
		x--;
		if(x<0)continue;
		if(x!=i){

			if(dis <=min(a[i]-a[x],a[x])){
				dis = min(a[i]-a[x],a[x]);
				idx=  i;
				jdx = x;
			} 
		}
		x+=2;
		if(x>=n)continue;
		if(x!=i){

			if(dis <=min(a[i]-a[x],a[x])){
				dis = min(a[i]-a[x],a[x]);
				idx=  i;
				jdx = x;
			} 
		}
	}
	cout<<a[idx]<<" "<<a[jdx]<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

int main() {
	string S,T;
	cin >> S>>T;
	map<char,int> dicS;
	map<char,int> dicT;
	set<char> ds;
	set<char> dt;
	
	for(int i=0;i<S.size();i++){
		if(dicS.count(S.at(i))){
			dicS[S.at(i)]++;
		}
		else{
			dicS[S.at(i)]=1;
			ds.insert(S.at(i));
		}
		
		if(dicT.count(T.at(i))){
			dicT[T.at(i)]++;
		}
		else{
			dicT[T.at(i)]=1;
			dt.insert(T.at(i));
		}
	}
	
	vector<int>numS(0);
	vector<int>numT(0);
	int tmp;
	for(auto i:ds){
		numS.push_back(dicS[i]);
	}
	for(auto i:dt){
		numT.push_back(dicT[i]);
	}
	
	sort(numS.begin(),numS.end());
	sort(numT.begin(),numT.end());
	bool pro=true;
	if(numS.size()!=numT.size()){
		pro=false;
	}
	else{
		for(int i=0;i<numS.size();i++){
			if(numS.at(i)!=numT.at(i)){
				pro=false;
				break;
			}
		}
	}
	if(pro)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	return 0;
}





Measured memory_bytes: 776
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <limits>
#include <random>
#include <utility>
#include <vector>

namespace procon {
  class UnionFind {
  private:
    struct nodeinfo {
      int par;
      int rank;
      nodeinfo(int par) : par(par), rank(0) {}
    };
    std::vector<nodeinfo> node;

  public:
    UnionFind(int n) : node() {
      node.reserve(n);
      for (int i = 0; i < n; ++i) {
	node.push_back(nodeinfo(i));
      }
    }
    int root(int x) {
      if (node[x].par == x) {
	return x;
      }
      return node[x].par = root(node[x].par);
    }
    void unite(int x, int y) {
      x = root(x);
      y = root(y);
      if (x == y) {
	return;
      }
      if (node[x].rank < node[y].rank) {
	node[x].par = y;
      } else {
	node[y].par = x;
	if (node[x].rank == node[y].rank) {
	  ++node[x].rank;
	}
      }
    }
    bool is_same_set(int x, int y) { return root(x) == root(y); }
  };
}
  
int main(void) {
  int size, n_query;
  std::cin.read((char *)&size, sizeof(int));
  std::cin.read((char *)&n_query, sizeof(int));

  std::vector<uint64_t> query(n_query);
  std::cin.read((char *)query.data(), sizeof(uint64_t) * n_query);

  const int mask = (1 << 30) - 1;

  uint64_t res = 123456789;
  procon::UnionFind uf(size);
  for (uint64_t q : query) {
    const int com = q >> 60;
    const int x = (q >> 30) & mask;
    const int y = (q >> 0) & mask;
    assert(0 <= x && x < size);
    assert(0 <= y && y < size);
    if (com) {
      res = res * 17 + (uf.is_same_set(x, y) ? 1 : 0);
    } else {
      uf.unite(x, y);
    }
  }
  std::cout << res << std::endl;
  return 0;
}



Measured memory_bytes: 89164