akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
	//Implement solution here.
			char[] s = next().toCharArray();
			int n = s.length;
			int mod = 1000000007;
			long[][] dp = new long[n + 1][13];
			dp[0][0] = 1;
			
			for(int i = 0; i < n; i++) {
				int dv = -1;
				if(s[i] != '?') dv = Character.getNumericValue(s[i]);
				
				for(int j = 0; j < 10; j++) {// j = next digit number
					if(dv != -1 && dv != j)continue;
					for(int rem = 0; rem < 13; rem++) {
						dp[i + 1][(rem * 10 + j) % 13] += dp[i][rem];
					}
				}
				for(int j = 0; j < 13; j++)dp[i + 1][j] %= mod;
			}			
			
			System.out.println(dp[n][5]);
	}

    //Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
        String debugDataPath = System.getenv("DD_PATH");        
        if(debugDataPath != null){
            try{
            	br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
            }catch(Exception e){
                throw new RuntimeException(e);
            }
        } 
        solve();
	}

    //Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
    //Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
    //Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
    //Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
    //Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
    //Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 35412
import java.io.*;

class Main{


public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    int answer = 0;
    for(int i = 0;i < n; i++){
        int number = Integer.parseInt(br.readLine());
        if(isPrime(number)) answer++;
    }
    System.out.println(answer);
    }

private static boolean isPrime(int numb){
    if(numb == 2 || numb == 3 || numb == 5 || numb == 7) {
	    return true;
	    }
    if(numb % 2 == 0) {
	    return false;
	    }
    for(int j=3;j <= Math.sqrt(numb);j++){
        if(numb % j == 0){ 
            return false;}
    }
    return true;
    }
}


Measured memory_bytes: 29944
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    int N;
    cin >> N;
    vector<vector<ll>> A(N, vector<ll>(N));
    Rep (i, N) Rep (j, N) cin >> A[i][j];

    vector<vector<bool>> need(N, vector<bool>(N, true));
    Rep (k, N) Rep (i, N) Rep (j, N) {
        if (A[i][j] > A[i][k] + A[k][j]) {
            cout << -1 << endl;
            return 0;
        } else if (A[i][j] == A[i][k] + A[k][j] && A[i][k] > 0 && A[k][j] > 0) {
            need[i][j] = false;
        }
    }

    ll ans = 0;
    Rep (i, N) {
        for (ll j = i+1; j < N; j++) {
            if (need[i][j]) ans += A[i][j];
        }
    }

    cout << ans << endl;

}

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

using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int pos[22];
  memset(pos, 0xff, sizeof(pos));

  int n;
  cin >> n;
  long long ans = 0;
  int right = -1;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int p = 0; p < 20; p++)
      if (a & (1 << p)) {
        right = max(right, pos[p]);
        pos[p] = i;
      }
    ans += i - right;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 2000000

int n,A[MAX+1];

void maxHeap(int i){
    int l,r,largest;
    l=2*i;
    r=2*i+1;
    
    if(l<= n&&A[l]>A[i]) largest=l;
    else largest=i;
    if(r<=n&&A[r]>A[largest])largest=r;
    if(largest!=i){
        swap(A[i],A[largest]);
        maxHeap(largest);
    }
}

int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>A[i];
    }
    for(int i=n/2;i>=1;i--){
        maxHeap(i);
    }
    for(int i= 1;i<=n;i++){
       cout<<" " <<A[i];
    }
    cout<<endl;
    return 0;
}



Measured memory_bytes: 4956
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    if(__builtin_popcount(n) == 1) puts("No");
    else{
        vector<pii> ans = {{1+n, 2+n}, {2+n, 3}, {3, 1}, {1, 2}, {2, 3+n}};
        for(int i=5; i<=n; i+=2){
            ans.emplace_back(i, i-1);
            ans.emplace_back(1, i);
            ans.emplace_back(i-1+n, i+n);
            ans.emplace_back(1, i-1+n);
        }
        if(n%2 == 0){
            int t = 1<<(31-__builtin_clz(n));
            ans.emplace_back(t+n, n);
            ans.emplace_back(n^1^t, n+n);
        }
        puts("Yes");
        for(auto p: ans) printf("%d %d\n", p.fi, p.se);
    }
}

Measured memory_bytes: 3952
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll X) {
  ll t = 0;
  ll p = 0;

  while (1) {
    if (t * (t + 1) >= 2 * X) {
      break;
    }
    t++;
  }

  cout << t << endl;
}

