akhauriyash/Code-Regression huggingface dataset:
def main():
    D = int(input())
    fuman = list(map(int, input().split()))
    manzoku = [[0]*26 for _ in range(D)]
    for i in range(D): manzoku[i] = list(map(int, input().split()))
    # できるだけ点数が下がらないように、満足度の高いものを選んでいく
    # d日目にテストiを受けた時、score += manzoku[d][i]-sigma[i以外25個](fuman[k]*それを受けてない日数)
    # >テストiをd日目に受ける
    # manzoku[d][i]-sigma[i以外25個](fuman[k]*それを受けてない日数)が一番大きいもの(i)を受けるそれだけ
    timepass = [0]*26
    # 初日のみ指定
    x,t = 0,0
    s = 0
    for j in range(26):
        tmp = manzoku[i][j]
        if tmp>x:
            x = tmp
            t = j
    s += x
    print(t+1)
    for i in range(1,D):
        # greedy
        x1 = 0
        t1 = 0
        for j in range(26):
            tmp = manzoku[i][j]
            for k in range(26):
                if not j==k: tmp -= fuman[k]*timepass[k]
            if tmp>x1:
                x1prev = x1
                t1prev = t1
                x1 = tmp
                t1 = j
            # たまに2番目を選んでみる
            if x1prev>0 and x1-100<=x1prev:
                x1 = x1prev
                t1 = t1prev

        # update timepass
        for j in range(26):
            if not j==t1: timepass[j] += 1
            else: timepass[j] = 0
        s += x1prev
        print(t1+1)
    #print(s)



main()


Measured memory_bytes: 9388
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int h,n,i,s=0;
  cin>>h >>n;
  long long int arr[n];
  for(i=0;i<n;i++)
  {
    cin>>arr[i];
    s=s+arr[i];
  }
  if(s>=h)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
int n; cin>>n;
int a[n]; rep(i,n) cin>>a[i];
int count = 0;
rep(i,n){
    if(a[a[i]-1] == i+1) count++;
}

cout<<count / 2<<endl;
   return 0;
}


Measured memory_bytes: 4032
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    large n, d;
    cin >> n >> d;

    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
        large x, y;
        cin >> x >> y;
        if (x*x + y*y <= d*d)
            cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        mp[s]++;
    }
    int maxs = 0;
    for (auto p : mp) maxs = max(maxs, p.second);
    for (auto p : mp){
        if (p.second != maxs) continue;
        cout << p.first << endl;
    }
}

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 値を取得
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n+2];
		int ans = 0;

		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			a[l]++;
			a[r + 1]--;
		}

		for (int i = 1; i <= n; i++) {
			if (a[i] == m) {
				ans++;
			}
			a[i + 1] += a[i];
		}

		System.out.println(ans);

		sc.close();
	}
}


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

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

		int[] intArray = new int[3];
		intArray[0] = sc.nextInt();
		intArray[1] = sc.nextInt();
		intArray[2] = sc.nextInt();
		Arrays.sort(intArray);
		StringBuilder sb = new StringBuilder();
		for (int i : intArray) {
			sb.append(i);
			sb.append(" ");
		}
		System.out.println(sb.toString().trim());
	}
}

Measured memory_bytes: 26360
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int A,B;

//解法
void solve() {

	cout << max(A + B, max(A - B, A*B));

	return;
}

int main() {
	//入力
	cin >> A>>B;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

int n, m, i, j, x, y, cnt;
int a[maxN];
bool us[maxN];
vector<int> list[maxN];
vector<int> aux, rez;
ll ans;

void dfs(int node) {
    us[node] = true;
    aux.pb(a[node]);

    for (auto to : list[node])
        if (!us[to])
            dfs(to);
}

int main()
{
   // freopen("test.in","r",stdin);

    cin >> n >> m;
    for (i = 1; i <= n; i++) cin >> a[i];
    for (i = 1; i <= m; i++) {
        cin >> x >> y;
        x++; y++;
        list[x].pb(y);
        list[y].pb(x);
    }

    for (i = 1; i <= n; i++) {
        if (us[i]) continue;
        aux.clear();
        dfs(i);

        cnt++;
        sort(aux.begin(), aux.end());
        ans += aux[0];
        for (j = 1; j < aux.size(); j++) rez.pb(aux[j]);
    }

    if (cnt == 1) {
        cout << 0;
        return 0;
    }

    sort(rez.begin(), rez.end());

    if (rez.size() < cnt - 2) {
        cout << "Impossible";
        return 0;
    }

    for (i = 0; i < cnt - 2; i++)
        ans += rez[i];

    cout << ans;


    return 0;
}


Measured memory_bytes: 7420
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1},
//           dx[] = {0, -1, -1, -1, 0, 1, 1, 1};

struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cerr << fixed << setprecision(10);
  }
} iosetup;
/*-------------------------------------------------*/
int main() {
  long long a, b; cin >> a >> b;
  cout << a / __gcd(a, b) * b << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N),memo(N+1);
    rep(i,N)cin >> A[i];
    rep(i,N){
        if(i+A[i] <= N){
            memo[i + A[i]]++;
        }
    }
    ll ans = 0;
    rep(i,N){
        if(i-A[i] >= 0){
            ans += memo[i-A[i]];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6420
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cout << setiosflags(ios::fixed) << setprecision(10);
	double W, H, w, h, x, y;
	cin >> W >> H >> w >> h >> x >> y;
	const double l = max(-W / 2, x - w / 2);
	const double r = min( W / 2, x + w / 2);
	const double u = max(-H / 2, y - h / 2);
	const double d = min( H / 2, y + h / 2);
	y = (u + d) / 2;
	x = (l + r) / 2;
	cout << y / x << endl;
	return 0;
}




Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//const ll MOD=(ll)1e9+7;
const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

unordered_map<ll,bool> mp;

void solve(int ca){
    while(1) {
        int N, x;
        cin >> N >> x;
        if(N==0&&x==0) break;
        int ans = 0;
        for (int i = 1; i <= N; ++i) {
            for (int j = i + 1; j <= N; ++j) {
                for (int k = j + 1; k <= N; ++k) {
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans << endl;
    }

}

//#define MULTI
int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}



Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    int happiness = 0;
    int nOf500 = X / 500;
    X -= nOf500 * 500;
    int nOf5 = X / 5;

    int res = nOf500 * 1000 + nOf5 * 5;
    cout << res << endl;
    return 0;
}


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

int child(int x, bool isleft) { return 2 * x + 1 + isleft; }
int parent(int x) { return (x - 1) / 2; }

template<class T, class F, T Init>
class SegmentTree{
private:
    int n;
    std::vector<T> node;
    F f;
public:
    SegmentTree(const std::vector<T>& v, F func) : f(func) {
        int vsize = v.size();
        n = 1;
        while (n < vsize) n <<= 1;
        node = std::vector<T>(2 * n - 1, Init);
        for (int i = 0; i < vsize; ++i) node[i + n - 1] = v[i];
        for (int i = n - 2; i >= 0; --i) node[i] = f(node[child(i, 0)], node[child(i, 1)]);
    }
    void update(int x, T val){
        x += n - 1;
        node[x] = val;
        while (x > 0) {
            x = parent(x);
            node[x] = f(node[child(x, 0)], node[child(x, 1)]);
        }
    }
    T query(int a, int b, int k = 0, int l = 0, int r = -1){
        if (r <= 0) r = n;
        if (r <= a || b <= l) return Init;
        if (a <= l && r <= b) return node[k];
        T vl = query(a, b, child(k, 0), l, (l + r) / 2);
        T vr = query(a, b, child(k, 1), (l + r) / 2, r);
        return f(vl, vr);
    }
};

using namespace std;

signed main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<int> v(n, 1);

    auto aton = [](char c) {
        int i = 1;
        while (c > 'a') i <<= 1, --c;
        return i;
    };
    
    for (int i = 0; i < n; ++i) v[i] = aton(s[i]);

    auto f = [](int a, int b) { return a | b; };
    SegmentTree<int, decltype(f), 0> st(v, f);

    while(q--){
        int qt;
        cin >> qt;
        if(qt==1){
            int i;
            char c;
            cin >> i >> c;
            --i;
            st.update(i, aton(c));
        } else {
            int l, r;
            cin >> l >> r;
            --l;
            cout << bitset<26>(st.query(l, r)).count() << endl;
        }
    }
}

Measured memory_bytes: 8964
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009

void solve()
{
	ll n,m;
	rl2(n,m);
	VL arr(n);
	fr(i,0,n)
		rl(arr[i]);
	sort(ALL(arr));
	vector<PLL> prs;
	fr(i,0,m)
	{
		ll b,c;
		rl2(b,c);
		prs.PB(MP(c,b));
	}
	sort(ALL(prs));
	reverse(ALL(prs));
	ll i=0,j=0;
	while(i<n&&j<m)
	{
		if(arr[i]<prs[j].F)
		{
			arr[i]=prs[j].F;
			prs[j].S--;
		}
		i++;
		if(prs[j].S==0)
			j++;
	}
	ll sum=0;
	fr(i,0,n)
		sum+=arr[i];
	//ll sum=accumulate(ALL(arr),0);
	wl(sum);
	NL;
	return;
}
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	solve();
	return 0;
}

