akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline

def scc(V, E):
    g = defaultdict(list)
    # g = [[] for _ in range(len(V))]
    rg = defaultdict(list)
    # rg = [[] for _ in range(len(V))]
    for u, v in E:
        g[u].append(v)
        rg[v].append(u)


    o = []
    done = set()
    for u in V:
        if u in done:
            continue

        s = [(u, True)]
        while s:
            u, f = s.pop()
            if f:
                if u in done:
                    continue
                done.add(u)
                s.append((u, False))
                for v in g[u]:
                    if v in done:
                        continue
                    s.append((v, True))
            else:
                o.append(u)

    done = set()
    ans = []
    while o:
        u = o.pop()
        if u in done:
            continue

        s = [u]
        vv = [u]
        done.add(u)
        while s:
            u = s.pop()
            for v in rg[u]:
                if v in done:
                    continue
                vv.append(v)
                s.append(v)
                done.add(v)
        ans.append(vv)


    return ans


def atcoder_practice2_g():
    N, M = map(int, input().split())

    E = []
    for _ in range(M):
        a, b = map(int, input().split())
        E.append((a, b))
    V = list(range(N))
    vv = scc(V, E)
    print(len(vv))
    for r in vv:
        print(len(r), *r)


def test():
    g = {
        1: [2],
        5: [2],
        2: [4, 3],
        3: [4, 7, 6],
        4: [5, 8],
        6: [9],
        7: [8],
        8: [9],
        9: [7, 10],
        10: []
    }

    V = list(range(1, 11))
    E = []
    for u, e in g.items():
        for v in e:
            E.append((u, v))

    vv = scc(V, E)
    for r in vv:
        print(r)


if __name__ == "__main__":
    # test()
    atcoder_practice2_g()


