akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#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 all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const int MOD = (int)1e9+7;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;

int n;
char s[100050];

int cache[100050];
int mypower(int k) {
	if(k == 0) return 1;

	int& ret = cache[k];
	if(ret != -1) return ret;
	ret = 10 * mypower(k-1);
	ret %= 13;
	return ret;
}

void precal() {
	rep(i,1,100000) {
		mypower(i);
	}
}

int main(void) {
	//ios_base::sync_with_stdio(false); 
	//cin.tie(NULL); 
	//cout.tie(NULL);
	//freopen("in.txt", "r", stdin);
	memset(cache, -1, sizeof(cache));
	scanf("%s", s);
	n = strlen(s);
	int dp[100050][13];
	memset(dp, 0, sizeof(dp));
	precal();

	if(s[n-1] == '?') {
		rep(i,0,10) {
			dp[n-1][i] = 1;
		}
	} else {
		dp[n-1][s[n-1]-'0'] = 1;
	}

	per(i,0,n-1) {
		if(s[i] == '?') {
			rep(j,0,10) {
				int nj = (j * mypower(n-1-i)) % 13;
				rep(k,0,13) {
					int nnj = (nj + k) % 13;
					dp[i][nnj] += dp[i+1][k];
					dp[i][nnj] %= MOD;
				}
			}
		} else {
			int j = s[i] - '0';
			int nj = (j * mypower(n-1-i)) % 13;
			rep(k,0,13) {
				int nnj = (nj + k) % 13;
				dp[i][nnj] += dp[i+1][k];
				dp[i][nnj] %= MOD;
			}
		}
	}

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


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <climits>
#include <functional>


int main(){
	
	int A, B;
	std::cin >> A >> B;

	if (A + B >= 10)
		std::cout << "error" << std::endl;
	else
		std::cout << A + B << std::endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int s, w;
    cin >> s >> w;
    if (s <= w) cout << "un";
    cout << "safe";
}


Measured memory_bytes: 3572
/*
 * じょえチャンネル
 * 高評価・チャンネル登録よろしくおねがいします！
 * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
 */

#include <bits/stdc++.h>

using namespace std;


using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 58) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int N, R;
  cin >> N >> R;
  if(N <= 10) R += 100 * (10 - N);
  cout << R << endl;
}




Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#include <bits/stdc++.h>
using namespace std;

int main(){
  int N,W;
  cin>>N>>W;
  
  int weight[N+1],value[N+1];
  for(int i=1;i<=N;i++){
    cin>>value[i]>>weight[i];
  }
  
  int dp[N+1][W+1];
  rep(i,W+1) dp[0][i]=0;
  
  for(int i=1;i<=N;i++){
    for(int w=0;w<=W;w++){
      if(w>=weight[i]){
        dp[i][w]=max(dp[i-1][w],dp[i-1][w-weight[i]]+value[i]);
      }
      else dp[i][w]=dp[i-1][w];
    }
  }
  
  cout<<dp[N][W]<<endl;
    
  return 0;
}


Measured memory_bytes: 7024
#!/usr/bin/env python3
from collections import deque
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]", b: "List[int]", c: "List[int]", Q: int,
          K: int, x: "List[int]", y: "List[int]"):
    G = [[] for _ in range(N)]
    for ai, bi, ci in zip(a, b, c):
        ai -= 1
        bi -= 1
        G[ai].append((bi, ci))
        G[bi].append((ai, ci))

    m = [-1] * N
    q = deque()
    K -= 1
    m[K] = 0
    q.append(K)
    while q:
        i = q.popleft()
        for j, cj in G[i]:
            if m[j] >= 0:
                continue
            m[j] = m[i] + cj
            q.append(j)

    for xi, yi in zip(x, y):
        xi -= 1
        yi -= 1
        print(m[xi] + m[yi])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int()] * (N - 1)  # type: "List[int]"
    b = [int()] * (N - 1)  # type: "List[int]"
    c = [int()] * (N - 1)  # type: "List[int]"
    for i in range(N - 1):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
    Q = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (Q)  # type: "List[int]"
    y = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, a, b, c, Q, K, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 60288
#include<stdio.h>

int h,H[251];
int right(int);
int left(int);
int parent(int);

main(){
  int i;
  scanf("%d",&h);
  
  for(i=1;i<=h;i++){
    scanf("%d",&H[i]);
  }
  for(i = 1;i<=h;i++){
    printf("node %d: key = %d, ",i,H[i]);
    if(parent(i)>=1) printf("parent key = %d, ",H[parent(i)]);
    if(left(i)<=h) printf("left key = %d, ",H[left(i)]); 
    if(right(i)<=h) printf("right key = %d, ",H[right(i)]);
    printf("\n");   
  }
  return 0;
}


