akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main
{
    public static void process(int test_number)throws IOException
    {
        int n = ni(), x = ni(), t = ni();
        int tot = n / x + (n % x == 0 ? 0 : 1);
        pn(tot * t);
    }
 
    static final long mod = (long)1e9+7l;
    
    static FastReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        out = new PrintWriter(System.out);
        sc = new FastReader();
 
        long s = System.currentTimeMillis();
        int t = 1;
       // t = ni();
        for(int i = 1; i <= t; i++)
            process(i);
 
        out.flush();
        System.err.println(System.currentTimeMillis()-s+"ms");
    }

    static void trace(Object... o){ System.err.println(Arrays.deepToString(o)); };
    static void pn(Object o){ out.println(o); }
    static void p(Object o){ out.print(o); }
    static int ni()throws IOException{ return Integer.parseInt(sc.next()); }
    static long nl()throws IOException{ return Long.parseLong(sc.next()); }
    static double nd()throws IOException{ return Double.parseDouble(sc.next()); }
    static String nln()throws IOException{ return sc.nextLine(); }
    static long gcd(long a, long b)throws IOException{ return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{ return (b==0)?a:gcd(b,a%b); }
    static int bit(long n)throws IOException{ return (n==0)?0:(1+bit(n&(n-1))); }
    
    static class FastReader{ 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ st = new StringTokenizer(br.readLine()); } catch (IOException  e){ e.printStackTrace(); } 
            } 
            return st.nextToken(); 
        } 
  
        String nextLine(){ 
            String str = ""; 
            try{ str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 36516
#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    #[allow(dead_code)]
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    #[allow(dead_code)]
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    #[allow(dead_code)]
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: usize = sc.read();
    let k: i32 = sc.read();
    let mut ans = 0;
    for _i in 0..n {
        let x: i32 = sc.read();
        ans += min((x - k).abs(), x) * 2;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main(){
 int n,d,x;
  cin >> n >> d >>x;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  
  int res=x;
  for(int j=0;j<n;j++){
  for(int i=0;i*a[j]+1<=d;i++){
     res++;
  }
  }

 cout << res << endl;
}

Measured memory_bytes: 256
def compute(data, n_min, n_max)
  gap = []
  n = n_min
  while n <= n_max
    diff = data[n] - data[n-1]
    gap.push([diff, n])
    n += 1
  end
  gap.sort! { |a, b|
    if a[0] != b[0]
      a[0] - b[0]
    else
      b[1] - a[1]
    end
  }
  puts gap[0][1]
end

while head = gets.split(" ")
  m = head[0].to_i
  n_min = head[1].to_i
  n_max = head[2].to_i
  break if m == 0 and n_min == 0 and n_max == 0
  
  data = []
  n = 0
  while n < m
    data.push(gets.to_i)
    n += 1
  end

  compute(data, n_min, n_max)
end

Measured memory_bytes: 8732
#include <bits/stdc++.h>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
typedef long long ll;
using namespace std;
#define mul(a, b, mod) (((ll)(a) * (b) ) % (mod))
const int h = 26;


int powmod(int a, int b, int mod){
	int s = 1;
	while(b){
		if(b & 1) s = mul(s, a, mod);
		a = mul(a, a, mod);
		b >>= 1;
	}
	return s;
}

int main() {

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

	#define endl '\n'

	#ifdef LOCAL_DEBUG
		freopen("data.in", "r", stdin );
	#endif
	int n; cin >> n;
	vector<string> ar(n);
	for(int i = 0; i <n; i++)
		cin >> ar[i];
	int ans = 0;
	vector<vector<int>> H(n, vector<int>(n));
	for(int i = 0; i <n; i++){
		H[i][0] = ar[i][0] - 'a';
		for(int j = 1; j < n; j++){
			H[i][j] = (mul(powmod(h, j, MOD), ar[i][j] - 'a', MOD) + H[i][j - 1]) % MOD;
		}
	}

	vector<vector<int>> V(n, vector<int>(n));
	for(int i = 0; i <n; i++){
		V[i][0] = ar[0][i] - 'a';
		for(int j = 1; j < n; j++){
			V[i][j] = (mul(powmod(h, j, MOD), ar[j][i]-'a', MOD) + V[i][j - 1]) % MOD;
		}
	}

	function<int(vector<int>&, int)> eval = [&](vector<int>& ha, int offset){
		int n = (int)ha.size();
		if(offset == 0)return ha[n - 1];
		else{
			int l = mul((ha[n - 1] - ha[offset - 1] + MOD) % MOD, powmod(h, mul(MOD - 2, offset, MOD - 1), MOD), MOD);
			int r = mul(ha[offset - 1] , powmod(h, n - offset, MOD), MOD);
			return (l + r) % MOD;
		}
	};

	for(int ba = -(n - 1); ba <= n - 1; ba++){
		bool ok = true;;

		for(int i = 0; i <n ;i++)

			if(eval(H[i], (n - ba) % n) != eval(V[(i - ba + n) % n], 0))
			{
				ok = false;
				break;
			}

		/*for(int j = 0;j < n; j++){
				if(ar[i][(j - ba + n) % n] != ar[j][(i - ba + n) % n]){
					ok = false;
					j = i = n;
				}
			}*/
		if(ok){
			if(ba < 0){
				ans += n + ba;
			}
			else{
				ans += n - ba;
			}
		}

	}
	cout << ans << endl;


}


Measured memory_bytes: 1152
import sys
input=sys.stdin.readline
S,T=input().strip(),input().strip()
Acc_S,Acc_T=[0],[0]
for s in S:
    if s=='A':
        Acc_S.append(Acc_S[-1]+1)
    else:
        Acc_S.append(Acc_S[-1]+2)
for t in T:
    if t=='A':
        Acc_T.append(Acc_T[-1]+1)
    else:
        Acc_T.append(Acc_T[-1]+2)
q=int(input())
for _ in range(q):
    a,b,c,d=map(int,input().split())
    print('YES' if (Acc_S[b]-Acc_S[a-1])%3==(Acc_T[d]-Acc_T[c-1])%3 else 'NO')

Measured memory_bytes: 54052
// Dont hack this or I hack ur mama
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#define ll long long 
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define EPS (1e-9)
using namespace std;

////////////// END OF TEMPLATE
const int nmax = 0;
ull dp[2][2], p, n;
void read()
{
	cin >> n >> p;
	int c;
	dp[1][0] = 1;
	for(int i = 0 ; i < n; ++i)
	{
		int next = i&1, prev = (i+1)&1;
		cin >> c;
		c%=2;
		if( c== 0)
		{
			dp[next][0] = dp[prev][0] * 2;
			dp[next][1] = dp[prev][1] * 2;
		}else{
			dp[next][0] = dp[prev][1] + dp[prev][0];
			dp[next][1] = dp[prev][0] + dp[prev][1];
		}
	}
	cout << dp[(n-1)&1][p] << endl;
}
void solve()
{

}
int main()
{
	std::ios::sync_with_stdio(false);
	read();
	solve();
	return 0;
}


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

using namespace std;

struct SuffixArray
{
    int sz;
    string s;
    vector<int> rank,sa;
    // vector<int> lcp,lcp_rank;

    SuffixArray(string str){
        s=str;
        sz=str.length();
        rank.resize(sz+1);
        sa.resize(sz+1);
        // lcp.resize(sz+1);
        // lcp_rank.resize(sz+1);
        build();
        // build_lcp();
    }

    void build(){
        for(int i=0;i<=sz;i++){
            sa[i] = i;
            rank[i] = i < sz ? s[i] : -1;
        }

        int k;
        auto compare = [&](int i, int j) {
            if (rank[i] != rank[j]) return rank[i] < rank[j];
            else {
                int ri = i + k <= sz ? rank[i + k] : -1;
                int rj = j + k <= sz ? rank[j + k] : -1;
                return ri < rj;
            }
        };

        vector<int> tmp(sz+1);
        for(k=1;k<=sz;k*=2){
            sort(sa.begin(),sa.end(),compare);
            tmp[sa[0]] = 0;
            for(int i=1;i<=sz;i++){
                tmp[sa[i]] = tmp[sa[i-1]] + (compare(sa[i-1],sa[i]) ? 1 : 0);
            }
            for(int i=0;i<=sz;i++){
                rank[i] = tmp[i];
            }
        }
    }
    // s縺荊繧貞性繧?縺?
    bool contains(string t){
        int l=0,r=sz;
        while(r-l>1){
            int mid=(l+r)/2;
            if(s.substr(sa[mid],t.length())<t) l=mid;
            else r=mid;
        }
        return s.substr(sa[r],t.size()) ==t;
    }
    /*
    void build_lcp(){
        for(int i=0;i<=sz;i++) lcp_rank[sa[i]]=i;
        int h=0;
        lcp[0]=0;
        for(int i=0;i<sz;i++){
            int j=sa[rank[i]-1];

            if(h>0) h--;
            for(;j+h<sz && i+h<sz;h++){
                if(s[j+h] != s[i+h]) break;
            }
            lcp[rank[i]-1]=h;
        }
    }
    */
};

int main(){
    string s;
    cin>>s;
    int n;
    cin>>n;
    SuffixArray sa(s);
    for(int i=0;i<n;++i){
        string sc;
        cin>>sc;
        if(sa.contains(sc))cout<<"1"<<endl;
        else cout<<"0"<<endl;
    }
}

Measured memory_bytes: 16596
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff first
#define INF 1000000001
#define inf1 1000000000000000001
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 300000+5;
const lli mod= 1000000007;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli digit(lli n){int res=(int)log10(n)+1;return res;}
lli lcm(lli a,lli b){lli ans=(a*b)/(__gcd(a,b));return ans;}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}

lli inf = 5e17;
///=================== ALWAYS CHECK 1 or 0 base case=================================================================================///
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------//

int dp[maxn];
void solve()
{
    int n;cin>>n;
    for(int i=0;i<=n;i++)dp[i]=0;
    //int digit[]={3,4,5,6,7,8,9};
    dp[0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=3;j<=n;j++)
        {
            if(j>i)break;
            dp[i]=(dp[i]+dp[i-j])%mod;
        }
    }
    cout<<dp[n]<<endl;

}
int main()
{
    solve();
}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
      string a,b;
      int ctn=0;
      cin>>a;
      while(cin>>b&&b!="END_OF_TEXT"){
            transform(b.begin(),b.end(),b.begin(),::tolower);
            if(a==b)ctn++;
      }
      cout<<ctn<<endl;
}

