akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int N, K, way[109][5009], dp[109][5009], mod = 1000000007;
int main() {
	cin >> N >> K;
	way[0][0] = 1;
	int mx = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= mx; j++) {
			for (int k = 0; k <= K; k++) {
				if (k > N - i) {
					way[i + 1][j] = (way[i + 1][j] + way[i][j]) % mod;
					dp[i + 1][j] = (dp[i + 1][j] + dp[i][j] + 1LL * (j + k) * way[i][j]) % mod;
				}
				else {
					int p = (j + k) / (N - i), q = (j + k) % (N - i);
					way[i + 1][j + p] = (way[i + 1][j + p] + way[i][j]) % mod;
					dp[i + 1][j + p] = (dp[i + 1][j + p] + dp[i][j] + 1LL * q * way[i][j]) % mod;
				}
			}
		}
		for (int j = 0; j <= 5000; j++) {
			if (way[i + 1][j]) mx = j;
		}
	}
	int ret = 0;
	for (int i = 0; i <= mx; i++) ret = (ret + dp[N][i]) % mod;
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 2816
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

//Time Sale
public class Main{

	int h, w, INF = 1<<29, n, si, sj;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};
	int[][] a, wf;
	int[][][] dp;
	int[] s, f, dis, sum;
	Set<Integer>[] set;
	
	int get(int i, int j, int S){
		if(dp[i][j][S]!=-1)return dp[i][j][S];
		if(S==0)return INF;
		int min = INF;
		for(int last=0;last<10;last++)if(((S>>last)&1)>0){
			if(!set[last].contains(i*w+j))continue;
			int sub = S-(1<<last);
			if(sub==0){
				int m = wf[i*w+j][si*w+sj];
				while(m < f[last]){
					if(s[last]<=m)break;
					m+=2;
				}
				if(f[last]<=m)m = INF;
				min = m;
				break;
			}
			for(int p=0;p<h*w;p++){
				if(a[p/w][p%w]!=-1)continue;
				int m = get(p/w, p%w, sub) + wf[i*w+j][p];
				while(m < f[last]){
					if(s[last]<=m)break;
					m+=2;
				}
				if(f[last]<=m)m = INF;
				min = Math.min(min, m);
			}
		}
		return dp[i][j][S] = min;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		dp = new int[20][20][1024];
		a = new int[20][20];
		dis = new int[10];
		s = new int[10];
		f = new int[10];
		wf = new int[400][400];
		sum = new int[1024];
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			si = -1; sj = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				char c = sc.next().charAt(0);
				if(c=='P'){
					si = i; sj = j; c = '.';
				}
				a[i][j] = c=='.'?-1:(c-'0');
			}
			Arrays.fill(dis, 0);
			Arrays.fill(s, 0);
			Arrays.fill(f, 0);
			n = sc.nextInt();
			for(int i=0;i<n;i++){
				int g = sc.nextInt();
				dis[g] = sc.nextInt(); s[g] = sc.nextInt(); f[g] = sc.nextInt();
			}
			set = new Set[10];
			for(int i=0;i<10;i++)set[i]=new HashSet<Integer>();
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(a[i][j]!=-1)continue;
				for(int k=0;k<4;k++){
					int ni = i+d[k][0], nj = j+d[k][1];
					if(0<=ni&&ni<h&&0<=nj&&nj<w&&a[ni][nj]!=-1)set[a[ni][nj]].add(i*w+j);
				}
			}
			Arrays.fill(sum, 0);
			for(int S=0;S<1024;S++)for(int j=0;j<10;j++)if(((S>>j)&1)>0)sum[S]+=dis[j];
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				int b = i*w+j;
				for(int p=0;p<h*w;p++)wf[b][p] = INF;
				Queue<Integer> q = new LinkedList<Integer>();
				wf[b][b] = 0;
				q.add(b);
				while(!q.isEmpty()){
					int V = q.poll();
					for(int k=0;k<4;k++){
						int ni = V/w+d[k][0], nj = V%w+d[k][1];
						if(0<=ni&&ni<h&&0<=nj&&nj<w&&a[ni][nj]==-1&&wf[b][ni*w+nj]==INF){
							wf[b][ni*w+nj] = wf[b][V]+1;
							q.add(ni*w+nj);
						}
					}
				}
			}
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)for(int S=0;S<1024;S++)dp[i][j][S]=-1;
			dp[si][sj][0] = 0;
			int res = 0;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				if(a[i][j]!=-1)continue;
				for(int S=1023;S>0;S--){
					if(sum[S]<=res)continue;
					if(get(i, j, S)<INF)res = sum[S];
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

int main(){
    string S;
    cin>>S;
    int N=S.size();
    for(int i=0;i<N-1;i++){
        if(S[i]==S[i+1]){
            cout<<i+1<<' '<<i+2<<endl;
            return 0;
        }
    }
    for(int i=0;i<N-2;i++){
        if(S[i]==S[i+2]){
            cout<<i+1<<' '<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<' '<<-1<<endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	int cnt =0;
	for(int i=0;i<n;i++)
		if(a[i] == i+1)
			cnt++;
	if(cnt == n || cnt == n-2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
N,Y = map(int, input().split())

A=0
B=0
C=int(Y/1000)
i=0
for j in range(2*10**7):
    for i in range(C,-1,-5):
        if((A+B+i)==N):
            print(A,B,i)
            exit()
        B+=1
    if((A+B+i)==N):
            print(A,B,i)
            exit()
    A+=1
    C-=10
    B=0
    if((10*A+5*B+i)>(Y/1000)):
        print("-1 -1 -1")
        exit()
print(A,B,i)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = -1000000000 * (ll)1000000000;
	
	ans = max(ans, a*c);
	ans = max(ans, a*d);
	ans = max(ans, b*c);
	ans = max(ans, b*d);
	cout << ans << endl;
	return 0;
}


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

int main(void){

    int l[10];
    int v1,v2;
    char c;


    while(cin >> l[0]){
        int sum = 0;
        int ans=0;
        sum= l[0];

        for(int i = 1;i < 10;i++){
            cin >> c >> l[i];
            sum+=l[i];
        }
        cin >> c >> v1 >> c >> v2;
        //cout << v1 << " " << v2 << endl;

        double ti = sum/double(v1+v2);
        double tmp = ti*double(v1);
        //cout << ti << " " << tmp << endl;

        for(int i = 0;i < 10;i++){
            tmp-=l[i];
            if(tmp<=0){
                ans=i+1;
                break;
            }

        }
        cout << ans << endl;

    }

   
    
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int dp[100005];
int a[100005];
int n;
int solve(int index)
{
    if(index>n) return 1e9;
    if(index==n) return 0;
    int &ret = dp[index];
    if(~ret) return ret;
    ret = INT_MAX;
    ret = min(ret, abs(a[index]-a[index+1]) +solve(index+1));
    ret = min( abs(a[index]-a[index+2]) +solve(index+2),ret);
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(int i=0;i<n;++i) cin>>a[i];
    a[n] = a[n-1];
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
}


Measured memory_bytes: 4224
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
inline int  in(){int n;scanf("%lld",&n);return n;}
inline void out(int n){printf("%lld\n",n);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

vi vec(3);

signed main(){
    io();
    rep(i, 3) cin>>vec[i];

    sort(all(vec));
    int ans = 0;
    REP(i,1,3) ans+=vec[i]-vec[i-1];

    out(ans);

    return 0;
}


Measured memory_bytes: 256
package main

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

type MyScanner struct {
	sc *bufio.Scanner
}

type MyWriter struct {
	stdout io.Writer
}

type MyPut interface{}

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func (mysc *MyScanner)String() string {
	mysc.sc.Scan()
	return mysc.sc.Text()
}

func (mysc *MyScanner)Int() int {
	i, _ := strconv.Atoi(mysc.String())
	return i
}

func (mysc *MyScanner)Int64() int64 {
	i, _ := strconv.ParseInt(mysc.String(), 10, 64)
	return i
}

func (mysc *MyScanner)Float64() float64 {
	i, _ := strconv.ParseFloat(mysc.String(), 64)
	return i
}

func (mw MyWriter)Puts(v MyPut) {
	_, _ = fmt.Fprintf(mw.stdout, "%v\n", v)
}

var dp [100][4][4][4]int
var mod int = 1000000007

func isAGC(i, j, k int) bool {
	return i == 0 && j == 2 && k == 1
}

func isACG(i, j, k int) bool {
	return i == 0 && j == 1 && k == 2
}

func isGAC(i, j, k int) bool {
	return i == 2 && j == 0 && k == 1
}

func isMatch(i, j, k int) bool {
	return isAGC(i, j, k) || isACG(i, j, k) || isGAC(i, j, k)
}

func DPInit() {
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				if isMatch(i, j, k) {
					dp[2][i][j][k] = 0
				} else {
					dp[2][i][j][k] = 1
				}
			}
		}
	}
}

func CalcDP(n int) {
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				if isMatch(i, j, k) {
					continue
				}
				for l := 0; l < 4; l++ {
					if isMatch(j, k, l) {
						continue
					}
					if isAGC(i, k, l) || isAGC(i, j, l) {
						continue
					}
					dp[n][j][k][l] += dp[n - 1][i][j][k]
					dp[n][j][k][l] %= mod
				}
			}
		}
	}
}