int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main() {
	while (1) {
		int mp[410][410];
		int h = 0, w = 0, ni, di, N, l, r;

		for (int j = 0; j < 410; j++) {
			for (int k = 0; k < 410; k++) mp[j][k] = -1;
		}

		cin >> N;
		if (N == 0) break;
		mp[205][205] = 0;
		for (int i = 1; i < N; i++) {
			// cerr << i << endl;
			cin >> ni >> di;
			bool found = false;
			for (int j = 0; j < 410; j++) {
				// cerr << j << endl;
				for (int k = 0; k < 410; k++) {
					if (mp[j][k] == ni) {
						if (di == 0)
							k--;
						else if (di == 1)
							j++;
						else if (di == 2)
							k++;
						else
							j--;
						mp[j][k] = i;
						found = true;
						break;
					}
					if (found) break;
				}
			}
		}
		// cerr << "map made" << endl;
		l = -1;
		r = -1;

		for (int j = 0; j < 410; j++) {
			bool found = false;
			for (int k = 0; k < 410; k++) {
				if (mp[j][k] >= 0) {
					found = true;
					if (l < 0) {
						l = k;
						r = k + 1;
					} else {
						if (k < l)
							l = k;
						else if (k + 1 > r)
							r = k + 1;
					}
				}
			}
			if (found) {
				h++;
			}
		}

		printf("%d %d\n", w = r - l, h);
	}
}


Measured memory_bytes: 3660
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<math.h>
#include<vector>
#include<cmath>


using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  
  for(int i=0;i<n;i++){
    int sum=0;
    for(int j=0;j<n;j++){
      if(s[i]==s[j]){
	sum++;
      }
    }
    if(sum%2==1){
      cout<<"No"<<endl;
      break;
    }
    if(i==n-1)cout<<"Yes"<<endl;
  }
	
  
  
  return 0;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

ll comb[51][51];

int main(){
    for(int i=0;i<=50;i++){
        for(int j=0;j<=i;j++){
            if(j==0||j==i){
                comb[i][j]=1;
            }else{
                comb[i][j]=comb[i-1][j-1]+comb[i-1][j];
            }
        }
    }
    int n,a,b;
    cin>>n>>a>>b;
    ll v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
        v[i]=-v[i];
    }
    sort(v,v+n);
    ll sum[n];
    sum[0]=-v[0];
    for(int i=1;i<n;i++){
        sum[i]=-v[i]+sum[i-1];
    }
    pair<ll,int> ans;
    ll num=0;
    ans={0,1};
    for(int i=a;i<=b;i++){
        ll res=1;
        int ub=upper_bound(v,v+n,v[i-1])-v;
        int lb=lower_bound(v,v+n,v[i-1])-v;
        //cout<<v[j]<<" "<<ub<<endl;
        //cout<<v[j]<<" "<<lb<<endl;
        res*=comb[ub-lb][i-lb];
        if(ans.first*i<ans.second*sum[i-1]){
            ans={sum[i-1],i};
            num=res;
        }else if(ans.first*i==ans.second*sum[i-1]){
            num+=res;
        }
        //cout<<i<<" "<<res<<endl;
    }
    cout<<fixed<<setprecision(25)<<(double)ans.first/ans.second<<endl;
    cout<<num<<endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<queue>
#include<utility>
#include<vector>
using namespace std;
typedef pair<long, int> P;

const int N_MAX = 1e5;
int n, m;
vector<pair<int, int>> v[N_MAX];
priority_queue<P, vector<P>, greater<P>> q;

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int l, r, c;
        scanf("%d %d %d", &l, &r, &c);
        v[l - 1].emplace_back(r - 1, c);
    }
    
    long ans = 1e18;
    q.emplace(0, 0);
    for (int i = 0; i < n - 1; i++) {
        for (int j = 0, e = v[i].size(); j < e; j++) {
            while (!q.empty() && q.top().second < i) q.pop();
            if (q.empty()) {
                printf("-1\n");
                return 0;
            }
            if (v[i][j].first == n - 1) {
                ans = min(ans, q.top().first + v[i][j].second);
            }
            else {
                q.emplace(q.top().first + v[i][j].second, v[i][j].first);
            }
        }
    }

    printf("%ld\n", (ans == 1e18) ? -1 : ans);
    return 0;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+7;

int d;
ll g;
vector<P> pc;


