akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;


public class Main {
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int x = sc.nextInt();
    long[] a = sc.nextLongList(N);
    
    long total = 0;
    for (int i = 0; i < N - 1; i ++) {
      long y = a[i] + a[i + 1];
      if (y > x) {
        long d = y - x;
        total += d;
        
        a[i + 1] = Math.max(0, a[i + 1] - d);
      }
    }
    System.out.println(total);
  }

}


class FastScanner {
	public static String debug = null;

	private final InputStream in = System.in;
	private int ptr = 0;
	private int buflen = 0;
	private byte[] buffer = new byte[1024];
	private boolean eos = false;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				if (debug != null) {
					buflen = debug.length();
					buffer = debug.getBytes();
					debug = "";
					eos = true;
				} else {
					buflen = in.read(buffer);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen < 0) {
				eos = true;
				return false;
			} else if (buflen == 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean isEOS() {
		return this.eos;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

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

	public long[] nextLongList(int n) {
		return nextLongTable(1, n)[0];
	}

	public int[] nextIntList(int n) {
		return nextIntTable(1, n)[0];
	}

	public long[][] nextLongTable(int n, int m) {
		long[][] ret = new long[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextLong();
			}
		}
		return ret;
	}

	public int[][] nextIntTable(int n, int m) {
		int[][] ret = new int[n][m];
		for (int i = 0; i < n; i ++) {
			for (int j = 0; j < m; j ++) {
				ret[i][j] = nextInt();
			}
		}
		return ret;
	}
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

const ll MAX_N = 100;
ll N;
ll h[MAX_N + 1] = {};
int main(){
   cin >> N;
   REP(i, N) cin >> h[i];

   ll cnt = 0;
   REP(i, N){
      cnt += h[i];
      REP(j, h[i]){
         ll k = i + 1;
         while(h[k] > 0){
            h[k] --;
            k++;
         }
      }
   }
   cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;
typedef pair<int, int> P;

#define pi 3.141592653589793)
#define mod 1000000007

int n, a[100001];
int ans = 1000000000;
int num;

void solve() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int left, right;
	
	left = a[n - 1];
	for (int i = 0; i < n-1; i++) {
		if (ans >= abs(left / 2 - a[i])) {
			ans = abs(left / 2 - a[i]);
			num = i;
		}
	}
	right = a[num];
	cout << left << " " <<right << endl;

}

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

Measured memory_bytes: 640
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        Arrays.sort(s);
        Arrays.sort(t);
        String ts = new StringBuilder(new String(t)).reverse().toString();
        System.out.println(new String(s).compareTo(ts) < 0 ? "Yes" : "No");
    }
}


Measured memory_bytes: 25172
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
   		ll N,M,sum=0;
		cin >> N;

		vector<long> T(N,0);

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

		cin >> M;

		vector<long> P(M,0);
		vector<long> X(M,0);

		for(int i=0;i<M;i++){
			cin >> P[i] >> X[i];
		}

		for(int i=0;i<M;i++){
			sum=0;
			for(int j=0;j<N;j++){
				if(j+1==P[i]){
					sum+=X[i];
				}else{
					sum+=T[j];
				}
			}
			cout << sum << endl; 
		}

		
		return 0;
    }

Measured memory_bytes: 256
<?php

while ($stdin = fgets(STDIN)) {
    $line[] = trim($stdin);
}
foreach ($line as $key => $value) {
    $data[] = explode(' ', $value);
}

foreach ($data as &$line) {
    $line = array_map(function($val) { return (int)$val; }, $line);
}


$N = $data[0][0];
$A = [];

for ($i = 0; $i < $N; $i++) {
    $A[$i] = $data[1][$i];
}

$num = (int)round(array_sum($A) / count($A));
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    $ans +=  ($num - $A[$i]) * ($num - $A[$i]);
}

printf('%s', $ans);


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



 int main(){

 int n;
 cin>>n;
 int arr[n];
for(int i=0;i<n;i++)
     cin>>arr[i];

     sort(arr,arr+n);

    int flag=0;

    for(int i=1;i<n;i++)
        if(arr[i]==arr[i-1])
    {
    flag=1;
    break;
    }
if(flag)
    cout<<"NO"<<endl;
else
    cout<<"YES"<<endl;

 return 0;

 }


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include<algorithm>
#include<iomanip>
#include<math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;


float kitai(float i, float K) {

	double a = 0;

	a = (i + K) / 2;


	cout << fixed << setprecision(6) << a;
	return 0;
}

int main()
{
	int N, K;
	int p;
	int q[200001] = { 0 };

	int m = 0;

float a = 0;
int b = 0;

cin >> N >> K;

for (int i = 0; i < N; i++) {

	cin >> p;
	if (i == 0) {
		q[i] = p;
	}
	else {

		q[i] = q[i - 1] + p;
	}
}

b = q[K - 1];
for (int i = 1; i < N - K + 1; i++) {
	m = q[i + K - 1] - q[i - 1];
	b = max(m, b);
}

kitai(b, K);

}


Measured memory_bytes: 1024
#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)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }

int A, B; string S;

#define yes "Yes"
#define no "No"
int check(char c) { return '0' <= c and c <= '9'; }
string solve() {
    rep(i, 0, A) if (!check(S[i])) return no;
    if (S[A] != '-') return no;
    rep(i, A + 1, A + B + 1) if (!check(S[i])) return no;
    return yes;
}

void _main() {
    cin >> A >> B >> S;
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



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

    int n;
    cin >> n;
    vector<ll> a(3);
    rep(i,3) cin >> a[i]; 
    map<string,int> mp;
    mp["AB"]=0;
    mp["BC"]=1;
    mp["AC"]=2;
    vector<int> b(n);
    rep(i,n) {
        string s;
        cin >> s;
        b[i]=mp[s];
    }
    bool flag=1;
    ll sum=0;
    rep(i,3) sum+=a[i];
    vector<char> ans;
    rep(i,n) {
        int fi=b[i],se=(b[i]+1)%3;
        if (a[fi]==0 && a[se]==0) {
            flag=0;
        } else if (a[fi]==1 && a[se]==1 && a[(fi+2)%3]==0) {
            if (i<n-1) {
                if (b[i+1]==se) {
                    --a[fi];
                    ++a[se];
                    ans.push_back(se+'A');
                } else {
                    ++a[fi];
                    --a[se];
                    ans.push_back(fi+'A');
                }
            } else {
                --a[fi];
                ++a[se];
                ans.push_back(se+'A');
            }
        } else {
            if (a[fi]>=a[se]) {
                --a[fi];
                ++a[se];
                ans.push_back(se+'A');
            } else {
                ++a[fi];
                --a[se];
                ans.push_back(fi+'A');
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
        rep(i,n) cout << ans[i] << endl;
    } else {
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = 1e5+5;
int n, k, q, a;
int r[maxn];

void read()
{
    cin >> n >> k >> q;
    for(int i = 0; i < q; ++i)
    {
        cin >> a;
        r[a]++;
    }
}

void solve()
{
    for(int i = 1; i <= n; ++i)
        if(r[i] + k - q <= 0)
            cout << "No" << endl;
        else
            cout << "Yes" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    read();
    solve();
    return 0;
}


Measured memory_bytes: 1024
// Problem : C - Tsundoku
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//mst,pq,mp,st,q
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n,m,k;
		cin>>n>>m>>k;
		int kk = k;
		int arr[n],brr[m];
		for(int i=0;i<n;++i)
		cin>>arr[i];
		for(int i=0;i<m;++i)
		cin>>brr[i];
		//int ct = 0;
		int pre1[n] = {};
		int pre2[m] = {};
		pre1[0] = arr[0];
		pre2[0] = brr[0];
		for(int i=1;i<n;++i)
		pre1[i] = pre1[i-1]+arr[i];
		for(int i=1;i<m;++i)
		pre2[i] = pre2[i-1]+brr[i];
		int maxx = 0,ct=0;
		for(int i=0;i<m;++i)
		{
			if(pre2[i]<=k)
			++ct;
		}
		maxx = ct;
		for(int i=0;i<n;++i)
		{
			if(k<pre1[i])
			break;
			int x = upper_bound(pre2,pre2+m,k-pre1[i]) - pre2;
			maxx = max(maxx,x+i+1);
		}
		cout<<maxx;
    }
    return 0;
}


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

int main(){
    int alpha[26] = {};
    string w;
    cin >> w;

    for(int i=0; i<w.size(); i++){
        alpha[w[i] - 'a']++;
    }
    for(int i=0; i<26; i++){
        if(alpha[i] % 2 != 0){
            puts("No");
            return 0;
        }
    }
    puts("Yes");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//#define int long long
//ask the right questions.  

//we have N vertices and M edges

// dp[i] means max length possible to reach vertex i (~item and not index) 
int dp[100001];


//LOGIC: if you are at vertex i then you could have reached there from finite incoming edges ending at i.
//then dp[i] is the maximum of (the maximum length to reach the node connecting i) for all incoming edges 
//and then we add 1 to connect i. 
//Our answer is maximum of dp[i] for all i.

//stores in a vector, all the edges which end at the vertex(KEY) 
map<int,vector<int>> edgesendsat;       


//since the dp equation is not exactly bottom up we use some sort of memoization.
//the code is identical and will go up a path until it finds the base case ie no incoming vertex at vertex i.
//the logic remains same as the main dp loop though.
void calculate(int i)
{
    vector<int> v = edgesendsat[i];
    int ans=0;
    for(int j=0;j<v.size();j++) 
    {
        //again if dp[v[j]]=-1 then further branch out to calculating that dp[v[j]]
        if(dp[v[j]]==-1)
            calculate(v[j]); 
        ans = max(ans, dp[v[j]]);    
    }
    dp[i] = 1 + ans;
}


int main()
{
    int N,M;
    cin >> N >> M;
    int x,y;
    for(int i=0;i<M;i++) 
    {
        cin >> x >> y;
        if(edgesendsat.find(y)!=edgesendsat.end()) 
        {
            edgesendsat[y].push_back(x);
        }
        else 
        {
            edgesendsat.insert({y,{x}});
        }
    }

    //trivial case : since vertex numbering starts from 1
    dp[0]=0;

    //base case: 
    for(int i=1;i<=N;i++) {
        dp[i]=-1;                                           //by default for memoization 
        if(edgesendsat.find(i)==edgesendsat.end())           
            dp[i]=0;    //means you cannot reach this vertex ie no incoming 
                        //edges to this vertex (may have outgoing edges though)
    }


    for(int i=1;i<=N;i++)
     {
        //we now construct our dp. 
        //we dont do it for no-incoming-edge vertices (base case) as they dont have any [KEY] in the map. 
        if(edgesendsat.find(i)!=edgesendsat.end()) 
        {
            vector<int> v = edgesendsat[i];
            int ans=0;
            for(int j=0;j<v.size();j++) 
            {
                //if dp[v[j]]=-1 then branch to calculating that dp[v[j]]
                //since we go in increasing i, all dp[k<i] have been updated (or are zero which were skipped
                //due to base case). Hence if we found a vertex in v whose state we have not seen before ie it
                //has v[j]>=i then we branch out to calculate and update it first.
                if(dp[v[j]]==-1)
                    calculate(v[j]); 
                ans = max(ans, dp[v[j]]);    
            }
            dp[i] = 1 + ans;
        }
    }
    

    //main answer   
    int ansterm=0;
    for(int i=1;i<=N;i++) {
        ansterm = max(ansterm, dp[i]);
    }
    cout << ansterm <<endl;

    return 0;
}



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

int k;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    vector <int> v={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};
    cin>>k;
    cout<<v[k-1];
    
    




    return 0;
}

Measured memory_bytes: 3596
n, m = map(int, input().split())
ml, mr = -1, -1
for _ in range(m):
    l, r = map(int, input().split())
    if ml == -1:
        ml = l
        mr = r
    else:
        if ml < l:
            ml = l
        if mr > r:
            mr = r
if mr - ml < 0:
    print(0)
else:
    print(mr - ml + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}// char to int
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}//MAX
int lcm(ll a,ll b){return a*b/gcd(a,b);}//MIN
 
int  main(){
ll a,b,c;
cin >> a >> b >> c;ll ans = 0;
ll aa,bb,cc;
    while(a%2==0&&b%2==0&&c%2==0){
        ll chea,cheb,chec;
        a/=2;
        b/=2;
        c/=2;
        chea=b+c;
        cheb=c+a;
        chec=a+b;
        a=chea;
        b=cheb;
        c=chec;
        if(a==c||b==c||b==a){
            ans = -1;
            break;
        }
        ans++;
    }
    cout << ans << endl;
}
 


Measured memory_bytes: 256
import queue

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

nexts = [[] for _ in range(N+1)]

for ab in AB:
    a,b = ab[0], ab[1]
    nexts[a].append(b)
    nexts[b].append(a)

ans = [0] * (N+1)

q = queue.Queue()
q.put(1)
while q.qsize() > 0:
    k = q.get()
    for i in nexts[k]:
        if ans[i] == 0:
            q.put(i)
            ans[i] = k

print('Yes')
for i in range(2,N+1):
    print(ans[i])


Measured memory_bytes: 124596
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N;
    cin >> N;
    int L, R, res{};
    REP( i, N )
    {
        cin >> L >> R;
        res += ( L == R ? 1 : R - L + 1 );
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ab =[list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda l: l[1])
t = 0
out = 'Yes'
for i in range(n):
  t += ab[i][0]
  if t > ab[i][1]:
    out = 'No'
    break
print(out)

Measured memory_bytes: 53728
#include<stdio.h>
	int main()
	{
		int A,B,C,D,Z;
		scanf("%d %d %d %d",&A,&B,&C,&D);
	    if(A<C)
	    {
	    	if(B>D)
	    	{
	    		Z=D-C;
	    		printf("%d\n",Z);
	    	}
	    	else
	   		{
	   			Z=B-C;
	   			if(Z>0)
	   				printf("%d\n",Z);
				else
					printf("0\n");
	   		}
	   }
	   else
	   {
	      	if(D>B)
	    	{
	    		Z=B-A;
	   			printf("%d\n",Z);
	   		}
	    	else
		    {
		    	Z=D-A;
		    	if(Z>0)
		    		printf("%d\n",Z);
		    	else
		   			printf("0\n");
		    }
	   }
		return 0;
	}

Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;
const ll MOD=1000000007LL;
int main(){
  ll n;
  cin>>n;
  vector<ll>a(n);
  rep(i,n)cin>>a[i];
  vector<ll>vec(3,-1);
  ll ans=1;
  rep(i,n){
    bool once=true;
    int count=0;
    rep(j,3){
      if(a[i]-1==vec[j]){
        count++;
        if(once){
          vec[j]=a[i];
          once=false;
        }
      }
    }
    ans*=count;
    ans%=MOD;
  }
  cout<<ans<<endl;
}
      

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

int main(){
  int n;
  cin >> n;
  string ans="Three";
  char s;
  for(int i=0;i<n;i++){
    cin >> s;
    if(s=='Y'){
      ans="Four";
    }
  }
  cout << ans;
}


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

int main(){
  int n;
  cin >> n;
  int i;
  for(i = 0; i < 10; i++){
    if(n % 1000 == 100 * i + 10 * i + i){
      cout << "Yes" << endl;
      return 0;
    }
    if(n / 10 == 100 * i + 10 * i + i){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  if (N >= 3200) cout << S << endl;
  else cout << "red" << endl;
}

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


int main() {
  double n; cin >> n;
  cout << fixed << setprecision(10);
  vector<pair<double,double>> p(n);
  vector<int> v(n);
  rep(i,n) {
    double x, y; cin >> x >> y;
    p[i] = make_pair(x,y);
    v[i] = i;
  }
  double ans = 0.0;
  int cnt=0;
  do {
    cnt++;
    rep(i,n-1) {
      double dx = p[v[i]].first - p[v[i+1]].first;
      double dy = p[v[i]].second - p[v[i+1]].second;
      ans += sqrt((dx*dx) + (dy*dy));
    }
  } while (next_permutation(v.begin(),v.end()));
  int f=1;
  for (int i = 2; i<=n; i++) f*=i;
  cout << ans / f << endl;
  return 0;
}

Measured memory_bytes: 3844
s = list(input())
ok = True
for i, c in enumerate(s):
    if i % 2 == 0 and (c not in list('RUD')):
        ok = False
    if i % 2 != 0 and (c not in list('LUD')):
        ok = False
if ok:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
# define ll long long int
#define mp	make_pair
#define pb	push_back
ll mod=1000000007;

int main() {
   
   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll n;
	cin>>n;
	ll k;
	cin>>k;
	int h[n+1];
	for(int i=1;i<=n;i++){
	   cin>>h[i];
	}
	int dp[n+1];
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[1]-h[2]);
   if(n>=k){
   	for(int i=3;i<=k;i++){
   	   dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
   	   for(int j=2;j<i;j++){
   	      dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
   	   }
   	}
   	for(int i=k+1;i<=n;i++){
   	      dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
   	      for(int j=2;j<=k;j++)
   	      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
   	}
	   
	}
	else{
	   for(int i=3;i<=n;i++){
   	   dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
   	   for(int j=2;j<i;j++){
   	      dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
   	   }
   	}
	}
	cout<<dp[n];
}

Measured memory_bytes: 1024
/* 
  ╔╗         ╔╗              ╔═══╗                                  
  ║║        ╔╝╚╗             ║╔═╗║                                  
  ║║╔╗╔╗╔══╗╚╗╔╝    ╔══╗     ║╚═╝║╔═╗╔══╗╔══╗╔═╗╔══╗ ╔╗╔╗╔╗╔╗╔══╗╔═╗
╔╗║║║║║║║══╣ ║║     ╚ ╗║     ║╔══╝║╔╝║╔╗║║╔╗║║╔╝╚ ╗║ ║╚╝║║╚╝║║╔╗║║╔╝
║╚╝║║╚╝║╠══║ ║╚╗    ║╚╝╚╗    ║║   ║║ ║╚╝║║╚╝║║║ ║╚╝╚╗║║║║║║║║║║═╣║║ 
╚══╝╚══╝╚══╝ ╚═╝    ╚═══╝    ╚╝   ╚╝ ╚══╝╚═╗║╚╝ ╚═══╝╚╩╩╝╚╩╩╝╚══╝╚╝ 
                                         ╔═╝║                       
                                         ╚══╝                       */


//Header files
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#ifndef ONLINE_JUDGE
#include<Personal/debug.h>
#else
#define debug(x...)
#endif

//Short data-types declaration
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vii;  
typedef vector<vector<long long> >vll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vbb;

//Macros
#define MK make_pair
#define EB emplace_back
#define PB push_back
#define F first
#define S second
#define rep(i,start,end) for(int i=(int)start;i<(int)end;i++)
#define repr(i,start,end) for(int i=(int)start;i>(int)end;i--)
#define all(x) (x).begin(), (x).end()

//Constants
const int mod = 1e9+7;

//Some useful functions
ll binpow(ll num,ll pow);
inline int mul(int a,int b) {return (a*1ll*b)%mod;}
inline int add(int a,int b) {return (a+0ll+b)%mod;}
inline int sub(int a,int b) {return ((a+0ll-b)%mod+mod)%mod; }
/*------------------------------------------------------Code Starts------------------------------------------------------*/
inline void solve()
{
	ll n;
	cin>>n;
	debug(__gcd(n,ll(10)),n);
	if(__gcd(n,ll(10))>1)
	{
		cout<<-1<<'\n';
		return;
	}
	ll num=7%n, ans=1;
	while(num!=0)
	{
		ans++;
		num=num*10+7;
		num%=n;
	}
	cout<<ans<<'\n';
}

int main()
{
	auto start = high_resolution_clock::now();
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start); 
	cerr<<duration.count()<<" microseconds\n";
	return 0;
}
/*------------------------------------------------------Code ends------------------------------------------------------*/
ll binpow(ll num,ll pow)
{
	if(pow==0)
		return 1;
	ll val=binpow(num,pow/2);
	val*=val;
	if(pow&1) val*=num;
	return val;
}



Measured memory_bytes: 3636
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in(),D=in();
	vector<vector<int>> X(N);
	REP(i,N){
		X[i].resize(D);
		REP(j,D){
			X[i][j] = in();
		}
	}
	int count = 0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			double dist = 0;
			REP(k,D) dist += pow(X[i][k]-X[j][k],2);
			dist = sqrt(dist);
			if((dist-floor(dist))<1e-5) count++;
		}
	}

	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second