func DPSum(n int) (ret int) {
	for i := 0; i < 4; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				ret += dp[n][i][j][k]
				ret %= mod
			}
		}
	}
	return
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := MyScanner{getScanner(stdin)}
	mw := MyWriter{stdout}

	n := sc.Int()

	DPInit()

	for i := 3; i < n; i++ {
		CalcDP(i)
	}

	mw.Puts(DPSum(n - 1))
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(){
    int sum = 0;
    char ch;
 
    while(true)
    {
        while((ch = getchar()) != '\n'){
            sum += ch - '0';
        }
        if(sum == 0)
            break;
        else{
            printf("%d\n",sum);
            sum = 0;
        }
    }
}


Measured memory_bytes: 2704
import java.util.*;

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

    public void main() {
        Scanner scanner = new Scanner(System.in);
        String[] xy = scanner.nextLine().split(" ", 2);
        int x = this.parseHex(xy[0].charAt(0));
        int y = this.parseHex(xy[1].charAt(0));
        if (x == y) {
            System.out.println("=");
        } else if (x < y) {
            System.out.println("<");
        } else {
            System.out.println(">");
        }
    }

    private int parseHex(char ch) {
        if ('A' <= ch && ch <= 'F') {
            return 10 + (ch - 'A');
        } else {
            return ch - '0';
        }
    }
}


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