Measured memory_bytes: 3188
# include <iostream>
using namespace std;
const int N=56,M=1000000007;
long long a[N];
string b,c;
int n;
void work (void)
{
	int i,f;
	f=0;
	i=0;
	while (i<n)
	if (b[i]==b[i+1]&&i<=n-2)
	{
		if (i==0)
		{
			a[1]=3;
			a[2]=6;
			f=1;
		}
   else if (f==0)
        {
        	a[i+1]=(a[i]*2)%M;
        	a[i+2]=a[i+1];
        	f=1;
        }
   else
        {
            a[i+1]=(a[i]*2)%M;
            a[i+2]=(a[i]*3)%M;
        }
        i+=2;
	}
else
    {
        if (i==0)
        a[1]=3;
   else if (f==0)
        a[i+1]=(a[i]*2)%M;
   else
        {
            a[i+1]=a[i];
            f=0;
        }
        i++;
    }
	cout<<a[n];
}
int main (void)
{
	cin>>n;
	cin>>b;
	cin>>c;
	work ();
	return 0;
}


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

public class Main {
    public static final long mod = 998244353;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        int s = in.ni();
        int[] a = in.ni(n);
        long[][] dp = new long[n+1][s+1];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= s; j++) {
                dp[i][j] += dp[i-1][j]*2;
                dp[i][j] %= mod;
                if(j-a[i-1]>=0){
                    dp[i][j] += dp[i-1][j-a[i-1]];
                    dp[i][j] %= mod;
                }
            }
        }
        out.println(dp[n][s]);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 104116
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>
#include <random>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFR INT_MAX
#define INFL (long long)(4e18)
#define INFLR LLONG_MAX
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}
string YN(bool y) { return (y ? "YES" : "NO"); }
string yn(bool y) { return (y ? "Yes" : "No"); }
string ON(bool y) { return (y ? "OK" : "NG"); }

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;

int dir4[4][2] = { {0,-1},{-1,0},{1,0},{0,1} };
int dir8[8][2] = { {-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{-1,1},{0,1},{1,1} };

// [a,b]の乱数
int irand(int a, int b) {
	static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
	uniform_int_distribution<int> dist(a, b);
	return dist(Rand);
}

// [a,b)の乱数
double drand(int a, int b) {
	static mt19937 Rand(static_cast<unsigned int>(time(nullptr)));
	uniform_real_distribution<double> dist(a, b);
	return dist(Rand);
}

//=======ここまでテンプレート===============================================



int main(void) {
	int N, M;
	cin >> N >> M;
	ll ans = (1LL << M) * ((ll)100 * N + 1800 * M);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
N, S1, S2 = open(0)
N = int(N)
m = 10**9+7

i = 0
dominos = []
while i < N:
    if S1[i] == S2[i]:# 縦のドミノ
        dominos.append(0)
        i += 1
    else:
        dominos.append(1)
        i += 2

ans = 3
for i in range(len(dominos)):
    if dominos[i] == 0:
        if i > 0 and dominos[i-1] == dominos[i]:
            ans = ans * 2 % m
    else:
        if i > 0 and dominos[i-1] == dominos[i]:
            ans = ans * 3 % m
        else:
            ans = ans * 2 % m
print(ans)

Measured memory_bytes: 9216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int ans=0;
		String genpon=sc.next();
		String[] base=new String[N];
		boolean[] kaz=new boolean[N];
		for(int i=0; i<N; i++) {
			base[i]=sc.next();
		}
		StringBuilder sb=new StringBuilder();
		for(int i=0; i<N; i++) {
			for(int j=0; j<base[i].length(); j++) {
				for(int k=1; k<=base[i].length(); k++) {
					int tmp=j;
					sb=new StringBuilder();
					while(tmp<base[i].length()) {
						sb.append(base[i].charAt(tmp));
						tmp+=k;
						if((sb.toString()).equals(genpon)) {
							//pl(sb.toString());
							kaz[i]=true;
							break;
						}
					}
				}
			}
		}
		for(int i=0; i<N; i++) {
			if(kaz[i]) {
				ans++;
			}
		}
		pl(ans);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 91152
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n; cin >> n;
    map<int, ll> m;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        m[a[i]]++;
    }

    ll ans = 0;
    for (auto kv: m) {
        ll v = kv.second;
        ans += v * (v-1) / 2;
    }

    rep(i, n) {
        ll t = m[a[i]];
        cout << ans - t*(t-1)/2 + (t-1)*(t-2)/2 << endl;
    }
}