int main() {
  ll X;
  scanf("%lld", &X);
  solve(X);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans=1e15;
  rep(i,n-k+1){
    if(a[i+k-1]<0){ans=min(-1*a[i],ans);continue;}
    if(a[i]>0){ans=min(a[i+k-1],ans);continue;}
    ans=min(2*min(-1*a[i],a[i+k-1])+max(-1*a[i],a[i+k-1]),ans);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 4028
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

immutable long MOD = 10^^9 + 7;
immutable int M = 62;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto X = s[1].to!long;
    auto D = s[2].to!long;
    auto A = new long[](N);
    A[0] = X;
    foreach (i; 0..N-1) A[i + 1] = A[i] + D;

    if (D == 0) {
        if (X == 0) {
            writeln(1);
        } else {
            writeln(N + 1);
        }
        return;
    }

    if (D < 0) A = A.dup.reverse.array, D *= -1, X = A.front;

    long mx = 1L * N * (N - 1) / 2;
    long mn = mx;

    Tuple!(long, long)[][long] hoge;

    foreach (i; 0..N+1) {
        long co = N - 2 * i;

        auto l = co * A.front + mn * D;
        long r = co * A.front + mx * D;
        auto q = (l % (2 * D) + (2 * D)) % (2 * D);
        hoge[q] ~= tuple(l, r);

        mx = mx - i * 2;
        mn = mn - (N - i - 1) * 2;
    }

    long ans = 0;
    foreach (v; hoge.values) {
        v.sort();
        auto last = v.front[0] - 1;
        foreach (x; v) {
            auto a = x[0];
            auto b = x[1];
            a = max(a, last);
            if (a > b) {
                last = a;
                continue;
            }
            ans += (b - a) / (2 * D) + 1;
            last = b + 2 * D;
        }
    }

    ans.writeln;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 33276
#include<iostream>

#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
using namespace std;

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

typedef pair<int, int> pii;

int wa,dp[101][10001],w[101],v[101],n;




int main() {
	
	
	
	long long cnt[100001] = { 0 }, a[100001] = { 0 },ans=0;
	

	cin >> n>>wa;

	for (int i = 0; i < n; i++) {
		cin >> v[i] >> w[i];
	}
	memset(dp, 0, sizeof(dp));
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= wa; j++) {
			

			

			
			 if (j < w[i])dp[i+1][j] = dp[i][j];
			 else dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);

			
		}
	}
	
	cout << dp[n][wa]<< endl;
	
	



	return 0;
}



Measured memory_bytes: 7060
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 1000000007
#define eps 1e-8
int n,m,R[3030],sum[3030];
ll f[3030][6060];
char s[3030];

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 main()
{
	n=read();m=read();
	scanf("%s",s+1);
	rep(i,1,n+1) sum[i]=sum[i-1]+(s[i]=='1');
	rep(i,1,n+1) R[i]=i;
	rep(i,1,m)
	{
		int l=read(),r=read();
		R[l]=max(R[l],r);
	}
	rep(i,1,n) R[i]=max(R[i],R[i-1]);
	f[1][sum[R[1]]]=1;
	rep(i,1,n)
	{
		rep(j,0,n)
		{
			if (f[i][j])
			{
				int l=R[i]+1,r=R[i+1],add=sum[r]-sum[l-1];
				if (j) f[i+1][j+add-1]=(f[i+1][j+add-1]+f[i][j])%maxd;
				if (R[i]-i+1>j) f[i+1][j+add]=(f[i+1][j+add]+f[i][j])%maxd;
			}
		}
	}
	printf("%lld",f[n+1][0]);
	return 0;
}


Measured memory_bytes: 141824
a=input().split()
H=int(a[0])
W=int(a[1])
n_list=[[0 for i in range(W)] for i in range(H)]
m_list=[]
for i in range(H) :
  m_list.append(input())

for i in range(H) :
  if m_list[i][0]=='.' :
    n_list[i][0]=1
  else :
    break

for i in range(W) :
  if m_list[0][i]=='.' :
    n_list[0][i]=1
  else :
    break

for i in range(1,H) :
  for j in range(1,W) :
    if m_list[i][j]=='#' :
      n_list[i][j]=0
    else :
      n_list[i][j]=n_list[i-1][j]+n_list[i][j-1]
print(n_list[-1][-1]%(10**9+7))

Measured memory_bytes: 209260
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll x = in(), a = in(), b = in();
	cout << (b <= a ? "delicious" : b - a <= x ? "safe" : "dangerous") << endl;
}

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