#define pi pair<ll, ll>
#define PI 3.141592653589793238462643383279502884L
#define mp make_pair
#define pb push_back
#define fall(i, a, b) for (int i = a; i < b; i++)
#define sz(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define ed cout << "ed";
#define time_passed 1.0 * clock() / CLOCKS_PER_SEC
ll MOD = 1e9 + 7;
ll MOD1 = 1e9 + 123;
ll MOD2 = 1e9 + 321;
int main()
{
    fio;
    ll t, c, p, a, n, q, k, i, l, m, u, f, j, x, y, b, d;
  string S;
  cin>>S;

  if(S[S.length()-1]=='s')cout<<S+"es"<<endl;
  else
      cout << S + "s" << endl;
    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long x = sc.nextLong();
		Long currentDeposit = (long)100; 
		Long yearElapse = (long)0;
		
		while(x > currentDeposit) {
			currentDeposit = (long)(currentDeposit * 1.01);
			yearElapse ++;
		}
		System.out.println(yearElapse);
	}
}

Measured memory_bytes: 35940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[][] x = new int[n][];
        int[][] y = new int[n][];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            x[i] = new int[a[i]];
            y[i] = new int[a[i]];
            for (int j = 0; j < a[i]; j++) {
                x[i][j] = sc.nextInt();
                y[i][j] = sc.nextInt();
            }
        }
        int max = 1;
        for (int i = 0; i < n; i++) {
            max *= 2;
        }
        int ans = 0;
        for (int i = 0; i < max; i++) {
            boolean isOk = true;
            int counter = 0;
            for (int j = 0; j < n; j++) {
                int isRight = (i >> j) % 2;
                // System.out.print(isRight);
                if (isRight == 1) {
                    for (int k = 0; k < a[j]; k++) {
                        if (y[j][k] == 1) {
                            // System.out.println("judge:" + (i >> (x[j][k] - 1)) % 2);
                            if ((i >> (x[j][k] - 1)) % 2 != 1) {
                                // NG
                                isOk = false;
                            } else {
                                counter++;
                            }
                        } else {
                            if ((i >> (x[j][k] - 1)) % 2 != 0) {
                                // NG
                                isOk = false;
                                // } else {
                                // counter++;
                            }
                        }
                    }
                }
            }
            // if (isOk && counter > ans) {
            // ans = counter;
            // // System.out.println("counter:" + counter);
            // }
            if (isOk) {
                int newCounter = 0;
                for (int j = 0; j < n; j++) {
                    int isRight = (i >> j) % 2;
                    if (isRight == 1) {
                        newCounter++;
                    }
                }
                if (newCounter > ans) {
                    ans = newCounter;
                }
            }
            // System.out.println();
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()
#define re(v) reverse(v.begin(),v.end())
#define so(v) sort(v.begin(),v.end())
#define vi(v) vector<int> v
#define CV(v) for(auto i : v) cout << i << " ";cout << endl

using namespace std;
typedef long long ll;




int main()
{
    
    int N,M;
    cin >> N >> M;
    string S;
    cin >> S;
    
    re(S);
    vi(ans);
    int now = 0;
    
    while (now != N) {
        int a = now,b = -1;
        for (int i = 1; i <= M; i++) {
            if(S[now+i]=='0'){
                a = now+i;
                b = i;
                if(a == N){
                    now = a;
                    ans.push_back(b);
                    re(ans);
                    CV(ans);
                    return 0;
                }
            }
        }
        
        if(a == now){
            cout << -1 << endl;
            return 0;
        }
        
        now = a;
        ans.push_back(b);
        
        
    }
    
   
    
    return 0;
}




Measured memory_bytes: 1144
#include <iostream>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;

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

    if (n < m) swap(n, m);

    if (n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if (m == 1) {
        cout << max(0ll, n - 2) << endl;
        return 0;
    }

    cout << (n - 2) * (m - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    if(a > k){
        cout << k;
    }else if(a+b > k){
        cout << a;
    }else{
        cout << a - (k-a-b);
    }

    return 0;
}

Measured memory_bytes: 3636
h, w = map(int, input().split())
m = [[] for _ in range(h)]
x = [False] * h
y = [False] * w
for i in range(h):
    m[i] = list(input())
    if "#" in m[i]:
        x[i] = True
zm = list(zip(*m))
for i, j in enumerate(zm):
    if "#" in j:
        y[i] = True
M = []
for i, H in enumerate(x):
    for v, W in enumerate(y):
        if H and W:
            M.append(m[i][v])
    if M:
        print("".join(M))
    M = []


Measured memory_bytes: 9308
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;


ll dp[55][2];
ll a[55];

int main(){
    int n, p;
    cin >> n >> p;
    rep(i, n) cin >> a[i];

    dp[0][0] = 1;

    for (int i = 1; i <= n; i++){
        if (a[i] % 2 == 0){
            dp[i][0] = 2 * dp[i-1][0];
            dp[i][1] = 2 * dp[i-1][1];
        }
        else {
            dp[i][0] = dp[i-1][0] + dp[i-1][1];
            dp[i][1] = dp[i-1][1] + dp[i-1][0];
        }
    }

    // rep(i, n) cout << dp[i][0] << " ";
    // cout << endl;
    // rep(i, n) cout << dp[i][1] << " ";
    // cout << endl;    

    cout << dp[n][p] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
  String r = sc.next();
  char[] a = r.toCharArray();
  String s = sc.next();
  long n = Long.parseLong(s);
  boolean b = true;
  char c = 'a';
  out:
  for(int i = 0;i < r.length();i++){
    c = a[i];
    if(c != '1'){
      if(n < i+1){
        break out;
      }
      else{
      b = false;
      break out;
      }
    }
  }
  System.out.println(b? "1":c);
}
}
      

Measured memory_bytes: 22356
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    vector<ll>x(n);
    rep(i,n)cin>>x[i];
    ll l,q;cin>>l>>q;
    vector<ll>nxt(n);
    vector<pll>b(0);
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            b.pb(mp(-x[i],i));
            nxt[i]=i;
            continue;
        }
        pll k=*lower_bound(all(b),mp(-x[i]-l,-1LL));
        nxt[i]=k.second;
        b.pb(mp(-x[i],i));
    }
    vector<vector<ll> >dp(n,vector<ll>(32));
    rep(i,n)dp[i][0]=nxt[i];
    REP(i,1,32){
        rep(j,n){
            dp[j][i]=dp[dp[j][i-1]][i-1];
        }
    }
    rep(i,32){
        //cout<<dp[0][i]<<endl;
    }
    while(q){
        q--;
        ll a,b;cin>>a>>b;
        a--;b--;
        if(a>b){
            swap(a,b);
        }
        ll l=0,r=n;
        while(r-l>1){
            ll mid=(r+l)/2;
            ll x=a;
            rep(j,32){
                if(mid&(1LL<<j)){
                    x=dp[x][j];
                }
            }
            if(q==3){
                //cout<<mid<<' '<<a<<' '<<b<<endl;
            }
            if(x>=b)r=mid;
            else l=mid;
        }
        cout<<r<<endl;
    }
}

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