Measured memory_bytes: 3140
#include <stdio.h>

int main() {

  int w, h;
  int i, j;

  while(1) {
    scanf("%d %d", &h, &w);

    if(h == 0 && w == 0)
      break;
    else {
      for(i = 0; i < h; i++) {
	for(j = 0; j < w; j++)
	  printf("#");
	printf("\n");
      }
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
while True:
    m,f,r = map(int,input().split())
    if m==-1 and f ==-1 and r ==-1:
        break
    if m==-1 or f ==-1:
        score='F'
    elif m+f>=80:
        score='A'
    elif 65<=m+f<80:
        score='B'
    elif 50<=m+f<65:
        score='C'
    elif 30<=m+f<50:
        score='D'
        if r >=50:
            score='C'
    elif m+f<30:
        score='F'
    print(score)



Measured memory_bytes: 5596
#include <iostream>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
long long gcd(long long x,long long y){
	if(y==0) return x;
	return gcd(y,x%y);
} 
long long lcm(long long x,long long y){
	return x*y/gcd(x,y);
}
map<long long,long long> a;
map<long long,long long> b;
map<long long,long long> c;
map<long long,long long> vis;
char q[1000002];
char w[1000002];
int main(){	
	unsigned long long n,m;
	cin>>n>>m;
	scanf("%s",q);
	scanf("%s",w);
	for(int i=0;i<n;i++) a[i]=q[i];
	for(int i=0;i<m;i++) b[i]=w[i];
	int p=0;
	 long long ll=lcm(n,m);
		for(int j=0;j<max(n,m);j++){
			if((vis[j*(ll/m)]&&c[j*(ll/m)]!=b[j])||(vis[j*(ll/n)]&&c[j*(ll/n)]!=a[j])){
				cout<<"-1";
				return 0;
			}
			if(j*(ll/m)==j*(ll/n)&&a[j]!=b[j]){
				cout<<"-1";
				return 0;
			}
			
			c[j*(ll/m)]=b[j],c[j*(ll/n)]=a[j];
			vis[j*(ll/m)]=1;
			vis[j*(ll/n)]=1;
		}
		cout<<ll;
		return 0;
}

Measured memory_bytes: 36736
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,tp,a=INT_MIN,b=INT_MAX;
int main(){
    ios::sync_with_stdio(0);
    cin>>n>>m>>x>>y;
    for(int i=1;i<=n;++i){
        cin>>tp;
        a=max(a,tp);
    }
    for(int j=1;j<=m;++j){
        cin>>tp;
        b=min(b,tp);
    }
    x=max(x,a);
    y=min(y,b);
    if(y-x>=1)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    return 0;
    }


Measured memory_bytes: 256
def inpl():
    return list(map(int, input().split()))


S = input()

ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        if S[j] not in "AGTC":
            ans = max(j - i, ans)
            break
    else:
        ans = max(len(S) - i, ans)
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
int main(){
    int n;
    int i;
    unsigned long long x, y;
    int t, a;
    unsigned long long p, q;
    scanf("%d %lld %lld",&n,&x,&y);
    for (i=1;i<n;i++){
        scanf("%d %d",&t,&a);
        if (x%t>0) x+=t-(x%t);
        if (y%a>0) y+=a-(y%a);
        p=x/t;
        q=y/a;
        if(p<q) p=q;
        x=p*t;
        y=p*a;
    }
    printf("%lld\n",x+y);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created by Harry on 5/10/20.
 */
public class Main {
    static class DSU{
        int[] parent;
        int[] size;

        public DSU(int N){
            parent = new int[N];
            size = new int[N];
            for(int i=0; i<parent.length; i++){
                parent[i] = i;
                size[i] = 1;
            }
        }

        public int find(int x){
            if(parent[x]!=x){
                parent[x] = find(parent[x]);
            }
            return parent[x];
        }

        public int union(int x, int y){
            int xParent = find(x);
            int yParent = find(y);
            if(xParent==yParent) return size[xParent];
            if(size[xParent]<=size[yParent]){
                parent[xParent] = yParent;
                size[yParent]+=size[xParent];
                return size[yParent];
            }
            else{
                parent[yParent] = xParent;
                size[xParent] += size[yParent];
                return size[xParent];
            }
        }

    }

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(new BufferedInputStream(System.in));
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        DSU dsu = new DSU(n);
        int max = 1;
        for(int i=0; i<m; i++){
            int a = scanner.nextInt()-1;
            int b = scanner.nextInt()-1;
            max = Math.max(max, dsu.union(a,b));
        }
        System.out.println(max);
    }
}


Measured memory_bytes: 60868
n,p=map(int,input().split())
a=list(map(int,input().split()))

dp=[[0]*2 for i in range(n+1)]

dp[0][0]=1

for i in range(n):
  if a[i]%2==0:
    dp[i+1][0]=dp[i][0]*2
    dp[i+1][1]=dp[i][1]*2
    
  else:
    dp[i+1][0]=dp[i][0]+dp[i][1]
    dp[i+1][1]=dp[i][0]+dp[i][1]
    
  
print(dp[-1][p])

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

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    vector<ll> sum(N,0);
    sum[0]=A[0];
    for(int i=1;i<N;i++) sum[i]=sum[i-1]+A[i];
    
    for(int i=N-2;i>=0;i--){
        if(sum[i]*2<A[i+1]){
            cout<<N-i-1<<endl;
            return 0;
        }
    }
    cout<<N<<endl;
}


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

signed main() {
	int ans = 0;
	string s;
	cin >> s;
	int n = s.size() - 1;
	for (int bit = 0; bit < (1ll << n); ++bit) {
		int prenas = 0;
		string tmp = s.substr(0, 1);
		for (int i = 0; i < n; ++i) {
			if (bit & (1ll << i)) { // i が bit に入るかどうか
				prenas += stol(tmp);
				tmp = s.substr(i + 1, 1);
			}
			else tmp += s[i + 1];
		}
		prenas += stoll(tmp);
		ans += prenas;
	}
	cout << ans << endl;
}

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

const int Mod = 1e9 + 7;

long long n,m;

long long sum(long long x)
{
	long long ans = 1;
	for(int i=1;i<=x;i++)
		ans = (ans*(i%Mod))%Mod;
	return ans;
}

int main()
{
	scanf("%lld %lld",&n,&m);
	if(abs(n-m)>1)
	{
		puts("0");
		exit(0);
	}
	else if(abs(n-m) == 1) printf("%lld\n",(sum(n)*sum(m))%Mod);
	else printf("%lld\n",(sum(n)*sum(m)*2)%Mod);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
using P = pair <int, int>;
 
 
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    bool ok = true;
    if(n%2==1){
        if(a[0]!=0) {
            cout << 0 << endl;
            return 0;
        }
        for(int i = 1 ;i<n-1;i+=2){
            if(a[i]!=a[i+1]){
            cout << 0 << endl;
            return 0;
            }           
        }
    }
    if(n%2==0){
        for(int i = 0;i<n-1;i+=2){
            if(a[i]!=a[i+1]){
                cout << 0 << endl;
            return 0;
        }
    }
    }
    ll ans=1;
    ll mod = 1000000007;
    if(ok) {
        rep(i,n/2){
            ans *=2;
            ans %=mod;
        }
        cout << ans <<endl;
        return 0;
    }
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n,k;
	cin >> n >> k;
	
	vector<int> v;
	REP(i,n)
	{
		int tmp;cin >> tmp;
		v.PB(tmp);
	}
	
	ll ans = 0;
	
	REP(i,n)
	{
		ans += min(v[i],(int)abs(v[i]-k))*2;
	}
	
	cout << ans << endl;
		
	
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Perform BFS from 2...N then use those values to print

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		ArrayList<Integer>[] graph = new ArrayList[N+1];
		for (int i = 1; i<=N; i++) {
			graph[i]=new ArrayList<Integer>();
		}
		for (int i = 0; i < M; i++) {
			int A = input.nextInt();
			int B = input.nextInt();
			graph[A].add(B);
			graph[B].add(A);
		}
		int[] ans = BFS(graph);
		boolean bad = false;
		for (int i = 2; i <= N; i++) {
			if (ans[i]==0) {
				bad=true;
				break;
			}
		}
		if (bad) System.out.println("No");
		else {
			System.out.println("Yes");
			for (int i = 2; i <= N; i++) {
				System.out.println(ans[i]);
			}
		}
	}	
	public static int[] BFS(ArrayList<Integer>[] graph) {
		int[] ans = new int[graph.length];
		boolean[] vis = new boolean[graph.length];
		Queue<Integer> cur = new LinkedList<Integer>();
		cur.add(1);
		while (!cur.isEmpty()) {
			int size = cur.size();
			for (int i = 0; i < size; i++) {
				int curSTART = cur.poll();
				for (int j = 0; j < graph[curSTART].size(); j++) {
					if (!vis[graph[curSTART].get(j)]) {
						ans[graph[curSTART].get(j)]=curSTART;
						vis[graph[curSTART].get(j)]=true;
						cur.add(graph[curSTART].get(j));
					}
				}
			}
		}
		return ans;
	}
}

Measured memory_bytes: 68956
#include<stdio.h>
int main(){
  int N,A[100],temp,count=0,i,j,k;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);

  for(i=0;i<N-1;i++){
    for(j=N-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	  temp=A[j-1];
	  A[j-1]=A[j];
	  A[j]=temp;
	  count++;
      }
    }
  }
  for(k=0;k<N-1;k++) printf("%d ",A[k]);
  printf("%d",A[N-1]);
  printf("\n%d\n",count);
  return 0;
}



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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int x,y,z;cin>>x>>y>>z;
  cout<<(x-z)/(y+z)<<endl;

  return 0;
}


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