Measured memory_bytes: 11852
#include<stdio.h>
#define H 250
#define K 2000000000

main(){
  int h,A[H];
  int i;

  scanf("%d",&h);

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

  for(i=1;i<=h;i++){
    if(i==1)printf("node %d: key = %d, left key = %d, right key = %d, \n",i,A[i],A[i*2],A[i*2+1]);
    else if(i*2>h)printf("node %d: key = %d, parent key = %d, \n",i,A[i],A[i/2]);
    else if(i*2+1>h)printf("node %d: key = %d, parent key = %d, left key = %d, \n",i,A[i],A[i/2],A[i*2]);
    else printf("node %d: key = %d, parent key = %d, left key = %d, right key = %d, \n",i,A[i],A[i/2],A[i*2],A[i*2+1]);
  }

  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================



int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================

	int H, W;
	cin >> H >> W;
	int N;
	cin >> N;
	vint A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	
	int now_H = 0;
	int now_W = 0;
	vvint ans(H);
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			ans[i].emplace_back(-1);
		}
	}

	int next_color = 0;
	int count = 0;
	while (count < H * W)
	{

		ans[now_H][now_W] = next_color;
		
		A[next_color]--;
		if (A[next_color] == 0)
		{
			next_color++;
		}

		if (now_W == W - 1 && now_H % 2 == 0)
		{
			// 右端で降りる
			now_H++;
		}
		else if (now_W == 0 && now_H % 2 == 1)
		{
			// 左端で降りる
			now_H++;
		}
		else if (now_H % 2 == 0)
		{
			// 右に進む
			now_W++;
		}
		else
		{
			// 左に進む
			now_W--;
		}

		count++;
	
	}

	for (int h = 0; h < H; h++)
	{
		for (int w = 0; w < W; w++)
		{
			cout << ans[h][w] + 1 << " ";
		}
		cout << endl;
	}




}





Measured memory_bytes: 384
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=a[0]
cnt=1
x=[]
for i in range(1,n):
	if b==a[i]:
		cnt+=1
	else:
		x.append([a[i-1],cnt])
		cnt=1
		b=a[i]
x.append([a[-1],cnt])
x.sort(key=lambda x:-x[1])
y=0
for i in range(min(k,len(x))):
	y+=x[i][1]
print(n-y)


