akhauriyash/Code-Regression huggingface dataset:
/*input
5 1 5
1000000000000000 999999999999999 999999999999998 999999999999997 999999999999996
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (int)(lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=105;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

pll av=MP(0,1);
ll a[maxn];

ll C[maxn][maxn];

int main(){
	IOS;
	int n,A,B;
	cin>>n>>A>>B;
	REP(i,n) cin>>a[i];


	REP(i,55) REP(j,i+1){
		if(j==0||j==i) C[i][j]=1;
		else C[i][j]=C[i-1][j]+C[i-1][j-1];
	}

	sort(a,a+n,greater<ll>());

	for(int len=A;len<=B;len++){
		ll sum=0;
		REP(i,len) sum+=a[i];
		if(av.F*len<av.S*sum){
			av=MP(sum,len);
		}
	}
	ll ans=0;
	for(int len=A;len<=B;len++){
		vector<ll> v;
		ll sum=0;
		REP(i,len) sum+=a[i],v.pb(a[i]);
		if(av.F*len==av.S*sum){
			reverse(ALL(v));
			while(v.back()!=v[0]) v.pop_back();

			int cnt=0;
			REP(i,n) if(a[i]==v[0]) cnt++;

			ans+=C[cnt][SZ(v)];
		}
	}
	cout<<fixed<<setprecision(12)<<(double)av.F/av.S<<'\n';
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9 + 7;
 
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}
 
int main() {
    int n, k;
    cin >> n >> k;
    ll a[n];
    FOR0(i, n) cin >> a[i];
    sort(a, a+n);
    ll ans = 1;
    if (a[n-1]==0 && k%2==1){
        cout << 0 << endl;
        return 0;
    }
    if (a[n-1] < 0 && k%2==1){
        for (int i = n - 1; i >= n - k; i--) ans = (ans*a[i] + mod)%mod;
        cout << ans << endl;
        return 0;
    }
    int i = 0, j = n-1;
    if (k %2 == 1) { 
        ans *= a[j];
        ans += mod;
        ans %= mod; 
        j--; 
        k--; 
    } 
    k/=2;
    for (int itr = 0; itr < k; itr++) { 
  
        ll left_product = a[i] * a[i + 1]; 
        ll right_product = a[j] * a[j - 1]; 
 
        if (left_product > right_product) { 
            left_product += mod;
            left_product%=mod;
            ans *= left_product; 
            i += 2; 
            ans += mod;
            ans %= mod;
        } 
        else { 
            right_product += mod;
            right_product%=mod;
            ans *= right_product; 
            j -= 2; 
            ans += mod;
            ans %= mod;
        } 
    } 
    cout << ans << endl;
 
}

Measured memory_bytes: 5152
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>

using namespace std;

int main()
{
	/*
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	char c = 'a';
	for (int i = 0; i < s.length(); i++)
	{
		while (true)
		{
			if (s[i] == c)
			{
				break;
			}
			if (s[i] == (c + 1))
			{
				c++;
				break;
			}
			else
			{
				printf("%c\r\n", c + 1);
				return 0;
			}
		}
	}
	cout << "None" << endl;
	*/
	string s;
	cin >> s;
	bool flag = false;
	for (char c = 'a'; c <= 'z'; c++)
	{
		for (int i = 0; i < s.length(); i++)
		{
			if (s[i] == c)
			{
				flag = true;
				break;
			}
		}
		if (!flag)
		{
			cout << c << endl;
			return 0;
		}
		flag = false;
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
import sys
# input関係の定義
sys.setrecursionlimit(200000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def fi(): return float(input())
def mfi(): return map(float, input().rstrip().split())
def lmfi(): return list(map(float, input().rstrip().split()))
def li(): return list(input().rstrip())
def si(): return input().rstrip()
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

# BEGIN CUT HERE
class RollingHash():
    """ロリハ。容易に衝突するので注意。"""
    BASE1 = 1007
    BASE2 = 2009
    MOD1 = 1000000007
    MOD2 = 1000000009

    def __init__(self, s, opt=2):
        self.n = len(s)
        self.opt = opt
        self.hash1 = [0] * (self.n + 1)
        self.power1 = [1] * (self.n + 1)
        if opt == 2:  # rollinghash by 2 mod
            self.hash2 = [0] * (self.n + 1)
            self.power2 = [1] * (self.n + 1)

        for i, e in enumerate(s):
            self.hash1[i + 1] = (self.hash1[i] * self.__class__.BASE1 + ord(e)) % self.__class__.MOD1
            self.power1[i + 1] = (self.power1[i] * self.__class__.BASE1) % self.__class__.MOD1
        if opt == 2:  # rollinghash by 2 mod
            for i, e in enumerate(s):
                self.hash2[i + 1] = (self.hash2[i] * self.__class__.BASE2 + ord(e)) % self.__class__.MOD2
                self.power2[i + 1] = (self.power2[i] * self.__class__.BASE2) % self.__class__.MOD2

    def get(self, l: int, r: int):
        res1 = self.hash1[r] - self.hash1[l] * self.power1[r - l] % self.__class__.MOD1
        if(res1 < 0):
            res1 += self.__class__.MOD1
        if self.opt == 2:
            res2 = self.hash2[r] - self.hash2[l] * self.power2[r - l] % self.__class__.MOD2
            if(res2 < 0):
                res2 += self.__class__.MOD2

        if self.opt == 2:
            return (res1, res2)
        else:
            return res1
# END CUT HERE

def ABC131E():
    N = ii()
    S = si()
    rh = RollingHash(S)
    def check(n: int):
        d = dict()
        for i in range(N - n + 1):
            p = rh.get(i, i + n)
            if p in d:
                if(i - d[p] >= n):
                    return True
            else:
                d[p] = i
        return False
    ok, ng = 0, N // 2 + 1
    while ng - ok > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)



if __name__ == '__main__':
    ABC131E()


Measured memory_bytes: 5032
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
  
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            List<int> list = new List<int>();
            for(int i = 0; i < N; i++)
            {
                list.Add(int.Parse(Console.ReadLine()));
            }
            int max = list.Max() / 2;
            Console.WriteLine(list.Sum() - max);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505

ll gcd(ll a, ll b)
{
	return (b == 0 ? a : gcd(b, a % b));
}

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

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

	int n;
	cin >> n;
	pair<int, int> po[n];

	for (int i = 0; i < n; ++i)
	{
		cin >> po[i].ff >> po[i].ss;
	}
	
	sort(po, po + n);
	ll max = 0; pair<ll, ll> max_in;
	ll p, q;
	ll ans = n;
	for (int i = 0; i < n; ++i)
	{
		for(int j = i + 1; j < n; ++j)
		{			
			p = po[j].ff - po[i].ff,
			q = po[j].ss - po[i].ss;
			ll no = 0;
			for(int k = 0; k < n; ++k)
			{
				ll px = po[k].ff + p, py = po[k].ss + q;
				for(int l = k + 1; l < n; ++l)
				{
					if(px == po[l].ff && py == po[l].ss)
					{
						no++;
					}
				}
			}
			if(no > max)
			{
				max = no;
				max_in = {p, q};
			}
		}
	}	
	// cout << max << "\n";
	ans -= max;

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

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    int N;
    int ans = 0;
    
    cin>>s;
    
    for(int i = 0; i < s.size(); i++){
        if(i%2 == 0){
            if(s[i] == 'p') ans--;
        } else {
            if(s[i] == 'g') ans++;
        }
    }

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


Measured memory_bytes: 512
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
void GridCompression() {
	int H, W;
	cin >> H >> W;
	char a[101][101];
	bool h[101],w[101];
	//memset(h, false, sizeof(h));
	//memset(w, false, sizeof(w));

	for (size_t i = 0; i < H; i++)
	{
		for (size_t j = 0; j < W; j++)
		{
			cin >> a[i][j];
			if (a[i][j] == '#') {
				h[i] = true;
				w[j] = true;
			}
		}
	}

	for (size_t i = 0; i < H; i++)
	{
		if (!h[i]) continue;
		for (size_t j = 0;  j < W;  j++)
		{
			if (!w[j]) continue;
			cout << a[i][j];
		}
		cout << "\n";
	}
}

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=50;
const int MM= +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL dp[NN][NN][NN]={};
int mat[NN][NN]={};
char s[NN]={};
LL getdp(int a,int b,int c){
	//cerr<<a<<" "<<b<<" "<<c<<endl;
	if(~dp[a][b][c])return dp[a][b][c];
	if(a==b&&b==c)return dp[a][b][c]=1;
	if(a==b||b==c)return dp[a][b][c]=0;
	dp[a][b][c]=0;
	for(int i=a;i<b;++i){
		for(int j=b+1;j<=c;++j){
			if(!mat[i][j])continue;
			for(int x1=i;x1<b;++x1){
				for(int x2=b+1;x2<=j;++x2){
					LL tp=getdp(a,i,x1)*getdp(x1+1,b,x2-1)*getdp(x2,j,c);
					dp[a][b][c]=dp[a][b][c]+tp;
				}
			}
		}
	}
	return dp[a][b][c];
}
int main(){
	//open();
	memset(dp,-1,sizeof dp);
	n=read();
	for(int i=1;i<=2*n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=2*n;++j){
			mat[i][j]=s[j]-'0';
		}
	}
	LL ans=0;
	for(int i=2;i<=2*n;++i){
		if(mat[1][i])ans=ans+getdp(2,i,2*n);
	}
	printf("%lld\n",ans);
	close();
	return 0;
}

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

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    vector<vector<int> > ijw;
    for(int i=0;i<n;i++){
      int ii,j,w;
      cin>>ii>>j>>w;
      ijw.push_back({ii,j,w});
    }
    sort(begin(ijw),end(ijw));
    int dp[367][367][2]={};
    for(auto e:ijw){
      for(int i=1;i<=366;i++){
	for(int j=1;j<=366;j++){
	  if(i<=e[0]){
	    dp[e[1]+1][j][1]=max(dp[e[1]+1][j][1],dp[i][j][0]+e[2]);
	  }
	  if(j<=e[0]){
	    dp[i][e[1]+1][1]=max(dp[i][e[1]+1][1],dp[i][j][0]+e[2]);
	  }
	}
      }
      for(int i=1;i<=366;i++){
	for(int j=1;j<=366;j++){
	  dp[i][j][0]=max(dp[i][j][0],dp[i][j][1]);
	}
      }
    }
    cout<<*max_element(dp[0][0],dp[367][0])<<endl;
  }
}

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