void frm(int H, int W){
  for (int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        if (i == 0 || i == H-1 || j == 0 || j == W - 1){
          cout << '#';
        }else{
          cout << '.';
        } 
      } 
      cout << endl;     
  }
}

int main(){
  int H,W;

  while(1){
    cin >> H >> W;
    if(H == 0 && W == 0) return 0;
    
    frm(H, W);
    cout << endl;
  }
}

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

dp = [0]*(N+100001)
for i in range(99999):
    dp[i] = 10**10

for i in range(100000,N+100001):
    dp[i] = min(dp[i-1] + 1,
                dp[i-6] + 1,
                dp[i-9] + 1,
                dp[i-36] +1,
                dp[i-81] + 1,
                dp[i-216] + 1,
                dp[i-729] + 1,
                dp[i-1296] + 1,
                dp[i-6561] + 1,
                dp[i-7776] + 1,
                dp[i-46656] + 1,
                dp[i-59049] + 1)

print(dp[N+99999])

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll a,b,k;scanf("%lld %lld %lld",&a,&b,&k);
    b+=min((ll)0,a-k);
    b=max((ll)0,b);
    a=max((ll)0,a-k);
    printf("%lld %lld",a,b);
    return 0;
}

Measured memory_bytes: 256
s=input()
if s=="SAT":
    print(1)
if s=="SUN":
    print(7)
if s=="MON":
    print(6)
if s=="TUE":
    print(5)
if s=="WED":
    print(4)
if s=="THU":
    print(3)
if s=="FRI":
    print(2)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(void){
	string s;

	cin >> s;

	int alp[26] = {};



	for (int i = 0; i < s.size(); i++){
		alp[s[i]-'a']++;
	}

	for (int i = 0; i < 26; i++){
		if (alp[i] == 0){
			cout << (char)('a' + i) << endl;
			break;
		}
		if (i == 25)
			cout << "None" << endl;
	}
}

Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
	string s;
	cin>>s;
	n=(s[5]-'0')*10+s[6]-'0';
	if (n<=4) cout<<"Heisei";
	else cout<<"TBD";
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
    int n = 0, i, min = 0, max = 0;
    long long int sum = 0;
    int input_num[10001], output_num[3];
 
    scanf("%d", &n);
     
    for (i = 0; i < n; i++)
    {
        scanf("%d", &input_num[i]);
        if (i == 0)
        {
            max = input_num[i];
            min = input_num[i];
        }
        if (input_num[i] > max)
        {
            max = input_num[i];
        }
        if (input_num[i] < min)
        {
            min = input_num[i];
        }
 
        sum += input_num[i];
    }
 
    output_num[0] = min;
    output_num[1] = max;
 
    printf("%d %d %lld\n", output_num[0], output_num[1], sum);
 
    return 0;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

#include <iomanip>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define FIND(x, target) find(x.begin(),x.end(),target)
#define pb(x) push_back(x)
#define pob(x) pop_back(x)
#define output(x) cout<<x<<endl
#define ERASE(x, n) x.erase(x.begin()+n)
// #define int long long
// #define P pair<int, int>
typedef long long ll;

const long long int MOD = 1e9+7;
const ll INF = 1e17;
ll dp[100005][13];

signed main(void) {
  ll N;
  cin >> N;
  cout << N*N << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
  int Q;
  vector<int> ls,rs,nums;
  set<int> primes;
  int Nmax=0,l,r;
  cin >> Q;
  for(int i=0;i<Q;i++){
    cin >> l >> r;
    if(r>Nmax) Nmax=r;
    ls.push_back(l);
    rs.push_back(r);
  }
  primes.insert(primes.end(),2);
  primes.insert(primes.end(),3);
  if(primes.find( (3+1)/2)!=primes.end()) nums.push_back(3);
  for(int i=6;i<=Nmax;i+=6){
    int flag1=1,flag2=1;
    for(auto itr=primes.begin();itr!=primes.end();++itr){
      if((i-1)%*itr==0){
        flag1 = 0;
      }
      if((i+1)%*itr==0){
        flag2 = 0;
      }
    }
    if ( (flag1==1) ){
      primes.insert(primes.end(),i-1);
      if(primes.find(i/2)!=primes.end()) nums.push_back(i-1);      
    }
    if ( (flag2==1) ){
      primes.insert(primes.end(),i+1);
      if(primes.find(i/2+1)!=primes.end()) nums.push_back(i+1);      
    }
  }
  sort(nums.begin(),nums.end());
  for(int i=0;i<Q;++i){
    cout << upper_bound(nums.begin(),nums.end(),rs[i])-lower_bound(nums.begin(),nums.end(),ls[i]) << endl;
  }
}
  