int main() {
  ll X;
  cin >> X;
  ll sum = 100;
  ll count = 0;

  while(sum < X) {
    sum += sum * 0.01;
    count++;
  }

  cout << count;
  return 0;
}


Measured memory_bytes: 3624
/*
[arc097] D - Equals
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;
const int MAX_M = 100000;

class UnionFind {
public:
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (data[y] < data[x]) {
            swap(x, y);
        }
        data[x] += data[y];
        data[y] = x;

        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : (data[x] = root(data[x])); }
    int size(int x) { return -data[root(x)]; }
};

int N, M;
int p[MAX_N];
pii xy[MAX_M];

int solve() {
    UnionFind uf(N);

    for (int i = 0; i < M; i++) {
        uf.unite(xy[i].first, xy[i].second);
    }

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (uf.same(i, p[i])) {
            cnt++;
        }
    }

    return cnt;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < M; i++) {
        cin >> xy[i].first >> xy[i].second;
        xy[i].first--;
        xy[i].second--;
    }

    cout << solve() << endl;

    return 0;
}


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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int D;
    cin >> D;
    vecInt c(26);
    rep(i,0,26) cin >> c[i];
    vector<vecInt> s(D,vecInt(26));
    rep(i,0,D) rep(j,0,26) cin >> s[i][j];
    vecInt last(26);
    vecInt ans(D,1);
    rep(i,0,D){
        ll score = -INF;
        int l;
        rep(j,0,26){
            ll res = s[i][j];
            rep(k,0,26){
                if (k==j) continue;
                res -= c[k] * ((j + 1) - last[k]);
            }
            if (res>score){
                score = res;
                l = j;
                ans[i] = j + 1;
            }
        }
        last[l] = i + 1;
    }
    rep(i,0,D) cout << ans[i] << endl;
    /*
    rep(i,0,D){
        score += s[i][t[i]-1];
        last[t[i]-1] = i + 1;
        rep(j,0,26){
            if (j==t[i]-1) continue;
            score -= c[j] * ((i + 1) - last[j]);
        }
        cout << score << endl;
    }
    */
    return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>