int main()
{
    
    cin>>d>>g;
    pc=vector<P>(d);
    rep(i,d)
    {
        cin>>pc[i].first>>pc[i].second;
    }
    int ans=1000;
    for(int bit=0;bit<(1<<d);bit++)
    {
        int point=0;int rest=-1;
        int num=0;
        rep(i,d)
        {
            if((bit>>i)&1)
            {
                point+=100*(i+1)*pc[i].first+pc[i].second;
                num+=pc[i].first;
            }
            else
            {
                rest=i;
            }
            
        }
        if(point<g)
        {
            int s=100*(rest+1);
            int need=(g-point+s-1)/s;
            if(need>=pc[rest].first)
            {
                continue;
            }
            num+=need;
        }
        ans=min(ans,num);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int datan, data[1000];
	cin >> datan;
	for (int i = 0; i < datan; i++)
		cin >> data[i];
	for (int i = datan-1; i >0; i--)
		cout << data[i] << " ";
	cout << data[0] << endl;
	return 0;
}

Measured memory_bytes: 3056
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
P = [0]+list(map(float, input().split()))

dp = [[0]*(N+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(1, N+1):
    for j in range(0, i+1):
        if j > 0:
            dp[i][j] = P[i]*dp[i-1][j-1]+(1-P[i])*dp[i-1][j]
        else:
            dp[i][j] = (1-P[i])*dp[i-1][j]

ans = 0
for i in range(N//2+1, N+1):
    ans += dp[-1][i]
print(ans)


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

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

  string S; cin >> S;
  bool flag = true;
  if (S.size() % 2) flag = false;
  for (int i = 0; i < S.size(); i++) {
    if (i % 2 == 0 && S[i] != 'h') flag = false;
    if (i % 2 && S[i] != 'i') flag = false;
  }
  cout << (flag ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
import numpy as np

N, T = np.array(input().split(), dtype="int")
A = np.array(input().split(), dtype="int")

max_num=A[-1]
num_dict = {}
for i in range(len(A)-1):
    ##print(A[-i-1],max_num - A[-i-2],num_dict)
    if(A[-i-1]>max_num):
        max_num=A[-i-1]
    if(max_num > A[-i-2]):
        if(max_num - A[-i-2] in num_dict):
            num_dict[max_num - A[-i-2]] +=1
        else:
            num_dict[max_num - A[-i-2]]=1
key = max(num_dict.keys())
print(num_dict[key])

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

int main(void) {
  string S;
  cin >> S;
  ll W;
  cin >> W;

  string ans = "";
  for(ll i = 0; i < S.length(); i += W) {
    ans += S[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
mod = 10**9 + 7

n = int(raw_input())

a = [0]*n
x = n - 1
for i in xrange(n - 1, - 1, -1):
    if i == n - 1:
        a[i] = n
    elif i == n - 2:
        a[i] = n*n
    else:
        x -= 1
        x += a[i + 3] if i + 3 < n else 1
        x %= mod
        a[i] += a[i + 1] + (n - 1)*(n - 1) + x
    a[i] %= mod
print a[0]


Measured memory_bytes: 34436
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){

  int x;
  int i = 1;
  while(cin >> x){
    if( x == 0 ) break;
    printf("Case %d: %d\n", i, x);
    i++;
  }

  return 0;
}








// EOF

Measured memory_bytes: 3116
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem in C++
// MAIN IDEA   :
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
int n, DP[45][405][405] = { }, a, b, x[44], y[44], c[44];
int solve(int idx, int tot_A, int tot_B) {
	if (idx > n) {
		if (tot_B) {
			ll d = tot_B * b;
			ll n1 = (d / b) * a;
			ll n2 = (d / tot_B) * tot_A;
			if (n2 == n1)
				return 0;
		}
		return 1e9;
	}
	int &ret = DP[idx][tot_A][tot_B];
	if (ret != -1)
		return ret;
	ret = 1e9;
	ret = min(ret, solve(idx + 1, tot_A + x[idx], tot_B + y[idx]) + c[idx]);
	ret = min(ret, solve(idx + 1, tot_A, tot_B));
	return ret;
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	clr(DP, -1);
	cin >> n >> a >> b;
	lp(i,1,n)
		cin >> x[i] >> y[i] >> c[i];
	int u = solve(0, 0, 0);
	if (u >= 1e9)
		f(-1);
	f(u);
	return 0;
}

Measured memory_bytes: 29056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int n=s.size();

    int res=0;
    rep(bit,1<<(n-1)){
        int tmp=s[0]-'0';
        rep(i,n-1){
            if(bit&(1<<i)){
                res+=tmp;
                tmp=s[i+1]-'0';
            }else{
                tmp*=10;
                tmp+=s[i+1]-'0';
            }
        }
        res+=tmp;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3628
n=int(input())
h=list(map(int,input().split()))
dp=[0,abs(h[1]-h[0])]
for i in range(n-2):
  way1=dp[i]+abs(h[i+2]-h[i])
  way2=dp[i+1]+abs(h[i+2]-h[i+1])
  dp.append(min(way1,way2))
#print(dp)
print(dp[n-1])

Measured memory_bytes: 13928
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
const int MAX_V=105;
int INF = 1000000000;
  
int main(){
  int n=1;
  int W,N,i,j;
  while(cin >> W ,W){
    cin >> N;
    int dp[N+1][W+1];
    rep(i,N+1){
      rep(j,W+1){
        dp[i][j]=0;
      }
    }

    rep(i,N){
      int v,w;
      char c;
      cin >> v >> c >> w;
      rep(j,W+1){
        dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
        if(j+w<W+1){
        dp[i+1][j+w]=max(dp[i][j]+v,dp[i+1][j+w]);
        }
      }
    }
    int value1=0;
    int weight=0;
/*    rep(j,W+1){
      if(dp[N][j]>value1){
        value1=dp[N][j];        
      }
}*/
    rep(j,W+1){
      if(dp[N][j]==dp[N][W]){
        weight=j;
        break;
      }
    }
    
    cout << "Case" << ' ' << n++ << ":" << endl;
    cout << dp[N][W]<< endl;
    cout << weight << endl;  
    
  }
    return 0;
}
 

Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vi W(N);
    REP(i, N) cin >> W.at(i);
    float total = accumulate(all(W), 0);

    int S1 = 0;
    int S2 = 0;
    int minDiff = total + 1;
    REP(i, N) {
        S1 += W.at(i);
        S2 = total - S1;
        int diff = abs(S1 - S2);
        if (diff < minDiff) {
            minDiff = diff;
        }
    }
    print(minDiff);

}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
listA=list(map(int,input().split()))
a=listA[0]
b=listA[1]
snow=[1]
for i in range(1,999):
    snow.append(0)
    snow[i]=snow[i-1]+i+1
for j in range(1,1000):
    if(b-a==j):
        print(snow[j-1]-b)
        break;

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

int main(void) {
    string s, t;
    cin >> s >> t;
    int ans = t.size();
    for (int i = 0; i <= (int)(s.size() - t.size()); i++) {
        int cnt = 0;
        for (int ii = 0; ii < (int)t.size(); ii++) {
            if (t.at(ii) != s.at(i + ii)) {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int z = 0;

		if (a >= z) {
			z = a;
		}
		if (b >= z) {
			z = b;
		}
		if (c >= z) {
			z = c;
		}

		System.out.println(a + b + c - z + z * (int)Math.pow(2, k));
	}
}

Measured memory_bytes: 21844
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)

	max := 0
	for i := 1; i < n; i++ {
		lhs := strings.Split(s[0:i], "")
		rhs := strings.Split(s[i:n], "")

		memo := make(map[string]int)
		count := 0
		for _, ss := range lhs {
			if contains(rhs, ss) {
				_, ok := memo[ss]
				if !ok {
					memo[ss] = 1
					count++
				}
			}
		}
		if max < count {
			max = count
		}
	}

	fmt.Println(max)
}

func contains(arr []string, str string) bool {
	for _, e := range arr {
		if e == str {
			return true
		}
	}

	return false
}


Measured memory_bytes: 1024
D,G = map(int, input().split())

p = []
c = []

for i in range(D):
    x,y = map(int, input().split())
    p.append(x)
    c.append(y)

ans = sum(p)
for i in range(2**D):
    score = 0
    tmp = 0
    notuse = [0]*D
    for j in range(D):
        if ((i >> j) & 1):
            score += (100*(j+1)*p[j] + c[j])
            tmp += p[j]
            notuse[j] += 1
    if score < G:
        k = D-1
        while notuse[k] == 1:
            k -= 1
        for l in range(p[k]-1):
            score += 100*(k+1)
            tmp += 1
            if score >= G:
                break
        if tmp < ans and score >= G:
            ans = tmp
    else:
        if tmp < ans:
                ans = tmp

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]";
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;

    vector<ll> x(N);
    vector<ll> y(M);

    FOR(i, 0, N){
        cin >> x.at(i);
    }
    FOR(i, 0, M){
        cin >> y.at(i);
    }
    sort(ALL(x));
    sort(ALL(y));

    ll Z = y[0];

    if(x[x.size()-1] < Z && Z <= y[0] && X < Z && Z <= Y){
        p("No War");
    }else{
        p("War");
    }
    
    
    return 0;
}

Measured memory_bytes: 256
import sys
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]

for i in range(h-1):
  for j in range(w-1):
    if s[i][j] == "#":
      if s[i+1][j] == "#" or s[i-1][j]=="#" or s[i][j+1]=="#" or s[i][j-1]=="#":
        pass
      else:
        print("No")
        sys.exit()
  
print("Yes")

Measured memory_bytes: 3064
n=input()[:-2]
s=sorted(set(range(10))-set(map(int,input().split())))
s=[str(i)for i in s]
if all(i in s for i in n):
  print(n)
  exit()
f=0
t=''
for i in n:
  if f:
    t+=s[0]
  elif i in s:
    t+=i
  else:
    for j in s:
      if int(j)>int(i):
        t+=str(j)
        f=1
        break
    else:
      break
else:
  print(t)
  exit()
t=(s[0]*(s[0]!='0')or s[1])+s[0]*len(n)
print(t)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long llong;

// 二分木の定義
struct Node {
    int key;
    Node *left, *right, *parent;
    };
// 根・葉を定義
Node *root, *NIL;

//  二分木に新しい値を挿入する
void insert(int key)
{
    Node *x, *y, *z;
    // 初期化
    z = new Node;
    z->key = key;
    z->left = NIL;
    z->right = NIL;
    y = NIL;
    x = root;

    // 根から適切な位置までたどる
    while (x != NIL) {
        y = x; // 親を設定
        if (z->key < x->key) {
            x = x->left;
        }
        else {
            x = x->right;
        }
    }

    z->parent = y;

    // 要素を配置する場所を決定する
    if (y == NIL) { // T が空の場合
        root = z;
    }
    else if (z->key < y->key){
        y->left = z; // z を y の左の子にする
    }
    else {
        y->right = z; // z を y の右の子にする
    }
}

// キーが存在するか確認する
bool find(Node* node, int key)
{
    while (node != NIL) {
        if (node->key == key) return true;

        // 二分木の特性を利用して場合分け
        if (node->key == key) {
            return true;
        } else if (node->key < key)
        {
            node = node->right;
        } else {
            node = node->left;
        }
    }
    return false;
}

// 根から先行順巡回を行う
// 親→左部分木→右部分木の順
void PreOrder(Node* node)
{
    cout << " " << node->key;

    // 左部分木をチェック
    if (node->left != NIL) {
        PreOrder(node->left);
    }
    // 右部分木をチェック
    if (node->right != NIL) {
        PreOrder(node->right);
    }
}

// 根から先行順巡回を行う
// 左部分木→親→右部分木の順
void InOrder(Node* node)
{
    // 左部分木をチェック
    if (node->left != NIL) {
        InOrder(node->left);
    }
    cout << " " << node->key;

    // 右部分木をチェック
    if (node->right != NIL)
    {
        InOrder(node->right);
    }
}

void PrintVec()
{
    // 先行順巡回、 中間順巡回
    InOrder(root);
    cout << "\n";
    PreOrder(root);
    cout << "\n";
}

int main() {
    // 節点の個数
    int n = 0;
    // 次数
    int iDeg = 0;
    int iNodeIdx = 0;
    int left, node;
    string strCmd,strRes;
    bool bRet = false;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        //節点番号を取得
        cin >> strCmd;
        if (strCmd == "insert") {
            cin >> iNodeIdx;
            insert(iNodeIdx);
        }
        else if (strCmd == "print") {
            PrintVec();
        } 
        else if(strCmd == "find") {
            cin >> iNodeIdx;
            bRet = find(root, iNodeIdx);
            strRes = bRet? "yes" : "no";
            cout << strRes << "\n";
        }
    }
    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] p = new int[a];
        int[] q = new int[b];
        int[] r = new int[c];
        for (int i = 0; i < a; i++) {
            p[i] = sc.nextInt();
        }
        for (int i = 0; i < b; i++) {
            q[i] = sc.nextInt();
        }
        for (int i = 0; i < c; i++) {
            r[i] = sc.nextInt();
        }
        Arrays.sort(p);
        Arrays.sort(q);
        Arrays.sort(r);
        int[] g = new int[x + y];
        for (int i = 0 ; i < x ; i++) {
            g[i] = p[a - 1 - i];
        }
        for (int i = 0 ; i < y ; i++) {
            g[x + i] = q[b - 1 - i];
        }

        Arrays.sort(g);

        for (int i = 0 ; i < c ; i++) {
            if (i < x + y) {
                if (g[i] < r[c - 1 - i]) {
                    g[i] = r[c - 1 - i];
                }
            }

        }
        long sum = 0;
        for (int i = 0 ; i < x + y ; i++) {
            sum += (long) g[i];
        }

        System.out.println(sum);

    }

}

Measured memory_bytes: 95760
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>

#define REP(i, n) for(int i=0;i<n;i++)
#define ll long long
#define INF 999999999
#define pb(a) push_back(a)

using namespace std;

int main(){

  int n, x;
  vector<int> v;
  
  scanf("%d %d", &n, &x);
  REP(i, n){
    int t;
    scanf("%d", &t);
    v.pb(t);
  }

  ll res = 0;
  REP(i, n - 1){
    int t = v[i] + v[i + 1] - x;
    if(t > 0){
      if(v[i + 1] - t >= 0){
        v[i + 1] -= t;
        res += t;
      }else{
        v[i] -= t - v[i + 1];
        v[i + 1] = 0;
        res += t;
      }
    }
  }

  printf("%lld\n", res);

  return 0;
}



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

using namespace std;
//poison
const int maxn = 1e5+10;
int pa[maxn];

int f(int x)
 {
    return x == pa[x] ? x : (pa[x] = f(pa[x]));
}
void un(int x, int y) {
    int px = f(x);
    int py = f(y);
    if (px != py) {
        pa[px] = py;
    }
}
int main() {
    int n, m;
int ans = 0;
    cin >> n >> m;
    vector<int> nums(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
    }
    for (int i = 0; i < maxn; i++) {
        pa[i] = i;
    }
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        un(x, y);
    }  
    for (int i = 1; i <= n; i++) {
        if (f(nums[i]) == f(i)) {
            ans++;
        }
    }
//
//
//
//
//
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	n := scanInt()
	a := make([]int, n+1)
	b := make([]int, n)

	for i := 0; i < n+1; i++ {
		a[i] = scanInt()
	}
	for i := 0; i < n; i++ {
		b[i] = scanInt()
	}

	ans := int64(0)

	pre := 0
	for i := 0; i < n+1; i++ {
		if a[i]-pre >= 0 {
			ans += int64(pre)
			a[i] -= pre
		} else {
			ans += int64(a[i])
			a[i] = 0
		}

		if i == n {
			break
		}

		if a[i]-b[i] >= 0 {
			ans+=int64(b[i])
			pre=0
		} else {
			ans+=int64(a[i])
			pre=b[i]-a[i]
		}
	}

	fmt.Println(ans)
}


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