Measured memory_bytes: 32960
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=1000,cnt=0;
	cin>>n;
	arrin(arr,n);
	j=n-1;
	while(j>0 and arr[j]<=arr[j-1])
	j--;
	for(i=0;i<n;i++)
	{
	    if(i==j)
	    {
	        sum+=cnt*arr[i];
	        break;
	    }
	    if(arr[i+1]>arr[i])
	    {
	        cnt+=sum/arr[i];
	        sum-=(sum/arr[i]*arr[i]);
	    }
	    else if(arr[i+1]<arr[i])
	    {
	        //cnt=0;
	        sum+=cnt*arr[i];
	        cnt=0;
	    }
	    //deb2(sum,cnt);
	}
	cout<<sum;
}
int32_t main() {
    fast
    //freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w+", stdout);
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

Measured memory_bytes: 3664
#include <cstdio>
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

string s,sol;
int n,col[N];

int main(){
    cin  >> n >> s;
    sol = 'S';
    for(int first = 0;first <= 1;first++){
    for(int last = 0;last <= 1;last++){

    col[0] = first;
    col[n-1] = last;

    for(int i = 1;i<n-1;i++){
        if(s[i-1] == 'x' && col[i-1] == 0){
            col[i] = !col[(i-2+n)%n];
        }
        if(s[i-1] == 'o' && col[i-1] == 0){
            col[i] = col[(i-2+n)%n];
        }
        if(s[i-1] == 'x' && col[i-1] == 1){
            col[i] = col[(i-2+n)%n];
        }
        if(s[i-1] == 'o' && col[i-1] == 1){
            col[i] = !col[(i-2+n)%n];
        }
    }
    bool good = 1;
    for(int i = 0;i<n;i++){
        if(col[i] == 0 && s[i] == 'o' && col[(i-1+n)%n] != col[(i+1+n)%n]) good = 0;
        if(col[i] == 1 && s[i] == 'x' && col[(i-1+n)%n] != col[(i+1+n)%n]) good = 0;
        if(col[i] == 0 && s[i] == 'x' && col[(i-1+n)%n] == col[(i+1+n)%n]) good = 0;
        if(col[i] == 1 && s[i] == 'o' && col[(i-1+n)%n] == col[(i+1+n)%n]) good = 0;
    }
    if(!good){
        continue;
    }
    else{
        for(int i = 0;i<n;i++){
            if(col[i]) cout << "W";
            else cout << "S";
        }
        cout << endl;
        return 0;
    }
    }}
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <array>
#include <map>

using tile = std::array<int, 4>;
constexpr int coeff[] = { 1, 2, 4 };
constexpr int perm[] = { 1, 1, 2, 6, 24 };

tile rotate(const tile &t, int r) {
  tile res{};
  for (int i = 0; i < 4; ++i) {
    res[i] = t[(i + r) & 3];
  }
  return res;
}

tile normalize(const tile &t) {
  std::array<tile, 4> tmp{};
  for (int i = 0; i < 4; ++i) {
    tmp[i] = rotate(t, i);
  }
  std::sort(tmp.begin(), tmp.end());
  return tmp.front();
}

int type(const tile &t) {
  if (t[0] == t[1] && t[1] == t[2] && t[2] == t[3]) return 2;
  if (t[0] == t[2] && t[1] == t[3]) return 1;
  return 0;
}

int main() {
  int N;
  std::cin >> N;
  std::vector<tile> C(N);
  std::vector<int> T(N);
  std::map<tile, std::array<int, 3>> memo;
  for (int i = 0; i < N; ++i) {
    for (auto &x: C[i]) {
      std::cin >> x;
    }
    C[i] = normalize(C[i]);
    T[i] = type(C[i]);
    memo[C[i]][T[i]]++;
  }
  int64_t ans = 0;
  for (int i = 0; i < N; ++i) {
    memo[C[i]][T[i]]--;
    const auto &up = C[i];
    for (int j = i + 1; j < N; ++j) {
      memo[C[j]][T[j]]--;
      for (int k = 0; k < 4; ++k) {
        auto down = rotate(C[j], k);
        std::map<tile, int> query;
        query[normalize(tile{ up[0], up[3], down[2], down[1] })]++;
        query[normalize(tile{ up[1], up[0], down[1], down[0] })]++;
        query[normalize(tile{ up[2], up[1], down[0], down[3] })]++;
        query[normalize(tile{ up[3], up[2], down[3], down[2] })]++;
        int64_t add = 1;
        for (auto &q: query) {
          auto itr = memo.find(q.first);
          if (itr == memo.end()) {
            add = 0;
            break;
          }
          const auto &data = itr -> second;
          std::array<std::array<int64_t, 5>, 4> dp{};
          dp[0][0] = 1;
          for (int l = 0; l < 3; ++l) {
            for (int m = 0; m <= 4; ++m) {
              int64_t cur = 1;
              for (int n = 0; m + n <= 4; ++n) {
                dp[l + 1][m + n] += dp[l][m] * cur;
                cur *= (data[l] - n) * coeff[l];
                cur /= (n + 1);
              }
            }
          }
          add *= dp[3][q.second] * perm[q.second];
        }
        ans += add;
      }
      memo[C[j]][T[j]]++;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
cx1,cy1,r1=gets.split.map(&:to_f)
cx2,cy2,r2=gets.split.map(&:to_f)
cxd=cx2-cx1
cyd=cy2-cy1
a=(cxd**2+cyd**2+r1**2-r2**2)/2
z=Math.sqrt((cxd**2+cyd**2)*r1**2-a**2)
w=cxd**2+cyd**2
puts [[(a*cxd+cyd*z)/w+cx1,(a*cyd-cxd*z)/w+cy1],[(a*cxd-cyd*z)/w+cx1,(a*cyd+cxd*z)/w+cy1]].sort*' '

Measured memory_bytes: 8792
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    max_i = int(math.log2(N))
    div = []
    for i in range(1,int(math.sqrt(N))+1):
        if N % i == 0:
            div.append((i,N//i)); div.append((N//i,i))

    ans = 0
    for a,b in div:
        if a == 1:
            for i in range(1,int(math.sqrt(b-1))+1):
                if (b-1) % i == 0:
                    p = 2 - (i*i == b-1) - (i == 1)
                    ans += p
        else:
            for i in range(1,max_i+1):
                c = round(math.pow(a,1/i))
                if c ** i == a:
                    if b % c == 1: ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 70888
namespace Test
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public class Test
    {
        public static void Main(string[] args)
        {
            var t = new Test();
            var n = t.ParseLongList(t.ReadInput());
            var a = n[0];
            var b = n[1];
            var c = n[2];
            var k = n[3];
            long ans = 0;

            if (k >= a)
            {
                k -= a;
                ans = a;
            }
            else
            {
                ans = ans + (k * 1);
                k -= a;
            }

            k -= b;

            if (k > 0)
            {
                if(c >= k)
                {
                    ans = ans - (k * 1);
                }
                else
                {
                    ans = ans - (c * 1);
                }
            }

            Console.WriteLine(ans);
        }



        public string[] ReadInput()
        {
            return Console.ReadLine().Split(' ');
        }

        public List<int> ParseIntList(string[] x)
        {
            var convertedList = new List<int>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(int.Parse(x[i]));
            }

            return convertedList;
        }


        public List<double> ParseDoubleList(string[] x)
        {
            var convertedList = new List<double>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(double.Parse(x[i]));
            }

            return convertedList;
        }

        public List<long> ParseLongList(string[] x)
        {
            var convertedList = new List<long>(x.Length);
            for (var i = 0; i < x.Length; i++)
            {
                convertedList.Add(long.Parse(x[i]));
            }

            return convertedList;
        }

        public int CountContainWords(string source, string word)
        {
            var count = 0;
            var loopCount = source.Length - (word.Length - 1);
            for (var i = 0; i < loopCount; i++)
            {
                if (source.Substring(i, word.Length) == word)
                {
                    count++;
                }
            }
            return count;
        }
    }
}

Measured memory_bytes: 27844
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars
    }
    let s_set = s .into_iter().collect::<std::collections::HashSet<_>>();
    let mut ret = None;
    for c in b'a'..b'z'+1 {
        if !s_set.contains(&(c as char)) {
            ret = Some(c as char);
            break;
        }
    }
    if let Some(src) = ret {
        println!("{}", src);
    } else {
        println!("None");
    }
}

Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        s = s.replace('1', '-');
        s = s.replace('9', '1');
        s = s.replace('-', '9');
        
        System.out.println(s);
    }
}