int Search(int S[],int n,int T){
  int i=0;
  S[n]=T;
  while(S[i] != T)i++;
  return i != n;
}

int main(){
  int n,S[10000+1],q,T,i,count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T);
    if( Search(S, n, T))
       count++;
  }
  printf("%d\n",count);
  return 0;
}



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

int main(){
  int n = 0;
  int h[100000] = {};
  int i = 0;
  int k = 0;
  int flag = 0;
  scanf("%d",&n);
  for(i = 0;i<n;i++){
    scanf("%d",&h[i]);
  }
  
  for(i = 0;i < n-1;i++){
   	if(h[n-1-i]<h[n-2-i]){
      h[n-2-i]--;
      if(h[n-1-i]<h[n-2-i]){
        flag = 1;
        break;
      }
    }
  }
  if(flag){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}
    
	



Measured memory_bytes: 512
N, A, B = map(int, input().split())

def ksum(N):
  Nlist = list(map(int, str(N)))
  return sum(Nlist)

numlist = []

for i in range(1, N+1):
  if ksum(i) >= A and ksum(i) <= B:
    numlist.append(i)
    
print(sum(numlist))

Measured memory_bytes: 3404
#include<iostream>
#include<string>
#include<algorithm>
const char east = 'E';
const char west = 'W';

int main(){
  int N;
  std::string S;
  std::cin >> N >> S;

  //一番左の人がリーダーの場合に向きを変える人の数を数える
  int changeCnt = 0;
  for(int i=1;i<N;i++) {
    if (S.at(i)==east) changeCnt++;
  }

  //リーダーを右の人に一人ずつずらしカウントの変化を比較
  int minChangeCnt = changeCnt;
  for(int i=1;i<N;i++) {
    if (S.at(i)==east) changeCnt--;
    if (S.at(i-1)==west) changeCnt++;
    minChangeCnt = std::min(minChangeCnt,changeCnt);
  }

  std::cout << minChangeCnt << '\n';

  return 0;
}


Measured memory_bytes: 900
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXN = 100005;
int a[MAXN], seen[MAXN];

LL fact[MAXN], inv[MAXN], factinv[MAXN];

LL mul(LL x, LL y) {
    return (x * y) % MOD;
}

void add(LL& x, LL y) {
    x += y;
    if (x >= MOD) x -= MOD;
}

void sub(LL& x, LL y) {
    x -= y;
    if (x < 0) x += MOD;
}

LL choose(LL x, LL y) {
    return mul(fact[x], mul(factinv[y], factinv[x-y]));
}

int n;

int main() {
    GI(n);

    memset(seen, 0, sizeof seen);

    int dup = -1, p = -1, q = -1;

    FOR1(i, n+1) {
        GI(a[i]);

        if (seen[a[i]]) {
            dup = a[i];
            q = i;
        }

        seen[a[i]] = 1;
    }

    FOR1(i, n+1) {
        if (a[i] == dup) {
            p = i;
            break;
        }
    }

    fact[0] = 1; for (int i = 1; i < MAXN; i++) fact[i] = mul(i, fact[i-1]);
    inv[0] = inv[1] = 1; for (int i = 2; i < MAXN; i++) { inv[i] = (MOD - (MOD / i) * inv[MOD % i] % MOD) % MOD; }
    factinv[0] = 1; for (int i = 1; i < MAXN; i++) factinv[i] = mul(inv[i], factinv[i-1]);

    FOR1(k, n) {
        LL res = 0;

        add(res, choose(n-1, k));

        if (k-1 >= 0) {
            add(res, mul(2, choose(n-1, k-1)));
            if (n-q+p >= k-1) sub(res, choose(n-q+p, k-1));
        }
        if (k-2 >= 0) {
            add(res, choose(n-1, k-2));
        }

        cout << res << "\n";
    }
    cout << 1 << "\n";

    return 0;
}


Measured memory_bytes: 4352
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
ans = [0] * n
for i in a:
    ans[i - 1] += 1
print(*ans)


Measured memory_bytes: 27760
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n,m,ans,a[N],f[N];
int find(int x){
	if(x==f[x])return x;
	return f[x]=find(f[x]);
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		f[i]=i;
	}
	for(int i=1;i<=m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		f[find(x)]=find(y);
	}
	for(int i=1;i<=n;i++)
		if(find(i)==find(a[i]))ans++;
	printf("%d",ans);
	return 0;
} 

