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

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
		    nodes[i] = new Node(i);
		}
		for (int i = 0; i < n; i++) {
		    int x = sc.nextInt();
		    int left = sc.nextInt();
		    int right = sc.nextInt();
		    nodes[x].left = left;
		    nodes[x].right = right;
		    if (left >= 0) {
		        nodes[left].sibling = right;
		        nodes[left].parent = x;
		    }
		    if (right >= 0) {
		        nodes[right].sibling = left;
		        nodes[right].parent = x;
		    }
		}
		for (Node x : nodes) {
		    if (x.parent == -1) {
		        set(nodes, x.idx, 0);
		        break;
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (Node x : nodes) {
		    sb.append(x).append("\n");
		}
		System.out.print(sb);
	}
	
	static int set(Node[] nodes, int idx, int depth) {
	    nodes[idx].depth = depth;
	    int max = 0;
	    if (nodes[idx].left >= 0) {
	        max = Math.max(max, set(nodes, nodes[idx].left, depth + 1));
	    }
	    if (nodes[idx].right >= 0) {
	        max = Math.max(max, set(nodes, nodes[idx].right, depth + 1));
	    }
	    nodes[idx].height = max;
	    return max + 1;
	}
	
	static class Node {
	    int idx;
	    int parent;
	    int depth;
	    int height;
	    int sibling;
	    int left;
	    int right;

	    public Node(int idx) {
	        this.idx = idx;
	        parent = -1;
	        sibling = -1;
	        left = -1;
	        right = -1;
	    }
	    
	    private int getDegree() {
	        int ans = 0;
	        if (left >= 0) {
	            ans++;
	        }
	        if (right >= 0) {
	            ans++;
	        }
	        return ans;
	    }
	    
	    public String toString() {
	        StringBuilder sb = new StringBuilder();
	        sb.append("node ").append(idx).append(": parent = ");
	        sb.append(parent).append(", sibling = ").append(sibling).append(", degree = ").append(getDegree());
	        sb.append(", depth = ").append(depth).append(", height = ").append(height).append(", ");
	        if (parent == -1) {
	            sb.append("root");
	        } else if (getDegree() == 0) {
	            sb.append("leaf");
	        } else {
	            sb.append("internal node");
	        }
	        return sb.toString();
	    }
	}
}



Measured memory_bytes: 26360
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int n, a, b;