Measured memory_bytes: 1908
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<int> flag(n,1);
    rep(i,n){
        cin >> h[i];
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(h[a] > h[b]){
            flag[b] = 0;
        }else if(h[a] < h[b]){
            flag[a] = 0;
        }else{
            flag[a] = 0;
            flag[b] = 0;
        }
    }
    int cnt = 0;
    rep(i,n){
        //cout << flag[i] << endl;
        if(flag[i] == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

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

const int N = 1e5 + 1;

pii nxt[N][26];

int main()
{
    //freopen("input.txt", "r", stdin);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);


    string s, t;
    cin >> s >> t;
    int n = (int)s.size();

    for (int c = 0; c < 26; ++c)
        nxt[n - 1][c] = {-1, 0};
    for (int i = n - 2; i >= 0; --i)
    {
        for (int c = 0; c < 26; ++c)
            nxt[i][c] = nxt[i + 1][c];
        nxt[i][s[i + 1] - 'a'] = {i + 1, 0};
    }
    if (nxt[0][s[0] - 'a'].first == -1)
        nxt[0][s[0] - 'a'] = {0, 1};
    for (int i = 1; i < n; ++i)
    {
        for (int c = 0; c < 26; ++c)
            if (nxt[i][c].first == -1)
                nxt[i][c] = {nxt[0][c].first, 1};
    }
    nxt[n - 1][s[0] - 'a'] = {0, 1};
    for (int i = 0; i < n; ++i)
        if (nxt[i][s[i] - 'a'].first == -1)
            nxt[i][s[i] - 'a'] = {i, 1};

    ll ans = 0;
    int cur = 0;
    int m = (int)t.size();
    for (int i = (s[0] == t[0]); i < m; ++i)
    {
        static pii cur_nxt;
        cur_nxt = nxt[cur][t[i] - 'a'];
        if (cur_nxt.first == -1)
        {
            cout << -1;
            return 0;
        }
        ans += cur_nxt.first - cur;
        if (cur_nxt.second)
            ans += n;
        cur = cur_nxt.first;
    }

    cout << ans + 1;
}


Measured memory_bytes: 20944
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define int         ll int
#define float       double
#define	endl		'\n'
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define mii         map<int,int>
#define msi         map<string,int>
#define mis         map< int, string>
#define mpi         map<pair< int, int>, int>
#define pii         pair< int, int>
#define vi          vector< int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define EPS         1e-9
#define INF         1e18
#define PI          3.14159265358979323846
#define MAXI        1000000
#define what_is(x)  cerr << #x << " is " << x << endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
#define N 100005

signed main()
{
	fast;
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n,k;
		cin>>n>>k;
		int arr[n];
		int i,j;
		for(i=0;i<=n-1;i++)
		{
			cin>>arr[i];
		}
		int dp[n+1];
		dp[1]=0;
		dp[2]=abs(arr[0]-arr[1]);
		for(i=3;i<=n;i++)
		{
			dp[i]=INT_MAX;
			for(j=max((int)1,i-k);j<i;j++)
			{
				dp[i]=min(dp[i],dp[j]+abs(arr[j-1]-arr[i-1]));
			}
		}
//		for(i=1;i<=n;i++) cout<<dp[i]<<" ";
//		cout<<endl;
		cout<<dp[n]<<endl;
	}
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, k; cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int d = min(x[i], k - x[i]);
        ans += 2 * d;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,m,x=MI()
tolls=LI()
left,right=0,0
for i in range(x):
    if i in tolls:
        left+=1
for j in range(x,n):
    if j in tolls:
        right+=1
print(min(left,right))

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
using namespace std;
int main(){
   int N,W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    for(int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
    }
    vector<vector<long long>> dp(N+1,vector<long long>(100100,100000000000LL));
    dp[0][0] = 0LL;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 100100; j++)
        {
            if (j-v[i] >= 0) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]]+w[i]);
            }
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    int ans;
    for(int i = 0; i < 100100; i++)
    {
        if (dp[N][i] <= W) {
            ans = i;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

using ll = long long;

int main() {
    int n, ans = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i <= 999; ++i) {
        int num = i, suf = 0;
        bool f = true;
        for (int j = 0; j < 3; ++j) {
            if ((suf = s.find('0' + num % 10, suf)) == string::npos) {
                f = false;
                break;
            }
            suf++;
            num /= 10;
        }
        if (f)
            ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<lint> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define N 305
vvi d(N, vi(N, LLONG_MAX));
vvi b(N, vi(N, 1));
bool warshall_floyd(int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                if (d[j][k] > d[j][i] + d[i][k])
                {
                    return false;
                }
                if (d[j][k] == d[j][i] + d[i][k] && i != j && i != k)
                {
                    b[j][k] = 0;
                    b[k][j] = 0;
                }
            }
        }
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        rep(j, n)
        {
            cin >> d[i][j];
        }
    }
    if (!warshall_floyd(n))
    {
        cout << -1 << endl;
    }
    else
    {
        lint ans = 0;
        rep(i, n)
        {
            rep(j, n)
            {
                if (b[i][j] == 1)
                {
                    ans += d[i][j];
                }
            }
        }
        cout << ans / 2 << endl;
    }
    return 0;
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, m; cin >> n >> m;
    vi v(n + 1); vector<bool> solved(n + 1);
    rep(i, 0, m) {
        int x; string s;
        cin >> x >> s;
        if (s == "WA" && !solved[x]) v[x]++;
        else solved[x] = true;
    }
    int ca = 0, pn = 0;
    rep(i, 1, n + 1) if (solved[i]) ca++, pn += v[i];
    cout << ca << " " << pn << endl;
}

