akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL << 25) // 33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void) {
  while (true) {
    int n;
    cin >> n;
    if (n == 1)
      break;

    VI ans;
    for (int i = 6; i <= n; ++i) {
      if (i % 7 != 1 && i % 7 != 6)
        continue;
      if (n % i)
        continue;
      bool flag = true;
      for (int j = 6; j < i; ++j) {
        if (j % 7 != 1 && j % 7 != 6)
          continue;
        if (i % j == 0)
          flag = false;
      }
      if (flag)
        ans.push_back(i);
    }

    cout << n << ":";
    for (int i : ans) cout << " " << i;
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,d;
	scanf("%d%d%d",&n,&m,&d);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			int x=(m+i+j)/d%2;
			int y=(m+i-j)/d%2;
			char c="RGBY"[2*x+y];
			printf("%c",c);
		}
		printf("\n");
	}	
	return 0;
}

Measured memory_bytes: 512
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int H, W;
    cin >> H >> W;

    int A, B;
    cin >> A >> B;

    const long long MOD = 1e9 + 7;

    int N = H + W + 10;
    vector<long long> invs(N + 1, 1);
    for (int i = 2; i <= N; ++i) {
        invs[i] = (MOD - MOD / i) * 1LL * invs[MOD % i] % MOD;

    }
    vector<long long> FS(N + 1, 1);
    vector<long long> IFS(N + 1, 1);
    for (int i = 1; i <= N; ++i) {
        FS[i] = FS[i - 1] * i % MOD;
    }
    for (int i = 1; i <= N; ++i) {
        IFS[i] = IFS[i - 1] * invs[i] % MOD;
        assert(IFS[i] * FS[i] % MOD == 1);
    }

    auto nCr = [&](int n, int r) {
        if (r > n || r < 0) {
            return 0LL;
        }
        return FS[n] * IFS[r] % MOD * IFS[n - r] % MOD;
    };

    int M = H - A - 1 + B;

    long long res = 0;

    for (int i = B; i <= W - 1 && i <= M; ++i) {
        long long cnt = nCr(M, i) * nCr(H - 1 + W - 1 - M, W - 1 - i) % MOD;
        // cout << M << " " << i << " " << cnt << endl;
        (res += cnt) %= MOD;
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 7892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
const int inf = 1000000000; //10~9


int main()
{
	int N;
	cin >> N;
	vector<int> X(N);
	rep(i, N)cin >> X.at(i);
	int ans = inf;
	for (int i = 1; i <= 100; i++)
	{
		int cost = 0;
		rep(j, N) cost += (X.at(j) - i) * (X.at(j) - i);
		ans = min(ans, cost);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

N, K = map(int,input().split())
A = list(map(int,input().split()))


for i in range(K):
    nxtA = [0]*N
    imos_l = [0]*N
    imos_r = [0]*N

    for j in range(N):
        if A[j]>0:
            if j+1<N:
                imos_l[j+1] += 1
            if j+1+A[j]<N:

                imos_l[j+1+A[j]] -= 1
    for j in reversed(range(N)):
        if A[j]>0:
            if j-1>=0:
                imos_r[j-1] += 1
            if j-1-A[j]>=0:
                imos_r[j-1-A[j]] -= 1
    cur = 1
    for j in range(N):
        cur += imos_l[j]
        nxtA[j] += cur
    cur = 0
    for j in reversed(range(N)):
        cur += imos_r[j]
        nxtA[j] += cur
    # print(imos_l, imos_r)
    if sum(nxtA)==N*N:
        print(*nxtA)
        exit()
    if i<N-1:
        for j in range(N):
            A[j] = nxtA[j]

print(*nxtA)

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

public class Main{
	static boolean[] prime = new boolean[1000001];

	public static void main(String[] args) {
		Arrays.fill(prime, true);
		furui();
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int d = sc.nextInt();
			int n = sc.nextInt();
			if(a==0&&d==0&&n==0) break;
			int count=0, i=0;
			while(count<n){
				if(prime[a+i*d]) count++;
				i++;
			}
			System.out.println(a+(i-1)*d);
		}
	}

	static void furui(){
		prime[1] = false;
		for(int i=2; i<prime.length; i++){
			if(prime[i]){
				int multiple = i + i;
				while(multiple<prime.length){
					prime[multiple] = false;
					multiple += i;
				}
			}
		}
	}
}

Measured memory_bytes: 29944
import itertools
 
 
def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    CC = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(N)]
 
    cost = [[0 for _ in range(C)] for _ in range(3)]
    for c in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i + j) % 3][c] += D[CC[i][j]][c]
 
    res = float("inf")
    color = [i for i in range(C)]
    for i, c in enumerate(list(itertools.permutations(color, 3))):
        tmp = 0
        for it in range(3):
            tmp += cost[it][c[it]]
        res = min(res, tmp)
 
    print(res)
 