const int maxn=200005;
int n,m,cnt;
int ans[maxn];
vector<int>pos[maxn],apos;
char s[maxn];

int main(){
	scanf("%d%s",&n,s);
	s[2*n-1]='1';
	for(int i=0;i<2*n;i++)if(s[i]=='1'){
		int j=i;
		while(j<2*n&&s[j]=='1')j++;
		for(int k=i;k<j;k++)pos[m].push_back(k);
		m++;
		i=j-1;
	}
	if(s[0]=='1'&&m>1){
		for(int k=0;k<int(pos[0].size());k++)pos[m-1].push_back(pos[0][k]);
		pos[0]=pos[m-1];
		m--;
	}
	int sum=0;
	for(int i=0;i<m;i++)sum+=int(pos[i].size())-1;
	if(m==1&&int(pos[0].size())==2*n)sum++;
	if(sum&1){
		puts("No");
		return 0;
	}
	int last=-1,fir=-1;
	if(sum%4==2){
		if(m==1&&sum==2*n){
			puts("No");
			return 0;
		}
		bool f=false;
		for(int i=0;i<m&&(!f);i++)for(int j=i+1;j<m&&(!f);j++)if(int(pos[i].size())>1&&int(pos[j].size())>1){
			f=true;
			fir=pos[i][0];
			ans[pos[i][1]]=ans[pos[j][1]]=++cnt;
			for(int k=2;k<int(pos[j].size());k++)apos.push_back(pos[j][k]);
			last=(pos[j].back()+1)%(2*n);
			ans[last]=ans[pos[j][0]]=++cnt;
			for(int k=2;k<int(pos[i].size());k++)apos.push_back(pos[i][k]);
			last=(pos[i].back()+1)%(2*n);
			for(int p=0;p<m;p++)if(p!=i&&p!=j){
				ans[last]=ans[pos[p][0]]=++cnt;
				for(int k=1;k<int(pos[p].size());k++)apos.push_back(pos[p][k]);
				last=(pos[p].back()+1)%(2*n);
			}
		}
		if(!f){
			puts("No");
			return 0;
		}
	}
	else{
		if(m==1&&sum==2*n){
			puts("Yes");
			for(int i=0;i<n/2;i++)printf("%d %d %d %d ",2*i+1,2*i+2,2*i+1,2*i+2);
			puts("");
			return 0;
		}
		for(int i=0;i<m;i++){
			if(fir<0)fir=pos[i][0];
			if(last>=0)ans[last]=ans[pos[i][0]]=++cnt;
			for(int k=1;k<int(pos[i].size());k++)apos.push_back(pos[i][k]);
			last=(pos[i].back()+1)%(2*n);
		}
	}
	puts("Yes");
	if(fir>=0&&last>=0)ans[fir]=ans[last]=++cnt;
	for(int i=0;i<int(apos.size());i+=4){
		ans[apos[i]]=ans[apos[i+2]]=cnt+1;
		ans[apos[i+1]]=ans[apos[i+3]]=cnt+2;
		cnt+=2;
	}
	int c=0;
	for(int i=0;i<2*n;i++){
		if(ans[i]==0){
			if(c==0)ans[i]=++cnt,c=1;
			else ans[i]=cnt,c=0;
		}
		printf("%d%c",ans[i],i==2*n-1?'\n':' ');
	} 
	return 0;
} 

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