Measured memory_bytes: 640
h,w=map(int,input().split())
ans=[float("inf") for i in range(10)]
p=[]
a=[]
for i in range(10):
    p.append(list(map(int,input().split())))
for i in range(h):
    a.append(list(map(int,input().split())))
for i in range(10):
    for j in range(10):
        for k in range(10):
            p[j][k]=min(p[j][i]+p[i][k],p[j][k])
ans=float("inf")
tmp=0
for j in range(h):
    for k in range(w):
        if a[j][k]!=-1:
            tmp+=p[a[j][k]][1]
print(tmp)

Measured memory_bytes: 40412
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long k = sc.nextLong();
        if(a+b<=k){
            long ans = a-(k-a-b);
            System.out.println(ans);
        } else if(a<=k){
            System.out.println(a);
        } else if(a>k){
            System.out.println(k);
        }
	}
}

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

using namespace std;
int n;
long double sum;
long double dp[3001][3001];
long double pro[3001];
bool visited[3001][3001];

long double calc(int idx , int heads){

    if (idx == n){
        if (heads > n - heads)return 1;
        else return 0;
    }

    if (visited[idx][heads] == true)return dp[idx][heads];

    long double head = pro[idx];
    long double tail = 1.0 - head;

    long double firstop = calc(idx + 1 , heads + 1) * head;
    long double secondop  = calc(idx + 1 , heads) * tail;


    dp[idx][heads] = firstop + secondop;
    visited[idx][heads] = true;

    return dp[idx][heads];


}




int main()
{

    cin >> n;


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



    cout << fixed << setprecision(10) << calc(0 , 0) << endl;


    return 0;
}


Measured memory_bytes: 94604
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
//#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int,int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;
int dx[4] = { 0,0,-1,1 }, dy[4] = { 1,-1,0,0 };