int main() {
	int N,K;
	cin >> N >> K;
  int keta = 0;
	while(pow(K,keta)<=N){
		keta++;
	}
	cout << keta << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=2002020,mod=1e9+7;
int n,m,fac[N],iv[N]; char s[N];
int read(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int fpow(int x,int y){
	int res=1;
	for(;y;y>>=1,x=1ll*x*x%mod)
		if(y&1)res=1ll*x*res%mod;
	return res;
}
int C(int n,int m){
	return 1ll*fac[n]*iv[m]%mod*iv[n-m]%mod;
}
int main()
{
	n=read();
	scanf("%s",s+1); m=strlen(s+1);
	fac[0]=iv[0]=1;
	for(int i=1;i<=n+m;i++)
		fac[i]=1ll*fac[i-1]*i%mod,iv[i]=fpow(fac[i],mod-2);
	int ans=0;
	for(int i=0;i<=n;i++)
		ans=(ans+1ll*C(m+n-i-1,m-1)*fpow(26,i)%mod*fpow(25,n-i)%mod)%mod;
	cout<<(ans%mod+mod)%mod<<endl;
	return 0;
}

Measured memory_bytes: 20280
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define all(arr) arr.begin(),arr.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
int mod = 1e9+7;
/*int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;*/

void solve()
{
	int n;
	cin>>n;
	int p = n%1000;
	if(p!=0)
		p = n/1000 +1;
	else
		p = n/1000;
	p *= 1000;
	cout<<p-n<<endl;
}

int32_t main()
{
	FastIO; PRECISION;
	int t = 1;
	//cin>>t;
	while(t--)
		solve();
	return 0;
}

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

const int IINF = 2002002002;
const ll LINF = 9009009009009009009LL;

//===



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

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

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

	int ans = IINF;
	for (int i = K - 1; i < N; ++i) {
		ans = min(ans, h[i] - h[i - K + 1]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

vector<string> bubbleSort(vector<string> vs) {
    int n = vs.size();
    for (int i=0; i<n; ++i) {
        for (int j=n-1; j>0; --j) {
            if (vs[j][1] < vs[j-1][1]) {
                swap(vs[j], vs[j-1]);
            }
        }
    }
    return vs;
}

vector<string> selectionSort(vector<string> vs) {
    int n = vs.size();
    for (int i=0; i<n; ++i) {
        int mini = i;
        for (int j=i+1; j<n; ++j) {
            if (vs[mini][1] > vs[j][1]) {
                mini = j;
            }
        }
        swap(vs[mini], vs[i]);
    }
    return vs;
}

void print(vector<string> vs) {
    for (int i=0; i<(int)vs.size(); ++i) {
        cout << (i == 0 ? "" : " ") << vs[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<string> cards(N);
    for (int i=0; i<N; ++i) {
        cin >> cards[i];
    }

    vector<string> seq1 = bubbleSort(cards);
    print(seq1);
    cout << "Stable" << endl;

    vector<string> seq2 = selectionSort(cards);
    print(seq2);
    cout << (seq1 == seq2 ? "Stable" : "Not stable") << endl;

    return 0;
}

Measured memory_bytes: 1216
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vi l(n);
	rep(i,n) cin >> l[i];
	// 4-bit 全探索: 0 から 4^n-1 まで探索  
	// bit 全探索を2重ループにする
	// n = 4, b1 = 1010(2), b2 = 1001(2) ならば bit = 3021(4) を表す
	// 0: A に使う 1: B に使う 2: C に使う 3: 使わない

	int mn = INT_MAX;

	rep(b1, (1<<n)){
		rep(b2, (1<<n)){
			vi Leng(3,0);
			int cnt = 0;
			rep(i,n){
				int bit = 0;
				if(b1&(1<<i)) bit += 2;
				if(b2&(1<<i)) bit ++;
				rep(j,3) {
					if(bit==j){
						if(Leng[j] != 0) cnt++;
						Leng[j] += l[i];
					}
				}
			}
			int temp = cnt*10 + abs(a-Leng[0]) + abs(b-Leng[1]) + abs(c-Leng[2]);
			/* if(b1 == 16 && b2 == 14) {
				cout << "test: " << temp << endl;
				cout << Leng[0] << " " << Leng[1] << " " << Leng[2] << endl;
				cout << cnt << endl;
				// ABBBC: bit = 01112(4) = 86; b1 = 00001(2) = 1, b2 = 01110(2) = 14
				// CBBBA: bit = 21110(4) = 596; b1 = 10000(2) = 16, b2 = 01110(2) = 14
			}
			*/
			if(Leng[0]==0 || Leng[1]==0 || Leng[2]==0) continue;
			mn = min(mn, temp);
		}
	} 
	cout << mn << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

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

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S1: String,
        S2: String,
        S3: String,
    }
    println!("{}{}{}", S1[0..1].to_uppercase(), S2[0..1].to_uppercase(), S3[0..1].to_uppercase());
}

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

using namespace std;

bool string_tail_check(string& s, const string& key) {
    unsigned int ls = s.length(), lk = key.length();
    if (ls<lk) return false;
    if(s.substr(ls-lk,lk) == key) {
        s = s.substr(0, ls-lk);
        return true;
    }
    return false;
}

int main(int argc, char const *argv[])
{
    string s, s2;
    cin >> s;

    for(bool flg=true;flg;) {
        flg=false;
        if(s.length()==0) {
            cout << "YES" << endl;
            return 0;
        } else {
            if ((flg = string_tail_check(s, "dream"))) continue;
            if ((flg = string_tail_check(s, "dreamer"))) continue;
            if ((flg = string_tail_check(s, "erase"))) continue;
            if ((flg = string_tail_check(s, "eraser"))) continue;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  cin>>s;
  while(s.size()>3){
    bool h=false;
    loop(i,3,s.size()){
      if((s[i-3]=='m'||s[i-3]=='e')&&s.substr(i-2,3)=="mew"){
	h=true;
	s=s.substr(0,i-2)+s.substr(i+1,s.size()-i-1);
	break;
      }
    }
    if(!h)break;
  }
  string ans="Rabbit";
  if(s=="mew")ans="Cat";
  cout<<ans<<endl;
}

Measured memory_bytes: 1196
#A - Kyu in AtCoder
X =int(input())

if X <= 1999 and X>=1800:
    print(1)
elif X <= 1799 and X>=1600:
    print(2)
elif X <= 1599 and X>=1400:
    print(3)
elif X <= 1399 and X>=1200:
    print(4)
elif X <= 1199 and X>=1000:
    print(5)
elif X <= 999 and X>=800:
    print(6)
elif X <= 799 and X>=600:
    print(7)
elif X <= 599 and X>=400:
    print(8)

Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <type_traits>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	uint64 q, h, s, d, n;
	std::cin >> q >> h >> s >> d >> n;
	h = std::min(q * 2, h);
	s = std::min(h * 2, s);
	d = std::min(s * 2, d);
	std::cout << (n & 1 ? (n / 2)*d + s : n / 2 * d) << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
ll jow(ll n, ll x){
  ll res = 1;
  while(n){
    if(n & 1) res = res*x % mo;
    x = x*x%mo;
    n >>= 1LL;
  }
  return res;
}
int main(){
  int N;  cin>>N;
  bool isok=true;
  vector<int> v(N,0);
  rep(i,0,N){
    int x;  cin>>x;
    if(i==0) if(x!=0) isok=false;
    v[x]++;
  }
  if(v[0] != 1 || !isok){
    cout<<0<<endl;
    return 0;
  }

  bool ok=true;
  rep(i,1,N){
    if(v[i-1]==0 && v[i]>0) ok=false;
  }
  if(!ok){
    cout<<0<<endl;
    return 0;
  }
  ll ans = 1;
  for(int i=1; i<N ; i++){
    if(v[i]==0) break;
    ans *= jow(v[i], v[i-1]);
    ans %= mo;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    int n ; 
    cin>>n ;
    int a[n] , b[n] , c[n] ;
    rep(i , n)cin>>a[i]>>b[i]>>c[i] ;
    int dp[n][3] ;
    dp[0][0] = a[0] ;
    dp[0][1] =b[0] ;
    dp[0][2] =c[0] ;
    repu(i  ,1 ,n-1){
    	dp[i][0] = a[i] + max(dp[i-1][1] , dp[i-1][2]) ;
    	dp[i][1]= b[i] + max(dp[i-1][0]  , dp[i-1][2]) ;
    	dp[i][2] = c[i] + max(dp[i-1][0] , dp[i-1][1]) ;
    }
    cout<<max(dp[n-1][0] , max(dp[n-1][1] , dp[n-1][2]))<<endl;
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 6124
#include <stdio.h>
 
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && ch[0] == '-' ) break;

     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
   
   
  return 0;
   
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define SpeeD ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define ll long long
#define endl '\n'
//pair<int, int> *p=new pair<int, int>[n];
//std::vector<pair<int,int>> vp;
//v.push_back(make_pair(x,y))
//pair<int, int> p[1000001];
//string *s=new string [n];
//int freq[e];
//freq[a[i]-'a']++; freq[a[i]]++;
 using namespace std;  
ll n,t,m,c,x,y,sum,mn,avg,pos,dif,j,dis,mx,xi,yi;
bool k=false;
bool vis[505][505];
char grid[505][505];
bool PE(int x)
{
for (int i=2;i*i<=x;i++)
if (x%i==0)
return false;
return true;
}
bool PR(string s)
{
int n=s.length();
for(int i=0;i<n/2;i++)
if(s[i]!=s[n-i-1])
return false;
return true;    
}
int main(void) 
{ 
ll n;
cin>>n;
    c=n/500;
    n-=c*500;
    c*=1000;
    



    x=n/5;
    x*=5;

cout<<x+c;
}


Measured memory_bytes: 256
#include<stdio.h>

int bubbleSort(int n, int *a)
{
	int count = 0;
	int flag = 1;
	int i, j, temp;
	for(j=0;flag;j++) {
		flag = 0;
		for(i=n-1;i>j;i--) {
			if(a[i] < a[i-1]) {
				temp = a[i];
				a[i] = a[i-1];
				a[i-1] = temp;
				flag = 1;
				count++;
			}
		}
	}
	return count;
}

void print_array(int n, int *a)
{
	int i;
	for(i=0;i<n;i++) {
		if(i > 0) printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
}

int main(void)
{
	int n, a[100], i, count;
	scanf("%d", &n);
	for(i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
    count = bubbleSort(n, a);
    print_array(n, a);
    printf("%d\n", count);
    return 0;
}
	


Measured memory_bytes: 2104
use std::io::prelude::*;

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let _n = input::<usize>();
    let s = input::<String>().chars().collect::<Vec<char>>();
    let mut head = 0;
    let mut d = 0;
    for &c in &s {
        if c == '(' {
            d += 1;
        } else  { // c == ')'
            // '(' が足りない
            if d == 0 {
                head += 1;
            } else {
                d -= 1;
            }
        }
    }
    let mut res = String::new();
    for _ in 0..head {
        res.push('(');
    }
    for c in s {
        res.push(c);
    }
    for _ in 0..d {
        res.push(')');
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
typedef unsigned long long ULL;

int main() {
	int n;
	int x;
	std::vector<int>a;
	int ans = 0;
	std::cin >> n >> x;

	for (int i = 0; i < n; ++i) {
		int b;
		std::cin >> b;
		a.push_back(b);
	}

	std::sort(a.begin(),a.end());

	for (int i = 0; i < n; ++i) {
		if (x - a[i] >= 0) {
			x -= a[i];
			ans += 1;
			if (i == n - 1) {
				if (x != 0) {
					ans -= 1;
				}
			}
		}
		else {
			break;
		}
	}

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

}

Measured memory_bytes: 256
from sys import stdin
INF = int(1e9+7)


def modadd(a, b):
    # aとbを足した値をmodする(a + b mod p)
    return (a + b) % INF


def main():
    lines = stdin.readlines()
    N = int(lines[0].split()[0])
    a = [True] * (N + 1)
    for i in map(int, lines[1:]):
        a[i] = False
    dp = [0] * (N + 1)
    dp[:2] = 1, 1 if a[1] else 0
    for i in range(2, N + 1):
        if a[i]:
            dp[i] = modadd(dp[i - 1], dp[i - 2])
    print(dp[N])
    return


main()


Measured memory_bytes: 11028
X,K,D=list(map(int,input().split()))
if X<0:
    X=-X
if X-K*D>=0:
    print(X-K*D)
else:
    N=X//D
    if (K-N)%2==0:
        print(X-N*D)
    else:
        print((N+1)*D-X)

Measured memory_bytes: 9184
x, k, d = map(int, input().split())

abs_x = abs(x)
ans = 0
left = 0

if x == 0:
    if k % 2 == 0:
        ans = 0
    else:
        ans = d

else:
    if abs_x // d > k:
        ans = abs_x - d * k
    elif x // d == k:
        ans = 0
    else:
        left = k - abs_x // d
        if left % 2 == 0:
            ans = abs_x % d
        else:
            ans = abs(abs_x % d - d)

print(ans)



Measured memory_bytes: 9180
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(ll x, ll y)
{
	return (x|y)&(~x|~y);	
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
	ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
	string str,str1;
	cin>>str;
	n = str.length();
	string aa = str.substr(0,(n-1)/2);
	a = (n+3)/2;
	a-=1;
	string bb = str.substr(a, n-a);
	// cout<<aa<<endl<<bb<<endl;
	bool res = true;
	rep(i,0,(aa.length())/2)
	{
		if(aa[i]!=aa[aa.length()-1-i])
			res&=false;
	}
	rep(i,0,bb.length()/2)
	{
		if(bb[i]!=bb[bb.length()-1-i])
			res&=false;
	}
	rep(i,0,str.length())
	{
		if(str[i]!=str[str.length()-1-i])
			res&=false;
	}
	if(res)
		cout<<"Yes";
	else
		cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	long long p=1000000007;
	long long n,m;
	scanf("%lld%lld",&n,&m);
	long long x[n];
	long long y[m];
	for(int i=0;i<n;i++){
		scanf("%lld",&x[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%lld",&y[i]);
	}
	long long s=0;
	long long e,f;
	for(int i=0;i<n-1;i++){
		e=(i+1)*(n-i-1)%p;
		s+=e*(x[i+1]-x[i])%p;
		if(s>p)s-=p;
	}
	s=(s+p)%p;
	long long ans=0;
	for(int i=0;i<m-1;i++){
		e=(i+1)*(m-i-1)%p;
		f=e*(y[i+1]-y[i])%p;
		ans+=f*s%p;
		if(ans>p)ans-=p;
	}
	printf("%lld\n",(ans+p)%p);
}

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  string S,T;
  cin >> S >> T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S[i]!=T[i]){
      count++;
    }
  }
  cout << count;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define INF 1000000009
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define so sizeof 
#define pii pair<ll,ll>
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a, b, c) max(c, max(a, b))
#define max4(a, b, c, d) max(d, max(c, max(a, b)))
#define repe(i,a) for(auto i:a)
#define st string
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define rrep(i,a,b) for(ll i=b;i>=a;i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); 
void solve(){
   ll n;
   cin>>n;
   ll cnt=0;
   rep(i,1,n-1){
       cnt+=(n-1)/i;   
  }
   //}
  cout<<cnt<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
#endif
    fast
    // ll t;
    // cin>>t;
    // while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>

using namespace std;

bool is_prime(int n) {
	if (n == 1 ) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	int p = 3;
	while (p * p <= n) {
		if (n%p == 0) return false;
		p += 2;
	}
	return true;
}

int main() {
	int N;
	cin >> N;
	int val, ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> val;
		if (is_prime(val)) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3096
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix
n, m, l = map(int, input().split())
F = np.zeros((n, n))
for _ in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  F[a, b] = c
  F[b, a] = c
csr = csr_matrix(F)
A = floyd_warshall(csr)
G = np.zeros((n, n))
for i in range(n-1):
  for j in range(i+1, n):
    if A[i][j] <= l:
      G[i, j] = 1
      G[j, i] = 1
ncsr = csr_matrix(G)
B =  floyd_warshall(ncsr)
q = int(input())
for _ in range(q):
  s, t = map(int, input().split())
  k = B[s-1][t-1]
  if k == float("inf"):
    print(-1)
  else:
    print(int(k)-1)

Measured memory_bytes: 19868
class UnionFind():
    def __init__(self, n: int):
        """
        n: ノード数
        """
        self.n = n
        """
        d: UnionFind木のデータ構造
            各要素の根要素を格納するリスト
            根要素の場合は, グループの要素数*-1を格納する
        """
        self.d = [-1] * n

    def find(self, x: int) -> int:
        """
        要素xが属するグループの根を返す
        """
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]

    def unite(self, x: int, y: int) -> bool:
        """
        要素xが属するグループと, 要素yが属するグループを併合する
        """
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False

        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True

    def same(self, x: int, y: int) -> bool:
        """
        要素x, yが同じグループに属するかどうかを返す
        """
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        """
        要素xが属するグループのサイズ(要素数)を返す
        """
        return -self.d[self.find(x)]

    def members(self, x: int) -> list:
        """
        要素xが属するグループの要素をリストで返す
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def groups(self) -> list:
        """
        すべての根の要素をリストで返す
        """
        return [i for i, x in enumerate(self.d) if x < 0]

    def group_count(self) -> int:
        """
        グループの数を返す
        """
        return len(self.groups())


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

    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(int, input().split())
        uf.unite(A-1, B-1)

    ans = 0
    for i in uf.groups():
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 18536
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
   ll N;
   cin>>N;
   ll n,h,w;
  for(int i=1;i<=3500;i++){
      for(int j=1;j<=3500;j++){
          if(4*i*j-N*(i+j)==0) continue;

          if((N*i*j)%(4*i*j-N*(i+j))==0){
              w=(N*i*j)/(4*i*j-N*(i+j));
              if(w<0) continue;
              cout<<i<<" "<<j<<" "<<w<<endl;
              return 0;
          }
      }
  }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb emplace_back
typedef pair<int,int> pi;

int n, m, dist[100005], par[100005];
vector<int> g[100005];
bool ok = true;

void bfs() {
	queue<int> q;
	memset(dist, -1, sizeof dist);
	dist[1] = 0;
	q.emplace(1);
	while (q.size()) {
		int x = q.front();
		q.pop();
		for (auto i: g[x]) {
			if (dist[i] != -1) continue;
			dist[i] = dist[x] + 1;
			par[i] = x;
			q.emplace(i);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	bfs();
	for (int i = 2; i <= n; ++i) {
		if (dist[i] == -1) {
			ok = false;
			break;
		}
	}
	if (!ok) {
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	for (int i = 2; i <= n; ++i) cout << par[i] << '\n';
	return 0;
}


Measured memory_bytes: 10788
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
#define pa pair<int,int>
#define pb push_back
#define be begin()
#define en end()
#define ret return puts("1"),0;
#define N 500055
#define int ll
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,a[N],l[N],dp[N],sum[N];
char str[N];
inline void add(int &x,int k){
	x+=k;x-=(x>=mod)?mod:0;
}
signed main(){
	scanf("%s",str+1);n=strlen(str+1);
	F(i,1,n) a[i]=(str[i]=='a')?1:2;
	int pd=0;
	F(i,1,n-1) pd|=(a[i]==a[i+1]);
	if (!pd) ret;
	l[1]=l[2]=-1;dp[0]=1;
	F(i,1,n){
		sum[i]=sum[i-1]+a[i];
		if (sum[i]%3==0&&i<n) dp[i]=1;
		F(j,1,2){
			if (l[(sum[i]+3-j)%3]!=-1) add(dp[i],dp[l[(sum[i]+3-j)%3]]);
		}
		l[sum[i]%3]=i;
	}
	wrn(dp[n]);
	return 0;
}

Measured memory_bytes: 9344
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, n, buf, weight[10] = {1,2,4,8,16,32,64,128,256,512}, binary[10]={0};
	while(scanf("%d", &n) != EOF){
		for(i=0; i<10; i++){
			binary[i] = n % 2;
			n = n / 2;
		}
		for(i=0; i<10; i++){
			if(binary[i] != 0)
				buf = i;
		}
		for(i=0; i<10; i++){
			if(binary[i] != 0){
				if(i == buf)
					printf("%d", weight[i]);
				else
					printf("%d ", weight[i]);
			}
		}
		printf("\n");
	}
	return 0;
}
			

Measured memory_bytes: 600
n, k = map(int, input().split())
MOD = 10 ** 9 + 7
ans = 0

for i in range(k, n + 2):
    mini = i * (i - 1) / 2
    maxx = i * (2 * n - i + 1) / 2

    ans += maxx - mini + 1
    ans %= MOD

print(int(ans))


Measured memory_bytes: 67688
#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()
using ll = long long;
const int inf = int(1e9);
//const ll inf = ll(1e19);
const int mod = int(1e9) + 7;

int main(){
    ll n, a[int(1e5)];cin >> n;
    rep(i, n) cin >> a[i];

    ll x1 = 0;
    rep(i, n){
        if(i%2 == 0) x1 += a[i];
        else x1 -= a[i];
    }
    
    cout << x1 << ' ';
    ll pre = x1;
    rep(i, n - 1){
        pre = 2*(a[i] - pre/2);
        cout << pre << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 4372
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define umap unordered_map
#define uset unordered_set
#define pq priority_queue

const ll MOD = 1e9 + 7;

ll pow_mod(ll base, ll exp, ll q) {
	base %= q;
	ll ans = 1;
	while (exp) {
		if (exp & 1) ans = (ans * base) % q;	
		base = (base * base) % q;
		exp /= 2;
	}
	return ans;
}

void madd(ll& a, ll b){
	a += b;
	if (a >= MOD) a -= MOD;
}

void msub(ll& a, ll b){
	a -= b;
	if (a < 0) a += MOD;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	ll x = pow_mod(10, n, MOD);
	msub(x, (2*pow_mod(9, n, MOD))%MOD);
	madd(x, pow_mod(8, n, MOD));
	cout << x % MOD;
}

Measured memory_bytes: 3604
from collections import deque

n = int(input())
a = [int(s) for s in input().split()]

b = deque([])

for i in range(n):
    if i % 2 == (n - 1) % 2:
        b.appendleft(str(a[i]))
    else:
        b.append(str(a[i]))

print(' '.join(list(b)))


Measured memory_bytes: 32964