using namespace std;

#define fr(i,a,b) for(int i=a;i<b;++i)
/////////////////

int const N = 2e5 + 41;

int c[N], a[N], b[N];
int n, m, ans;

void pop(int x){
	if(x-c[x]+1 > 0){
		--b[x-c[x]+1];
		if(b[x-c[x]+1] == 0) ++ans;
	}	
	--c[x];
}

void push(int x){
	++c[x];
	if(x-c[x]+1 > 0){
		++b[x-c[x]+1];
		if(b[x-c[x]+1] == 1) --ans;
	}
}

void solve(){
	cin >> n >> m;
	fr(i, 0, n){
		cin >> a[i];
		++c[a[i]];
	}
	fr(i, 0, N){
		fr(j, 0, c[i]){
			if(i - j > 0) ++b[i - j];
		}
	}
	fr(i, 1, n+1) if(b[i] == 0) ++ans;
	fr(i, 0, m){
		int x, y;
		cin >> x >> y;
		--x;
		pop(a[x]);
		a[x] = y;
		push(a[x]);
		cout << ans << endl;
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Measured memory_bytes: 3712
#include <stdio.h>

int main(){

  int a,b,i;
  char ans[10];
  scanf("%d%d",&a,&b);

  if(a>b){
    for(i=0;i<a;i++){
      printf("%d",b);
    }
  } else {
    for(i=0;i<b;i++){
      printf("%d",a);
    }
  }

  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    set<int> st;
    for(int i=0; i<3; i++){
        int a; cin>>a; st.insert(a);
    }
    if(st.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
N=int(input())

def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n+1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

x=primes(N//2+1)
s=[0]*len(x)

for n,i in enumerate(x):
    for j in range(1,7):
        if i**j > N:
            break
        s[n]+=N//(i**j)

c2=0
c4=0
c14=0
c24=0
c74=0
for i in s:
    if i>=2:
        c2+=1
        if i>=4:
            c4+=1
            if i>=14:
                c14+=1
                if i>=24:
                    c24+=1
                    if i>=74:
                        c74+=1
    else:
        break

ans=c4*(c4-1)//2*(c2-2)
ans+=c14*(c4-1)
ans+=c24*(c2-1)
ans+=c74
print(ans)

Measured memory_bytes: 62512
def main():
    k, s = map(int, input().split())

    ans = 0
    for i in range(k + 1):
        for j in range(k + 1):
            now_num = i + j
            if 0 <= s - now_num <= k:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

#define MAX (20000)
int T;
int P[MAX+1];
int main(){
  cin >> T;
  for(int i=0;i*i<MAX;i++){
    for(int j=0;j*j+i*i<MAX;j++){
      int mn = i*i+j*j;
      if( mn <= 1 ) continue;
      for(int k=0;k*k*mn<MAX;k++){
        for(int l=0;(k*k+l*l) * mn < MAX; l++){
          int xy = k*k + l*l;
          if( xy <= 1 ) continue;
          P[mn*xy] = 1;
        }
      }
    }
  }
  for(int i=0;i<T;i++){
    int N,M;
    cin >> N >> M;
    cout << (P[N*N+M*M]==1?"C":"P") << endl;
  }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

int main() {
    set<string> substr;
    string s;
    int K;
    cin >> s >> K;

    for(int begin=0; begin<s.size(); begin++) {
        for(int end = 1; end<=K; end++) {
            string t = s.substr(begin, end);
            substr.insert(t);
        }
    }
  auto itr = substr.begin();
  advance(itr, K-1);
  cout << *itr << endl;
}



Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int dp[3003][3003] = {};
int main(){
    string S,T; cin >> S >> T;
    int ans = 0;
    for(int s = 1; s <= S.size(); s++){
        for(int t = 1; t <= T.size(); t++){
            if (S[s-1] == T[t-1]){
                dp[s][t] = dp[s-1][t-1] + 1;
            } else {
                dp[s][t] = max(dp[s-1][t], dp[s][t-1]);
            }
        }
    }
    string lcs = "";
    int s = S.length(), t = T.length();
    while(s && t){
        if (S[s-1] == T[t-1]){
            lcs += S[s-1];
            s--; t--;
        } else {
            if (dp[s][t] == dp[s-1][t]){
                s--;
            } else {
                t--;
            }
        }
    }
    reverse(lcs.begin(),lcs.end());
    cout << lcs << endl;
}
  



Measured memory_bytes: 35456
#include<stdio.h>
#include <string.h>
#include<iostream>
#include <cmath>

using namespace std;

int Check(int &N,int &K){

  //Kを求める
  double root;
  root = sqrt(2*N);
  //  cout << "root:" <<root <<endl;  
  K=ceil(root);
  //    cout<<"root:"<<root<<endl;
  //    cout<<"N:"<<N<<endl;
  //    cout<<"K:"<<K<<endl;
  
  if(K*(K-1)/2 == N){
    return 0;
  }else{
    return -1;
  }
}

int MakeSet(int &K){
  int N = K*(K-1)/2;

  //array initialize
  //なんかうまく初期化できなかったので、力尽くで実施   
  int array[N][K] ;//(x,y)
  for (int i=0;i<N;i++){
    for (int j=0;j<K;j++){
      array[i][j]=0;
    }
  }
  
  // K=5の場合                                                                  
  //  y                                                                         
  //                                                                            
  //K   X X X 4 | X X 7 | X 9 | 10
  //    X X 3 X | X 6 X | 8 X | 10
  //    X 2 X X | 5 X X | 8 9 | XX
  //    1 X X X | 5 6 7 | X X | XX
  //    1 2 3 4 | X X X | X X | XX
  //                                x
  
  //phase (0,0)=x
  int x=0;
  int y=0;
  int num=K-1; 
  for(int i=0; i<K;i++){
    //    cout<<"x  :"<<x <<endl;       //debut
    //    cout<<"y  :"<<y <<endl;       //debut 
    //    cout<<"num:"<<num <<endl;     //debut 
    //列指定
    for(int jx=0; jx<num;jx++){
      //行指定
      for(int jy=0; jy<num+1;jy++){	
	if(jy==0){
	  array[jx+x][jy+y]=1;
	  //	  cout<<jx+x <<endl;
	}
	if(jx+1==jy){
          array[jx+x][jy+y]=1;
	}
      }
    }
    //原点の移動
    x=x+num;
    y=y+1;
    num=num-1;
  }




  //output***************::::::
  for(int y=K-1; y>-1;y--){
    //合計値
    int sum=0;
    for(int i=0;i<N;i++){
      sum=array[i][y]+sum;
    }
    cout << sum << " ";        //|Sx|
    //    cout <<"S"<<y <<" ";
    for(int x=0; x<N;x++){
      if (array[x][y]==1){
	cout <<x+1<<" " ;     //要件
      }else
	cout <<"  " ;
	//	cout <<"X"<<" " ;       //debug
    }
    cout <<endl;
  }
  return 0;
}








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

  result=Check(N,K);
  //  cout<<"result:"<<result<<endl;
  
  if(result ==-1){
    cout <<"No"<<endl;   //要件
  }else if (result ==0){
    cout <<"Yes"<<endl;  //要件
    cout <<K<<endl;      //要件
    MakeSet(K);
  }else{
    cout <<"Error function Check"<<endl;
  }
  return 0;
}


Measured memory_bytes: 262144
N, C = map(int, input().split())
MAX_N = (10 ** 5 + 5)
X = [[0] * MAX_N for _ in range(C)]

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    X[c][s] += 1
    X[c][t + 1] -= 1
# print(X)
res = [[0] * MAX_N for _ in range(C)]
for c in range(C):
    for i in range(MAX_N - 1):
        res[c][i + 1] = res[c][i] + X[c][i]
# print(ans)
ans = 0
for i in range(MAX_N - 1):
    count = 0
    for c in range(C):
        if 0 < res[c][i]:
            count += 1
    ans = max(ans, count)
print(ans)


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

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

    double n;
    double total = 0;
    cin >> n;
    vector<double> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        total += A[i];
    }

    double mid = total / n;
    double d = 1e9;
    bool f = false;
    for(int i = 0; i < n; i++){
        double t = abs(A[i] - mid);
        d = min(d, t);
    }

    for(int i = 0; i < n; i++){
        double t = abs(A[i] - mid);
        if(t == d){
            cout << i << endl;
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n = int(input())
    if n % 2 == 1:
        print(0)
        return
    ans = n // 10
    for i in range(1, 32):
        ans += n // (5**i*10)
    print(ans)

main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  if(a[0] <sum-a[0]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

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

int main(int argc, char const* argv[])
{
	string str;
	cin >> str;
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
			string command;
			int x, y;
			cin >> command;
			if(command == "replace"){
					string z;
					cin >> x >> y >> z;
					for(int j = x; j <= y; j++){
							str[j] = z[j-x];
					}
			}else{
					cin >> x >> y;
					if(command == "reverse"){
							string orig = str.substr(x, y+1);
							for(int j = x; j <= y; j++){
									str[j] = orig[y-j];
							}
					}else if(command == "print"){
							for(int j = x; j <= y; j++){
									cout << str[j];
							}
							cout << endl;
					}
			}
	}
	return 0;
}



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

int main(){
    string s,p;
    
    cin >> s;
    cin >> p;
    
    bool f;
    for(int i=0; i<(int)s.size(); ++i){
        f = true;

        for(int k=0; k<(int)p.size(); ++k){
            if(i + k < (int)s.size() ){
                if(s[i + k] != p[k]){
                    f = false;
                    break;
                }
            }else{
                if(s[i + k - (int)s.size()] != p[k]){
                    f = false;
                    break;
                }
            }
        }
        
        if(f){
            cout << "Yes" << endl;
            break;
        }
        
    }
    
    if(!f){
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
map<long long,int> reps;
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int l = max(a,c);
    int r = min(b,d);
    cout << max(r-l,0);
}


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

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

Measured memory_bytes: 1024
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)
all_maxc=max(clist)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd2<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>4*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))
  else:
    max_c=0
    for i in index_set:
      max_c=max(max_c,clist[i])
    if max_c<all_maxc*(365-d)//365:
      index_set=set(range(26))

Measured memory_bytes: 69420
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
 
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;
void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=1e6+5,M=3e5+5,MOD=1e9+7,OO=1e9;

int main()
{	
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 	//file();
 	
 	int n;
 	string a,b;

 	cin>>n>>a>>b;

 	string ans;

 	for(int i=0;i<n;i++)ans.pb(a[i]),ans.pb(b[i]);

 	cout<<ans<<endl;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
uint64_t M;
uint64_t A[100001];
uint64_t sum[100001] = {};

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> M;
	uint64_t res = 0;
	for (int32_t i = 1; i <= N; i++)
	{
		in >> A[i];
		A[i] %= M;
	}

	for (int32_t i = 1; i <= N; i++)
	{
		sum[i] = A[i] + sum[i-1];
		sum[i] %= M;
	}
	std::unordered_map<int32_t, int32_t> num;
	for (int32_t i = 0; i <= N; i++)
	{
		num[sum[i]]++;
	}


	for (auto& c : num)//numの中で、存在する添え字のものだけを列挙します
	{
		//c.firstが添え字、c.secondが値です。
		uint64_t len = c.second;
		res += len * (len - 1) / 2;
	}
	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 4640
#include <stdio.h>
#include <stdlib.h>
int main(){
  int n;
  scanf("%d", &n);
//  int *R;
//  R = (int *)malloc(sizeof(int) * n);
  int t;
  int max = 0, def = 1000000000;
  for(t = 0; t < n; t++){
    int R;
    scanf("%d", &R);
    if(t == 1)
      max = R - def;
    if(R < def)
      def = R;
    else
      if(R - def > max)
	max = R - def;
  }
  printf("%d\n", max);
  return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    int a, b;
    string op;
    cin >> a >> op >> b; 
    if(op == "+") {
        cout << a + b; 
    } else {
        cout << a - b; 
    }
    return 0;
}   
/** atcoder **/


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

using namespace std;

int main() {
    int H, A;
    cin >> H >> A;
    cout << H / A + (H % A ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from operator import itemgetter
from collections import deque
sys.setrecursionlimit(10*5)

ans=0
p,q,r=0,0,0
n=int(input())
s=[]
for i in range(n):
    a=input()
    st=a[0]
    ed=a[-1]
    ans+=a.count('AB')
    if st=='B' and ed=='A':
        p+=1
    elif ed=='A':
        q+=1
    elif st=='B':
        r+=1
if q>0 and r>0:
    ans+=max(0, p+1+min(q-1,r-1) )
elif q==0:
    ans+=max(0, p-1 +(1 if r>0 else 0) )
elif r==0:
    ans+=max(0, p-1 +(1 if q>0 else 0) )
    
print(ans)

Measured memory_bytes: 44520
import sys
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
for line in sys.stdin:
    a, b = [int(x) for x in line.split()]
    c = math.gcd(a, b)
    d = lcm(a, b)
    print("%d %d" % (c, d) )


Measured memory_bytes: 5668
n=int(input())
c=input()
l,r=0,n-1
a=0
while r>l:
  while c[l]=='R' and l<n-1: l+=1
  while c[r]=='W' and r>=0: r-=1
  if r>l: a+=1
  l+=1
  r-=1
print(a)

Measured memory_bytes: 67664
#include <bits/stdc++.h>
using namespace std;
void program(); int main() {cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); program();}
#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>

#define N 10007
#define D 107
#define MOD 1000000007

int a[N], dp1[N][D], dp2[N][D];

void program(){
    string K;
    cin>>K;
    int n = K.size();

    for(int i=0;i<n;i++)
        a[i] = K[i] - '0';
    int d;
    cin>>d;

    for(int j=0;j<=9;j++) dp1[n-1][j%d] += 1;
    for(int i=n-2;i>=0;i--)
        for(int j=0;j<d;j++){
            //cout << "BLAH" << endl;
            for(int v=0; v<=9; v++) 
            {
                dp1[i][j] = (dp1[i][j] + dp1[i+1][(j-v+9*d)%d])%MOD;
                //cout << dp1[i][j] <<  " " << dp1[i+1][(j-v+d)%d] << " " << (j-v+d)%d << endl;
            }
        }

    for(int j=0;j<=a[n-1];j++) dp2[n-1][j%d] += 1;
    for(int i=n-2;i>=0;i--)
        for(int j=0;j<d;j++) {
            for(int v=0; v<a[i]; v++) 
                dp2[i][j] = (dp2[i][j] + dp1[i+1][(j-v+9*d)%d])%MOD;
            dp2[i][j] = (dp2[i][j] + dp2[i+1][(j-a[i]+9*d)%d])%MOD;
        }
    /*
    cout<<"dp1[i][j]"<<endl;
    for(int j=0;j<d;j++){
        for(int i=0;i<n;i++){
            cout <<"\t"<<dp1[i][j];
        }
        cout<<endl;
    }

    cout<<"dp2[i][j]"<<endl;
    for(int j=0;j<d;j++){
        for(int i=0;i<n;i++){
            cout <<"\t"<<dp2[i][j];
        }
        cout<<endl;
    }
    */

    cout<<(dp2[0][0]-1+MOD)%MOD<<endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-different perspective?
-bruteforce?
-greedy?
-reduce dimensionality with problem contraints?
*/


Measured memory_bytes: 17024
from operator import itemgetter

N, M = map(int, input().split())
AB = []
for _ in range(M):
    AB.append(list(map(int, input().split())))
AB.sort(key=itemgetter(1,0))
# print(AB)

ans = 1
p = 0
for i in range(1, M):
    if AB[i][0] >= AB[p][1]:
        ans += 1
        p = i
print(ans)

Measured memory_bytes: 35444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
bool vis[maxn];
vector<int> E[maxn];
typedef pair<int, int>pii;
pii edge[maxn];

void dfs(int u, int layer){
    edge[u].first = layer;

    for(auto v:E[u]){
        if(edge[v].first == 0){
            dfs(v, layer+1); 
            if(edge[v].second % 2 == 0){
                cout<<u<<" "<<v<<endl;
                edge[u].second += 1;
            }
            else{
                cout<<v<<" "<<u<<endl;
                edge[v].second += 1;
            }
        }
        else{
            if(edge[u].first < edge[v].first) {
                cout<<u<<" "<<v<<endl;
                edge[u].second += 1;
            }
        }
    }
}

int main()
{
    int n, m, u, v;
    while(cin>>n>>m){
        memset(vis, 0, sizeof(vis));
        for(int i=0;i<m;i++){
            cin>>u>>v;
            E[u].push_back(v);
            E[v].push_back(u);
            edge[i] = pii(0, 0);
        }
        edge[n] = pii(0, 0);
        if(m&1){
            cout<<-1<<endl;
        }
        else{
            dfs(1, 1);
        }
    }
    return 0;
}

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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder
//abc166

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

    int h[n];
    bool isGood[n];
    FOR0(i, n) isGood[i] = true;
    FOR0(i, n) cin>>h[i];

    int a, b;

    for (int i = 0; i < m; ++i)
    {
        cin>>a>>b;
        a--;
        b--;

        if(h[a]>h[b])
            isGood[b] = false;
        else if(h[a]<h[b])
            isGood[a] = false;
        else{
            isGood[a] = isGood[b] = false;
        }
    }

    int count = 0;

    for (int i = 0; i < n; ++i)
    {
        if(isGood[i])
            count++;
    }

    cout<<count<<endl;
}


Measured memory_bytes: 4128
using System;

class NumberTheory {
    public static int[] Sieve(int m) {
        var minFactor = new int[m + 1];
        var nextPrime = minFactor;
        int previousPrime = 0;
        for (int i = 2; i <= m; ++i) {
            int currentMinFactor = minFactor[i];
            if (currentMinFactor == 0) {
                currentMinFactor = i;
                previousPrime = nextPrime[previousPrime] = i;
            }
            for (int prime = 2; i * prime <= m; prime = nextPrime[prime]) {
                minFactor[i * prime] = prime;
                if (prime >= currentMinFactor) break;
            }
        }
        nextPrime[previousPrime] = m + 1;
        return minFactor;
    }
}

class C {
    public static void Main() {
        var n = int.Parse(Console.ReadLine());
        var sieve = NumberTheory.Sieve(n);
        var p = new int[n + 1];
        for (int i = 2; i <= n; ++i) {
            int m = i;
            while (sieve[m] < m) {
                ++p[sieve[m]];
                m /= sieve[m];
            }
            ++p[m];
        }
        var answer = 1L;
        for (int i = 2; i <= n; ++i)
            answer = answer * (1 + p[i]) % 1000000007L;
        Console.WriteLine(answer);
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

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

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











int main(){
    ll n, q;
    cin >> n >> q;
    REP(_, q){
        ll v, w;
        cin >> v >> w;
        if(n == 1){
            cout << min(v, w) << endl;
            continue;
        }
        while(v != w){
            if(v > w) swap(v, w);
            while(v < w){
                ll t = w % n;
                if(t == 0){
                    w /= n;
                }
                else if(t == 1){
                    w = (w - 1) / n;
                }
                else{
                    w = (w + (n - t)) / n;
                }
            }
        }
        cout << v << endl;
    }
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<queue>
#define NUM 8
#define MAX 40320

using namespace std;

struct Board{
	int key;
	int num[NUM];
	int pos[NUM];
	int depth;
	bool vis;
	void print() const {
		cout << num[0];
		for(int i = 1; i < NUM; ++i)
			cout << ' ' << num[i];
		cout << '\n';
	}
	bool check() const {
		for(int i = 0; i < NUM; ++i)
			if( num[i] != i )
				return false;
		return true;
	}
	void refreshKey(){
		key = num[0] + 1;
		for(int i = 1; i < NUM; ++i){
			key *= 10;
			key += num[i] + 1;
		}
	}
	bool operator<(const Board &b) const { return key < b.key; }
};

Board M[MAX];
int sz;

void ClearMap(void){
	for(int i = 0; i < sizeof(M)/sizeof(*M); ++i){
		M[i].vis = false;
		M[i].depth = 0;
	}
}
void PERM(int p[], int n)
{
	int *c,*pc,*q,k,t;

	c = new int[n];
	for(k=1,q=p,pc=c;k<=n;)*q++=*pc++=k++;k=1;pc=c;
	do{t=*(p+k);*(p+k)=*(q=p+((k&1)?*pc:0));*q=t;
	
	for(int i = 0; i < NUM; ++i){
		M[sz].num[i] = p[i] - 1;
		M[sz].pos[p[i] - 1] = i;
	}
	M[sz].refreshKey();
	M[sz].vis = false;
	M[sz].depth = 0;
	sz++;
	
	k=1;pc = c;while(*pc==0)*pc++=k++;(*pc)--;}while(k<n);
	delete [] c;
}
int BinDet( const Board &b ){
	int l = 0, r = MAX, m = r;

	if( b.key == M[l].key ) return l;
	if( b.key == M[r-1].key ) return r - 1;

	while( r - 1 > l ){
		m = (l + r) / 2;
		if( b.key > M[m].key )		l = m;
		else if( b.key < M[m].key )	r = m;
		else break;
	}
	return m;
}
inline void SubNext(Board &bd, int from, int to){
	swap( bd.pos[bd.num[from]], bd.pos[bd.num[to]] );
	swap( bd.num[from], bd.num[to] );
}
void Next( const Board &b, vector< int > &vNext ){
	Board bt[3];
	int dp[NUM][3] = {{1,4,-1},{0,2,5},{1,3,6},{2,7,-1},{0,5,-1},{1,4,6},{2,5,7},{3,6,-1}};
	int x;

	for(int i = 0; i < 3; ++i){
		bt[i] = b;
	}
	x = b.pos[0];

	for(int i = 0; i < 3; ++i){
		if( dp[x][i] >= 0 ){
			int pos;
			
			SubNext( bt[i], x, dp[x][i] );
			bt[i].refreshKey();
			pos = BinDet( bt[i] );
			
			assert( M[pos].key == bt[i].key );

			vNext.push_back( pos );
		}
	}
}

void BFS(int s){
	queue< int > q;

	q.push( s );

	while( !q.empty() ){
		int n = q.front();
		vector< int > next;
		q.pop();
		
		if( M[n].vis ) continue;
		else M[n].vis = true;
		
		Next( M[n], next );
		for( unsigned int i = 0; i < next.size(); ++i ){
			if( !M[next[i]].vis ){
				M[next[i]].depth = M[n].depth + 1;
				q.push( next[i] );
			}
		}
	}
}
int main(void){
	int p[NUM];
	//cout << "INITIALIZE...\n";
	PERM( p, NUM );
	//cout << "PERM END\n";
	sort( M, M+sizeof(M)/sizeof(*M) );
	//cout << "SORT END\n";
	BFS( 0 );
	//cout << "BFS END\n";
	while( true ){
		Board bst;
		
		//cout << "DATASET: \n";
		for(int i = 0; i < NUM; ++i){
			int t;

			cin >> t;
			if( cin.eof() ) return 0;
			bst.num[i] = t;
			bst.pos[t] = i;	
		}
		bst.refreshKey();
		int pos = BinDet( bst );
		cout << M[pos].depth << '\n';
	}
	return 0;
}

Measured memory_bytes: 3908
package main

// https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func main() {
	scanner.Split(bufio.ScanWords)

	for {
		n, err := nextInt()
		if err != nil {
			break
		}
		maybePrime := make([]bool, n+1)
		for i := 0; i <= n; i++ {
			maybePrime[i] = true
		}

		maybePrime[0] = false
		maybePrime[1] = false
		for i := 2; i <= int(math.Sqrt(float64(n)))+1; i++ {
			j := i * 2
			for j <= n {
				maybePrime[j] = false
				j += i
			}
		}

		nPrimes := 0
		for _, p := range maybePrime {
			if p {
				nPrimes++
			}
		}
		// fmt.Println(maybePrime)
		fmt.Println(nPrimes)
	}
}



Measured memory_bytes: 7044
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    ll ans = 0;
    if (m%2 == 1) m--;
    ll k = (m-2*n)/4;
    if (2*n <= m) cout << n + k << endl;
    else cout << m / 2 << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

struct query { int v, d, c; };

int main() {
    int n, m, q;
    cin >> n >> m;
    vector<int> G[n];
    for (int i=0; i<m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> q;
    vector<query> ques;
    for (int i=0; i<q; i++) {
        int v, d, c;
        cin >> v >> d >> c;
        ques.push_back({v-1, d, c});
    }
    reverse(ques.begin(), ques.end());
    int dist[n], color[n];
    fill(dist, dist+n, -1);
    fill(color, color+n, 0);
    queue<query> qq;
    for (auto que:ques) {
        qq.push(que);
        while (!qq.empty()) {
            query f = qq.front(); qq.pop();
            if (color[f.v] == 0) color[f.v] = f.c;
            cerr << f.v << ' ' << f.d << ' ' << f.c << '\n';
            for (auto g:G[f.v]) {
                if (f.d - 1 <= dist[g]) continue;
                dist[g] = f.d - 1;
                qq.push({g, f.d-1, f.c});
            }
        }
    }
    for (auto c:color) cout << c << '\n';
    return 0;
}

Measured memory_bytes: 9712
#include <stdio.h>
#include <iostream>

using namespace std;

char hyou[100][100];
int H,W;

void tyousa(char a,int x, int y) {
	hyou[y][x] = '0';
	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			int nx = x + dx;
			int ny = y + dy;
			if (0 <= nx && nx <= W-1 && 0 <= ny && ny <= H-1 && hyou[ny][nx] == a && dx * dy == 0) {
				tyousa(hyou[ny][nx],nx,ny);
			}
		}
	}
}

int main() {
	int count;
	while (cin >> H >> W) {
		if (H == 0 && W == 0) {
			break;
		} 
		count = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cin >> hyou[i][j];
			}
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (hyou[i][j] != '0') {
					tyousa(hyou[i][j],j,i);
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 2104
import java.util.*;

/**
 * B
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        Queue<String> name_array = new ArrayDeque<String>();
        Queue<Integer> time_array = new ArrayDeque<Integer>();

        int n = sc.nextInt();
        int q = sc.nextInt();
        
        int sum_time = 0;

        for (int i = 0; i < n; i++) {
            name_array.add(sc.next());
            time_array.add(sc.nextInt());
        }

        sc.close();

        while (name_array.peek() != null) {

            String str = name_array.remove();
            int tmp = time_array.remove();

            if(tmp > q) {
                name_array.add(str);
                time_array.add(tmp - q);
                sum_time += q;
            } else {
                System.out.println(str + " " + (sum_time + tmp));
                sum_time += tmp;
            }

        }
    }
}


Measured memory_bytes: 73388
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a <= b){
      for(int i = 0;i < b;i++){
        System.out.print(a);
      }
    }else{
      for(int i = 0;i < a;i++){
        System.out.print(b);
      }
    }
  }
}

Measured memory_bytes: 21716
import sys
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N,K = map(int, input().split())
    h = []
    for _ in range(N):
      h.append(int(input()))
  else:
    N = 5
    K = 3
    h = [10,15,11,14,12]
    # N = 5
    # K = 3
    # h = [5,7,5,7,7]

  h.sort()  

  ans = (h[K-1] - h[0])
  
  max_i = len(h)-K+1
  for i in range(1,max_i):
    tmp = (h[i+K-1] - h[i])
    if ans > tmp:
      ans = tmp
    if ans == 0:
      print(ans)
      sys.exit()
  
  print(ans)

main()

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

int main()
{
    int S,h,m,s;
    cin >> S;
    h = S/3600;
    m = S%3600/60;
    s = S%3600%60;  
    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3080
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>

#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N,M;
    cin >> N;
    vector<int> X(N,0);
    for(int i=0; i<N; i++){
        cin >> X[i];
    }
    cin >> M;
    vector<int> A(M,0);
    for(int i=0; i<M; i++){
        cin >> A[i];
    }
    unsigned char flg;
    //シミュレーション
    for(int i=0; i<A.size(); i++){
        flg=0;
        for(int j=0; j<X.size(); j++){
            if((A[i]-1)!=j && (X[A[i]-1]+1)!=X[j]){
                continue;
            }else if((A[i]-1)!=j && (X[A[i]-1]+1)==X[j]){
                flg = 1;
            }
        }
        if(flg==0 && X[A[i]-1]<2019){
            X[A[i]-1]+=1;
        }
    }
    for(int i=0; i<X.size(); i++){
        cout << X[i] << endl;
    }
    return 0;
}






Measured memory_bytes: 3096