void solve() {
	char c; cin >> c;
	print(++c);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
def check(h):
    for i in range(len(h)-1, -1, -1):
        if i == len(h)-1:
            continue
        if h[i] <= h[i+1]:
            continue
        else:
            h[i] -= 1
        if h[i] <= h[i+1]:
            continue
        else:
            return False
    return True

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

if check(H):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<int> v(q);
    for (int i = 0; i < q; i++)
        cin >> v[i];
    for (int ii = 0; ii < q; ii++)
    {
        int k = v[ii];
        long long dp[6] = {};
        for (int i = 0; i < k; i++)
        {
            long long nxt[6];
            for (int j = 0; j < 6; j++)
                nxt[j] = dp[j];
            if (s[i] == 'D')
                nxt[0]++;
            else if (s[i] == 'M')
            {
                nxt[1]++;
                nxt[2] += dp[0];
            }
            else if (s[i] == 'C')
            {
                nxt[3] += dp[1];
                nxt[4] += dp[2];
                nxt[5]++;
            }
            for (int j = 0; j < 6; j++)
                dp[j] = nxt[j];
        }
        long long ans = dp[4];
        for (int i = 1; i + k <= n; i++)
        {
            //cout << ans << endl;
            if (s[i - 1] == 'D')
            {
                dp[0]--;
                dp[2] -= dp[1];
                dp[4] -= dp[3];
            }
            if (s[i - 1] == 'M')
            {
                dp[1]--;
                dp[3] -= dp[5];
            }
            if (s[i - 1] == 'C')
            {
                dp[5]--;
            }
            if (s[i + k - 1] == 'D')
            {
                dp[0]++;
            }
            if (s[i + k - 1] == 'M')
            {
                dp[1]++;
                dp[2] += dp[0];
            }
            if (s[i + k - 1] == 'C')
            {
                dp[3] += dp[1];
                dp[4] += dp[2];
                ans += dp[2];
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1948
#include <iostream>
#include <algorithm>
using namespace std;
struct shop{
    long long a;
    long long b;
};
bool compare(shop a,shop b){
    return a.a<b.a;
}
int main(){
    long long n,m,i,w=0,s=0;
    cin >> n >> m;
    struct shop a[n];
    for (i=0;i<n;i++)
        cin >> a[i].a >> a[i].b;
    sort(a,a+n,compare);
    for (i=0;i<n;i++){
        if (s+a[i].b>m){
            w+=(m-s)*a[i].a;
            break;
        }
        else{
            w+=a[i].a*a[i].b;
            s+=a[i].b;
        }
    }
    cout << w << endl;
    return 0;
}


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

void cal_cnt(vector<int> &cnt, vector<vector<int>> &child, int p, int x)
{
    for (int u : child.at(p))
    {
        if (u != x)
        {
            cnt.at(u) += cnt.at(p);
            cal_cnt(cnt, child, u, p);
        }
    }
}

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

    // 点同士の関係を保持するvector
    vector<vector<int>> children(n);
    for (int i = 1; i < n; i++)
    {
        int a, b;
        cin >> a >> b;
        children.at(a - 1).push_back(b - 1);
        children.at(b - 1).push_back(a - 1);
    }

    vector<int> counters(n, 0);
    for (int i = 0; i < q; i++)
    {
        int p, x;
        cin >> p >> x;
        counters.at(p - 1) += x;
    }
    cal_cnt(counters, children, 0, -1);

    for (int i = 0; i < counters.size(); i++)
        cout << counters.at(i) << " ";
    // cout << counters.back();

    return 0;
}

Measured memory_bytes: 32896
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n, temp;
	cin >> n;
	vector<int>ans(n, 0);
	for (int i = 0; i < n - 1; i++) {
		cin >> temp;
		ans[temp - 1]++;
	}
	for (auto i : ans) {
		cout << i << endl;
	}
}

Measured memory_bytes: 4048
N = int(input())
x = []
u = []
Y = 0
for i in range(N):
    s = [i for i in input().split()]
    x.append(float(s[0]))
    u.append(s[1])

    if u[i] == 'BTC':
        Y += x[i]*380000
    else:
        Y += x[i]

print(Y)

Measured memory_bytes: 3060
import math

n = int(input())
a = list(map(int,input().split()))

def combi(n):
    if n == 1: return 0
    return math.factorial(n) // (math.factorial(n - 2) * 2)

a2 = sorted(a)
a2.append(n+1)
dic = {}
n = 0
cnt = 1
total = 0
for i in a2:
    if n != i:
        if cnt > 1:
            dic[str(n)] = cnt
            total += combi(cnt)
        n = i
        cnt = 1
    else:
        cnt += 1

for i in a:
    if str(i) in dic:
        cnt = dic[str(i)]
        print(total - cnt + 1)
    else:
        print(total)


Measured memory_bytes: 26140
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int a, b;
    cin >> a >> b;
    int now = 1, ans = 0;
    while(now < b){
        now += a-1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * Problem     : AOJ0015
 * Title       : Integral
 * Author      : mizo0203
 * Status      : Accepted
 * Date        : Sun Jun 24 20:50:52
 * Copyright   : Your copyright free
 * Description : 文字列・多倍長演算
 */

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int N, f;
char str1[81], str2[81];
int sum[80];

void init() {
  scanf("%d", &N);
}

bool input() {
  char c;

  if (!N)
    return false;
  N--;

  f = 0;
  scanf("%80s", str1);
  scanf("%c", &c);
  if ('0' <= c && c <= '9') {
    while ('0' <= c && c <= '9') scanf("%c", &c);
    f = 1;
  }
  scanf("%80s", str2);
  scanf("%c", &c);
  if ('0' <= c && c <= '9') {
    while ('0' <= c && c <= '9') scanf("%c", &c);
    f = 1;
    return true;
  }

  return true;
}

int main() {
  int i;

  init();
  while (input()) {
    if (f) {
      printf("overflow\n");
      continue;
    }
    fill(sum, sum + 80, 0);
    for (i = 0; i < (int) strlen(str1); i++) {
      sum[i] = str1[strlen(str1) - i - 1] - '0';
    }
    f = 0;
    for (i = 0; i < (int) strlen(str2); i++) {
      sum[i] += str2[strlen(str2) - i - 1] - '0' + f;
      f = 0;
      if (sum[i] > 9) {
        sum[i] -= 10;
        f = 1;
      }
    }
    for (; i < 80; i++) {
      sum[i] += f;
      f = 0;
      if (sum[i] > 9) {
        sum[i] -= 10;
        f = 1;
      }
    }
    if (f) {
      printf("overflow\n");
      continue;
    }
    for (i = 0; i < 79; i++) {
      if (sum[79 - i] != 0)
        break;
    }
    for (; i < 80; i++) {
      printf("%d", sum[79 - i]);
    }
    printf("\n");
  }

  return 0;
}

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

public class Main {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String s1 = sc.nextLine();
        if ((s1 != null) && (s1.length() > 0)) {
           s1 = s1.substring(0, s1.length() - 1);
         }
        if(s.equals(s1)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}


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

int main(){
  int h,w;
  cin >> h >> w;

  vector<vector<int>> dist(10,vector<int>(10));
  for (int i = 0; i < 10; i++)
  {
    for (int j = 0; j < 10; j++)
    {
      cin >> dist[i][j];
    }
  }

  for (int k = 0; k < 10; k++)
  {
    for (int i = 0; i < 10; i++)
    {
      for (int j = 0; j < 10; j++)
      {
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }

  int ans=0;
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      int a;
      cin >> a;
      if(a!=-1) ans+=dist[a][1];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = [0]*m
r = [0]*m

for i in range(m):
    l[i], r[i] = map(int, input().split())
    

    
ans = min(r) - max(l)
if ans >= 0 :
    print(ans+1)
else:
    print(0)

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

int main() {
  int a,b;
  cin >> a >> b;
  int ans=0;
  for(int i=a; i<=b; i++) {
    string s;
    stringstream ss;
    ss << i;
    ss >> s;
    string t=s;
    reverse(t.begin(),t.end());
    if(s==t) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto D = [s[1], s[2]];
    auto G = new int[][][](2, 4*N*N);
    auto C = new int[][](2, 4*N*N);
    C[0][] = C[1][] = -1;

    auto xyd = new int[][](2, 2*N);

    foreach (i; 0..2) {
        xyd[i][] = -1;
        foreach (x; 0..2*N) {
            foreach (y; 0..2*N) {
                if (x*x+y*y == D[i]) {
                    xyd[i][x] = y;
                }
            }
        }
    }


    foreach (i; 0..2) {
        foreach (x1; 0..2*N) {
            foreach (y1; 0..2*N) {
                foreach (x2; x1..2*N) {
                    if (xyd[i][x2-x1] == -1) continue;
                    foreach (k; [-1, 1]) {
                        int y2 = y1 + k * xyd[i][x2-x1];
                        if (y2 < 0 || y2 >= 2*N) continue;
                        G[i][x1*2*N+y1] ~= x2*2*N+y2;
                        G[i][x2*2*N+y2] ~= x1*2*N+y1;
                    }
                }
            }
        }
    }

    foreach (i; 0..2) {
        foreach (x1; 0..2*N) {
            foreach (y1; 0..2*N) {
                if (C[i][x1*2*N+y1] == -1) {
                    dfs(x1*2*N+y1, 0, G[i], C[i]);
                }
            }
        }
    }

    int cnt = 0;

    foreach (i; 0..2) {
        foreach (j; 0..2) {
            if (iota(4*N*N).map!(k => C[i][k] == i && C[j][k] == j).sum < N*N) continue;
            foreach (x; 0..2*N) {
                foreach (y; 0..2*N) {
                    if (C[0][x*2*N+y] == i && C[1][x*2*N+y] == j) {
                        writeln(x, " ", y);
                        ++cnt;
                        if (cnt >= N * N) {
                            return;
                        }
                    }
                }
            }
        }
    }
}

void dfs(int n, int c, ref int[][] G, ref int[] C) {
    if (C[n] != -1) return;
    C[n] = c;
    foreach (m; G[n]) if (C[m] == -1) dfs(m, c^1, G, C);
}


Measured memory_bytes: 156540
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i,n) cin >> a[i];

	map<int, int> mp;
	REP(i,n) mp[a[i]]++;
	ll total = 0;
	for(auto p: mp){
		total += (ll)p.second*(p.second-1)/2;
	}
	REP(k,n){
		cout << max(0LL, total - (ll)(mp[a[k]]-1)) << '\n';
	}
	return 0;
}



Measured memory_bytes: 8448
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int DP [][] = new int[s.length()+1][t.length()+1];
        int List [][] = new int[s.length()+1][t.length()+1];
        StringBuilder opt = new StringBuilder();
        for(int i=0;i<s.length()+1;i++) DP[i][0]=0;
        for(int j=0;j<t.length()+1;j++) DP[0][j]=0;
        for(int i=1;i<=s.length();i++){
            for(int j=1;j<=t.length();j++){
                if(s.charAt(i-1)==t.charAt(j-1)){
                    DP[i][j]=DP[i-1][j-1]+1;
                    List[i][j] = 2;
                }
                else if(s.charAt(i-1)!=t.charAt(j-1)) {
                    DP[i][j] = Math.max(DP[i][j - 1], DP[i - 1][j]);
                    if(DP[i][j]==DP[i][j-1])List[i][j]=3;
                    else List[i][j]=1;
                }
            }
        }
       int i = s.length(), j = t.length();
        for(int k=0;k<s.length()*t.length();k++){
            if(s.charAt(i-1)==t.charAt(j-1)) opt.append(s.charAt(i-1));
            if(List[i][j]==1) i--;
            else if(List[i][j]==3) j--;
            else if(List[i][j]==2){
                i--;
                j--;
            }
            if(i==0||j==0) break;
        }
        for(i=opt.length()-1;i>=0;i--)System.out.print(opt.charAt(i));
        System.out.println();
    }
}

Measured memory_bytes: 129680
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		String n ="";
		
		switch (s) {
			case "Sunny":
				n = "Cloudy";
				break;
			case "Cloudy":
				n = "Rainy";
				break;
			case "Rainy":
				n = "Sunny";
				break;
		}
		
		System.out.println(n);
		
		sc.close();	
	}
}

Measured memory_bytes: 21716
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.regex.Pattern;


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

    Scanner sc = new Scanner(System.in);

    String s = sc.next();

    int k = sc.nextInt();

    if (s.length() <= 0 || 5000 < s.length() || k <= 0 || 5 < k ) {
      return;
    }
    for(int t = 1; s.length() >= t; t++) {
      if (!Pattern.matches("^[a-z]+$", s)) {
        return;
      }
    }


    ArrayList<String> foo = new ArrayList<>();

    for (int i = 1; k >= i; i++) {
      for (int n = 0; s.length() >= n + i; n++) {
        foo.add(s.substring(n, n + i));
      }
    }

    if (foo.size() < k) {
      return;
    }

    ArrayList<String> list = new ArrayList<String>(new HashSet<>(foo));
    Collections.sort(list);

    String str = list.get(k - 1);
    System.out.println(str);

    return;
  }
}