using namespace std;

int main()
{
  int n,w;
  cin>>n>>w;
  
  pair<long long ,long long>a[n];
  
  for(int i=0;i<n;i++)
    cin>>a[i].first>>a[i].second;
  
    long long dp[n+1][w+1];
    
    memset(dp,0,sizeof(dp));
  
  	for(int i=1;i<n+1;i++)
    {
      	for(int j=1;j<=w;j++)
        {
          	if(a[i-1].first>j)
            {
              dp[i][j] = dp[i-1][j];
            }
          
          	else if(j==a[i-1].first)
            {
              	dp[i][j] = max(dp[i-1][j],a[i-1].second);
            }
          
          	else
            {
              	dp[i][j] = max(dp[i-1][j],dp[i-1][j-a[i-1].first] + a[i-1].second);
            }
        }
    }

	cout<<dp[n][w]<<endl;  
  
}

Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <cstring>
#include <queue>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
typedef pair<int,int> pii;

int cost[1100][1100];

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<string> s;
	s.push_back(string(W+2,'X'));
	rep(i,H) {
		string t;
		cin >> t; s.push_back("X" + t + "X");
	}
	s.push_back(string(W+2,'X'));

	int res = 0;
	rep(i,N) {
		queue<pii> q;
		memset(cost, -1, sizeof(cost));
		rep(j,H+2) {
			rep(k,W+2) {
				if(s[j][k] == (i ? i+'0' : 'S')) {
					q.push(pii(j,k));
					cost[j][k] = 0;
				}
			}
		}
		while(q.size()) {
			pii a = q.front(); q.pop();
			const int dxy[] = {1,0,-1,0,1};
			if(s[a.fi][a.se] == i+'1')
				res += cost[a.fi][a.se];
			rep(j,4) {
				int y = a.fi + dxy[j];
				int x = a.se + dxy[j+1];
				if(s[y][x] != 'X' && !(cost[y][x]+1)) {
					cost[y][x] = cost[a.fi][a.se]+1;
					q.push(pii(y,x));
				}
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 9428
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int K;
	cin >> K;

	string S;
	cin >> S;

	if (S.length() <= K) {
		cout << S << endl;
	}
	else {
		for (int i = 0; i < K; i++) {
			cout << S[i];
		}
		cout << "..." << endl;
	}

	
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<math.h>
double x[101],y[101],sum,max;
int n,i;
void D(int p){
	for(i=0,sum=0;i<n;i++) sum+=pow(fabs(x[i]-y[i]),p);
	printf("%.8lf\n",pow(sum,(double)1/p));
}
int main(void){
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%lf",&x[i]);
	for(i=0;i<n;i++) scanf("%lf",&y[i]);
	D(1);D(2);D(3);
	for(i=0,max=0;i<n;i++){
		if(max<fabs(x[i]-y[i])) max=fabs(x[i]-y[i]);
	}
	printf("%.8lf\n",max);
	return 0;
}

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

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

int Lcm(int a, int b) { return a * b / Gcd(a, b); }

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


Measured memory_bytes: 3096
#include <stdio.h>
int main(){
  int menu[5];
  int menu_1keta[5] = {0};
  int min = 0;
  int time = 0;

  for(int i = 0; i < 5; i++){
    scanf("%d", &menu[i]);
  }

  for(int i = 0; i < 5; i++){
    menu_1keta[i] = menu[i] % 10;
    //    printf("menu_1keta[i] = %d\n", menu_1keta[i]);
  }

  for(int i = 1; i < 5; i++){
    if(menu_1keta[min] > menu_1keta[i] && menu_1keta[i] != 0){
      min = i;
    }
  }

  for(int i = 0; i < 5; i++){
    if(i != min){
      time += menu[i];
      if(time % 10 != 0){
	time += 10 - (time % 10);
      }
    }
  }

  time += menu[min];

  printf("%d", time);

  printf("\n");

}


Measured memory_bytes: 128
//２つの整数 a と b を読み込んで、以下の値を計算するプログラム
//a ÷ b ： d (整数)
// a ÷ b の余り ： r (整数)
// a ÷ b ： f (浮動小数点数)
#include <stdio.h>

int main(void)
{   
    //変数定義
    int iInputA;
    int iInputB;
    int iDivisionResult;
    int iSurplus;
    // float fDivisionResult;
    double fDivisionResult;
    //変数の初期化
    iInputA = 0;
    iInputB = 0;
    iDivisionResult = 0;
    iSurplus = 0;
    fDivisionResult = 0;

    //iInputAとiInputBを標準入力
    scanf ("%d %d",&iInputA,&iInputB);
    
    iDivisionResult = iInputA / iInputB;
    iSurplus = iInputA % iInputB;
    // fDivisionResult = (float)((float)iInputA / (float)iInputB);
    fDivisionResult = (double)((double)iInputA / (double)iInputB);
    //計算結果を標準出力
    printf("%d %d %.5f\n",iDivisionResult,iSurplus,fDivisionResult);

    return 0;
}


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

ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) {return b*(a/gcd(a,b));}

int main(){
  int n;
  cin >> n;
  ll t[100];
  for(int i=0; i<n; i++)
    cin >> t[i];
  
  ll ans = 1;
  for(int i=0; i<n; i++)
    ans=lcm(ans,t[i]);
  cout << ans << endl;
             
}

Measured memory_bytes: 256
import sys

n = int(input())
b = [int(i) for i in input().split()]

ans = []

for i in range(n):
    j = len(b)
    while j:
        if b[j-1] == j:
            ans.append(b.pop(j-1))
            break
        else:
            j -= 1
    if j == 0:
        print(-1)
        sys.exit()

for i in reversed(ans):
    print(i)

Measured memory_bytes: 3060
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順
#include <map>

using namespace std;
using ll = long long int;

int main(){
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++) cin >> S[i];
    int cnt = 0;


    vector<vector<int>> H_cnt(H,vector<int>(W));
    vector<vector<int>> W_cnt(H,vector<int>(W));
    queue<int> que;

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                while(que.size()){
                    int p = que.front();que.pop();
                    H_cnt[i][p] = cnt;
                }
                cnt = 0;
            }else{
                que.push(j);
                cnt++;
            }
        }
        while(que.size()){
            int p = que.front();que.pop();
            H_cnt[i][p] = cnt;
        }
        cnt = 0;
    }

    for(int i=0;i<W;i++){
        for(int j=0;j<H;j++){
            if(S[j][i]=='#'){
                while(que.size()){
                    int p = que.front();que.pop();
                    W_cnt[p][i] = cnt;
                }
                cnt = 0;
            }else{
                que.push(j);
                cnt++;
            }
        }
        while(que.size()){
            int p = que.front();que.pop();
            W_cnt[p][i] = cnt;
        }
        cnt = 0;
    }

    
    int ans = 0;
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(H_cnt[i][j]+W_cnt[i][j]>ans) ans = H_cnt[i][j] + W_cnt[i][j];
    cout << ans - 1 << endl;
    return 0;
}

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