int main(){
  int N;cin>>N;
  int ans=0;
  for(int i=1;i<=N;i+=2){
    int tmp=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)++tmp;
    }
    if(tmp==8)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int root(int arr[],int i){
    while(arr[i]!=i){
         arr[i]=arr[arr[i]];
        i=arr[i];
    }
    return i;
}
void Union(int arr[],int Size[],int a,int b){
int rootA=root(arr,a);
int rootB=root(arr,b);
if(Size[rootA]<Size[rootB]){
    arr[rootA]=arr[rootB];
    Size[rootB]+=Size[rootA];
}else{
arr[rootB]=arr[rootA];
Size[rootA]+=Size[rootB];
}
}
bool findRoot(int a,int b,int arr[]){
 if(root(arr,a)==root(arr,b))return true;
 else return false;
}
 vector<vector<int> >adj(105);
bool nCyc=false;
/*void dijkstra(int v,long long dis[]){
dis[v]=0;
multiset<pair<int,int> >s;
s.insert({0,v});
while(!s.empty()){
    pair<int,int>p= *s.begin();
    s.erase(s.begin());
    int x=p.second;
  if(vis[x])continue;
    vis[x]=1;
    for(int i=0;i<adj[x].size();i++){
        int e=adj[x][i].first,w=adj[x][i].second;
      //  cout<<dis[e]<<" "<<dis[x]+w<<endl;
        if(dis[e]>dis[x]+w){
            dis[e]=dis[x]+w;
            s.insert(make_pair(dis[e],e));
        }
    }
}
}*/
/*void bfs(int s){
    queue<int>q;
    q.push(s);
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i=0;i<adj[v].size();i++){
            if(!vis[adj[v][i]]){
                 q.push(adj[v][i]);
                 vis[adj[v][i]]=1;
            }
        }
    }
}*/
int vis[55][55];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/*bool isVal(int i,int j){
      if(i<0 || j<0 || j>=m || i>=n)return false;
      return true;
}*/
/*void dfs(int i,int j) {

    if(!isVal(i,j) || vis[i][j] || arr[i][j]=='#')return;
      vis[i][j]=1;
	  if(arr[i][j]=='G'){
	  check++;
	  }
	  if(arr[i][j]=='B'){
        b=1;
        return;
	  }
	for(int k=0;k<4;k++){
     int pos1=i+dx[k],pos2=j+dy[k];
   //  cout<<pos1<<" "<<pos2<<endl;
     if( isVal(pos1,pos2) && (arr[pos1][pos2]=='#'))continue;
               dfs(pos1,pos2);
	}
}
void dfs2(int i,int j){
 if(isVal(i,j)==false || arr[i][j]!='.')return;
  arr[i][j]='#';
}*/
/*
double prim(int x){
    priority_queue<pair<double,int>,vector<pair<double,int> >,greater<pair<double,int> > >q;
    double min_cost=0.0;
    pair<double,int>p;
     q.push(make_pair(0.0,x));
     while(!q.empty()){
      p=q.top();
      q.pop();
      x=p.second;
      if(vis[x])continue;
      min_cost+=p.first;
      vis[x]=1;
      for(int i=0;i<adj[x].size();i++){
         int y=adj[x][i].second;
         if(!vis[y]){
            q.push(adj[x][i]);
        }
      }
     }
     return min_cost;
}*/
int n;
long long dp[105][100005];
vector<pair<long long ,long long> >v(105);
long long solve(int i,int W){
    if(i==n || W==0)return 0;
    if(dp[i][W]!=-1)return dp[i][W];
    if(v[i].first>W)return solve(i+1,W);
    return dp[i][W]=max(v[i].second+solve(i+1,W-v[i].first),solve(i+1,W));
}
int freq[1000005],check[1000005];
int main()
{
    int W;
    cin>>n>>W;
    for(int i=0;i<n;i++)cin>>v[i].first>>v[i].second;
    memset(dp,-1,sizeof dp);
    cout<<solve(0,W);
return 0;
}