main()

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;


void mxin(ll& a,ll b){
    if(a<b)
        a = b;
}


/////////////////////////////////////////////////////
#define INF (ll)1e18

char S[202020];
ll S2[202020], Sn;
ll dp[202020][4];
ll mk[3][3] = {{0, 2}, {0, 1}};
ll i, j, k;
vector<ll> anss;

int main(){
    scanf("%s", S);
    for (Sn=0; S[Sn]; Sn++)
        ;
    //printf("%lld\n", Sn);
    fornum(i, 0, Sn)
    {
        if (S[i] == 'D')
        {
            S2[i] = 1;
        }
        else if (S[i] == '?')
        {
            S2[i] = 2;
        }
    }
    dp[0][0] = INF;
    fornum(i, 0, Sn)
    {
        if (S2[i] != 1)
        {
            mxin(dp[i + 1][0], dp[i][0]);
            mxin(dp[i + 1][0], dp[i][1]);
        }
        if (S2[i] != 0)
        {
            mxin(dp[i + 1][1], dp[i][0] + 2);
            mxin(dp[i + 1][1], dp[i][1] + 1);
        }
        //assert(false);
    }
    
    ll a=0, b=0,c=0;
    if(dp[Sn][0]>dp[Sn][1]){
        a = Sn;
        b = 0;
        c = dp[Sn][0];
    }else{
        a = Sn;
        b = 1;
        c = dp[Sn][1];
    }
    //printf("%lld\n", c);
    while(a>0){
        anss.push_back(b);
        --a;
        if(dp[a][0]+mk[0][b]==c){
            b = 0;
            c = dp[a][0];
        }else
        {
            b = 1;
            c = dp[a][1];
        }
        assert(b == 1 || b == 0);
    }
    i = Sn - 1;
    while(i>=0){
        if(anss[i]==0){
            printf("P");
        }
        else{
            printf("D");
        }
        --i;
    }
    return 0;
}