int main(){
    int N; cin >> N;
    int T[N];
    int S=0;
    for (int i=0; i<N; i++){
        cin >> T[i];
        S += T[i];
    }
    int M; cin >> M;
    int p[M], x[M];
    for (int i=0; i<M; i++){
        cin >> p[i] >> x[i];
    }
    for (int i=0; i<M; i++){
        cout << S - T[p[i]-1] + x[i] << endl;
    }
}

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

struct Card
{
    char suit, value;
};

void bublleSort(struct Card a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = n - 1; j >= i + 1; j--)
        {
            if (a[j].value < a[j - 1].value)
            {
                struct Card v = a[j];
                a[j] = a[j - 1];
                a[j - 1] = v;
            }
        }
    }
}

void selectionSort(struct Card a[], int n)
{
    for (int i = 0; i < n - 1; i++)
    {
        int minj = i;
        for (int j = i + 1; j < n; j++)
        {
            if (a[j].value < a[minj].value)
            {
                minj = j;
            }       
        }
        struct Card v = a[i];
        a[i] = a[minj];
        a[minj] = v;
    }
}

bool isStable(struct Card card1[], struct Card card2[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (card1[i].suit != card2[i].suit)
        {
            return false;
        }
    }
    return true;
}

void print(struct Card card[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (i > 0)
        {
            printf(" ");
        }
        printf("%c%c", card[i].suit, card[i].value);
    }
    printf("\n");
}