Measured memory_bytes: 85676
import java.util.*;

public class Main {
	static class Tree {
		public class Edge {
			int to, rev, cost;

			public Edge(int to, int rev, int cost) {
				this.to = to;
				this.rev = rev;
				this.cost = cost;
			}
		}
		
		int V;
		ArrayList<ArrayList<Edge>> G;
		int root;
		int[] p;
		
		public Tree(int[] a, int[] b, int[] cost) {
			this.V = a.length+1;
			p = new int[V];
			
			G = new ArrayList<ArrayList<Edge>>();
			for(int i=0; i<V; i++) {
				G.add(new ArrayList<Edge>());
			}
			
			for(int i=0; i<V-1; i++) {
				G.get(a[i]).add(new Edge(b[i], G.get(b[i]).size(), cost[i]));
				G.get(b[i]).add(new Edge(a[i], G.get(a[i]).size()-1, cost[i]));
			}
			setRoot(0);
		}
		
		public void setRoot(int root) {
			this.root = root;
			
			LinkedList<Integer> q1 = new LinkedList<Integer>();
			LinkedList<Integer> q2 = new LinkedList<Integer>();
			q1.add(root);
			q2.add(-1);
			while(q1.size()>0) {
				int cur = q1.poll();
				int parent = q2.poll();
				p[cur]=-1;
				for(int i=0; i<G.get(cur).size(); i++) {
					if(G.get(cur).get(i).to==parent) {
						p[cur] = i;
					} else {
						q1.add(G.get(cur).get(i).to);
						q2.add(cur);
					}
				}
			}
		}
		