Measured memory_bytes: 332696
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = min(a, k) - min(c, max(0LL, k - a - b));
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int dp[100005][11][11][11];
int main(){
	ios_base::sync_with_stdio(false);
	int N, A[3];
	bool ans=true;
	vector<int> Q;

	cin >> N;
	rep(i,3) cin >> A[i];
	rep(i,N){
		string s;
		cin >> s;
		if(s == "AB") Q.push_back(0);
		if(s == "BC") Q.push_back(1);
		if(s == "AC") Q.push_back(2);
	}

	Fill(dp, -1);
	dp[0][min(A[0],3)][min(A[1],3)][min(A[2],3)] = 0;
	rep(i,N){
		int q = Q[i];
		int p = (q+1) % 3;
		// int r = (q+2) % 3;
		bool f = true;
		rep(a,10) rep(b,10) rep(c,10) if(dp[i][a][b][c] != -1){
			int d[] = {a, b, c};
			if(d[q] > 0){
				d[q]--;
				d[p]++;
				dp[i+1][min(d[0],9)][min(d[1],9)][min(d[2],9)] = p;
				d[q]++;
				d[p]--;
				f = false;
				//cout << i << "\t" << d[0] << d[1] << d[2] << " " << p << endl;
			}
			if(d[p] > 0){
				d[q]++;
				d[p]--;
				dp[i+1][min(d[0],9)][min(d[1],9)][min(d[2],9)] = q;
				d[q]--;
				d[p]++;
				f = false;
				//cout << i << "\t" << d[0] << d[1] << d[2] << " " << q << endl;
			}
		}
		if(f) ans = false;
	}

	cout << (ans ? "Yes" : "No") << endl;

	if(ans){
		rep(a,10) rep(b,10) rep(c,10) if(dp[N][a][b][c] != -1){
			vector<int> out;
			int d[] = {a, b, c};
			rrep(i,N){
				int p = dp[i+1][d[0]][d[1]][d[2]];
				int q = (Q[i] == p ? (p+1)%3 : (p+2)%3);
				d[p]--;
				d[q]++;
				out.push_back(p);
				//cout << d[0] << " " << d[1] << " " << d[2] << " : " << p << " " << q << endl;
			}
			reverse(all(out));
			for(auto p: out) cout << (char)('A' + p) << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 524340
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, n) for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (i64 i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (i64 i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T> using MaxHeap = priority_queue<T>;
template <class T> using MinHeap = priority_queue<T, vector<T>, greater<>>;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
inline i64 sigma(i64 n) { return n * (1 + n) >> 1; }
inline i64 updiv(i64 n, i64 d) { return (n + d - 1) / d; }
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

#ifndef DEBUG
#define dump(...)
#endif

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

inline void outs() { cout << "\n"; }
template <class Head, class... Tail>
inline void outs(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? " " : "");
    outs(forward<Tail>(tail)...);
}

template <class T>
inline void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e == &vec.back()]; }

template <class T>
inline void outs(vector<vector<T>> &df) { for (auto &vec : df) outs(vec); }

inline void outl() { cout << "\n"; }
template <class Head, class... Tail>
inline void outl(Head&& head, Tail&&... tail) {
    cout << head << (sizeof...(tail) ? "\n" : "");
    outl(forward<Tail>(tail)...);
}

template <class T>
inline void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

inline void outn() {}
template <class Head, class... Tail>
inline void outn(Head&& head, Tail&&... tail) {
    cout << head;
    outn(forward<Tail>(tail)...);
}

template <class T>
inline void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(size_t, N);

    vector<int> a(N);
    rep(i, N) input(a[i]);

    int res = 0;
    int base = 1;
    rep(i, N) {
        if (a[i] == base) {
            base++;
        } else {
            res++;
        }
    }

    if (base == 1) {
        outl(-1);
    } else {
        outl(res);
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int 
#define mod 1000000007
#define modulo 998244353
#define endl '\n'
using namespace std;
ll fxp(ll a, ll b)
{
    if(b == 0)return 1;
	if(b%2 == 0){
		ll c = fxp(a,b/2);
		return (c*c)%1000000007;
	}
	return (a*fxp(a,b-1))%1000000007;
}
int lcm(int c,int d)
{
    int a=c;
    int b=d;
    int ans;
    if(a>=b)
    {
        while(b!=0)
        { 
            int x=b;
            b=a%b;
            a=x;
        }
        ans = ( c*d)/a;
    }
    else
    {
        while(a!=0)
        {
            int x=a;
            a=b%a;
            b=x;
        }
        ans = ( c*d)/b;  
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    int k;
    cin>>k;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    ll dp[n];
    dp[n-1]=0;
    dp[n-2]=abs(h[n-1]-h[n-2]);
    for(int i=n-3;i>=0;i--)
    {
        if(k>1)
            dp[i]=min(abs(h[i]-h[i+1])+dp[i+1],abs(h[i]-h[i+2])+dp[i+2]);
        else
        {
            dp[i]=abs(h[i]-h[i+1])+dp[i+1];
        }
        
        for(int j=i+2;j<i+k && j<n-1;j++)
        {
            ll t = min(abs(h[i]-h[j])+dp[j],abs(h[i]-h[j+1])+dp[j+1]);
            dp[i]= min(t,dp[i]);
        }
    }
    cout<<dp[0]<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	--n;
	cout << (long long) n * (n + 1) / 2 << "\n";

	return 0;

}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<ll, ll>;

void merge(vector<int> &a, vector<int> &b){
    if(a.size() < b.size()){
        swap(a, b);
    }
    for(auto &e : b){
        a.emplace_back(e);
    }
    b.clear();
}

int solve(){
    int n, m;
    cin >> n >> m;
    vector<P> arms(m);
    for(int i=0;i<m;i++){
        int x, y;
        cin >> x >> y;
        arms[i] = P(x,y-1);
    }
    sort(arms.rbegin(),arms.rend());
    vector<vector<int> > l(n), r(n);
    for(int i=0;i<n;i++){
        l[i].emplace_back(i);
        r[i].emplace_back(i);
    }
    for(auto p : arms){
        int i = p.second;
        merge(l[i], l[i+1]);
        merge(r[i+1], r[i]);
    }
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        for(auto j : r[i]){
            ans[j] += i+1;
        }
        for(auto j : l[i]){
            ans[j] -= i;
        }
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << " \n"[i==n-1];
    }
    return 0;
}


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



Measured memory_bytes: 27196
def comb(current, mx, target: int):
    if len(current) == target:
        yield current
    elif len(current) < target and len(alphabet) > 0:
        for i in range(mx + 1):
            yield from comb(current + [chr(i + 97)], mx + 1 if i == mx else mx, target)


if __name__ == '__main__':
    n = int(input())
    alphabet = [str(chr(i)) for i in range(97, 97 + 26)]
    result = set()

    for perm in comb([], 0, n):
        print("".join(perm))


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

//define
#define ALL(a) a.begin(),a.end()
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) if(1) cout<<#x<<":"<<x<<endl;
#define DEBUG(x) if(1) cout<<#x<<":"<<x<<endl;
#define ll long long

//constant
const int MOD=1000000007;
const int INF=INT_MAX/3-1;
const double EPS=1e-9;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

//typedef
typedef vector<int> vi;
typedef vector<vector<int>> vvi;






int main(){
    int t,r,p;
    while(cin>>t>>p>>r,t){
        vvi team(t,vi(p,0));
        vector<tuple<int,int,int>> tem(t,make_tuple(0,0,0));
        REP(i,t)
            get<0>(tem[i])=i+1;
        REP(i,r){
            int tid,pid,time;
            string mes;
            cin>>tid>>pid>>time>>mes;
            tid--,pid--;

            if(mes=="CORRECT"){
                get<1>(tem[tid])++;
                get<2>(tem[tid])+=time+team[tid][pid]*1200;


            }
            if(mes=="WRONG")
                team[tid][pid]++;



        }
        REP(i,t)
            get<0>(tem[i]);
        sort(ALL(tem),
        [](tuple<int,int,int> lef,tuple<int,int,int> rig)
{return (get<1>(lef)>get<1>(rig)
        || get<1>(lef)==get<1>(rig) && get<2>(lef)<get<2>(rig)
        || get<1>(lef)==get<1>(rig) && get<2>(lef)==get<2>(rig) && get<0>(lef)<get<0>(rig));});

        for(int i=0;i<t;i++)
            cout<<get<0>(tem[i])<<" "<<get<1>(tem[i])<<" "<<get<2>(tem[i])<<endl;

    }

    return 0;
}

Measured memory_bytes: 3160
package main

import "fmt"

// 解説見た

func main() {
    var (
        n, cnt int
    )
    
    fmt.Scan(&n)
    
    for i:=11; i<=55555; i+=5{
        if isPrime(i) {
            fmt.Printf("%d ", i)
            cnt++
            if cnt == n {
                break
            }
        }
    }
    
}

func isPrime(n int) bool {
    if n <= 1 {
        return false
    }
    
    for i:=2; i<n; i++ {
        if n % i == 0 {
            return false
        }
    }
    
    return true
}

Measured memory_bytes: 512
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	string st("");
	for(ll i=0;i<n;i++)
	{
		st+=s[i];
		st+=t[i];
	}
	cout<<st;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6 + 8;
const int MOD = 1e9 + 7;
const int sz = 1e5 + 5;
void f_io(){
    IOS;
    // #ifndef ONLINE_JUDGE
    // FRE
    // #endif
}
bool possible(vector<int> &v, int len, int k) {
    if(!len) return false;
    for(auto l : v) {
        if(l <= len) continue;
        k -= l / len;
    }
    return k >= 0;
}

int32_t main(){
    f_io();
    int tc = 1;
    // cin>>tc;
    while(tc--){
        int n, k; cin >> n >> k;
        vector<int> v(n);
        for(auto &el : v) cin >> el;
        int l = 0, r = 1e9 + 100;
        while(l < r) {
            int mid = l + (r - l) / 2;
            if(possible(v, mid, k)) {
                r = mid;
            } else l = mid + 1;
        }
        cout << r << endl;
    }
}

Measured memory_bytes: 4780
#include<cstdio>
using namespace std;
#define re register int
int n,m,to[200003],ne[200003],he[100003],tot=1,res,st[100003],ed[100003],du[100003];
bool vis[100003];
inline void rea(re&dd)
{
	dd=0;re ch=getchar();
	while(ch<48||ch>57)ch=getchar();
	while(ch>=48&&ch<=57)dd=(dd<<3)+(dd<<1)+(ch^48),ch=getchar();
}
inline void dfs(re u,re fa)
{
	vis[u]=1;
	for(re i=he[u];i;i=ne[i])
	if(vis[to[i]]&&to[i]!=fa)
	++du[u],st[++res]=u,ed[res]=to[i];
	for(re i=he[u];i;i=ne[i])
	if(!vis[to[i]])dfs(to[i],u);
	if(u==1)return;
	if(du[u]&1)++du[u],st[++res]=u,ed[res]=fa;
	else ++du[fa],st[++res]=fa,ed[res]=u;
}
int main()
{
	rea(n),rea(m);
	if(m&1)return putchar(45),putchar(49),0;
	for(re i=1,u,v;i<=m;++i)
	{
		rea(u),rea(v);
		to[++tot]=v,ne[tot]=he[u],he[u]=tot;
		to[++tot]=u,ne[tot]=he[v],he[v]=tot;
	}
	dfs(1,0);
	for(re i=1;i<=res;++i)printf("%d %d\n",st[i],ed[i]);
 	return 0;
}

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

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

  int ans = N / 111;
  if (N % 111 != 0)
    ans += 1;
  ans *= 111;
  cout << ans << endl;
  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 all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
	int h, w;
	cin >> h >> w;
    vector<vector<int>> c(10, vector<int>(10));
    rep(i,10) rep(j,10) cin >> c[i][j];
    rep(k,10) rep(i,10) rep(j,10) chmin(c[i][j], c[i][k] + c[k][j]);
    int ans = 0, A;
    rep(i,h) rep(j,w) {
        cin >> A;
        if (A>=0) ans += c[A][1];
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys

def main():
    input = sys.stdin.readline
    
    n = int(input())
    l = list(map(int, input().split()))
    
    view = 0
    
    for i in range(len(l)):
        if max(l[:i + 1]) <= l[i]:
            view = view + 1
            
    print(view)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
	for(int w,h;cin>>w>>h,w|h;){
		int ci=0,cj=0;
		int di[]={0,1,0,-1},dj[]={1,0,-1,0},d=1;
		for(;;){
			string cmd; cin>>cmd;
			if(cmd=="FORWARD"){
				int n; cin>>n;
				ci+=di[d]*n; cj+=dj[d]*n;
				ci=max(ci,0); cj=max(cj,0);
				ci=min(ci,h-1); cj=min(cj,w-1);
			}
			if(cmd=="BACKWARD"){
				int n; cin>>n;
				ci-=di[d]*n; cj-=dj[d]*n;
				ci=max(ci,0); cj=max(cj,0);
				ci=min(ci,h-1); cj=min(cj,w-1);
			}
			if(cmd=="RIGHT")
				d=(d+3)%4;
			if(cmd=="LEFT")
				d=(d+1)%4;
			if(cmd=="STOP"){
				cout<<cj+1<<" "<<ci+1<<endl;
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
import Control.Applicative
import Control.Monad
import Text.Printf

circleCulc :: (PrintfArg a, Floating a) => a -> IO () 
circleCulc x = let area = x * x * pi
                   circum = 2 * x * pi
               in printf "%.6f %.6f" area circum

main = do
    line <- readLn :: IO Double 
    circleCulc line



Measured memory_bytes: 4056
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <iomanip>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 4e5 + 10;
const int maxm = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 1e9;

ll a[maxn], b[maxn], c[maxn], fen[maxn];
ll n;
int N = 200000;

ll get (ll x) {
    ll ret = 0;
    x += N;
    for (; x; x -= x & -x)
        ret += fen[x];
    return ret;
}

void update (ll x) {
    x += N;
    for (; x < maxn; x += x & -x)
        fen[x] ++;
}

ll check () {
    memset (fen, 0, sizeof fen);
    memset (c, 0, sizeof c);
    for (int i = 1; i <= n; i++)
        c[i] = c[i - 1] + b[i] - (b[i] == 0);

    update (0);
    ll ret = 0;
    for (int i = 1; i <= n; i++) {
        ret += get (c[i] - 1);
        update (c[i]);
    }
    return ret;
}

void build (ll x) {
    for (int i = 1; i <= n; i++)
        b[i] = (a[i] < x);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    ll tot = n * (n + 1) / 2;
    ll lo = 0, hi = 1000ll * 1000 * 1000 * 1000 + 1;
    while (hi - lo > 1) {
        ll mid = (lo + hi) >> 1;
        build (mid);
//      cout << lo << " " << mid << " " << hi << " -> " << check () << " " <<  tot / 2 + 1 << endl;
        if (check () > tot / 2)
            hi = mid;
        else
            lo = mid;
    }
    cout << lo << endl;
}

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

int main() {
  int W, a, b;
  cin >> W >> a >> b;

  if (a > b)
    swap(a, b);

  int ans = b - (a + W);

  if (ans > 0)
    cout << ans << endl;
  else
    cout << 0 << endl;
}

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

typedef long long ll;

int main() {
    int N, ans = 0;
    cin >> N;
    for (int i = 1; i <= N; i += 2) {
        int c = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) c++;
        }
        if (c == 8){
            ans++;
            //cout << i << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php

$stdin = trim(fgets(STDIN));

$nums = explode(' ', $stdin);

$a = $nums[0];

$b = $nums[1];

$c = $nums[2];

if ($a < $b && $b < $c){
echo "Yes",PHP_EOL;
} else {
echo "No",PHP_EOL;
}

Measured memory_bytes: 15280
#include <iostream>

using namespace std;

int main()
{
   string A,B;
   cin >> A >> B;

   int count = 0;
  
  for(int i=0;i<A.size();i++){
  	if(A[i]!=B[i])count++;
  }
  
   cout << count << endl;
   

   return 0;
}


Measured memory_bytes: 3836
a = int(input())
b = a%10
c = int(((a-b)/10)%10)
d = int(((a-b-c*10)/100)%10)
e = int(((a-b-c*10-d*100)/1000)%10)
mylst = [e, d, c, b]
if e == d:
    print("Bad")
elif d == c:
    print("Bad")
elif c == b:
    print("Bad")
else:
    print("Good")

Measured memory_bytes: 3064
from collections import defaultdict


def main():
    N, M = list(map(int, input().split(' ')))
    A = list(map(int, input().split(' ')))
    d = defaultdict(int)
    d[0] += 1
    cs = 0
    for i in range(N):
        cs += A[i]
        cs %= M
        d[cs] += 1
    ans = 0
    for v in d.values():
        ans += v * (v - 1) // 2
    print(ans)


if __name__ == '__main__':
    main()

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

int main() {
  int n;

  cin >> n;

  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);

  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    cin>>c[i];
  }

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  long long int ans = 0, k, x, y;
  for (int i = 0; i < n; i++) {
    k = b[i];
    x = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    y = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    ans += x * y;
  }

  cout << ans << endl;
}



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

int main() {
    int n;cin>>n;
    int a[n];
    int oddcnt=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]%2==1) oddcnt++;
    }
    //cout<<oddcnt<<endl;
    cout<<((oddcnt%2==1)?"NO":"YES")<<endl;

}


Measured memory_bytes: 640
#include <cstdio>
 #include <queue>
 using namespace std;
 
 int main()
 {
         priority_queue<int> pmount;

         int mount[11];

         for(int j=0;j<10;j++){
                 scanf("%d",&mount[j]);
                 pmount.push(mount[j]);
         }

         for(int i=0;i<3;i++){
                 printf("%d\n",pmount.top());
                 pmount.pop();
         }

         return 0;

 }

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

int gcd(int x, int y) {
    if(y%x == 0) return x;
    gcd(y%x, x); 
}

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

    cout << gcd(min(x, y), max(x, y)) << endl;
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Satoshi
{
	class Program
	{
		public static void Main(string[] args)
		{
			string[] s;
			s = Console.ReadLine().Split(' ');
			long n = long.Parse(s[0]);
			long a = long.Parse(s[1]);
			long b = int.Parse(s[2]);
			s = Console.ReadLine().Split(' ');
			long[] x = new long[n + 1];
			for (int i = 1; i <= n; i++)
			{
				x[i] = long.Parse(s[i - 1]);
			}
			long ans = 0;

			for (int i = 1; i < n; i++)
			{
				if ((x[i + 1] - x[i]) * a > b)
					ans += b;
				else
					ans += (x[i + 1] - x[i]) * a;
			}
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 12504
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

s = ns()
ans = 0
c = 0
acgt = ["A", "C", "G", "T"]
for si in s:
    if si in acgt:
        c += 1
    else:
        ans = max(c, ans)
        c = 0
if c != 0:
    ans = max(c, ans)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void ABC147D();

int main()
{
	ABC147D();
	fflush(stdout);
	return 0;
}

template <class _T> static _T tp_modpow(_T a, _T n, _T mod = (_T)1) {
	_T ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans = (ans * a) % mod;
		}
		a = (a * a) % mod;
		n >>= 1;
	}
	return ans;
}
template <class _T> static _T tp_modinv(_T a, _T mod) {
	return tp_modpow<_T>(a, mod - 2, mod);
}

static void ABC147D()
{
	int N;
	getint(N);

	std::vector<LLONG> ai(N);
	std::vector<std::vector<int>> bits(N, std::vector<int>(60, 0));
	for (int i = 0; i < N; i++) {
		if (i) bits[i] = bits[i - 1];

		getint(ai[i]);

		int bit = 0;
		LLONG tmp = ai[i];
		while (tmp) {
			if (tmp & 1LL) bits[i][bit]++;
			tmp >>= 1LL;
			bit++;
		}
	}
	
	std::vector<LLONG> sum(60, 0);
	for (int i = 0; i < N - 1; i++) {
		for (int bit = 0; bit < 60; bit++) {
			int on = bits[N - 1][bit] - bits[i][bit];
			if ((ai[i] >> (LLONG)bit) & 1LL) {
				sum[bit] += (N - i - 1) - on;
			}
			else {
				sum[bit] += on;
			}
		}
	}

	LLONG ans = 0;
	for (int bit = 0; bit < 60; bit++) {
		ans = (ans + (sum[bit] % MOD_NUM) * tp_modpow<LLONG>(2LL, bit, MOD_NUM)) % MOD_NUM;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 87660
import Control.Monad
main = do
    [n, m, c] <- fmap read . words <$> getLine :: IO [Int]
    b <- fmap read . words <$> getLine :: IO [Int]
    a <- forM [1..n] . const $ fmap read . words <$> getLine :: IO [[Int]]
    print . length . filter (0<) $ flip fmap a $ sum . (c:) . zipWith (*) b


Measured memory_bytes: 1020
#n=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
left=[];ri=[]
for i in range(m):
    l,r=map(int,input().split())
    left.append(l)
    ri.append(r)

ans=min(ri)-max(left)+1
if ans<=0:
    ans=0
print(ans)




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

int main(){
   int n,x;
   cin >> n >> x;
   vector<int> m(n);
   int min=100000;
   for (int i=0;i<n;i++) {
      cin >> m.at(i);
      x-=m.at(i);
      if (min>m.at(i))min=m.at(i);
   }
   int ans=n;
   ans+=x/min;
   cout << ans << endl;
}


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

const int Maxn = 100005;

int n;
int a[Maxn];

bool Check(int c)
{
    int un = 0, notun = 0;
    for (int i = 0; i < n; i++)
        if (a[i] == c) notun++;
        else un++;
    if (un > c) return false;
    int lft = c - un;
    if (notun == 0) return lft == 0;
    if (lft == 0) return false;
    return notun >= 2 * lft;
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    if (a[n - 1] - a[0] > 1) { printf("No\n"); return 0; }
    if (Check(a[n - 1])) { printf("Yes\n"); return 0; }
    if (a[0] == a[n - 1] && Check(a[0] + 1)) { printf("Yes\n"); return 0; }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;


int main(){
	int n;
	cin >> n;
	vector<ll> a(n+1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	vector<ll> sum(n+1);
	sum[0] = 0;
	for (int i = 1; i <= n; i++){
		sum[i] = sum[i-1] + a[i];
		sum[i] %= MOD;
	}
	ll ans = 0;
	for (int i = n; i >= 1; i--){
		ans += a[i]*sum[i-1];
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int n,m,x,ans,a[120000];

int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i){
		scanf("%d",&a[i]);
		if (a[i]==1) x=a[i];
	}
	ans=n+1;
	for (int i=1;i<=m;++i){
		int t=x-1,tmp=1;
		t-=i-1; if (t>0) tmp+=(t+m-2)/(m-1);
		t=n-x;
		t-=m-i; if (t>0) tmp+=(t+m-2)/(m-1);
		ans=min(ans,tmp);
	}
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 640
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const K = parseInt(arg[0].split(" ")[0]);
    const A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

    console.log(A[K - 1]);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <stdio.h>

int main()
{
  int N,L;
  int i;
  int small=1;
  int sum=0;
  scanf("%d %d",&N,&L);

  int A[N+1][3];
  for(i=1;i<=N;i++)
  {
    A[i][1]=i;
    A[i][2]=L+i-1;/*taste*/
    sum = sum + A[i][2];
    /*絶対値判定*/
    A[i][3]=A[i][2];
    if(A[i][2]<0)
    {
      A[i][3]=-1*A[i][3];
    }
    if(A[i][3]<A[small][3])
    {
      small=i;
    }
  }

sum = sum - A[small][2];

printf("%d",sum);

return 0;
}

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

int main(){

  int A, B, K;
  cin >> A >> B >> K;
  int count = 0;
  int ans;
  for(int i = min(A,B); i > 0; i--){
    if(A % i == 0 && B % i == 0){
      count++;
      if(count == K){
        ans = i;
        break;
      }
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    if(C < D){
        ll tmp = C;
        C = D;
        D = tmp;
    }
    ll tmpC = C,tmpD = D;
    ll r = tmpC % tmpD;
    while(r != 0){
        tmpC = tmpD;
        tmpD = r;
        r = tmpC % tmpD;
    }
    r = (C * D) / tmpD;
    ll ans = 0;
    ll first = (A + (C - 1)) / C,second = (B - A) / C;
    if((first + second) * C > B)second--;
    ans += second + 1;
    first = (A + (D - 1)) / D;
    second = (B - A) / D;
    if((first + second) * D > B)second--;
    ans += second +  1;
    first = (A + (r - 1)) / r,second = (B - A) / r;
    if((first + second) * r > B)second--;
    ans -= second + 1;
    cout << B - A + 1 - ans <<  "\n";
}

Measured memory_bytes: 256
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

def func(x, y):
    return x//y

a, b, c, d = list(map(int, input().split()))
n = b-a+1
candivide1 = func(b,c) - func(a-1,c)
candivide2 = func(b,d) - func(a-1,d)
cd = c*d // gcd(c,d)
both = func(b, cd) - func(a-1, cd)
ans = n - candivide1 - candivide2 + both
print(ans)

Measured memory_bytes: 3064
n, m = [int(x) for x in input().split()]
a_list = [0] * m
for i in range(m):
    a_list[i] = int(input())

mod = 1000000007

temp_list = [0] * (n + 1)
temp_list[0] = 1
temp_list[1] = 1
j = 0
if j < m and a_list[0] == 1:
    temp_list[1] = 0
    j = 1

for i in range(2, n + 1):
    if j < m and i == a_list[j]:
        j += 1
        continue
    temp_list[i] = (temp_list[i - 2] + temp_list[i - 1]) % mod
print(temp_list[n])

Measured memory_bytes: 7668
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int n,m,k,maxx=0x0fffffff;
string ch[15];
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;++i){
		cin>>ch[i];
	}
	for(int mas=0;mas<(1<<(n-1));++mas){
		int cnt=__builtin_popcount(mas);
		vector<int>v(cnt+1,0);
		for(int j=0;j<m;++j){
			bool flag=false;
			int p=0;
			for(int i=0;i<n;++i){
				v[p]+=(ch[i][j]=='1');
				if((mas>>i)&1){
					++p;
				}
			}
			for(int i=0;i<v.size();++i){
				if(v[i]>k)flag=true;
			}
			if(flag){
				++cnt;
				fill(v.begin(),v.end(),0);
				flag=false;
				p=0;
				for(int i=0;i<n;++i){
					v[p]+=(ch[i][j]=='1');
					if((mas>>i)&1){
						++p;
					}
				}
				for(int i=0;i<v.size();++i){
					if(v[i]>k)flag=true;
				}
				if(flag)cnt=0x0fffffff;
			}
		}
		maxx=(cnt<maxx?cnt:maxx);
	}
	cout<<maxx<<"\n";
	return 0;
}

Measured memory_bytes: 3588
let decompress s =
  let rec loop t = function
    i when i == String.length s -> t
  | i ->
     if s.[i] == '@' then
       let len = String.sub s (i+1) 1 |> int_of_string in
       loop (t^(String.make len s.[i+2])) (i+3)
     else
       loop (t^(String.make 1 s.[i])) (i+1)
  in loop "" 0
;;

let () =
  let rec read () =
    try let line = read_line () in
        Printf.printf "%s\n" (decompress line);
        read ()
    with End_of_file -> ()
  in read ()
;;

Measured memory_bytes: 2144
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define Yes(condition) if(condition){ cout << "Yes" << '\n'; }else{ cout << "No" << '\n'; }
#define YES(condition) if(condition){ cout << "YES" << '\n'; }else{ cout << "NO" << '\n'; }
#define yes(condition) if(condition){ cout << "yes" << '\n'; }else{ cout << "no" << '\n'; }




int main() {
    ll n, m;
    cin >> n >> m;
    vector<pair<ll, pair<ll, ll>>> v;
    REP(i, m){
        ll p, y;
        cin >> p >> y;
        v.push_back({y, {p, i}});
    }
    sort(v.begin(), v.end());
    vector<ll> cnt(n + 1, 1);
    vector<string> ans(m);
    REP(i, m){
        ans[v[i].second.second] = to_string(cnt[v[i].second.first]);
        while(ans[v[i].second.second].size() < 6){
            ans[v[i].second.second] = '0' + ans[v[i].second.second];
        }
        ans[v[i].second.second] = to_string(v[i].second.first) + ans[v[i].second.second];
        while(ans[v[i].second.second].size() < 12){
            ans[v[i].second.second] = '0' + ans[v[i].second.second];
        }
        cnt[v[i].second.first]++;
    }
    REP(i, m){
        cout << ans[i] << '\n';
    }
}


Measured memory_bytes: 10736
def main():
    from sys import setrecursionlimit, stdin
    from os import environ
    from collections import defaultdict, deque, Counter
    from math import ceil, floor
    from itertools import accumulate, combinations, combinations_with_replacement
    setrecursionlimit(10**6)
    dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in environ else lambda *x: 0
    input = lambda: stdin.readline().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    P = 10**9+7
    INF = 10**9+10


    h1,m1,h2,m2,k = LMIIS()
    wake = h1*60+m1
    sleep = h2*60+m2
    if wake > sleep:
        sleep += 24*60
    print((sleep-wake-k)%(24*60))

    
main()

Measured memory_bytes: 65252
#include <stdio.h>

int main(void)
{
	int a,count=0,c,d,b;
	scanf("%d",&a);
	b=a/1000;
	d=a/10;
	c=a/100;
	if(b==2)count=count+1;
	if(c%10==2)count=count+1;
	if(d%10==2)count=count+1;
	if(a%10==2)count=count+1;
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
n,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
if a[0] > x:
  c += a[0] - x
  a[0] = x
for i in range(n-1):
  if a[i]+a[i+1] > x:
    c +=  a[i]+a[i+1] - x
    a[i+1] = x-a[i]
print(c)  

Measured memory_bytes: 84876
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C
import Data.Vector.Unboxed (Vector, (!))
import qualified Data.Vector.Unboxed as U
import Data.Vector.Unboxed.Mutable (unsafeRead, unsafeWrite)
import qualified Data.Vector.Unboxed.Mutable as UM

main :: IO ()
main = do
  [n, k] <- readInts
  s <- C.getLine
  print $ solve n k s

{-
000110100011110
K+1 個の 1 の塊をつなげられる
000 11 0 1 000 1111 0
K=1の時
000 11 0 1 [000] 1111 0
000 11 0 1 111 1111 0
が最大となる
連続する数字の数を次のように格納する
3 2 1 1 3 4 1
一番左が0の時は先頭に0を追加する
0 3 2 1 1 3 4 1
また後ろには0を追加する(最終的に奇数になっていれば不要だが常に追加してよい)
0 3 2 1 1 3 4 1 0
として、連続するK+2個が最大になるものを探していく
K=1なら
[0 3 2] 1 1 3 4 1
0 3 [2 1 1] 3 4 1
0 3 2 1 [1 3 4] 1
-}

solve n k s = getMax preProcess
  where
    getMax :: Vector Int -> Int
    getMax v = if (2 * k + 1) >= len then U.sum v else maximum $ getMaxSub 0 (U.sum $ U.take 2 v) firstK2Sum []
      where
        getMaxSub i p cnt xs =
          if (i + 2 * k + 2) >= len
            then (cnt:xs)
            else getMaxSub (i + 2) first2Sum (cnt - p + next2Sum) (cnt:xs)
          where
            next2Sum = (v U.! (i + 2 * k + 1) + v U.! (i + 2 * k + 2))
            first2Sum = (v U.! (i + 2) + v U.! (i + 3))
        firstK2Sum = U.sum $ U.take (2 * k + 1) v
    len = U.length preProcess
    preProcess :: Vector Int
    preProcess = U.fromList $ if C.index s 0 == '0'
      then preProcessSub 1 '0' 1 [0]
      else preProcessSub 1 '1' 1 []
    preProcessSub i prev cnt xs = if i >= n
      then reverse (0:cnt:xs)
      else if c == prev
        then preProcessSub (i + 1) prev (cnt + 1) xs
        else preProcessSub (i + 1) c 1 (cnt:xs)
      where
        c = C.index s i

vectest :: Vector Int -> Vector Int
vectest input = U.create $ do
  v <- UM.replicate 1000 0
  forM_ [0 .. 999] (\i -> do
    let e = input ! i
    unsafeWrite v i e
    )
  return v

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

Measured memory_bytes: 13692
#!/usr/bin/perl
use POSIX qw(ceil);

my ($n,$k) = map {$_ - 0} split(/\s+/o,<STDIN>);
my @a = map {$_ - 0} split(/\s+/o,<STDIN>);

my $c =  ceil( ( $n - 1 ) / ( $k - 1 ) );

print "$c\n";



Measured memory_bytes: 19620
N = int(input())
S = {}

for i in range(N):
    str = ''.join(sorted(input()))
    if str in S.keys():
        S[str] += 1
    else:
        S.setdefault(str, 1)

cnt = 0
for v in S.values():
    cnt += (v * (v-1) // 2)

print(cnt)

Measured memory_bytes: 17848
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd __gcd
//#define int ll

using namespace std;
//using namespace __gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 40, T = 4 * N, inf = 1e9 + 7;

int n, m, f, r, l, e, w, o, z, test, id, mx;
vector < int > g[N];
int d[N];

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void dfs(int v)
{
    for (int i = 0; i < g[v].ss; i++)
    {
        int to = g[v][i];
        if (!d[to]) dfs(to);
        d[v] = max(d[v], d[to] + 1);
    }
    mx = max(mx, d[v]);
}

main()
{
    int x, y;
    //freop();
    boos();
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y;
        g[x].pb(y);
    }
    for (int i = 1; i <= n; i++)
    {
        if (d[i]) continue;
        dfs(i);
    }
    cout << mx;
}


Measured memory_bytes: 7680
// I am Nothing, You Are Nothing!
// Krishna is Everything ...
// Jai Shree Krishna

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 5, mod = 1e9 + 7;

vector<int> a[N];
int dp[N][3];

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		int a2, b, c;
		cin >> a2 >> b >> c;
		a[i] = {a2, b, c};
	}

	memset(dp, -1, sizeof dp);
	for (int j = 0; j < 3; j++) {
		dp[0][j] = 0;
	}

	for (int i = 1; i <= n; i++) {
		dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = a[i][2] + max(dp[i - 1][0], dp[i - 1][1]);
	}

	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;

	return 0;
}


Measured memory_bytes: 11412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int i;
    int c;
    c = 0;
    for (i=0; i < N;i++){
        cin >> A.at(i);
    }
    while(true){
        bool odd_flag = false;
        for (i=0; i < N;i++){
            if(A.at(i) % 2 != 0){
                odd_flag = true;
            }
        }
        if(odd_flag) 
            break;
        for (i=0; i < N;i++){
            A.at(i) /= 2;
        }
        c++;
    }
    cout << c << endl;
}

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

using namespace std;

string s;

int main() {
	cin >> s;
	if(s.length() & 1) {
		puts("No");
		return 0;
	}
	for(register int i = 0; i < s.length(); i += 2) {
		if(s[i] != 'h') {
			puts("No");
			return 0;
		}
	}
	for(register int i = 1; i < s.length(); i += 2) {
		if(s[i] != 'i') {
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;


const i64 MAXN = 300005;

i64 n;
i64 a[MAXN];
i64 c[10][10];

inline i64 last(i64 v) {
    return v % 10;
}

inline i64 first(i64 v) {
    i64 r = 0;
    while (v > 0) {
        r = v;
        v /= 10;
    }
    return r;
}


int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 1; i <= n; i++) {
        c[first(i)][last(i)] += 1;
    }

    i64 R = 0;
    for (i64 i = 0; i <= 9; i++) {
        for (i64 j = 0; j <= 9; j++) {
            R += c[i][j] * c[j][i];
        }
    }

    cout << R << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
   var h = long.Parse(Console.ReadLine());
   var i = 1;
   if(h <= 1){
     Console.WriteLine("1");
     return;
   }
   while(h > 1){
     i +=1;
     h = h/2;
   }
   if(i ==1){
     Console.WriteLine("1");
     return;
   }
   long g = 1;
   for(var n = 0;n<i;n++){
     g *= 2;
   } 
   Console.WriteLine(g-1);
  }
}

Measured memory_bytes: 13140
import math

n, d = [int(x) for x in input().split()]
x = []
for i in range(n):
    x.append([int(j) for j in input().split()])

count = 0
for i in range(n):
    for j in range(i,n):
        if (i == j):
            continue
        dist = 0
        for dd in range(d):
            dist += math.pow(x[i][dd] - x[j][dd], 2)
        dist = math.sqrt(dist)
        if dist == int(dist):
            count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//B
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
        ///memset   ///regular use
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b);}
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b);}

pair<string,int> arr[101];
map<pair<string,int>,int> mp;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string city;
    int score;
    for(int i =0; i<n;i++){
        cin>>city>>score;
        arr[i] = {city,-score};
        mp[{city,-score}] = i+1;
    }
    sort(arr,arr+n);
    for(int i =0; i<n; i++){
        cout<<mp[arr[i]]<<"\n";
    }

}


Measured memory_bytes: 3624