int main()
{
    struct Card card1[100], card2[100];
    int n;

    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf(" %c", &card1[i].suit);
        scanf(" %c", &card1[i].value);
    }

    for (int i = 0; i < n; i++)
    {
        card2[i].suit = card1[i].suit;
        card2[i].value = card1[i].value;
    }
    
    bublleSort(card1, n);
    selectionSort(card2, n);

    print(card1, n);
    printf("Stable\n");
    print(card2, n);
    
    if (isStable(card1, card2, n))
    {
        printf("Stable\n");
    } else
    {
        printf("Not stable\n");
    }

    return 0;
}


Measured memory_bytes: 2132
#include <iostream>

using namespace std;

#include <math.h> 

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

    int prime = x;
    for(; IsPrime(prime) == false; ++prime){
        
    }
    cout << prime << endl;
}

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

int main() {
  int N,M; cin>>N>>M;
  vector<int> A(N); for(int i=0; i<N; i++) cin>>A[i];
  vector<long long> B(N+1);
  B[0] = 0;

  for (int i=0; i<N; i++) {
    B[i+1] = (B[i] + A[i]) % M; // 累積和 (mod M)
  }

  // <B[i] を M で割った余り, B[i] を M で割った余りが x (= 0,...,M-1) であるような i の個数>
  map<int,int> mp;
  long long ans = 0;
  for (int i=0; i<B.size(); i++) {
    ans += mp[B[i]];
    mp[B[i]]++;
  }

  cout<<ans<<endl;
  return 0;
}

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