		public int getMaxWin(int idx) {
			ArrayList<Integer> childWin = new ArrayList<>();
			for(int i=0; i<G.get(idx).size(); i++) {
				if(i != p[idx]) {
					childWin.add(getMaxWin(G.get(idx).get(i).to));
				}
			}
			Collections.sort(childWin);
			int max = childWin.size();
			for(int i=0; i<childWin.size(); i++)
				max = Math.max(max, childWin.get(i)+childWin.size()-i);
			
			return max;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N-1];
		int[] b = new int[N-1];
		int[] c = new int[N-1];
		for(int i=0; i<N-1; i++) {
			a[i] = sc.nextInt()-1;
			b[i] = i+1;
		}
		
		Tree tree = new Tree(a, b, c);
		
		System.out.println(tree.getMaxWin(0));
		
		sc.close();
	}
}


Measured memory_bytes: 85700
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = list(map(int,input().split()))

# import numpy as np

# def gcd(x, y):
#     while x != 0 and y != 0:
#         x, y = max(x, y), min(x, y)
#         x %= y
#     return y

from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

import sys

a = 0

B = [0] * n
C = A[:]

for i in range(n):
    while A[i] % 2 == 0:
        A[i] //= 2
        B[i] += 1

if len(set(B)) != 1:
    print("0")
else:
    for i in range(n):
        C[i] //= 2
    A = C
    b = A[0]
    for i in range(1,n):
        b = lcm(A[i], b)
        if b > m:
            print(0)
            sys.exit()
        # b = np.lcm(A[i],b)
    # print("b", b)

    # b=np.lcm.reduce(A)

    ans = (m//b + 1) // 2
    # if (m//(b*2))*(b*2)+b<=m:
    #     ans += 1
    print(ans)

Measured memory_bytes: 80480
n,y=map(int, input().split()) 

flag = False
for i in range(0,n+1):
  if not flag:
    for j in range(0,n-i+1):
      if (10000*i + 5000*j + 1000*(n-i-j))==y:
        print('{} {} {}'.format(i,j,n-i-j))
        flag = True
        break
      
if not flag:
  print(*[-1, -1, -1])


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	int n, k;
	cin >> n >> k;
	int sum = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int ans = 0;
	for (int cur = 1; cur * cur <= sum; cur++) {
		if (sum % cur == 0) {
			// cur
			{
				vector<int> t = a;
				sort(t.begin(), t.end(), [&](int a, int b) {
					return a % cur < b % cur;
				});
				vector<int> suff(n);
				suff[n - 1] = cur - t[n - 1] % cur;
				for (int i = n - 2; i >= 0; i--)
					suff[i] = suff[i + 1] + cur - t[i] % cur;
				int min_k = 1e9 + 1;
				if (suff[0] == cur * n)
					min_k = 0;
				int neg = 0;
				for (int i = 0; i < n - 1; i++) {
					neg += t[i] % cur;
					if (suff[i + 1] == neg)
						min_k = min(min_k, neg);
				}
				if (min_k <= k)
					ans = max(ans, cur);
			}
			// sum / cur
			{
				int cur2 = sum / cur;
				vector<int> t = a;
				sort(t.begin(), t.end(), [&](int a, int b) {
					return a % cur2 < b % cur2;
				});
				vector<int> suff(n);
				suff[n - 1] = cur2 - t[n - 1] % cur2;
				for (int i = n - 2; i >= 0; i--)
					suff[i] = suff[i + 1] + cur2 - t[i] % cur2;
				int min_k = 1e9 + 1;
				if (suff[0] == cur2 * n)
					min_k = 0;
				int neg = 0;
				for (int i = 0; i < n - 1; i++) {
					neg += t[i] % cur2;
					if (suff[i + 1] == neg)
						min_k = min(min_k, neg);
				}
				if (min_k <= k)
					ans = max(ans, cur2);
			}
		}
	}

	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

const ll mod=1e9+7;

//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
      cin>>a[i];
    }
    bool flag=true;
    ll ans=0;
    while(flag){
      rep(i,n){
        if(a[i]%2==0){
          a[i]/=2;
        }else{
          flag=false;
          break;
        }
      }
      ans++;
    }
    ans--;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;


int main() {
	ll N;
	cin >> N;

	vector<ll> A(N);
	
	rep(i, N) {
		cin >> A[i];
	}

	sort(A.begin(), A.end(), greater<>());

	ll L = 0, count = 0, ans = 1, key = 0;

	rep(i, N) {
		if (L == A[i]) {
			count++;
		}
		else {
			L = A[i];
			count = 1;
		}

		if (count == 2) {
			ans *= L;
			count = 0;
			key++;
		}

		if (key == 2) {
			break;
		}
	}

	if (key == 2) {
		cout << ans;
	}
	else {
		cout << 0;
	}


	return 0;

}


Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
bool dp[101000];
int x;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	dp[0]=true;
	cin>>x;
	for(int i=0;i<=x;i++){
		if(dp[i]){
			dp[i+100]=true;
			dp[i+101]=true;
			dp[i+102]=true;
			dp[i+103]=true;
			dp[i+104]=true;
			dp[i+105]=true;
		}
	}
	cout<<dp[x]<<endl;
	return 0;
}


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