int main(){
	cin >> n >> a >> b;
	if((a-b)%2 == 0){
		cout << "Alice" << endl;
	}
	else{
		cout << "Borys" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
while 1:
  a, op, b = input().split()
  a = int(a)
  b = int(b)

  if op == '+':
    print(a+b)
  elif op == '-':
    print(a-b)
  elif op == '*':
    print(a*b)
  elif op == '/':
    print (int(a/b))
  else:
    break;


Measured memory_bytes: 5596
#include <stdio.h>

int main() {

  int M, N, C, i = 0, j = 0, check = 0, count = 0;
  int array[21][21];
  int B[21];

  scanf("%d %d %d", &N, &M, &C);

  for(i = 0; i < M; i++) {
    scanf("%d", &B[i]);
  }

  for(i = 0; i < N; i++) {
    for(j = 0; j < M; j++) {
      scanf("%d", &array[i][j]);
      check += array[i][j] * B[j];
    }
    check += C;
    if(check > 0) {
      count++;
    }
    check = 0;
  }

  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
	int cars[10];
	int carsnum=0;
	int sousa;
	while(!feof(stdin)) {
		scanf("%d",&sousa);
		if(feof(stdin))break;
		if(sousa==0) {
			carsnum--;
			printf("%d\n",cars[carsnum]);
		} else {
			cars[carsnum]=sousa;
			carsnum++;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

string s;

int n;

bool pos(int len)
{
    if(len <= (n >> 1))
        return 1;

    int st = n - len + 1;
    int dr = len;
    int sum = 0;
    for(int i = st; i <= dr; i ++)
        sum += s[i - 1] - '0';

    return (sum == 0 || sum == dr - st + 1);
}

int cautBin()
{
    int i = 0;
    int pas = 1 << 20;
    while(pas != 0)
    {
        if(i + pas <= n && pos(i + pas))
            i += pas;

        pas >>= 1;
    }

    return i;
}

int main()
{
    cin >> s;

    n = s.size();

    cout << cautBin() << "\n";

    return 0;
}


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

int main() {
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if(r>x){
    cout << "No" << endl;
  }
  else if(r>y){
    cout << "No" << endl;
  }
  else if(W<x+r){
    cout << "No" << endl;
  }
  else if(H<y+r){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back



using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;


int main(){
	fast_io; cout_precision;
	int n;	cin >>n ;	int arr[n];	for(int i=0; i<n; i++)	cin >> arr[i];
	int dp[n];	for(int i=0; i<n; i++)	dp[i]  = 1;	
	int prev = dp[n-1];
	for(int i=n-2; i>=0; i--){
		if(arr[i] >= arr[i+1]){
			dp[i] = 1 + dp[i+1];
		}
	}
	int M=INT_MIN;
	for(int i=0; i<n; i++)	M = max(M , dp[i]);
	cout<<M-1;
	
	return 0;
}

Measured memory_bytes: 1024
/*input
10
90 52 56 71 44 8 13 30 57 84
*/
#include <bits/stdc++.h>
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;
long long power(long long a,long long p,long long m=1e17+7,long long k=0){
	return p?k=power(a,p/2,m),(k*k%m)*(p&1?a:1)%m:1;
}
int main(){
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	#endif
	long long q,m,k,h,ans=0,sum=0,p,x=1,y;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
		a[i]%=2;
	}
	for(int i=1;i< 1<<n ;++i){
		sum=0,p=1;
		for(int j=0;j<n;++j){
			if(i&(1<<j)) p*=(a[j]?2:1);
			else p*=(a[j]?1:2);
			sum^=i&(1<<j);
		}
		if(sum) ans+=p;
		else ans-=p;
	}
	cout<<ans;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
int main(void){
int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(b-c>=0){printf("delicious");}
  if(b-c<0&&a-abs(b-c)>=0){printf("safe");}
  if(b-c<0&&a-abs(b-c)<0){printf("dangerous");}
  
return 0;
}

Measured memory_bytes: 128
// use proconio::input;
use std::io;

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut line = String::new();
    io::stdin().read_line(&mut line)
        .ok()
        .expect("Faild to read Vec");
    line.trim().split_whitespace()
        .map(|i| i.parse().ok().unwrap()).collect()
}

fn main() {
    loop {
        // input! {
        //     x: i32,
        //     y: i32,
        // }
        let vec = read_vec::<i32>();
        let x = vec[0];
        let y = vec[1];

        if x == 0 && y == 0 { break; }
        if x < y {
            println!("{} {}", x, y);
        } else {
            println!("{} {}", y, x);
        }
    }
}


Measured memory_bytes: 5032
n,p=map(int,input().split())
l=list(map(int,input().split()))
l=[i%2 for i in l]
nodd=sum(l)
neven=n-nodd
ans=2**(neven+max(0,nodd-1))
if p==1:
    ans=2**n-ans
print(ans)

Measured memory_bytes: 3064
#include <cstdio>

typedef long long LL;
const int Mod = 1000000007;
const int MN = 15;

int N, M, A[MN][MN];
int w[MN * MN];
int c[1 << MN][MN], f[1 << MN];

int main() {
	scanf("%d%d", &N, &M), w[0] = 1;
	for (int i = 1; i <= M; ++i) w[i] = 2 * w[i - 1] % Mod;
	for (int i = 1, x, y; i <= M; ++i) scanf("%d%d", &x, &y), A[--x][--y] = 1;
	for (int S = 1; S < 1 << N; ++S) {
		int j = 0;
		while (~S >> j & 1) ++j;
		for (int u = 0; u < N; ++u)
			c[S][u] = c[S ^ 1 << j][u] + A[u][j];
	}
	for (int S = 0; S < 1 << N; ++S) if ((S & 3) == 3) {
		f[S] = 1;
		for (int T = S & (S - 1); T; --T &= S) if ((T & 1) == (T >> 1 & 1)) {
			if (T & 1) {
				int Coef = 1;
				for (int i = 0; i < N; ++i) if (S >> i & 1) {
					if (T >> i & 1) Coef = (LL)Coef * (w[c[S ^ T][i]] - 1) % Mod;
					else Coef = (LL)Coef * w[c[T][i]] % Mod;
				}
				f[S] = (f[S] + (LL)Coef * f[T]) % Mod;
			} else {
				int Coef = 1;
				for (int i = 0; i < N; ++i) if (S >> i & 1) {
					if (T >> i & 1) Coef = (LL)Coef * (w[c[S ^ T][i]] - 1) % Mod * w[c[T][i]] % Mod;
					else Coef = (LL)Coef * w[c[T][i]] % Mod;
				}
				f[S] = (f[S] + Coef) % Mod;
			}
		}
	}
	printf("%d\n", (w[M] - f[(1 << N) - 1] + Mod) % Mod);
	return 0;
}

Measured memory_bytes: 3760
// 条件を満たすB以下の整数の個数から
// 条件を満たすA-1以下の整数の個数の差が答え

// B以下の整数の個数(1)は，B以下の整数の個数/B個(2)から
// B以下のCの倍数の個数(3)と，
// B以下のDの整数の個数(4)を引き，重複(5)を足し戻す．

// B以下のC,Dの倍数の個数は，B/C,B/Dの小数点以下切り捨てで求められる．

// また，重複は，C,Dの最小公倍数をlとすると，
// B/lの小数点以下切り捨てで求められる．

// l(6)は，C,Dの最大公約数をgとすると，
// CD/gと求められる．

// g(7)はユークリッドの互除法から求められる．

//(1) = (2) - (3) - (4) + (5)
//(5) = B / (6)
//(6) = CD / (7)
//(7) = euclid(C,D)

#include<iostream>
using namespace std;

long long euclid(const long long& a, const long long& b){
    if(a % b == 0)return b;
    return euclid(b, a%b);
}

int main(){
    long long A, B, C, D;

    cin >> A >> B >> C >> D;

    cout <<(B - ((B/C) + (B/D)) + (B /((C*D) / euclid(C,D)))) -
    ((A-1) - (((A-1)/C) + ((A-1)/D)) + ((A-1) /((C*D) / euclid(C,D))));
}

Measured memory_bytes: 256
def solve(string):
    n, *a = map(int, string.split())
    a = ["{:060b}".format(_a) for _a in a]
    m = 10**9 + 7
    ans = 0
    for i, d in enumerate(zip(*a)):
        # s = "".join(d).count("1")
        s = d.count("1")
        ans += s * (n - s) * pow(2, 59 - i, m)
        ans %= m
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 75128
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

char c;
inline void solve(){
  IN(c);
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')OUT("vowel");
  else OUT("consonant");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt

  val table = Array.ofDim[Long](n+1)
  val a = in.readLine.split(" ").map(_.toLong)
  (0 until n).foreach { i =>
    table(i+1) = table(i) + a(i)
  }

  val ans = (1 until n)./:(Int.MaxValue.toLong) { (acc, i) =>
    acc min ( table(i) - (table(n) - table(i)) ).abs
  }
  
  println(ans)
}

Measured memory_bytes: 57080
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')
cnt = 0
for j in range(n-2):
  sj = s[j]
  for i in range(1, (n-j)//2+1):
    if n <= j+2*i:
      break
    sd = s[j+i]
    sd2 = s[j+2*i]
    if (sj != sd) and (sj != sd2) and (sd != sd2):
      cnt += 1
print(r*g*b - cnt)

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > Matrix;

int main() {
	string s;
	int i;

	cin >> s;
	rep(i, 3) {
		if (s[i] == s[i + 1]) {
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";

	return 0;
}


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

#define N_MAX 100002

using namespace std;

const int INF = 1e9+1;

int n, k;

int h[N_MAX];

int dp[N_MAX];

int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> h[i];
    dp[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        dp[i] = INF;
        for(int j = 1; j <= min(i - 1, k); j++)
            dp[i] = min(dp[i], abs(h[i] - h[i - j]) + dp[i - j]);
    }
    cout << dp[n] << "\n";
    return 0;
}


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

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

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

namespace ConsoleApp15
{
    class Class307
    {
        static void Main()
        {
            const long mod = 1000000007;

            var nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int n = nk[0];
            int k = nk[1];

            long[] D = new long[n + 2];
            for (int i = 1; i <= n+1; i++)
                D[i] = D[i - 1] + (i-1);
            long[] E = new long[n + 2];
            for (int i = 1; i <= n+1; i++)
                E[i] = E[i - 1] + (n - i + 1);

            long ans = 0;
            for(int i = k; i <= n; i++)
            {
                ans += E[i] - D[i]+1;
                ans %= mod;
            }
            Console.WriteLine((ans+1)%mod);
        }
    }
}


Measured memory_bytes: 30576
S = input()
N = len(S)
K = int(input())

if len(set(S)) == 1 or len(S) == 1:
    ans = K * len(S) // 2
    print(ans)
    exit()

left = 0
right = 1

while left < N and S[left] == S[0]:
    left += 1
while right <= N and S[-right] == S[-1]:
    right += 1
right -= 1

change = 0
isChanged = False
T = list(S[::])

for i, t in enumerate(T[1:], start=1):
    if t == T[i - 1]:
        if not isChanged:
            change += 1
            isChanged = True
            continue
    isChanged = False

ans = change * K

if S[0] == S[-1]:
    ans -= (left // 2 - (left + right) // 2 + right // 2) * (K - 1)
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>

using namespace std;

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
 int solve()
 {
int n,a,b;
cin>>n>>a>>b;
cout<<min(a,b)<<" "<<max(0,a+b-n);

return 0;
}


int main()
{  int t=1;


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

  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;
    bool flag=true;
   while(t--)
     { 
      solve();
     }

         time_req = clock() - time_req;
   // cout << "Processor time taken is "
     //  << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}


Measured memory_bytes: 256
import sys
from collections import Counter

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
counter = Counter(A)
total = sum(x*(x-1)//2 for x in counter.values())
for a in A:
    x = counter[a]
    temp = total
    temp -= x * (x-1) // 2
    if x > 2:
        temp += (x-1) * (x-2) // 2
    print(temp)


Measured memory_bytes: 26780
n = int(input())

if 1 <= n <= 9:
  print(n)
elif n <= 99:
  print(9)
elif n <= 999:
  print(n - 90)
elif n <= 9999:
  print(909)
elif n <= 99999:
  print(n - 9090)
else:
  print(90909)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
int main( void )
{
    int A[3];
    std::cin >> A[0] >> A[1] >> A[2];
    std::sort( A, A+3 );
    std::cout << A[0] << " " << A[1] << " " << A[2] << std::endl;
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define jam(t) cout<<"Case #"<<t<<": "
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007ll
#define sz 400005
#define bitcnt(x) __builtin_popcountll(x)
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}



void solve(){
    string s;
    cin >> s;
    for(auto c:s){
        if(c =='7'){
            g("Yes");
            return;
        }
    }
    g("No");
}
int main()
{
#ifndef ONLINE_JUDGE
input_from_file
#endif
 
    FASTIO
    cin.tie(NULL);
    fflush(stdout);
    ll t = 1;
  //  cin >> t;
    for(ll tcase = 1;tcase <= t;tcase++){
        solve();
        
    }
return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](int a, int b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
bool rev(string s){
  string s2=s;
  reverse(s.begin(),s.end());
  if(s==s2){return true;}
  else{return false;}
}
int main() {
  string s;
  cin >> s;
  int length = s.size()/2;
  if(rev(s.substr(0,length))&&rev(s)&&rev(s.substr(length+1))){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
from collections import deque

s = deque(list(input()))
n = int(input())
q = [list(input().split()) for _ in range(n)]
rev = False

for tfc in q:
    if tfc[0] == "1" and rev is False:
        rev = True
    elif tfc[0] == "1" and rev is True:
        rev = False
    elif rev is False:
        if tfc[1] == "1":
            s.appendleft(tfc[2])
        else:
            s.append(tfc[2])
    elif rev is True:
        if tfc[1] == "1":
            s.append(tfc[2])
        else:
            s.appendleft(tfc[2])

if rev:
    s.reverse()
print("".join(s))


Measured memory_bytes: 34792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cmath>
using namespace std;
int main()
{
	long long n;
	scanf("%lld",&n);
	long long a[n+1];
	long long b[n+1];
	for(int i=0;i<n+1;i++)
	{
		cin >> a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin >> b[i];
	}
	long long sum=0;
	for(int i=0;i<n;i++)
	{
		if(b[i]<a[i])sum+=b[i],b[i]=0,a[i]=a[i]-b[i];
		else sum+=a[i],b[i]=b[i]-a[i],a[i]=0;
		if(b[i]<a[i+1])sum+=b[i],a[i+1]=a[i+1]-b[i],b[i]=0;
		else sum+=a[i+1],a[i+1]=0,b[i]=b[i]-a[i+1];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <algorithm>
using namespace std;

int v[1024];
long long w[1024];
int dp[100][10001];

int main(void) {
	int N;
	long long W;
	
	scanf("%d %lld", &N, &W);
	for (int i = 0; i< N; i++) {
	    scanf("%d %lld", &v[i], &w[i]);
	}
	
/*	for (int i = 0; i < N; i++) {
		scanf("%d %d", &w[i], &v[i]);
	}
	*/
	int V = 0;
	
	for(int i = 0; i < N; i++) {
		V += v[i]; 
	}
	int inf = 1000000000;
	dp[0][0] = 0;
	for(int i = 1; i <= V; i++) {
		if (i <= v[0]) {
			dp[0][i] = w[0];
		} else {
			dp[0][i] = inf;
		}
	}
	
	for(int i = 1; i < N; ++i) {
		for(int j = 0; j <= V; j++) {
			dp[i][j] = dp[i - 1][j];
			int left_cost = 0;
			if(j - v[i] > 0) {
				left_cost = j - v[i];
			}
			if(dp[i][j] > dp[i-1][left_cost] + w[i]) {
				dp[i][j] = dp[i - 1][left_cost] + w[i];
			}

		}
	}
	for (int i = V; i >= 0; i--) {
		if(dp[N - 1][i] <= W) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}
				


Measured memory_bytes: 6608
# -*- coding: utf-8 -*-
import sys
import math
input = sys.stdin.readline


def main():
    n = int(input())
    h = list(map(int, input().split()))

    for i in reversed(range(n - 1)):
        if h[i] <= h[i + 1]:
            continue
        elif h[i] == h[i + 1] + 1:
            h[i] -= 1
            continue
        elif h[i] > h[i + 1]:
            print("No")
            return
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14252
import java.util.*;

public class Main {
	public static void main(String[] args){
		
		Scanner sc=new Scanner(System.in);
	
		int n=sc.nextInt();
		int m=sc.nextInt();
		
		int[] a=new int[m];
		
		for(int i=0;i<n;i++){
			int k=sc.nextInt();
		    int[] A=new int[k];
			for(int j=0;j<k;j++)a[sc.nextInt()-1]++;
		}
		sc.close();
		
		int ans=0;
		
		for(int i=0;i<m;i++){
			if(a[i]==n)ans++;
		}
		
		System.out.println(ans);
		
	}

}


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

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

    vector<long long int> a(n+1);
    for(int i=0; i<=n; i++){
        cin >> a[i];
    }

    if(n == 0){
        if(a[0] == 1) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }

    if(a[0] != 0){
        cout << -1 << endl;
        return 0;
    }

    vector<long long int> sa(n+1);
    for(int i=1; i<=n; i++){
        sa[i] = sa[i-1] + a[i];
    }

    long long int ans = 1;
    vector<long long int> b(n+1);
    b[0] = 1;
    for(int i=1; i<=n; i++){
        b[i] = min(2 * b[i-1] - a[i], sa[n] - sa[i]);
        //cout << a[i] << " " << b[i] << endl;
        if(b[i] < 0){
            cout << -1 << endl;
            return 0;
        }
        ans += a[i] + b[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5500
#include<stdio.h>
#include<string.h>
int main(void)
{
  int n,i,j,keta[4];
  scanf("%d",&n);
  i=1;
  while(n>0){
    keta[i] = n%10;
    if(keta[i]==1){
      keta[i]=9;
    }else if(keta[i]==9){
      keta[i]=1;
    }
    n /= 10;
    i++;
  }
  for(j=i-1;j>0;j--){
    printf("%d",keta[j]);
  }
  return 0;
}


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

int main() {
  char a, b, c, d ,e, f;
  cin >> a >> b >> c >> d >> e >> f;
  
  
  if ( a == f && b == e && c == d ) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <functional>
#include <sstream>

using namespace std;

#define fst first
#define scd second
#define pb push_back
#define mp make_pair
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define rep(i,x) for(int i=0;i<(int)x;++i)
#define rep1(i,x) for(int i=1;i<=(int)x;++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)
#define repf(i,a,x) for(int i=a;i<(int)x;++i)
#define repf1(i,a,x) for(int i=a;i<=(int)x;++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

template<typename T> T get(){T a;cin >> a;return a;}
template<typename T> T rev(T & a){reverse(all(a));return a;}

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

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

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

	string s;
	while (cin >> s, s[0] != '0') {
		map<string, bool> m;

		queue<string> q, r;

		q.push(s);

		int cnt = 0;

		while (q.size()) {
			while (q.size()) {
				string t = q.front(); q.pop();
				if (m[t]) continue;
				m[t] = true;
				bool f = true;
				rep(i, t.size() - 1) {
					if ((t[i] == 'r' && t[i + 1] == 'b') || (t[i] == 'b' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'g';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'b' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'b')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'r';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					} else if ((t[i] == 'r' && t[i + 1] == 'g') || (t[i] == 'g' && t[i + 1] == 'r')) {
						char c = t[i], d = t[i + 1];
						t[i] = t[i + 1] = 'b';
						r.push(t);
						t[i] = c, t[i + 1] = d;
						f = false;
					}
				}
				if (f) {
					cout << cnt << endl;
					goto nxt;
				}
			}
			while (r.size()) {
				string t = r.front(); r.pop();
				q.push(t);
			}
			cnt++;
		}

		cout << "NA\n";
nxt:;
	}
}

Measured memory_bytes: 3328
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    int n, m;
    cin >> n >> m;
    char A[n + 2][m + 2];
    rep(i, 0, n + 2) rep(j, 0, m + 2) A[i][j] = '.';
    repp(i, 1, n) repp(j, 1, m) cin >> A[i][j];
    repp(i, 1, n) repp(j, 1, m){
        if(A[i][j] == '#') continue;
        int c = 0;
        repp(a, -1, 1) repp(b, -1, 1) if(A[i + a][j + b] == '#') c++;
        A[i][j] = '0' + c;
    }
    repp(i, 1, n){
        repp(j, 1, m) cout << A[i][j];
        cout << endl;
    }
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}


Measured memory_bytes: 256
let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    bubbleSort(inputString[1].split(' ').map(str => Number(str)));
});

const bubbleSort = (arr) => {
  let swap = 0;
  let swapped = true;
  for (let i=0; swapped; i++) {
    swapped = false;
    for (let j=arr.length-1; j>i; j--) {
      const left = arr[j-1];
      const right = arr[j];
      if (left > right) {
        arr[j-1] = right;
        arr[j] = left;
        swap++;
        swapped = true;
      }
    }
  }

  console.log(arr.join(' '));
  console.log(swap);
};


Measured memory_bytes: 15592
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int f[14][14] = {0};
int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int gx[12] = {-2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2};
int gy[12] = {-1, 0, 1, -2, 2, -2, 2, -2, 2, -1, 0, 1};

signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(px, py);
    if(!(px | py))break;

    rep(i, 14)rep(j, 14)f[i][j] = -1;
    f[px + 2][py + 2] = 0;

    int(n);
    int q, k, l;
    rep(q, n){
      int2(x, y);
      for(i = 2;i < 12;++i)for(j = 2;j < 12;++j)if(f[i][j] == q)
      rep(k, 9)rep(l, 12)if(x + dx[k] == i + gx[l] - 2 && y + dy[k] == j + gy[l] - 2)
      f[i + gx[l]][j + gy[l]] = q + 1;
    }

    bool is = false;
    for(i = 2;i < 12;++i)for(j = 2;j < 12;++j)if(f[i][j] == n)is = true;
    puts(is ? "OK" : "NA");
    /*rep(i, 14){
      rep(j, 14)printf("%3d ", f[j][i]);
      kara;
    }*/


//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3060
# include <stdio.h>

int main(void)  {
  int A[100], n, i, sw;
  
  scanf("%d", &n);
  for (i  = 0; i < n; i++)
    scanf("%d", &A[i]);
  
  sw = selectionSort(A, n);
  
  for (i = 0; i < n; i++)  {
    if (i > 0)
      printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
  printf("%d\n", sw);

  return 0;
}

int selectionSort(int A[], int n)  {
  int i, j, t, sw = 0, minj;
  for (i = 0; i < n - 1; i++)  {
    minj = i;
    for (j = i; j < n; j++)  {
      if (A[j] < A[minj])
        minj = j;
    }
    t = A[i];
    A[i] = A[minj];
    A[minj] = t;
    if (i != minj)
      sw++;
  }
  return sw;
}

Measured memory_bytes: 1804
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
//#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int main(){
	int n,ruler=1;
	string s[1111];
	cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	if(std::count(s,s+n,s[0])>1)ruler=0;
		DEB(ruler)END
	for(int i=1;i<n;i++){
		if(s[i-1][s[i-1].size()-1]!=s[i][0]){
			ruler=0;
		}
		if(std::count(s,s+n,s[i])>1){
			ruler=0;
		}
		DEB(ruler)END
	}
	if(ruler)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;	
}

Measured memory_bytes: 256
#include <stdio.h>
void mergesort(   long int [],  unsigned int,  unsigned int);
void merge(  long   int [],  unsigned int,  unsigned int,  unsigned int);

  unsigned int c =0, n ;
  long int l[260000], r[260000];

int main()
{
  unsigned int i ;   long   int s[500000];
  scanf("%d", &n);
  //printf("aaa%d\n",n);
  for( i = 0; i < n; i++){
    scanf("%ld" , &s[i]);
  }
  mergesort(s , 0 ,n );
  for ( i = 0; i < n; i++){
    printf("%ld", s[i]);
    if ( i != n-1){printf(" ");}
  }
  printf("\n%d\n",c);
  return 0;
}
void mergesort(   long  int a[] ,  unsigned int lef,  unsigned int rig){
    
  if ( lef +1 < rig){
      unsigned int mid = ( lef + rig)/2;
    mergesort( a , lef ,mid);
    mergesort(a , mid ,rig);
    merge (a ,lef ,mid ,rig);
  }
}
void merge (   long   int a[] ,   unsigned int lef ,   unsigned int mid ,  unsigned int rig){
  unsigned int k,none = mid - lef,i,j,ntwo = rig - mid;

  for (i = 0; i <  none;i++ ){
    l[i] = a[lef+ i];
  }
  for ( i = 0; i < ntwo ; i++){
    r[i] = a[mid + i];
  }l[none] = 2500000000;r[ntwo]= 2500000000; i= 0;j= 0;
  for (k = lef ;k < rig ;k++ ){
    c++;
    if (l[i] <= r[j]){
      a[k] = l[i];
      i = i + 1;
    }else{ 
      a[k] = r[j];
      j = j + 1;
    }
  }
}



Measured memory_bytes: 9512
import numpy as np
N = int(input())

F = np.empty((N,10))
P = np.empty((N,11))
for i in range(N):
  Flist = np.array(list(map(int, input().split())), dtype = int)
  F[i] = Flist
for i in range(N):
  Plist = np.array(list(map(int, input().split())), dtype = int)
  P[i] = Plist
BenefitMax = 0

for i in range(1,1024):
  A = np.zeros(10)
  iForBin = i
  for j in range(10):
    if iForBin %2 == 1:
      A[j] = 1
    iForBin = iForBin // 2
  ADotF = np.tensordot(A,F,((0),(1)))
  Benefit = 0
  for j in range(N):
    Benefit += P[j,int(ADotF[j])]
  if i == 1:
    BenefitMax = Benefit
  else:
    if BenefitMax < Benefit:
      BenefitMax = Benefit

print(int(BenefitMax))

Measured memory_bytes: 27316
S = list(input())
T = list(input())

S.sort()
T.sort(reverse=True)

def cmp(A, B):
    for i in range(min(len(A), len(B))):
        if A[i] < B[i]:
            return True

        elif A[i] > B[i]:
            return False

    if len(A) < len(B):
        return True

    return False



if cmp(S, T):
    print('Yes')
else:
    print('No')




Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, l;
    while (cin >> n >> l && n){
        VI p(n), v(n);
        REP(i,n){
            char c;
            cin >> c >> p[i];
            if (c == 'R') v[i] = 1;
            else v[i] = -1;
        }
        FOR(t,1,l){
            map<int, int> a;
            REP(i,n){
                p[i] += v[i];
                a[p[i]]++;
            }
            FOR(i,1,l-1){
                if (a[i] >= 2){
                    REP(j,n){
                        if (p[j] == i) v[j] *= -1;
                    }
                }
            }
            bool f = 1;
            REP(i,n) if (p[i] > 0 && p[i] < l) f = 0;
            if (f){
                int ans;
                REP(i,n) if (p[i] == l) ans = i+1;
                REP(i,n) if (p[i] == 0) ans = i+1;
                cout << t << " " << ans << endl;
                break;
            }
        }

    }
    return 0;
}

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

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    double n, d; cin >> n >> d;
    double cnt = 0;
    while(n--)
    {
        double x, y; cin >> x >> y;
        double xi = x*x;
        double yi = y*y;
        double ans = sqrt(xi+yi);
        if(ans<=d) cnt++;
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3860
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

DENOMINATOR = 1000000007

pos = 0
route = 1
before = 0

for i in range(1, N+1):
    route, before = route+before, route
    if pos < M:
        if A[pos] == i:
            route = 0
            pos+=1

print(route%DENOMINATOR)

Measured memory_bytes: 49240
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

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

#define all(s) s.begin(), s.end()
#define ok puts("ok")
#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >
#define pii pair < int, pi >
#define next next123

const int N = 5007;
const int INF = 1e9 + 7;

ll dp[2][N], x[N];
ll m, ans;
int n;

main(){
    cin >> n >> m;
    if (n == 2){
        puts("3");
        return 0;
    }
    for (int i = 2; i <= n / 2 + 1; i++)
        x[i] = x[i - 1] + 1;
    for (int i = n + 1; i > n / 2 + 1; i--)
        x[i] = x[i + 1] + 1;
    ll cur = 0, prv;
    dp[0][0] = 1;
    for (int i = 2; i <= n; i++){
        prv = cur;
        cur ^= 1;
        for (int j = 0; j < n; j++){
            dp[cur][j] = 0LL;
            for (int t = 0; t * x[i] <= j; t++)
                dp[cur][j] += dp[prv][j - t * x[i]];
            dp[cur][j] %= m;
        }
    }
    for (int j = 0; j < n; j++){
        ans += 1LL * (n - j) * dp[cur][j];
        ans %= m;
    }
    cout << ans % m << endl;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, ll> P;

ll d[100000] = {};
vector<P> g[100000];

void bfs(int s)
{
    queue<int> q;
    q.push(s);

    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        rep(i, g[u].size())
        {
            P v = g[u][i];
            if (d[v.first] == 0)
            {
                d[v.first] = d[u] + v.second;
                q.push(v.first);
            }
        }
    }
}

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

    rep(i, n - 1)
    {
        int a, b;
        ll c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].push_back(P(b, c));
        g[b].push_back(P(a, c));
    }

    int q, k;
    cin >> q >> k;
    --k;
    bfs(k);
    rep(i, q)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        OP(d[x] + d[y]);
    }

    return 0;
}

Measured memory_bytes: 10864
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int a,b;
  cin >> a >> b;

  int ans = 0;
  if(a > b){
    ans += a;
    a--;
  } else {
    ans += b;
    b--;
  }
  if(a > b){
    ans += a;
    a--;
  } else {
    ans += b;
    b--;
  }

  cout << ans << endl;


  return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
const int N = 200010; 
const int LOGN = 20;
const ll oo = 1e18;


int n , a[N];

struct rn{
    int l,r,c;
    rn(int _c , int _l , int _r){
      r = _r,l = _l,c = _c;
    }
};
vector< rn > current;

bool check(int mid){
  current.clear();
  current.push_back(rn(0,1,a[0]));
  int idx = a[0],cur = 0;
  for(int i = 1  ; i < n ; ++i){
    if(a[i]>a[i-1]){
      idx = a[i];
      current.push_back(rn(0,a[i-1]+1,a[i]));
    }else{
      while(idx > a[i] && current.back().l > a[i])current.pop_back();
      idx = min(idx,a[i]);
      current.back().r = min(current.back().r, idx);
      while(current.size() && current.back().c == mid-1){
       current.back().r--;
       idx--;
        if(current.back().l > current.back().r)current.pop_back();
      }
      if(!current.size())return 0;
      int curC = current.back().c;
      int cut = current.back().r--;
      if(current.back().l > current.back().r)current.pop_back();
       current.push_back(rn(curC+1,cut,cut));
        if(cut != a[i]){
        current.push_back(rn(0,cut+1,a[i]));
        idx = a[i];
      }
    }
   /* cout << "OUT " << i << endl;
    for(int j = 0 ; j < current.size();++j){
      printf("[%d,%d] char %d\n",current[j].l,current[j].r,current[j].c);
    }*/
  }
  return true;
}
int main(){ 
  cin >> n;
  for (int i = 0; i < n; ++i)scanf("%d",&a[i]);
    //cout << check(1) << endl;
  int lo = 1 , hi = n,best = n;
  while(lo <= hi){ 
    int md = (lo+hi)/2;
    if(check(md)){
      best = md;
      hi = md-1;
    }else{
      lo = md+1;
    }
  }
  cout << best << endl;
  return 0;
}

Measured memory_bytes: 4852
n,m=map(int,input().split())
s=input()[::-1]
ans=[]
pos=0
while pos!=n:
  for i in range(min(n-pos,m),0,-1):
    if s[pos+i]=='0':
      ans.append(i)
      pos+=i
      break
  else:
    print(-1)
    exit()
print(*ans[::-1])

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int wa(int n)
{
    int s = 0;
    while (n)
    {
        s += n % 10;
        n /= 10;
    }

    return s;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    rep(i, n) cin >> l[i];

    sort(all(l));
    reverse(all(l));

    int ans = 0;
    rep(i, k)
    {
        ans += l[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.util.Arrays;
import java.util.HashMap;

@SuppressWarnings("unchecked")
public class Main {
    static HashMap<Integer, Integer> pf;

    // 素因数分解
    static void primeFactor(int n) {
        int a = 2;

        // JDK 1.8 Map.merge
        // map value increment
        while (a * a <= n) {
            if (n % a == 0) {
                pf.merge(a, 1, Integer::sum);
                n = n / a;
            } else {
                a++;
            }
        }
        pf.merge(n, 1, Integer::sum);
    }

    static int f(int x) {
        int cnt = 0;

        for (Integer i : pf.values())
            if (x - 1 <= i) cnt++;

        return cnt++;
    }

    public static void main(String[] args) throws IOException {
        final String s;

        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            s = reader.readLine();
        }

        PrintWriter out = new PrintWriter(System.out);

        final String[] sl = s.split(" ");
        int N = Integer.parseInt(sl[0]);

        pf = new HashMap<>();

        for (int i = 2; i < N + 1; i++) primeFactor(i);

        int ans = f(75) + f(25) * (f(3) - 1)
            + f(15) * (f(5) - 1)
            + f(5) * (f(5) - 1) * (f(3) - 2) / 2;

        out.println(ans);

        out.flush();
    }
}


Measured memory_bytes: 26580
#include <stdio.h>
#include <stdlib.h>
#define MAXN 21

int main()
{
	int n, prev_dish, score = 0;
	scanf("%d", &n);
	int a[MAXN], b[MAXN], c[MAXN];
	for (int i = 1; i <= n;i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n;i++)
		scanf("%d", &b[i]);
	for (int i = 1; i <= n - 1;i++)
		scanf("%d", &c[i]);
	score += b[a[1]];
	prev_dish = a[1];
	for (int i = 2; i <= n; i++)
	{
		score += b[a[i]];
		if (prev_dish + 1 == a[i])
			score += c[a[i - 1]];
		prev_dish = a[i];
	}
	printf("%d", score);
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline

n = int(input())
l = list(map(int, input().split()))
l.insert(0, 0)
l.append(0)
costs = []


def log(v):
    print(v, file=sys.stderr)


for l2 in [l[i:i+2] for i in range(0, len(l)-1, 1)]:
    costs.append(abs(l2[0] - l2[1]))
all_cost = sum(costs)
print(all_cost, file=sys.stderr)
for i in range(1, n+1):
    print(all_cost - (abs(l[i - 1] - l[i]) +
                      abs(l[i] - l[i + 1]) - abs(l[i - 1] - l[i + 1])))


Measured memory_bytes: 20948
#include <iostream>
#include <vector>

void print(std::vector<int> readVec){
    int sz = readVec.size();
    for(int i = 0; i < sz; ++i){
        std::cout << readVec.at(i);
        if(sz - 1 == i){
            std::cout << std::endl;
        }else{
            std::cout << " ";
        }
    }
}

int main(){
    int h, w, n;
    std::cin >> h >> w >> n;
    
    std::vector<int> ref;
    for(int i = 0; i < n; ++i){
        int val;
        std::cin >> val;

        for(int j = 0; j < val; ++j){
            ref.push_back(i + 1);
        }
    }

    std::vector<std::vector<int>> ans;
    for(int i = 0; i < h; ++i){
        if(0 == i){
            ans.push_back(std::vector<int>(ref.begin(), ref.begin() + w));
        }else{
            std::vector<int> buf(ref.begin() + i * w, ref.begin() + (i + 1) * w);
            if(ans.at(i - 1).at(w - 1) == buf.at(0)){
                std::reverse(buf.begin(), buf.end());
            }
            ans.push_back(buf);
        }
    }

    for(int i = 0; i < h; ++i){
        print(ans.at(i));
    }    

    return 0;
}

Measured memory_bytes: 888