Measured memory_bytes: 21716
#AtCorder用　自動木取得コード

#１行目がノードの数、２行目以降が２つの数字でノードを繋ぐ辺を表すとき、使える

#変数
#node_n :ノードの数
#edge   :エッジを、入力の順番でリストとして提供
#【注意】ノードクラスのリストは関数で取り出さないと、連動して変わってしまう


#関数
#・getroot()で根を取り出す
#・getleaf()で葉を取り出す
#・childに子のノードクラスのリストが格納
#・parentに親のノードクラスが格納

import sys
sys.setrecursionlimit(1000000)
from collections import deque


#ノードクラス
class Node():
    def __init__(self):
        self.name=-1
        self.parent=-1
        self.child=[]
        self.color=0
        
        
        
        
    #ノードに対する子供の数を取得
    def childnum(self):
        return len(self.child)

    

#木クラス
class Tree():
    
    
    #作成した瞬間、入力の数だけノードを作る。
    def __init__(self):
        self.tree=[]
        self.node_n=int(input())
        for i in range(self.node_n):
            a=Node()
            a.name=i
            self.tree.append(a)
        self.edge=[]
        for i in range(self.node_n-1):
            self.edge.append([int(j) for j in input().split()])
        copyedge=sorted(self.edge)
        checkedge=deque()
        for edge in copyedge:
            first=self.tree[edge[0]-1]
            second=self.tree[edge[1]-1]
            if first.parent!=-1 or first.name==0:
                first.child.append(second)
                second.parent=first
            elif second.parent!=-1:
                second.child.append(first)
                first.parent=second
            else:
                checkedge.append(edge)
                
        while checkedge:
            edge=checkedge.popleft()
            first=self.tree[edge[0]-1]
            second=self.tree[edge[1]-1]
            if first.parent!=-1:
                first.child.append(second)
                second.parent=first
            elif second.parent!=-1:
                second.child.append(first)
                first.parent=second
            else:
                checkedge.append(edge)
       
     
    #根ノードを取得
    def getroot(self):
        return self.tree[0]
    
    #葉ノードのリストを取得
    def getleaf(self):
        leaf=[]
        for i in self.tree:
            if i.child==[]:
                leaf.append(i)
        return leaf
    
    
    #全ノードリストを取得
    def gettree(self):
        return self.tree[:]

    
    
    
    
    