int N, A, B, C;
vector<int> l;
int answer;

void dfs(int current, int mpA, int mpB, int mpC, int lengthA, int lengthB, int lengthC) {
  
  if (current == N) {
    // lengthA,B,C は 0 ではダメ 
    if (lengthA != 0 && lengthB != 0 && lengthC != 0 ) {
      int c_ = max(0, mpA - 1) + max(0, mpB - 1) + max(0, mpC - 1);
      int cost_ = abs(A - lengthA) + abs(B - lengthB) + abs(C - lengthC) + c_ * 10;
      answer = min(answer, cost_);
    }
    return;
  }
  
  // l[current] を A, B, C のどれにも使わずに次へ
  dfs(current + 1, mpA, mpB, mpC, lengthA, lengthB, lengthC);

  // l[current] を A に使って次へ
  dfs(current + 1, mpA + 1, mpB, mpC, lengthA + l[current], lengthB, lengthC);

  // l[current] を B に使って次へ
  dfs(current + 1, mpA, mpB + 1, mpC, lengthA, lengthB + l[current], lengthC);

  // l[current] を C に使って次へ
  dfs(current + 1, mpA, mpB, mpC + 1, lengthA, lengthB, lengthC + l[current]);
  
  return;
}

int main() {

  cin >> N >> A >> B >> C;

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

  answer = 1000000000;

  dfs(0, 0, 0, 0, 0, 0, 0);

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<char> s(n);
  for (auto &x: s) cin >> x;

  for (auto &x: s) {
    if (x == 'Y') {
      cout << "Four" << endl;
      return 0;
    }
  }

  cout << "Three" << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main() {

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

  bool e=false;string f;
  for(int i=sn-tn;i>=0;i--){
    f=s;
    for(int j=0;j<tn;j++){
      if(!(f[i+j]==t[j]||f[i+j]=='?')){
        e=false;
        break;
      }else {
        f[i+j]=t[j];
        e=true;
      }
    }
    if(e){
      s=f;
      break;
    }
  }

  if(e){
    rep(i,0,sn){
      if(s[i]=='?')s[i]='a';
    }
    out(s);
  }else{
    out("UNRESTORABLE");
  }

  return 0;
}


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

int main(){
    string s, t, u;
    cin >> s >> t;
    
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(s == u) a--;
    else b--;
    
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<int char_size,int margin>
class Trie{
private:
    struct Node{
        int ne[char_size];
        int num;
        vec<int> accept;
        Node():num(0){
            memset(ne,-1,sizeof(ne));
        }
    };

    vec<Node> nodes;
    int root;
public:
    Trie():root(0){
        nodes.push_back(Node());
    }

    void update_direct(int node,int id){
        nodes[node].accept.push_back(id);
        nodes[node].num++;
    }

    void add(const string& S,int s_id,int node_id,int id){
        if(s_id==S.size()) update_direct(node_id,id);
        else{
            int c = S[s_id]-margin;
            if(nodes[node_id].ne[c]==-1){
                nodes[node_id].ne[c] = (int) nodes.size();
                nodes.push_back(Node());
            }
            add(S,s_id+1,nodes[node_id].ne[c],id);
        }
    }

    void add(const string& S,int id){
        add(S,0,0,id);
    }

    void add(const string &S){
        add(S,nodes[0].num);
    }

    template<class F>
    void query(const string& S,F& f,int s_id,int node_id){
        for(auto& id:nodes[node_id].accept) f(id);
        if(s_id==S.size()) return ;
        else{
            int c = S[s_id]-margin;
            if(nodes[node_id].ne[c]==-1) return ;
            query(S,f,s_id+1,nodes[node_id].ne[c]);
        }
    }

    void dfs(const string& S,int s_id,int node_id,set<char>& st,ll& ans){
        if(node_id==-1) exit(0);
        if(s_id==S.size()){
            ans += nodes[node_id].num;
            return ;
        }
        int nc = S[s_id]-margin;
        dfs(S,s_id+1,nodes[node_id].ne[nc],st,ans);
        st.insert(S[s_id]);
        for(auto& c:st){
            int id = nodes[node_id].ne[c-margin];
            if(id!=-1) nodes[id].num++;
        }
    }

    template<class F>
    void query(const string& S,F& f){
        query(S,f,0,0);
    }

    int count()const{
        return nodes[0].num;
    }

    int size()const{
        return (int) nodes.size();
    }

};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<string> S(N);
    Trie<26,'a'> trie;
    for(auto& s:S){
        cin >> s;
        reverse(s.begin(),s.end());
        trie.add(s);
    }
    ll ans = 0;
    sort(S.begin(),S.end(),[](string& s,string& t){return s.size()>t.size();});
    for(auto& s:S){
        set<char> st;
        trie.dfs(s,0,0,st,ans);
    }
    cout << ans-N << "\n";
}

Measured memory_bytes: 348664
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 100010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}