Measured memory_bytes: 4568
#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
int n,a[maxn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	bool ok=true;
	for(int i=2;i<=n;i++)
		if(a[i]<a[i-1])
		{
			ok=false;
			break;
		}
	if(ok)
	{
		puts("YES");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			swap(a[i],a[j]);
			bool flag=true;
			for(int k=2;k<=n;k++)
				if(a[k]<a[k-1])
				{
					flag=false;
					break;
				}
			if(flag)
			{
				puts("YES");
				return 0;
			}
			swap(a[i],a[j]);
		}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){
    int a, b;
    cin >> a >> b;
    cout << a + (b / 2) << endl;

    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline ll read()
{
	ll re=0,flag=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll n;
ll m=200000;
struct BIT
{
	ll a[200010];
	void clear()
	{
		memset(a,0,sizeof(a));
	}
	ll lowbit(ll x)
	{
		return x&(-x);
	}
	void add(ll x,ll val)
	{
		for(; x<=m; x+=lowbit(x)) a[x]+=val;
	}
	ll sum(ll x)
	{
		ll re=0;
		for(; x>0; x-=lowbit(x)) re+=a[x];
		return re;
	}
} T;
struct ele
{
	ll val,num;
} a[100010];
ll w[100010];
bool cmp1(ele l,ele r)
{
	return l.val<r.val;
}
bool cmp2(ele l,ele r)
{
	return l.num<r.num;
}
ll x[100010];
ll lim;
bool check(ll val)
{
	ll i;
	ll sum=0,re=0;
	T.clear();
	for(i=1; i<=n; i++)
	{
		if(a[i].val<val) x[i]=-1;
		else x[i]=1;
	}
	T.add(100000,1);
	for(i=1; i<=n; i++)
	{
		sum+=x[i];
		re+=T.sum(sum+100000);
		T.add(sum+100000,1);
	}
	return re>=(lim/2+lim%2);
}
int main()
{
	ll i;
	n=read();
	lim=n*(n+1)/2;
	for(i=1; i<=n; i++) a[i].val=read(),a[i].num=i;
	sort(a+1,a+n+1,cmp1);
	for(i=1; i<=n; i++) w[i]=a[i].val;
	sort(a+1,a+n+1,cmp2);
	ll l=1,r=n,mid;
	while(l<r)
	{
		mid=(l+r)>>1;
		mid++;
		if(check(w[mid])) l=mid;
		else r=mid-1;
	}
	printf("%lld\n",w[l]);
}

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

if N == 1:
    print(0)
elif N == 2:
    print(2)
else:
    a = 10 ** 2
    b = 2 * 9 ** 2
    c = 8 ** 2
    mod = 10 ** 9 + 7
    ans = 0
    for i in range(N-2):
        a = a * 10 % mod
        b = b * 9 % mod
        c = c * 8 % mod
        ans = a - b + c
        ans %= mod
    print(ans)


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

int main() {
	int r,c ;
	cin >> r >> c;
	
	int matrix[r+1][c+1];
	matrix[r][c]=0;
	for(int i=0; i<r; i++){
		matrix[i][c]=0;
		for(int j=0; j<c; j++){
			if(i==0)matrix[r][j]=0;
			cin >> matrix[i][j];
			cout << matrix[i][j] << " ";
			matrix[r][j]+=matrix[i][j];
			matrix[i][c]+=matrix[i][j];
			matrix[r][c]+=matrix[i][j];
		}
		cout<<matrix[i][c]<<endl;
		
	}
	
	for(int i=0;i<c;i++){
		cout<<matrix[r][i]<<" ";
	}
	cout<< matrix[r][c]<<endl;
	
	return 0;
}

Measured memory_bytes: 1200
def kyori(l1,l2):
    l=sum([(l1[i]-l2[i])**2 for i in range(len(l1))])
    if l**0.5==int(l**0.5):
        return 1
    else:
        return 0

def resolve():
    n,d=map(int,input().split())
    x=[list(map(int,input().split())) for i in range(n)]
    ans=0
    for i in range(n):
        for j in range(i+1,n):
            ans+=kyori(x[i],x[j])
    print(ans)
resolve()

Measured memory_bytes: 38256
#include<iostream>
#include<iomanip>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;
const long long INF = 9223372036854775807;
const int MAX = 50;

int main() {
	int N, K;
	vector<pair<long long, long long>> point;
	long long ans = INF;

	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		long long x, y;
		cin >> x >> y;
		point.push_back(make_pair(x, y));
	}

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

	for (int b = 0; b < N - 1; b++) {
		for (int e = b + 1; e < N; e++) {

			vector<long long> py;
			for (int i = b; i <= e; i++) {
				py.push_back(point[i].second);
			}

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

			long long x = abs(point[b].first - point[e].first);
			long long y = INF;

			for (int i = 0; i < (int)py.size() - (K - 1) ; i++) {
				y = min(abs(py[i + (K - 1)] - py[i]), y);
			}

			if (y == INF)continue;
			ans = min(ans, x * y);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1000000007;

int main() {
    ll n, m;
    cin>>n>>m;
    vector<ll> a(n),b(m);
    vector<vector<ll>> dp(n+1, vector<ll>(m+1,1));
    for(ll i=0; i<n; i++) cin>>a[i];
    for(ll j=0; j<m; j++) cin>>b[j];

    for(ll i=0; i<n; i++){
        for(ll j=0; j<m; j++){
            dp[i+1][j+1]=dp[i+1][j] + dp[i][j+1] - dp[i][j];
            if(a[i]==b[j]) dp[i+1][j+1]+=dp[i][j];
            dp[i+1][j+1] += mod;
            dp[i+1][j+1] %= mod;
        }
    }
    cout<<dp[n][m]<<endl;
    
    // for(ll i=0; i<=n; i++){
    //     for(ll j=0; j<=m; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

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

Measured memory_bytes: 256