tree=Tree()

ans=0
node=tree.getroot()


def dps(Node):
    global ans
    colorlist=[]
    p_col=Node.color
    childnum=Node.childnum()
    for i in range(childnum+1):
        colorlist.append(i+1)
    if p_col in colorlist:
        colorlist.remove(p_col)
    else:
        colorlist.pop()
    
    if colorlist!=[]:
        maxcol=colorlist[-1]
        if maxcol>=ans:
            ans=maxcol
        children=Node.child
        for i in range(childnum):
            children[i].color=colorlist[i]
        for child in children:
            dps(child)
    

dps(node)

print(ans)

tre=tree.gettree()
edge=tree.edge
n=tree.node_n

for i in edge:
    print(tre[i[1]-1].color)


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

using namespace std;
int k;
string s;
set<string> se;
set<string>::iterator ite;
int main()
{
    cin>>s;
    cin>>k;
    for (int i=0;i<(int)s.size();i++){
        for (int j=1;(int)j<=k;j++) {
            if (i+j>s.size()) break;
            se.insert(s.substr(i,j));
        }
    }
    int i=0;
    for (ite = se.begin(); ite!=se.end(); i++, ite++){
        if (i==k-1) cout<<*ite;
    }
    return 0;
}


Measured memory_bytes: 1664
import java.util.Scanner
import scala.collection.mutable

class Card(s: String, n: Int) {
  val suit: String = s
  val num: Int = n
  override def toString = suit + num
  override def equals(other: Any) = other match {
    case that: Card => this.suit == that.suit && this.num == that.num
    case _ => false
  }
}

object Card {
  def apply(text: String): Card = new Card(text take 1, (text drop 1).toInt)
}


object Main extends App {

  val sc = new Scanner(System.in)

  def next() = sc.next
  def nextInt() = next.toInt

  def bubbleSort(x: mutable.Seq[Card]): Seq[Card] = {
    val n = x.length
    for {
      i <- 0 to n-1
	  j <- n-1 to i+1 by -1
    } if(x(j).num < x(j-1).num) {
        val tmp = x(j)
        x(j) = x(j-1)
        x(j-1) = tmp
    }
    x
  }

  def selectionSort(x: mutable.Seq[Card]): Seq[Card] = {
    val n = x.length
    for (i <- 0 until n) {
      val minj = (i /: (i until n)) { (minj, j) =>
        if (x(j).num < x(minj).num) j
        else minj
      }
      val tmp = x(i)
      x(i) = x(minj)
      x(minj) = tmp
    }
    x
  }

  def testStability(xs: Seq[Card], ys: Seq[Card]): Boolean = {
    def loop(ns: List[Int]): Boolean = ns match {
      case n :: ns =>
        if (xs.filter(_.num == n) == ys.filter(_.num == n)) loop(ns)
        else false
      case Nil => true
    }
    loop((1 to 9).toList)
  }