Measured memory_bytes: 32832
#include<iostream>
#include<cmath>
#include<unordered_map>
#include<math.h>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#include<iomanip>
#include<string>
#include<map>
#define PI 3.14159265
#define mod 998244353  
#define mod1 1e9 + 7  
using namespace std;

int dfs(vector<vector<int>> &graph , vector<int> &visited , int src){
    int maxi = -1;
    for(int i = 0 ; i < graph[src].size() ; ++i){
        if(visited[graph[src][i]] == -1){
            visited[graph[src][i]] = dfs(graph,visited,graph[src][i]);
        }
        maxi = max(visited[graph[src][i]] , maxi);
    }
    visited[src] = maxi + 1;
    return maxi + 1;
}

void func(){

int n , m ;
cin >> n >> m ;

vector<vector<int>> graph(n + 1) ;
vector<int> visited(n + 1,-1);

for(int i = 0 ; i < m ; ++i){
    int inp1 , inp2;
    cin >> inp1 >> inp2;
    graph[inp1].push_back(inp2);
}
int maxi = -1;
for(int i = 1 ; i <= n ; ++i){
 if(visited[i] == -1)
   maxi = max(maxi, dfs(graph,visited,i));
}
 cout << maxi << "\n";

return;

}

int main(){
    int t = 1 , cnt = 0 ;
   // cin >> t;
    
    while(t--){
        
        func();
    }
}

Measured memory_bytes: 10368