int main(){
    //freopen("A.in","r",stdin);
    //freopen("A.out","w",stdout);
    int i,j,k,ca=0,n,m,K;
    int a[3];ll ans=-1;
    rep(i,0,3)scanf("%d",&a[i]);
    rep(i,0,3){
        int x=a[i]/2,y=a[i]-x;
        ll v=abs(x-y);
        if(v==0){ans=0;break;}
        v=1;
        rep(j,0,3)if(j!=i)v*=a[j];
        if(ans==-1||ans>v)ans=v;
    }
    printf("%lld\n",ans);
    //cerr<<1.*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}//*/

Measured memory_bytes: 256
n = gets.to_i
hs = gets.chomp.split.map(&:to_i)

cur_h = hs[0]
flag = true
hs.each do |h|
  if h >= cur_h
    cur_h = h - 1 if cur_h < h - 1
  else
    flag = false
  end
end

puts flag ? "Yes" : "No"

Measured memory_bytes: 9604
char m[7*14],v[7*14];
C(i,c){
	if(m[i]==c&&!v[i]){
		v[i]=1;
		return 1+C(i+1,c)+C(i-1,c)+C(i+7,c)+C(i-7,c);
	}
	return 0;
}
E(i,c){
	if(m[i]=='O')
		m[i]='.';
	else if(m[i]==c){
		m[i]='.';
		E(i+1,c),E(i-1,c),E(i+7,c),E(i-7,c);
	}
}
main(){
	int N,i,j,e,n;
	scanf("%d",&N);
	if(N>99)
		exit(1);
	for(;N--;){
		for(i=0;i<7*12;i++)
			m[7+i]=getchar();
		for(n=0;;n++){
			e=0;
			memset(v,0,sizeof(v));
			for(i=0;i<7*12;i++){
				if(strchr("RGBYP",m[7+i])&&C(7+i,m[7+i])>=4){
					e=1;
					E(7+i,m[7+i]);
				}
			}
			if(!e)
				break;
			for(i=0;i<11;i++){
				for(j=7*12;j--;){
					if(m[7+j]=='.'){
						m[7+j]=m[j];
						m[j]='.';
					}
				}
			}
		}
		printf("%d\n",n);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<set>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

struct SegmentTree{
    int N;
    vector<map<char,int> > dat;
    SegmentTree(int n_){
        N = 1;
        while(N < n_) N *= 2;
        dat.resize(2*N-1);
    }

    void update_init(int q, int a){
        q  = q + N - 1;
        dat[q][a]++;
        while(q>0){
            q = (q-1)/2;
            dat[q][a]++;
        }
    }

    void update(int q, char a){
        q  = q + N - 1;
        char old = dat[q].begin()->first;
        dat[q].erase(old);
        dat[q][a]++;
        while(q>0){
            q = (q-1)/2;
            if(dat[q][old] == 1)dat[q].erase(old);
            else dat[q][old]--;
            dat[q][a]++;
        }

    }

    set<char> queri(int a, int b,int k, int l, int r){ //[a,b)の文字数を調べる kは節点
        if(r <= a || b <= l){
            set<char> st; return st;
        }
        if(a <= l && r <= b){
            set<char> st;
            for(auto i = dat[k].begin(); i != dat[k].end(); i++){
                st.insert(i->first);
            }
            return st;
        }
        else{
            set<char> stl = queri(a,b, k*2+ 1, l, (l+r)/2);
            set<char> str = queri(a,b,k*2 + 2, (l+r)/2, r);
            for(auto i = str.begin(); i != str.end(); i++){
                stl.insert(*i);
            }
            return stl;
        }
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,Q; string S;
    cin>>N; cin>>S; cin>>Q;
    SegmentTree seg(N);
    REP(i,S.length()){
        seg.update_init(i,S[i]);
    }
    vector<int> ans;
    REP(k,Q){
        int q; cin>>q;
        if(q == 1){
            int i;
            char c; 
            cin>>i>>c; i--;
            seg.update(i,c);
        }
        else{
            int l,r; cin>>l>>r; l--,r--;
            int push = seg.queri(l,r+1,0,0,seg.N).size();
            ans.push_back(push);
        }
    }

    REP(i,ans.size()){
        cout << ans[i] << endl;
    }

}


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

int main()
{
    int N, M;
    cin >> N >> M;
    bool *ac = new bool[N];
    int *pe = new int[N];

    for(int n=0; n<N; n++){
        ac[n] = false;
        pe[n] = 0;
    }

    for(int m=0; m<M; m++){
        int p;
        string S;
        cin >> p >> S;
        if(S[0] == 'A'){
            ac[p-1] = true; 
        } else if(ac[p-1] == false) {
            pe[p-1] += 1;
        }
    }

    int sac = 0;
    int spe = 0;
    for(int n=0; n<N; n++){
        if(ac[n]){
            sac++;
            spe += pe[n];
        }
    }

    cout << sac << " " << spe << endl;

	return 0;
}


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

int main(){
    int i;
    string S, T;
    cin >> S >> T;
    for(int j = 0; j < 3 ; j++){
    if(S.at(j) == T.at(j)){
        i++;
    }
    }
    cout << i << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
class Watch{
public:
  void cal(int time){
    int h,m,s;
    h=time/3600;
    time=time%3600;
    m=time/60;
    time=time%60;
    s=time;
    cout<<h<<":"<<m<<":"<<s<<endl;
  }
};
int main(){
  int time;
  cin>>time;
  Watch watch;
  watch.cal(time);
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;
char vs[10];
char vt[10];
char vu[10];
int main()
{
    char s,t,u,i;
int a,b;
cin>>vs;
cin>>vt;

cin>>a>>b;

cin>>vu;

for (i=0;i<10;i++)
{
    if (vs[i]!=vu[i])
    {
        b--;
        cout<<a<<" "<<b;
        return 0;
    }
}
a--;
cout<<a<<" "<<b;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
char mat[3][3];
  for(auto i=0; i<3; i++){
  	for(auto j=0; j<3; j++) cin>>mat[i][j];
  }
  
  for(auto i=0; i<3; i++){
  	for(auto j=0; j<3; j++) if(i == j) cout<<mat[i][j];
  }
  return 0;
}


Measured memory_bytes: 3596
n, m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]

ans = 'No'
for i in range(n - m + 1):
    sel = []
    for j in range(n):
        sel.append(a[j][i: i + m])
    for k in range(n - m + 1):
        tar = sel[k:k + m]
        if b == tar:
            ans = 'Yes'
            break

print(ans)


Measured memory_bytes: 3060