  val n = nextInt
  val cards = mutable.Seq.fill(n)(Card(next))

  val bubble = bubbleSort(cards.clone)
  println(bubble mkString " ")
  println(if (testStability(cards, bubble)) "Stable" else "Not stable")

  val selection = selectionSort(cards.clone)
  println(selection mkString " ")
  println(if (testStability(cards, selection)) "Stable" else "Not stable")
}



Measured memory_bytes: 45236
#!/usr/bin/env python3

def main():
    s = input()
    n = len(s)
    chs = changes(s, n)

    res = n
    for c in chs:
        di = max(c, n - c)
        res = min(res, di)

    print(res)

def changes(s, n):
    res = []
    for i in range(1, n):
        if s[i - 1] != s[i]:
            res.append(i)
    return res

main()


Measured memory_bytes: 5180
#include<bits/stdc++.h>
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
void solve() {
	int x = 0, y = 0, a, b;
	int ansx = 0, ansy = 0;
	while (cin >> a >> b, abs(a + b) + abs(a)) {
		x += a; y += b;
		if (ansx * ansx + ansy * ansy < x * x + y * y) { ansx = x; ansy = y; }
		if (ansx * ansx + ansy * ansy == x * x + y * y && ansx < x) { ansx = x; ansy = y; }
	}
	cout << ansx << ' ' << ansy << endl;
}
signed main() {
	int q = input(); while (q--)solve();
}


Measured memory_bytes: 3124
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2442&lang=jp
// references:http://purple-jwl.hatenablog.com/entry/20121013/1350099039
typedef long long ll;
typedef pair<ll, ll> Point;
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N; cin >> N;
	vector<Point> P(N);
	for (int i = 0; i < N;i++) {
		ll X, Y; cin >> X >> Y;
		P[i] = { X,Y };
	}
	if (N % 2 != 0) { cout << "NA" << endl; return 0; }

	ll H = N / 2;
	for (int i = 0; i < H;i++) {
		ll l1 = pow(P[i].first - P[(i + 1) % N].first, 2) + pow(P[i].second - P[(i + 1) % N].second, 2);
		ll l2 = pow(P[i + H].first - P[(i + 1 + H) % N].first, 2) + pow(P[i + H].second - P[(i + 1 + H) % N].second, 2);
		ll l3 = pow(P[i].first - P[(i + 1 + H) % N].first, 2) + pow(P[i].second - P[(i + 1 + H) % N].second, 2);
		ll l4 = pow(P[(i + 1) % N].first - P[i + H].first, 2) + pow(P[(i + 1) % N].second - P[i + H].second, 2);
		if ((l1 == l2) && (l3 == l4)) continue;
		else { cout << "NA" << endl; return 0; }
	}

	double gx, gy; gx = gy = 0;
	for (int i = 0; i < N;i++) {
		gx += (double)P[i].first;
		gy += (double)P[i].second;
	}
	gx /= (double)N;
	gy /= (double)N;
	cout << fixed << setprecision(20) << gx << " " << gy << endl;
}

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int SZ = 1 << 18;

template<class T>
struct segtree {
	vector<T> dat;

	const T inf = numeric_limits<T>::max();

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = inf;
	}

	void update(int pos, T x) {
		pos += SZ - 1;
		chmin(dat[pos], x);

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = min(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	T get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return inf;
		if (a <= l && r <= b) return dat[k];
		return min(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
};

int main() {
	int N, M;
	cin >> N >> M;

	V<pair<pii, int>> vec;

	rep(i, M) {
		int L, R, C;
		cin >> L >> R >> C;
		--L; --R;
		vec.eb(mp(L, R), C);
	}

	vec.eb(mp(N-1, N-1), 0);
	sort(ALL(vec));

	segtree<ll> seg;
	seg.init();
	seg.update(0, 0);

	for (auto p : vec) {
		int l = p.fi.fi, r = p.fi.se, c = p.se;
		ll t = seg.get(l, r+1);
		if (t == seg.inf) continue;
		t += c;
		seg.update(r, t);
	}

	ll ans = seg.get(N-1, N);
	if (ans == seg.inf) ans = -1;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5620