Measured memory_bytes: 13300
/*input
5 5
1 2
3 5
5 1
3 4
2 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> 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 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) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//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;
}

int cnt[maxn];

int main()
{
	//IOS;
	int n,m;
	cin>>n>>m;
	REP(i,m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		cnt[u]++;cnt[v]++;
	}
	REP(i,n) if(cnt[i]%2){
		cout<<"NO\n";
		return 0;
	}
	cout<<"YES\n";
	return 0;
}


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

// For given x, return maximum 2^n such that 2^n <= x
// This can be used for calculating the width of a segment(it's size/f(i))
// FIXME: dynamic segtree may use as large segments as int can't represent
// FIXME: what if the compiler is not gcc?
int HighestPow2(int x) {
  if (!x) return 0;
  return 1 << (31-__builtin_clz(x));
}

// T must support a constructor with no argument(works as the identity element)
// T must support `T operator *(T y)` which is associative
template<class T>
struct MonoidSegTree {
  int n;
  int size;
  vector<T> seg;

  MonoidSegTree(const vector<T> A) {
    n = A.size();

    size = 1;
    while (size < n) size *= 2;
    
    seg.resize(size);
    seg.insert(seg.end(), A.begin(), A.end());
    seg.resize(size*2);
    for (int i=size-1; i>0; --i) seg[i] = seg[i*2] * seg[i*2+1];
  }

  void Update(int k, const T v) {
    k += size;
    seg[k] = v;
    while (k > 1) {
      k /= 2;
      seg[k] = seg[k*2] * seg[k*2+1];
    }
  }

  T Get(int l, int r) {
    T retl = T(); // the identity element
    T retr = T();

    l += size;
    r += size;
    for (; l < r; l>>=1, r>>=1) {
      if (r & 1) retr = retr * seg[--r];
      if (l & 1) retl = seg[l++] * retl;
    }
    return retl * retr;
  }
};

#define INF 0x7fffffff
struct Monoid {
  int v;
  Monoid() {v = INF;}
  Monoid(const Monoid &a) : v(a.v) {}
  Monoid(int a) : v(a) {}
  Monoid operator*(Monoid y) {
    return Monoid(min(v, y.v));
  }
};

using SegTree = MonoidSegTree<Monoid>;

int n;
int q;

int main() {
  scanf("%d%d", &n, &q);
  SegTree seg = SegTree(vector<Monoid>(n));
  while (q--) {
    int cmd;
    int x, y;
    scanf("%d", &cmd);
    scanf("%d%d", &x, &y);
    if (cmd == 0) {
      seg.Update(x, y);
    } else {
      printf("%d\n", seg.Get(x, y+1).v);
    }
  }
}
  

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

const int mod = 1000000007;
int N;
int dp[1000002], psum[1000002];

int main() {
    scanf("%d", &N);

    dp[1] = N;
    psum[1] = dp[1];
    for(int i = 2; i <= N; i++) {
        if(i != 2) {
            dp[i] += psum[i - 1] + mod - dp[i - 2];
            dp[i] %= mod;
            dp[i] += 1LL * (N - 1) * (i - 3) % mod;
            dp[i] %= mod;

        }
        dp[i] += 1LL * (N - i + 2) * N % mod;
        dp[i] %= mod;
        psum[i] = (dp[i] + psum[i - 1]) % mod;
    }
    printf("%d", dp[N]);
}


Measured memory_bytes: 8064
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
using namespace std;

int main(void){
	string s[3];
	int n[3]{}, mode = 0, tmp;

	cin >> s[0] >> s[1] >> s[2];

	while (true){
		if (n[mode] == s[mode].size()){
			cout << (char)(mode + 'A') << endl;
			break;
		}
		mode = (int)(s[mode][n[mode]++] - 'a');
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
#include <set>
#include <functional>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e4 + 7;

bool table[11000];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n,x,t;cin>>n>>x;
    table[0] = true;
    int loc = 0;
    REP(i,n){
        cin >> t;
        loc += t;
        table[loc] = true;
    }
    int cnt = 0;
    REP(i,x+1){
        if(table[i]) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}

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

int calc_ten(int);

std::vector<int> d;
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	d.resize(k);
	for (int i = 0; i < k; i++)
		scanf("%d", &d[i]);
	while (true)
	{
		int ten{calc_ten(n)};
		if (ten < 0) break;
		n = n / ten * ten + ten;
	}
	printf("%d\n", n);

	return 0;
}

int calc_ten(int n)
{
	int ten{1};
	while (n)
	{
		for (auto& e: d)
			if (e == n % 10)
				return ten;
		n /= 10;
		ten *= 10;
	}
	return -1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[100];
int main(){
    cin>>s; int a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';


    if(a+b+c+d==7){
        printf("%d+%d+%d+%d=7\n",a,b,c,d);
    }
    else if(a+b+c-d==7){
        printf("%d+%d+%d-%d=7\n",a,b,c,d);
    }
    else if(a+b-c+d==7){
        printf("%d+%d-%d+%d=7\n",a,b,c,d);
    }


    else if(a+b-c-d==7){
        printf("%d+%d-%d-%d=7\n",a,b,c,d);
    }

    else if(a-b+c+d==7){
        printf("%d-%d+%d+%d=7\n",a,b,c,d);
    }
    else if(a-b-c+d==7){
        printf("%d-%d-%d+%d=7\n",a,b,c,d);
    }
    else if(a-b-c-d==7){
        printf("%d-%d-%d-%d=7\n",a,b,c,d);
    }

    else if(a-b+c-d==7){
        printf("%d-%d+%d-%d=7\n",a,b,c,d);
    }

}




Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int x,y;
int t;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0 && y==0)break;
        if(x>y){
        t=x;x=y;y=t;
        }
        printf("%d %d\n",x,y);
    }
return 0;
}



Measured memory_bytes: 2100
#include <iostream>
#include <stdio.h>
using namespace std;

int main(){

	long a, b, d, r;
	double f;
	cin>>a>>b;

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;
	
	printf("%d %d %.5lf\n", d, r, f);
	return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define inf (long long)1e18
using namespace std;
int n, k, a[101];
bool dp[100001];
int main(){
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++) 
        scanf("%d", &a[i]);
    for (int i = 0; i < k; i++)
        if (!dp[i]){ //losing position 
            for (int j = 0; j < n; j++)
            if (i + a[j] <= k)
                dp[i + a[j]] = true; //winning 
            //removing a[j] stones will result in losing position (of opponent)
            //so you win (first player)
        }
    printf(dp[k] ? "First\n" : "Second\n");
    return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

int main(){
    vector<ll> vec[26];
    string s,t;
    cin >> s >> t;
    rep(i,0,s.size()){
        vec[s[i] - 'a'].push_back(i);
    }

    ll cnt = 0,index = -1;
    rep(i,0,t.size()){
        ll temp = t[i] - 'a';
        if(vec[temp].size() == 0){
            cout << -1 << endl;
            return 0;
        }
        else{
            ll ng = -1, ok = vec[temp].size();
            while(abs(ok-ng) > 1){
                ll mid = (ok+ng)/2;
                if(vec[temp][mid] > index){
                    ok = mid;
                }
                else{
                    ng = mid;
                }
            } 

            if(ok == vec[temp].size()){
                cnt++;
                index = vec[temp][0];
            }
            else{
                index = vec[temp][ok];
            }
        }
        //cout << cnt << " " << index << endl;
    }
    cout << cnt*s.size() + index + 1 << endl;
}




Measured memory_bytes: 4644
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MAX 505
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int k,n;
int main()
{
	k=read();
	if(k==1) return printf("1\n1"),0;
	n=(k+1)/2;if(n&1) n++;
	printf("%d\n",n);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			int now=(i+j)%n+1;
			if((i&1)&&now+n<=k) now+=n;
			printf("%d ",now);
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 3764
using System;
using System.IO;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();

        Console.WriteLine(nk[0] % nk[1] == 0 ? 0 : 1);
    }
}

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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N); // 頂点の数
    const int M = N - 1; // 辺の数
    vector<unordered_map<int, ll>> edges(N); // 各頂点から出る辺
    REP(i, M){ // 辺の数はM
        scanInt(ai); --ai;
        scanInt(bi); --bi;
        // scanInt(ci); // 辺の長さ
        edges[ai].emplace(bi, 1);
        edges[bi].emplace(ai, 1);
    }
    scanVecInt(C, N);
    sort(C.begin(), C.end());
    const int Csum = accumulate(C.begin(), C.end(), 0) - C.back();

    /* 木構造を作る */
    struct Node {
        int parent = -1; // 親ノードのi
        ll distance = -1; // 根からの距離
        vector<int> children; // 子ノード（複数）のi
    };
    vector<Node> nodes(N); // 各ノード（木構造）
    function<void(int, ll)> makeTree = [&](int n, ll dist){ // 頂点n以下の木構造を作る
        nodes[n].distance = dist;
        for (auto& e : edges[n]){
            auto& next = e.first;
            if (next == nodes[n].parent) continue; // 親に戻らない
            // if (nodes[next].distance != -1 || 0 < nodes[next].children.size()) continue; // 余分な辺がある場合は、既に訪れた頂点を弾く処理をする
            nodes[n].children.emplace_back(next);
            nodes[next].parent = n;
            makeTree(next, dist + e.second);
        }
    };
    const int R = 0; // 根はR
    nodes[R].parent = -1; // 根の親は適当に入れておく
    makeTree(R, 0); // 根（距離0）から始める
    using mytype = pair<int, ll>;
    vector<mytype> V; V.reserve(N);
    REP(i, N) V.emplace_back(i, nodes[i].distance);
    sort(V.begin(), V.end(), [](mytype& l, mytype& r){return l.second > r.second;});
    vector<int> result(N);
    REP(i, N){
        result[V[i].first] = C[i];
    }
    cout << Csum << endl;
    REP(i, N){
        cout << result[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
 
using namespace std;
using ll = long long;
 
void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
 
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

int main(void){
    Cin(int, t);
    vector<int> a { t/1000, t/100%10, t/10%10, t%10 };
    if(a[0] + a[1] + a[2] + a[3] == 7){
        Cout(a[0], "+", a[1], "+", a[2], "+", a[3], "=7");
    }
    else if(a[0] + a[1] + a[2] - a[3] == 7){
        Cout(a[0], "+", a[1], "+", a[2], "-", a[3], "=7");
    }
    else if(a[0] + a[1] - a[2] + a[3] == 7){
        Cout(a[0], "+", a[1], "-", a[2], "+", a[3], "=7");
    }
    else if(a[0] + a[1] - a[2] - a[3] == 7){
        Cout(a[0], "+", a[1], "-", a[2], "-", a[3], "=7");
    }
    else if(a[0] - a[1] + a[2] + a[3] == 7){
        Cout(a[0], "-", a[1], "+", a[2], "+", a[3], "=7");
    }
    else if(a[0] - a[1] + a[2] - a[3] == 7){
        Cout(a[0], "-", a[1], "+", a[2], "-", a[3], "=7");
    }
    else if(a[0] - a[1] - a[2] + a[3] == 7){
        Cout(a[0], "-", a[1], "-", a[2], "+", a[3], "=7");
    }
    else{
        Cout(a[0], "-", a[1], "-", a[2], "-", a[3], "=7");
    }
}


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

int main()
{
  std::string a, b;
  std::cin >> a;
  std::cin >> b;
  int l = a.length();
  if (a == b.substr(0, l)) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define MOD2 998244353
#define sp fixed<<setprecision
#define sz(x) (int)(x).size()
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
ll fpow(ll x,ll y,ll p=MOD){x=x%p;ll sum=1;while(y){if(y&1)sum=sum*x;sum%=p;y=y>>1;x=x*x;x%=p;}return sum;}
ll inv(ll a,ll m=MOD){ll c=m;ll y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=c;return x;}
ll add(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD + b%MOD + MOD)%MOD;}
ll sub(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return (a%MOD - b%MOD + MOD)%MOD;}
ll mul(ll a, ll b) {if(a<0)a+=MOD; if(b<0)b+=MOD; return ((a%MOD)*(b%MOD) + MOD)%MOD;}
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (sz(name)) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
int main(){
    setIO();
    ll n,k;
    cin>>n>>k;
    ll dp[n+1],sum[n+1];
    memset(dp,0,sizeof(dp));
    memset(sum,0,sizeof(sum));
    vector<pair<ll,ll> >v(k);
    for(int i=0;i<k;i++)
      cin>>v[i].f>>v[i].se;
    dp[1]=1;
    sum[1]=1;
    for(int i=2;i<=n;i++){
      for(int j=0;j<k;j++){
        ll left = i-v[j].se;
        ll right = i-v[j].f;
        if(right<=0)
          continue;
        left=max(left,1LL);
        //cout<<i<<" "<<left<<" "<<right<<"\n";
        dp[i]+=sum[right];
        dp[i]%=MOD2;
        dp[i]-=sum[left-1];
        if(dp[i]<0)
          dp[i]+=MOD2;
      }
      //cout<<dp[i]<<"\n";
      sum[i]=(sum[i-1]+dp[i])%MOD2;
    }
    cout<<dp[n];
}


Measured memory_bytes: 6764
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

abc = "abcdefghijklmnopqrstuvwxyz"
num = [i for i in range(26)]
dic = {"null":-1}
for i in range(26):
    dic[abc[i]] = num[i]+1

l = []
tmp = "null"
if len(s) == 26:
    for i in range(25,-1,-1):
        if dic[tmp] < dic[s[i]]:
            tmp = s[i]
            l.append(s[i])
        else:
            for j in l:
                if dic[j] < dic[s[i]]:
                    continue
                else:
                    print(s[:i]+j)
                    exit()
                    break
    else:
        print(-1)
else:
    for i in range(26):
        if abc[i] in s:
            continue
        else:
            print(s+abc[i])
            break

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

r = [0]*N
for i in range(1, N+1):
    for j in range(i+1, N+1):
        d = min(j-i, abs(j-X)+abs(i-Y)+1)
        d = min(d, abs(i-X)+abs(j-Y)+1)
        r[d] += 1
for x in r[1:]:
    print(x)


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

using namespace std;
int main(){
    int N;
    cin>>N;
    int h[20];
    int ans=1;
    for(int i=0;i<N;i++){
        int k;
        cin>>k;
        h[i]=k;
    }
    int m=h[0];
    for(int i=1;i<N;i++){
        m=max(m,h[i-1]);
        if(m<=h[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
#define mp make_pair
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

int main(){
   FASTIO
   int n, k;
   cin >> n >> k;
   int h[n];
   rep(i, 0, n)
   cin >> h[i];
   sort(h, h + n);
   int ans = INT_MAX;
   rep(i, k - 1, n){
       ans = min(ans, h[i] - h[i-k+1]);
   }
   cout << ans;
}




Measured memory_bytes: 640
n = int(input())
w = []
result = "Yes"
for i in range(n):
        w.append(input())
        if i > 0:
                if w[i][0:1] != w[i-1][len(w[i-1])-1:len(w[i-1])] or w.count(w[i]) > 1:      
                        result = "No"
print(result)

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

map<string,string> board;
map<string,string> word;
 
void config(){
  string w = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  string s = "00000";
  string h[] = {"100101","10011010","0101","0001","110","01001","10011011",
		"010000","0111","10011000","0110","00100","10011001",
		"10011110","00101","111","10011111","1000",
		"00110","00111","10011100","10011101",
		"000010","10010010","10010011","10010000",
		"101","010001","000011","10010001","000000","000001"};
  for(int i=0;i<w.size();i++){
    string tmp = "";
    tmp += w[i];
    board[s] = tmp;
    word[tmp] = h[i];
    /*
      cout << tmp << " " << s << endl;
      cout << h[i] << " " << w[i] << endl << endl;
    */
    if(s[4] == '0') s[4] = '1';
    else {
      for(int j=4;j>=0;j--){
	if(s[j] == '0'){
	  s[j] = '1';
	  break;
	}
	else s[j] = '0';
      }
    }
  }
}

int main(){
  config();
  string str;
  while(getline(cin,str)){
    string next = "";
    for(int i=0;i<str.size();i++){
      string tmp = "";
      tmp += str[i];
      next += word[tmp];
    }
    while(next.size() % 5){
      next += "0";
    }
    string ans = "";
    string now = "";
    for(int i=0;i<next.size();i++){
      now += next[i];
      if(now.size() == 5){
	ans += board[now];
	now = "";
      }
    }
    cout << ans << endl;
  }
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int l[111];
int times[111];

ll dp[(1<<17)];

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>n;
		if(n==0)break;
		memset(times,0,sizeof(times));
		rep(i,n){
			int m;
			cin>>m>>l[i];
			rep(j,m){
				int s,e;
				cin>>s>>e;
				s-=6; e-=6;
				times[i]|=(1<<e)-(1<<s);
			}
		}
		memset(dp,-1,sizeof(dp));
		dp[0]=0;
		ll res=0;
		rep(S,1<<17){
			if(dp[S]==-1)continue;
			rep(i,n){
				if((S&times[i])==0)maxch(dp[S|times[i]],dp[S]+l[i]);
			}
		}
		rep(S,1<<17)maxch(res,dp[S]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 4152
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int N;
    cin >> N;
    int i = 1;
    for (; i * i <= N; ++i)
    {
    }
    --i;
    cout << i * i << endl;
}


Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

slist = gets_nsp_list.uniq

ns = slist.include?("N") && slist.include?("S")
se = slist.include?("W") && slist.include?("E")

size = slist.size
if size == 4
  puts "Yes"
elsif size == 2
  if ns
    puts "Yes"
  elsif se
    puts "Yes"
  else
    puts "No"
  end
elsif size == 1 || size == 3
  puts "No"
end

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

using namespace std;

int dp[1000000];
int h[1000000];

int main(){
    int N;
    cin >> N;
    cin >> h[1];
    cin >> h[2];
    dp[2] = abs(h[2]-h[1]);
    for(int i = 3; i<=N; i++){
            cin >> h[i];
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 4736
#include <iostream>
using namespace std;
int main()
{
	long long m, n, a, b = 0, c = 0, num = 1;
	cin >> m >> n;
	a = m;
	for (int i = 1; i < n; i++)
	{
		m = m * a;
		if (m > 1000000007)
		{
			b = m;
			num = (num * (b % 1000000007)) % 1000000007;
			m = 1;
			c = 1;
		}
	}
	if(c == 1)
    {
        num = (num * (m % 1000000007)) % 1000000007;
        cout << num << endl;
    }
	else cout << m << endl;
	return 0;
}



Measured memory_bytes: 3104
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
AB=sorted(AB)
cost=0
x=0
for ab in AB:
    if x+ab[1]<M:
        cost+=ab[0]*ab[1]
        x+=ab[1]
    else:
        cost+=ab[0]*(M-x)
        break
print(cost)

Measured memory_bytes: 28656
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if(N % 111 == 0){
  	cout << N << endl;
  }else{
  	int hund = N/100;
    if(N - hund*111 < 0){
    	cout << hund*111 << endl;
    }else{
    	cout << (hund+1)*111 << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;
typedef int64_t ll;


int main() {
    int K;
    cin >> K;
    vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout << A.at(K - 1) << endl;
}


Measured memory_bytes: 768
n, k = map(int, input().split())

def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+str(X%n)
  return str(X%n)

xn = Base_10_to_n(n, k)
print( len(str(xn)) )

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

int main()
{
	double a, b, c, d, e, f;

	while (cin >> a >> b >> c >> d >> e >> f){
		double x, y;
		x = (c * e - b * f) / (a * e - b * d);
		y = (c - (a * x)) / b;
		
		if (x == -0.000) x = 0.000;
		if (y == -0.000) y = 0.000;

		printf("%.3f %.3f\n", x, y);
	}

	return (0);
}

Measured memory_bytes: 1236
/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll              long long int
#define ld              long double
#define db              double
#define pi              3.1415926535897932384626
#define PI              acos(-1.0)
#define endl            "\n"
#define mod             1000000007
#define mk              make_pair
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            ll t; cin>>t; while(t--)
#define sc(a)	        scanf("%lld",&a);
#define pr(a)	        printf("%lld\n",a)
#define rep(i,a,n)		for(ll i=a;i<n;i++)
#define m(a)		    memset(a,0,sizeof(a))
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define min3(a,b,c)     min(a,min(b,c))


int main(){ FastIO;

int i,n,q,k;
cin>>n>>k>>q;
int a[n];
for(i=0;i<n;i++) a[i]=k-q;
while(q--){
	int b;cin>>b;
	a[b-1]++;
}
for(i=0;i<n;i++){
	if(a[i]>0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
}

Measured memory_bytes: 4016
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPractice
{
    class MinorChange
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int count = 0;

            for(int i = 0; i < s.Length; i++)
            {
                if(s[i] != t[i])
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 27280
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = b;
        if (a >= 13) {

        } else if (a >= 6) {
            ans = b / 2;
        } else {
            ans = 0;
        }
        System.out.println(ans);
        sc.close();
    }
}

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

int main()
{
    int n, m;
    int low, up;
    int max = 0, min = n;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        cin >> low >> up;
        //cout << low << up;
        max = max > low ? max : low;
        min = min < up ? min : up;
    }


    int ans = min - max + 1;
    if(ans > 0)
    {
        cout << ans << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    

    //system("pause");

}

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

#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define ss second
#define ff first
#define sz(s) (int)s.size()
#define all(a) a.begin(),a.end()

#ifndef ONLINE_JUDGE
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

#else
#define trace(args...) { }
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;

int main()
{
  IOS;
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  int ans = (W - w) * H;
  ans -= (h * (W - w));
  cout << max(0, ans);
  return 0;
}

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

using namespace std;

int main(){
  
  int n;
  cin>>n;
  int pay=0;
  int ans=0;

  for(int i=0; i<11; i++){
    if(i*1000>=n){
      pay=i*1000;
      break;
    }
  }

  cout<<pay-n<<endl;

}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

map<char, int>mp;

//反時計まわり
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };

struct aa {
	int x;
	int y;
	int way;
	bool operator ==(const aa&r) {
		return x == r.x&&y == r.y&&way == r.way;
	}
};

void cou(aa aaa) {
	char c;
	if (aaa.way == 0) {
		c = 'W';
	}
	else if (aaa.way == 1) {
		c = 'S';
	}
	else if (aaa.way == 2) {
		c = 'E';
	}
	else {
		c = 'N';
	}
	cout << aaa.y << " " << aaa.x << " " << c << endl;
}
int main() {
	mp['E'] = 2;
	mp['W'] = 0;
	mp['N'] = 3;
	mp['S'] = 1;
	while (1) {
		long long int H, W, L; cin >> H >> W >> L;
		if (!H)break;
		int sx, sy, sway;
		vector<vector<bool>>field(H + 2, vector<bool>(W + 2));
		for (int i = 0; i < H; ++i) {
			string st; cin >> st;
			for (int j = 0; j < W; ++j) {
				if (st[j] == '.') {
					field[i + 1][j + 1] = true;
				}
				else if (st[j] == '#') {

				}
				else {
					field[i + 1][j + 1] = true;
					sx = j + 1; sy = i + 1; sway = mp[st[j]];
				}
			}
		}
		vector<aa>memo;
		int nx = sx;int ny = sy; int way = sway;
		auto it = find(memo.begin(), memo.end(), (aa{ nx,ny,way }));
		while (it == memo.end()) {
			memo.push_back(aa{ nx,ny,way });
			int nextx = nx + dx[way];
			int nexty = ny + dy[way];
			while (!field[nexty][nextx]) {
				way = (way + 3) % 4;
				nextx = nx + dx[way];
				nexty = ny + dy[way];
			}
			ny = nexty; nx = nextx;
			it = find(memo.begin(), memo.end(), (aa{ nx,ny,way }));
		}
		if (memo.size() > L) {
			cou(memo[L]);
		}
		else {
			int roopnum = memo.end() - it;
			int roopstart = it - memo.begin();
			int anum = (L - roopstart) % roopnum + roopstart;
			cou(memo[anum]);
		}
	}
	return 0;
}

Measured memory_bytes: 3288
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> rate(12);
    int tourist = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        rate[a/400]++;
        if (a >= 3200) tourist++;
    }
    int mi = 0, ma = 0;
    for (int i = 0; i < 8; i++) {
        if (rate[i]) mi++, ma++;
    }
    mi = max(1, mi);
    ma += tourist;

    print(mi, ma);
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>

using namespace std;

int
main(int argc, const char *argv[])
{
    int H, W;
    while (cin >> H >> W) {
        if (!H && !W) break;
        for (int i = 0; i != H; ++i) {
            for (int j = 0; j != W; ++j) putchar('#');
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 3076
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#define int long long
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0,-1 }; // x軸方向への変位
int dy[4] = { 1, 0,-1, 0 }; // y軸方向への変位

std::vector<int> v;
int c[51][51];	//nCr->c[n][r];
long double ave[51];

int nCr(int n, int r) {
	if (r == 0) return 1;
	if (n == r) return 1;
	if (c[n][r] != -1) return c[n][r];
	//停止条件じゃなくてメモに載ってなかったら漸化式を計算
	int comb = nCr(n - 1, r - 1) + nCr(n - 1, r);
	c[n][r] = comb;
	return comb;
}

signed main() {
	int N, A, B;
	cin >> N >> A >> B;
	//メモ化再帰の初期化
	for (int n = 0; n < 51; n++) {
		for (int r = 0; r < 51; r++) {
			if (r == 0) c[n][r] = 1;
			else if (n == r) c[n][r] = 1;
			else c[n][r] = -1;
		}
	}


	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end(), std::greater<int>());

	map<int, int> allMap;
	for (int i = 0; i < N; i++) {
		allMap[v[i]] += 1;
	}

	for (int i = A; i <= B; i++) {
		int tmp = 0;
		for (int j = 0; j < i; j++) {
			tmp += v[j];
		}
		ave[i] = (long double)tmp / (long double)i;
	}
	long double maxAve = -1;
	for (int i = 1; i <= N ; i++) {
		if (ave[i] > maxAve) maxAve = ave[i];
	}


	int ans = 0;
	for (int i = A; i <= B; i++) {
		map<int, int> countMap;
		if (abs(ave[i] - maxAve) < 0.00000000000000001) {
			for (int j = 0; j < i; j++) {
				countMap[v[j]] += 1;
			}
			int tmpAns = 1;
			for (auto p : countMap) {
				tmpAns *= nCr(allMap[p.first], p.second);
			}
			ans += tmpAns;
		}
	}
	cout << std::setprecision(20) << maxAve << "\n";
	cout << ans << "\n";

	return 0;




}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		String[][] list = new String[9][9];
		for(int i=1; i <= 8; i++){
			String str = sc.next();
			for(int j=1; j <= 8; j++){
				list[i][j] = "" + str.charAt(j-1);
			}
		}

		//90
		System.out.println(90);
		for(int i=1; i <= 8; i++){
			for(int j=8; j >= 1; j--){
				System.out.print(list[j][i]);
			}
			System.out.println("");
		}

		//180
		System.out.println(180);
		for(int i=8; i >= 1; i--){
			for(int j=8; j >= 1; j--){
				System.out.print(list[i][j]);
			}
			System.out.println("");
		}

		//270
		System.out.println(270);
		for(int i=8; i >= 1; i--){
			for(int j=1; j <= 8; j++){
				System.out.print(list[j][i]);
			}
			System.out.println("");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 11000
#include<cstdio>
#include<cctype>

using namespace std;

int main(){
	char ch;
	while(1){
		scanf("%c", &ch);
		if(isalpha(ch)){
			if(islower(ch)) printf("%c", toupper(ch));
			else printf("%c", tolower(ch));
		} else printf("%c", ch);
		if(ch == '\n') break;
	}
	return 0;
}

Measured memory_bytes: 944
// package arc.arc102;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    static long __startTime = System.currentTimeMillis();

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        long n = in.nextInt();
        long k = in.nextInt();

        long mk = n / k;
        long mkh = k % 2 == 0 ? (n + k / 2) / k : 0;

        long ans = (long)(Math.pow(mk, 3) + Math.pow(mkh, 3));

        out.println(ans);
        out.flush();
    }

    private static void printTime(String label) {
        debug(label, System.currentTimeMillis() - __startTime);
    }

    private static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

Measured memory_bytes: 22484
N,M=map(int,input().split())

H=list(map(int,input().split()))

route={i:[] for i in range(1,N+1)}

for i in range(M):
    array=tuple(map(int,input().split()))
    route[array[0]].append(array[1])
    route[array[1]].append(array[0])

Obs=[True for i in range(N)]

for i in range(1,N+1):
    if Obs[i-1]==True:
        for j in route[i]:
            if H[i-1]>H[j-1]:
                Obs[j-1]=False
            else:
                Obs[i-1]=False

ans=0
for i in range(len(Obs)):
    if Obs[i]:
        ans+=1

print(ans)

Measured memory_bytes: 38076
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<astd::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define lolo 92233720368547757
#define susu 1000000007

using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	cout << n*m-(n+m-1);
	return 0;
}

Measured memory_bytes: 256