void myswap( int& a, int& b );

int main(){
    int n;
    std::cin >> n;

    std::vector<int> vec(n);
    for( auto& e : vec ){
        std::cin >> e;
    }

    int numOfSwap = 0;
    int i = 0;
    for( ; i < n; ++i ){
        for( int j = n - 1; j > i; --j ){
            if( vec[j] < vec[j-1] ){
                myswap( vec[j], vec[j-1] );
                ++numOfSwap;
            }
        }
    }

    for( i = 0; i < n; ++i ){
        std::cout << vec[i] << ( (i < n - 1)? " " : "" );
    }
    std::cout << '\n' << numOfSwap << '\n';
}

void myswap(int& a, int& b){
    int tmp = std::move(a);
    a = std::move(b);
    b = std::move(tmp);
}


Measured memory_bytes: 3116
fn main(){
  loop {
    let mut input = String::new();
    match std::io::stdin().read_line(&mut input).unwrap() {
      0 => break,
      _ => {
        let v: Vec<&str> = input.trim().split(',').collect();
        let (w, h): (f64, f64) = (v[1].parse().unwrap(), v[2].parse().unwrap());
        if w / (h * h) >= 25.0 { println!("{}", v[0]) }
      }
    };
  }
}


Measured memory_bytes: 5048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    static boolean arr[];

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt(),k=s.nextInt();
        arr = new boolean[11];
        for(int i=0;i<k;i++)arr[s.nextInt()]=true;
        for(int i=n; ;i++){
            if(ok(i+"")){
                System.out.println(i);
                break;
            }
        }

    }

    public static boolean ok (String word){
        //System.out.println(word);
        for(int i=0;i<word.length();i++){
            //System.out.println(Arrays.binarySearch(arr,10));
            if(arr[word.charAt(i)-'0'])return false;
        }
        return true;
    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 37096
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    l = len(s)
    d = collections.defaultdict(int)

    m = {}
    m[''] = True
    def f(s):
        if s in m:
            return m[s]
        if s[0] != 'm' or s[-1] != 'w':
            m[s] = False
            return False
        l = len(s)
        for i in range(1,l-1):
            if s[i] != 'e':
                continue
            if f(s[1:i]) and f(s[i+1:-1]):
                m[s] = True
                return True
        m[s] = False
        return False

    if f(s):
        return 'Cat'
    return 'Rabbit'


print(main())




Measured memory_bytes: 13588