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

public class Main
{
    static PrintWriter out = new PrintWriter((System.out));

    public static void main(String args[]) throws IOException
    {
        Kioken sc = new Kioken();
        int x=sc.nextInt();
        int y=sc.nextInt();
        boolean found=false;
        outer:
        for(int i=0;i<=x;i++)
        {
            int j=x-i;
                if(2*i+4*j==y||4*i+2*j==y)
                {
                    found=true;
                    break outer;
                }
        }
        out.println(found?"Yes":"No");
        out.close();
    }


    static class Kioken
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        public String next()
        {
            while (!st.hasMoreTokens())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt()
        {
            return Integer.parseInt(next());
        }

        public long nextLong()
        {
            return Long.parseLong(next());
        }

        public double nextDouble()
        {
            return Double.parseDouble(next());
        }

        public String nextLine()
        {
            try
            {
                return br.readLine();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext()
        {
            String next = null;
            try
            {
                next = br.readLine();
            }
            catch (Exception e)
            {
            }
            if (next == null)
            {
                return false;
            }
            st = new StringTokenizer(next);
            return true;
        }
    }
}

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

card = list()

marks = ["S","H","C","D"]

for mark in marks:
  for i in range(13):
    card.append([mark,i+1])

def f(s):
  lst = s.split();
  return lst[0], int(lst[1])

for i in range(n):
  had_mark, had_num = f(input())
  card.remove([had_mark, had_num])

for i in range(len(card)):
  print(str(card[i][0]) + " " + str(card[i][1]))


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

int main(){
  int A,B;
  while(1){
    scanf("%d %d",&A,&B);
    if(B % 2 != 1){
      break;
    }else{
      exit(-1);
    }
  }  
  if(A<=5){
    printf("0");
  }else if(A>5&&A<=12){
    printf("%d",B/2);
  }else if(A>12){
    printf("%d",B);
  }
  return 0;
}
  

Measured memory_bytes: 128
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	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(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static long mod = (long) (1e9+7);
	public static long[] fac,inv;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		boolean found = true;
		for(int i=0;i<n;++i) {
			int x = sc.nextInt();
			if((x&1) == 0) {
				if(!(x%3 == 0 || x%5 == 0)) found = false;
			}
		}
		if(found) out.print("APPROVED");
		else out.print("DENIED");
	    out.close();

	}
	

}


Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int x;cin>>x;
  	if(x>=30){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MN 201000

bool A[MN], B[MN];
int n; 
long long ans = 1e18, sum = 0;

struct xxx{
	int w, id;
}d[MN];

bool cmp(xxx a, xxx b) {return a.w < b.w;}

bool check()
{
	bool ok1 = 0, ok2 = 0, ok3 = 0;
	for(int i = 1; i <= n; i++)
	{
		if(A[i]) ok1 = 1;
		if(B[i]) ok2 = 1;
		if(A[i] && B[i]) ok3 = 1; 
	}
	if(ok1 && !ok2 || ok2 && !ok1 || ok3) return 1;
	return 0;
}

void add(int i)
{
	if(d[i].id & 1) A[d[i].id + 1 >> 1] = 1;
	else B[d[i].id >> 1] = 1;
	sum += d[i].w; 
}

void del(int i)
{
	if(d[i].id & 1) A[d[i].id + 1 >> 1] = 0;
	else B[d[i].id >> 1] = 0;
	sum -= d[i].w; 
}

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d%d", &d[2 * i - 1].w, &d[2 * i].w);
		d[2 * i - 1].id = 2 * i - 1;
		d[2 * i].id = 2 * i; 
	}
	std::sort(d + 1, d + 2 * n + 1, cmp);
	for(int i = 1; i <= n; i++) add(i);
	if(check()) ans = std::min(ans, sum);
	del(n); add(n + 1); 
	if(check()) ans = std::min(ans, sum);
	del(n + 1); add(n + 2);
	if(check()) ans = std::min(ans, sum); 
	del(n + 2); add(n + 1); del(n - 1); add(n);
	if(check()) ans = std::min(ans, sum);
	printf("%lld\n", ans);
}

Measured memory_bytes: 2048
import java.io.*;
import java.util.*;
import java.util.Map.Entry;

 
 
public class  Main{
	public static void main(String[] args) throws Exception{
		MScanner sc=new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		int n=sc.nextInt(),h=sc.nextInt();
		Integer[]b=new Integer[n];
		int maxa=-1;
		for(int i=0;i<n;i++) {
			maxa=Math.max(maxa, sc.nextInt());
			b[i]=sc.nextInt();
		}
		Arrays.sort(b);
		int ans=0;
		for(int i=n-1;i>=0 && b[i]>maxa && h>0;i--) {
			ans++;
			h-=b[i];
		}
		h=Math.max(h, 0);
		pw.println(ans+((h+maxa-1)/maxa));

		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] takearr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] takearrl(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public Integer[] takearrobj(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] takearrlobj(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

using namespace std;

typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define pb push_back
#define ctz __builtin_ctz
#define csb __builtin_popcount
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl

const int inf=1e9;

int sum(int a) {
	int ans=0;
	while(a) {
		ans+=a%10;
		a/=10;
	}
	return ans;
}

int main() {
	int n;
	cin>>n;
	int ans=inf;
	for(int i=1;i<=n/2;++i) {
		int t=sum(i)+sum(n-i);
		if(n-i && t<ans) ans=t;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n,A,B = map(int, input().split())
x = list(map(int, input().split()))

if A >= B:
    ans = B*(n-1)
else:
    ans = 0
    for i in range(n-1):
        a = x[i+1]-x[i]
        ans += min(a*A, B)
print(ans)

Measured memory_bytes: 20028
import itertools
import collections
import bisect


def main():
    N, Q = map(int, input().split())
    S = list(input())
    T = []
    D = []
    for _ in range(Q):
        t, d = input().split()
        T.append(t)
        D.append(d)

    def is_l_out(start):
        pointer = start
        for i in range(Q):
            if S[pointer] == T[i]:
                if D[i] == 'L':
                    pointer -= 1
                    if pointer < 0:
                        return True
                else:  # R
                    pointer += 1
                    if pointer >= N:
                        pointer = N -1
        return False

    def is_r_out(start):
        pointer = start
        for i in range(Q):
            if S[pointer] == T[i]:
                if D[i] == 'L':
                    pointer -= 1
                    if pointer < 0:
                        pointer = 0
                else:  # R
                    pointer += 1
                    if pointer >= N:
                        return True
        return False

    left = 0
    right = N - 1
    l_candidate = -1
    while left <= right:
        mid = (left + right) // 2
        l_out = is_l_out(mid)
        if l_out:
            # print("l out = {}".format(mid))
            l_candidate = mid
        if l_out:
            left = mid + 1
        else:
            right = mid - 1

    left = 0
    right = N - 1
    r_candidate = N
    while left <= right:
        mid = (left + right) // 2
        # print(mid)
        r_out = is_r_out(mid)
        if r_out:
            # print("r out = {}".format(mid))
            r_candidate = mid
        if r_out:
            right = mid - 1
        else:
            left = mid + 1

    if l_candidate == -1 and r_candidate == N:  # どっちも消えない
        print(N)
    elif l_candidate == -1:  # 左は消えない
        print(r_candidate)
    elif r_candidate == N: # 右は消えない
        print(N - (l_candidate + 1))
    else:
        print(r_candidate - (l_candidate + 1))


if __name__ == '__main__':
    main()


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

public class Main {
	
	static int ns[],res[][],L[][];
	static int time=1;
	
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt(); L=new int[n+1][n+1];
		ns=new int[n+1]; res=new int[n+1][2];
		
		 for(int i=0;i<n;i++) {
			 int u=Integer.parseInt(in.next()), k=Integer.parseInt(in.next());
			 
			 for(int j=0;j<k;j++) {
				 int v=Integer.parseInt(in.next());
				 L[u][v]=1;
			 }
		 }
		 
		 Stack<Integer> stk=new Stack<>();
		 for(int i=1;i<=n;i++) {
			 if(ns[i]!=1) {
				 stk.push(i);
				 DFS(stk);
			 }
		 }
		 
		 PrintWriter out=new PrintWriter(System.out);
		 for(int i=1;i<=n;i++)out.printf("%d %d %d\n", i, res[i][0], res[i][1]);
		 out.flush();
	}
	
	static void DFS(Stack<Integer> stk) {
		int v=stk.peek();
		ns[v]=1; res[v][0]=time; time++;
		
		for(int i=1;i<=ns.length-1;i++) {
			if(L[v][i]==1 && ns[i]!=1) {
				stk.push(i);
				DFS(stk);
			}
		}
		
		res[v][1]=time; time++;
		stk.pop();
		return;
	}
}



Measured memory_bytes: 28476
#include<bits/stdc++.h>
using namespace std;
long long a[1200],b[1200],c[1200];
long long dp[1200][1200][10];
int n,m;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int k=0;k<8;k++){
				dp[i][j][k]=-1e18;
			}
		}
	}
	for(int i=0;i<8;i++)
		dp[0][0][i]=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<=m;j++){
			for(int k=0;k<8;k++){
				dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);//不选他
				long long cur=dp[i][j][k];
				if(k&1)
					cur+=a[i+1]; 
				else
					cur-=a[i+1]; 
				if(k&2)
					cur+=b[i+1]; 
				else
					cur-=b[i+1]; 
				if(k&4)
					cur+=c[i+1]; 
				else
					cur-=c[i+1]; 
				dp[i+1][j+1][k]=max(dp[i+1][j+1][k],cur);//选他
			}
		}
	}
	long long res=0;
	for(int i=0;i<8;i++)
		res=max(res,dp[n][m][i]);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 94208
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String str = sc.next();
		int r=0;
		int b=0;
		
		for(int i=0; i<a; i++){
		    if(str.charAt(i)=='R'){
		        r++;
		    }else{
		        b++;
		    }
		}
		
		if(r>b){
		    System.out.println("Yes");
		}else{
		    System.out.println("No");
		}
    }
}

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

using namespace std;

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;

int n, m;
int a[N], b[N], f[N], lp[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    if (a[i] != a[i - 1]) {
      b[++m] = a[i];
    }
  }

  f[1] = 1;
  lp[b[1]] = 1;
  for (int i = 2; i <= n; ++i) {
    f[i] = (f[i - 1] + f[lp[b[i]]]) % MOD;
    lp[b[i]] = i;
  }
  printf("%d\n", f[m]);
  
  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
int main()
{
    int d;
    input:
    scanf("%d",&d);
    if(d==22)
        printf("Christmas Eve Eve Eve\n");
    else if(d==23)
        printf("Christmas Eve Eve\n");
    else if(d==24)
        printf("Christmas Eve\n");
    else if(d==25)
        printf("Christmas\n");
    else goto input;
}


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

int main() {
    int n; cin >> n;
    int a[3 * n + 1];
    for (int i = 0; i < 3 * n; i++) cin >> a[i];
    sort(a, a + 3 * n);
    long long ans = 0;
    for (int i = n; i < 3 * n; i+=2) {
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - '0';}
char myitoc(int N) {return '0' + N;}

signed main()
{
  vector<int> n(4);
  for (int i = 0; i < 4; i++)
  {
    char c;
    cin >> c;
    n.at(i) = myctoi(c);
  }

  vector<string> op = {"+++", "++-", "+-+", "-++",
                       "+--", "-+-", "--+", "---"};
  for (int i = 0; i < 8; i++)
  {
    int sum = n.at(0);
    for (int j = 0; j < 3; j++)
    {
      if (op.at(i).at(j) == '+')
        sum += n.at(j + 1);
      else
        sum -= n.at(j + 1);
    }
    if (sum == 7)
    {
      cout << n.at(0);
      for (int j = 0; j < 3; j++)
      {
        cout << op.at(i).at(j) << n.at(j + 1);
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 1e5 + 5;
int p[N], d[N];
vector<int> nxt[N];

void dfs(int u, int depth=0){
	d[u] = depth;
	for(int v:nxt[u]){
		dfs(v,depth+1);
	}
}

set<pii> s;

void clear(int u){
	for(int v:nxt[u]){
		clear(v);
	}
	nxt[u].clear();
	s.erase({d[u],u});
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;
	cin >> n >> k;
	int ans = 0;
	rep(i,0,n){cin >> p[i];--p[i];}
	if(p[0] != 0){
		p[0] = 0;	
		++ans;
	}
	rep(i,1,n)nxt[p[i]].push_back(i);
	dfs(0);
	rep(i,1,n)s.insert({d[i], i});
	while(s.size() && s.rbegin()->first > k){
		int i = s.rbegin()->second;
		int cur = k-1;
		while(cur--)i = p[i];
		clear(i);
		++ans;
	}
	cout << ans << '\n';
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using ll = long long;

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> v(M);
  rep(i,M) cin>>v[i];
  vector<int> d(M-1);
  sort(v.begin(),v.end());
  rep(i,M-1) d[i]=v[i+1]-v[i];
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  int ans= 0;
  for(int i = 0; i < min(N-1,M-1); i++){
    ans += d[i];
  }
  cout<<v[M-1]-v[0]-ans<<endl;
}
  

Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[112];
int main(){
	while(~scanf("%s",str)){
		int r1=0;
		int r2=0;
		char r3='+';
		bool dame=false;
		for(int i=0;str[i];i++){
			if('0'<=str[i]&&str[i]<='9'){
				r2*=10;
				r2+=str[i]-'0';
			}else{
				if(r3=='+')r1+=r2;
				else if(r3=='-')r1-=r2;
				else r1*=r2;
				r2=0;r3=str[i];
			}
			if(r1<0||r1>9999||r2<0||r2>9999){dame=true;break;}
		}
		if(dame)printf("E\n");
		else printf("%d\n",r1);
	}
}

Measured memory_bytes: 984
import math

def combination_count(n,r):
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

N=int(input())
a=list(map(int,input().split()))
maxoutput=0
output=0


a.sort(reverse=True)
n=a[0]
r=a[N-1]

for i in range(1,N):
  if abs(r-n/2)>abs(a[i]-n/2):
    r=a[i]
print(n,r)

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

using namespace std;

#define N 5200

int n,mod,ans,c[N],f[N];

void upd(int &x,int y){x=(x+y)%mod;}

int main(){
	scanf("%d%d",&n,&mod);
	for (int i=2;i<=(n+1)/2;++i) c[i]=i-1;
	for (int i=(n+1)/2+1;i<=n;++i) c[i]=n-max(i,n-(n-1)/2+1)+2;
	f[0]=1;
	for (int i=2;i<=n;++i)
		for (int j=c[i];j<=n;++j) upd(f[j],f[j-c[i]]);
	for (int i=0;i<=n;++i) upd(ans,(long long)f[i]*(n-i)%mod);
	printf("%d\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 256
N,K=map(int,input().split())
D=list(map(int,input().split()))
C=[]

for i in range(0,10):
  if i not in D:
    C.append(i)
#print(C)

for i in range(N,10**10):
  cnt=0
  for j in list(map(int,list(str(i)))):
    if j in C:
      cnt+=1
  if len(str(i))==cnt:
    print(i)
    exit()

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline


def fctr1(n): 
    f=[]
    c=0
    r=int(n**0.5)
    for i in range(2,r+2):
        while n%i==0:
            c+=1
            n=n//i
        if c!=0:
            f.append(c)
            c=0
    if n!=1:
        f.append(1)
    return f


n = int(input())

if n == 1:
    print(0)
    exit()

a = fctr1(n)

res = 0
d = dict()

for e in a:
    c = 1
    while e:
        if e >= c:
            res += 1
            e -= c
            c += 1
        else:
            break
print(res)





Measured memory_bytes: 63412
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007;
#define INF (1<<28)
#define int long long
#define double long double
#define floot10 cout<<fixed<<setprecision(10)


signed main(){
  int n;
  cin>>n;
  int a[100001];
  lp(i,n){
    cin>>a[i+1];
  }
  a[0]=0;
  a[n+1]=0;
  int ansb=0;
  lp(i,n+1){
    //cout<<abs(a[i]-a[i+1])<<endl;
    ansb+=abs(a[i]-a[i+1]);
  }
  lp(i,n){
    int x=i+1;
    //cout<<(abs(a[x]-a[x-1])<<" "<<abs(a[x]-a[x+1])<<abs(a[x-1]-a[x+1])
    if(i!=0) cout<<" ";
	   cout<<ansb-(abs(a[x]-a[x-1])+abs(a[x]-a[x+1]))+abs(a[x-1]-a[x+1]);
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int P = sc.nextInt();
        final int Q = sc.nextInt();
        final int R = sc.nextInt();

        System.out.println(IntStream.of(P, Q, R).sorted().limit(2).sum());
    }
}


Measured memory_bytes: 28500
import java.util.*;
import java.util.HashSet;
import java.util.Set;
public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        long m=0;
        long a=0;
        long r=0;
        long c=0;
        long h=0;
        String[]namae=new String[N];
        for(int i=0;i<N;i++){
            namae[i]=sc.next();
            char[]aa=namae[i].toCharArray();
            if(aa[0]=='M'){
                m++;
            }
            if(aa[0]=='A'){
                a++;
            }
            if(aa[0]=='R'){
                r++;
            }
            if(aa[0]=='C'){
                c++;
            }
            if(aa[0]=='H'){
                h++;
            }
        }
        long sum=0;
        sum+=m*a*r;
        sum+=m*a*c;
        sum+=m*a*h;
        sum+=m*r*c;
        sum+=m*r*h;
        sum+=m*c*h;
        sum+=a*r*c;
        sum+=a*r*h;
        sum+=a*c*h;
        sum+=r*c*h;
        System.out.println(sum);
        
        
        

        }
       
        
    }

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

using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define SORT(v) sort(v.begin(), v.end())
typedef long long ll;

int main()
{
    int a, b, c, d;
    string s;

    cin >> a >> b >> c >> d;

    //vector<int> v(/*size*/);
    while (true)
    {
        c -= b;
        if (c <= 0)
        {
            cout << "Yes";
            break;
        }
        a -= d;
        if (a <= 0)
        {
            cout << "No";
            break;
        }
    }
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int N;
    cin >> N;
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    H[0]--;
    for (int i = 1; i < N; i++) {
        if (H[i-1] < H[i]) H[i]--;
        if (H[i-1] > H[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n, k;
int a[MAXN];

void init ();
void input ();
void work ();

int gcd ( int x, int y )
{
	return y ? gcd ( y, x%y ) : x;
}



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d", &n, &k );
	lp ( i, 0, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work

	int g = a[0];
	lp ( i, 1, n ) g = gcd ( g, a[i] );

	printf ( ( k <= *max_element ( a, a + n ) && ( k % g == 0 ) ) ? "POSSIBLE\n" : "IMPOSSIBLE\n" );
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp make_pair
#define sz(x) ((int)(x).size())
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define all(x) x.begin(),x.end()

#define INF 1000000010
#define FOR(x, n) for(int x=0; x<n; x++)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;



int n, ans;
vi v(200010);
unordered_map<int, int> M;

int main() {
	fastio;
	cin >> n;
	FOR(i, n) {
		cin >> v[i + 1];
		M[v[i + 1]]++;
	}
	for (int i = 1; i <= n; i++) {
		int flag = 1;
		for (ll j = 1; j * j <= v[i]; j++) {
			if (v[i] % j == 0) {
				//v[i]/j, j
				if (j == v[i] && M[j] >= 2 || j != v[i] && M[j] >= 1 || v[i]/j == v[i] && M[v[i]/j] >= 2 || v[i]/j != v[i] && M[v[i]/j] >= 1) {
					flag = 0;
					break;
				}
			}
		}
		if (flag) ans++;
	}
	cout << ans;
}

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

const int DIM = 3e2 + 5;
const int MOD = 1e9 + 7;

int dp[DIM][DIM][DIM];
vector<pair<int, int>> edg[DIM];

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    int ans = 0;
    for( int i = 1; i <= m; i ++ ) {
        int x, y, z;
        cin >> x >> y >> z;
        
        edg[y].push_back( make_pair(x, z) );
    }
    
    dp[0][0][0] = 1;
    for( int i = 0; i <= n; i ++ ) {
    for( int j = 0; j <= n; j ++ ) {
    for( int k = 0; k <= n; k ++ ) {
        int q = max( i, max( j, k ) );
        
        for( pair<int, int> pr : edg[q] ) {
            int nr = 0;
            
            if( i >= pr.first )
                nr ++;
            if( j >= pr.first )
                nr ++;
            if( k >= pr.first )
                nr ++;
            
            if( nr != pr.second ) {
                dp[i][j][k] = 0;
                break;
            }
        }
        
        if( q == n )
            ans = ( ans + dp[i][j][k] ) % MOD;
        else {
            dp[q + 1][j][k] = ( dp[q + 1][j][k] + dp[i][j][k] ) % MOD;
            dp[i][q + 1][k] = ( dp[i][q + 1][k] + dp[i][j][k] ) % MOD;
            dp[i][j][q + 1] = ( dp[i][j][q + 1] + dp[i][j][k] ) % MOD;
        }
    } } }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 110848
n = int(input())
d = []
z = 0

for i in range(n):
  d1, d2 = map(int, input().split())
  z = z+1 if d1==d2 else 0
  d.append(z)

ans = 'Yes' if max(d)>=3 else 'No'
print(ans)


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    n = 20000 - n;
    cout << n % 1000 << endl;
    return 0;
}



Measured memory_bytes: 3592
#include "bits/stdc++.h"
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr_inv(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rep(i,n) repr(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
#define PI 3.1415926535
using namespace std;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int x, a, b;

	cin>>x>>a>>b;

	if(abs(x-a)<abs(x-b)){
		cout<<"A"<<endl;
	} else{
		cout<<"B"<<endl;
	}
}

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

vector<vector<int> > adj(200100);
bool done[200100];

void dfs(int i, int &x, int &y, int &z) {
    done[i] = true;
    (i % 2 ? y : x)++;
    for (int j : adj[i]) { z++; if (!done[j]) dfs(j, x, y, z); }
}

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        adj[2*a].push_back(2*b+1);
        adj[2*b+1].push_back(2*a);
    }
    long long ans = 0;
    for (int i = 0; i <= 200001; i++)
        if (!adj[i].empty() && !done[i]) {
            int x = 0, y = 0, z = 0;
            dfs(i, x, y, z);
            ans += (long long)x * y - z/2;
        }
    cout << ans << endl;
}


Measured memory_bytes: 12928
import java.util.*;;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int ans = A * X + B * Y;

        for(int i=1; i<=Math.max(X, Y); i++){
            int sum = C * 2 * i + Math.max(0, X - i) * A + Math.max(0, Y - i) * B;
            ans = Math.min(ans, sum);
        }
        System.out.println(ans);
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[101010];

int V[101010];
int num[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	cin>>N;
	multiset<int> M;
	FOR(i,N) {
		cin>>x;
		auto it=M.lower_bound(x);
		if(it!=M.begin()) M.erase(--it);
		M.insert(x);
	}
	cout<<M.size()<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4992
from itertools import accumulate
n = int(input())
s = input()
list_e = [0]*n
list_w = [0]*n
for i in range(n):
  if s[i]=="E":
    list_e[i]=1
for i in range(n):
  if s[i]=="W":
    list_w[i]=1
    
list_e = list(accumulate([0]+list_e))
list_w = list(accumulate([0]+list_w))
m = 10**7
for i in range(n):
  a = list_w[i]
  b = list_e[-1]-list_e[i+1]
  m = min(m,a+b)
print(m)

Measured memory_bytes: 32916
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 1000000000;
using namespace std;
int main() {
  int N, ans = 0;
  cin >> N;
  int A[N];
  rep(i, N) cin >> A[i];
  rep(i, N) {
    if (A[A[i] - 1] == i + 1)
      ans++;
  }
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 640
package main

import (
	"fmt"
)

func abs(n int) int {
	if n >= 0 {
		return n
	}
	return -n
}

func main() {
	var n int
	fmt.Scan(&n)

	weights := make([]int, n)
	totalWeight := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&weights[i])
		totalWeight += weights[i]
	}

	minDiff := 101
	currentWeight := 0
	for t := 0; t < n-1; t++ {
		currentWeight += weights[t]

		diff := abs(currentWeight - (totalWeight - currentWeight))
		if minDiff > diff {
			minDiff = diff
		}
	}

	fmt.Println(minDiff)
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 1000005;
const int mod = 1000000007;

ll f[maxn];

int main() {
  //freopen("in.cpp","r",stdin);
  int n;
  cin>>n;
  ll ret=0,sum3=0,agg3=0;
  f[0]=1;
  for(int i=1; i<=n; i++) {
    f[i]=f[i-1];
    if(i<n) {
      //for(int j=3; j<=i; j++)f[i]=(f[i-j]+f[i])%mod;
      f[i]=(f[i]+sum3)%mod;
    } else {
      f[i]=(f[i]+f[i-2]*(n-1)%mod)%mod;
      //for(int j=3; j<=i; j++)f[i]=(f[i]+f[i-j]*(n-j+2)%mod)%mod;
      f[i]=(f[i]+agg3)%mod;
    }
    if(i>=2){
      agg3=(agg3+mod-sum3+f[i-2]*(n-1)%mod)%mod;
      sum3=(sum3+f[i-2])%mod;
    }
  }
  ret=(f[n]+f[n-1]*(n-1)%mod)%mod;
  for(int i=0; i+1<n; i++) {
    ret=(ret+f[i]*(n-1)%mod*(n-1)%mod)%mod;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 8064
class Node:
    def __init__(self, nid):
        self.nid = nid
        self.parent = None
        self.left = None
        self.right = None
    
    def preo(self):
        tmp = ""
        tmp += " " + str(self.nid)
        if self.left:
            tmp += self.left.preo()
        if self.right:
            tmp += self.right.preo()
        return tmp
    
    def ino(self):
        tmp = ""
        if self.left:
            tmp += self.left.ino()
        tmp += " " + str(self.nid)
        if self.right:
            tmp += self.right.ino()
        return tmp
    
    def posto(self):
        tmp = ""
        if self.left:
            tmp += self.left.posto()
        if self.right:
            tmp += self.right.posto()
        tmp += " " + str(self.nid) 
        return tmp
    
n = int(input())
T={}
for i in range(n):
    T[i] = Node(i)
for i in range(n):
    nid, left, right = [int(i) for i in input().split()]
    if left != -1:
        T[nid].left = T[left]
        T[left].parent = T[nid]
    if right != -1:
        T[nid].right = T[right]
        T[right].parent = T[nid]
root = T[0]
while(True):
    if root.parent:
        root = root.parent
    else:
        break
print("Preorder")
print(root.preo())
print("Inorder")
print(root.ino())
print("Postorder")
print(root.posto())


Measured memory_bytes: 5612
n,d,a=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
lim=[0]*n
pos=0
for i in range(n):
  while pos!=n-1:
    if arr[i][0]+2*d>=arr[pos+1][0]:
      pos+=1
    else:
      break
  lim[i]=pos
ans=0
damage=[0]*n
acum=0
pos=0
for i in range(n):
  while i>lim[pos]:
    acum-=damage[pos]
    pos+=1
    if pos==n:
      break
  ans+=max(0,(arr[i][1]-acum+(a-1))//a)
  damage[i]=a*max(0,(arr[i][1]-acum+(a-1))//a)
  acum+=damage[i]
print(ans)

Measured memory_bytes: 67636
fn solve() {
    let stdin = std::io::stdin();
    let mut scn = Scanner { stdin: stdin.lock() };
    let n = scn.chars();
    let result = if n.into_iter().any(|x| x == '7') {
        "Yes"
    } else {
        "No"
    };
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}
pub mod utils {
    const DYX: [(isize, isize); 8] = [
        (0, 1),   //right
        (1, 0),   //down
        (0, -1),  //left
        (-1, 0),  //top
        (1, 1),   //down right
        (-1, 1),  //top right
        (1, -1),  //down left
        (-1, -1), //top left
    ];

    pub fn try_adj(y: usize, x: usize, dir: usize, h: usize, w: usize) -> Option<(usize, usize)> {
        let ny = y as isize + DYX[dir].0;
        let nx = x as isize + DYX[dir].1;
        if ny >= 0 && nx >= 0 {
            let ny = ny as usize;
            let nx = nx as usize;
            if ny < h && nx < w {
                Some((ny, nx))
            } else {
                None
            }
        } else {
            None
        }
    }
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        expired solver = new expired();
        solver.solve(1, in, out);
        out.close();
    }

    static class expired {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int b = in.nextInt();
            int a = in.nextInt();
            if (a <= b) {
                out.print("delicious");
                return;
            }
            if (a - b <= x) {
                out.println("safe");
                return;
            }
            out.println("dangerous");
        }

    }
}



Measured memory_bytes: 23636
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    k = read_int()
    x = read_int_list()

    res = 0
    for i in range(n):
        r = 2 * x[i]
        if k - x[i] < x[i] - 0:
            r = 2 * (k - x[i])
        res += r
    print(res)


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
        cin >> a[i];

    ll res = 0;
    for (ll d = 60; d >= -1; d--)
    {
        if (d != -1 && !(k & (1LL << d)))
            continue;

        ll tmp = 0;
        for (ll e = 60; e >= 0; e--)
        {
            ll mask = 1LL << e;
            ll num = 0;

            for (ll i = 0; i < n; i++)
            {
                if (a[i] & mask)
                    num++;
            }

            if (e > d)
            {
                if (k & mask)
                    tmp += mask * (n - num);
                else
                    tmp += mask * num;
            }
            else if (e == d)
            {
                tmp += mask * num;
            }
            else
            {
                tmp += mask * max(num, n - num);
            }

            res = max(res, tmp);
        }
    }
    cout << res << endl; 
}

Measured memory_bytes: 1024
N = int(input())
A, B = [0]*N, [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
A.sort()
B.sort()
if N % 2 == 1:
    print(abs(A[N//2]-B[N//2])+1)
else:
    a_median = (A[N//2] + A[(N//2)-1])/2
    b_median = (B[N//2] + B[(N//2)-1])/2
    print(int(abs(a_median-b_median)*2+1))

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// Vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
	for (int i = 0; i < len; i++) {
    if (i > 0) s << ", ";
		s << v[i];
  }
  s << "]";
  return s;
}

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

  string s;
  int64 k;
  cin >> s >> k;

  vector<int> ls;
  char current = '^';
  int current_length = 0;
  for (char c : s) {
    if (c == current) {
      current_length++;
    } else {
      if (current_length > 0) ls.push_back(current_length);
      current = c;
      current_length = 1;
    }
  }
  if (current_length > 0) ls.push_back(current_length);

  // cout << ls << endl;

  if (ls.size() == 1) {
    cout << ls[0] * k / 2 << endl;
    return 0;
  }

  if (s.front() == s.back()) {
    int64 sum = 0;
    sum += ls.front() / 2;
    sum += ls.back() / 2;
    sum += (ls.front() + ls.back()) / 2 * (k - 1);
    for (int i = 1; i < ls.size() - 1; i++) {
      sum += ls[i] / 2 * k;
    }
    cout << sum << endl;
  } else {
    int64 sum = 0;
    for (int l : ls) {
      sum += l / 2 * k;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(){
int n,N,i=0,j,count=0;
double sqrtN;

scanf("%d",&n);

for(j=0;j<n;j++){
    scanf("%d",&N);
     
    if(N==2 || N==3){
        count++;
        continue;
    }
    else if(N<2 || N%2==0) continue;
    else{
        sqrtN=sqrt(N);

        for(i=2;i<=sqrtN;i++){
            if(N%i==0) break;
        }
        if(i==((int)sqrtN+1)) count++;
    }
}
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 2068
import java.util.*;

class Main{
	public static void main(String[]args){
		Scanner s = new Scanner(System.in);
		int[] a = new int[6];
		for(int i = 0; i < 6; i++) a[i] = s.nextInt();
		
		String mozi = s.next();
		int k = mozi.length();
		int i, tmp;
		for(i = 0; i < k; i++){
			char z = mozi.charAt(i);
			if(z == 'N'){
				tmp = a[0];
				a[0] = a[1];
				a[1] = a[5];
				a[5] = a[4];
				a[4] = tmp;
			}else if(z == 'S'){
				tmp = a[0];
				a[0] = a[4];
				a[4] = a[5];
				a[5] = a[1];
				a[1] = tmp;
			}else if(z == 'E'){
				tmp = a[0];
				a[0] = a[3];
				a[3] = a[5];
				a[5] = a[2];
				a[2] = tmp;
			}else if(z == 'W'){
				tmp = a[0];
				a[0] = a[2];
				a[2] = a[5];
				a[5] = a[3];
				a[3] = tmp;
			} //if
		} //for
		System.out.println(a[0]);
	} //main
} //class


Measured memory_bytes: 26276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>

using namespace std;

bool consistent(const vector<int>& people, const vector<int>& target, const vector<int>& testimony, const bitset<15>& honests) {
    bool consistent = true;
    for (int i = 0; i < people.size(); ++i) {
        if (honests.test(people[i])) {
            if (honests.test(target[i]) == testimony[i]) {
                continue;
            }
            else {
                consistent = false;
                break;
            }
        }
        else {
            continue;
        }
    }
    return consistent;
}

int main() {
    int N;
    cin >> N;
    vector<int> people;
    vector<int> target;
    vector<int> testimony;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        for (int j = 0; j < A; ++j) {
            int x, y;
            cin >> x >> y;
            people.push_back(i);
            target.push_back(x - 1);
            testimony.push_back(y);
        }
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); ++i) {
        bitset<15> bit(i);
        bool cons = consistent(people, target, testimony, bit);
        if (cons) {
            int nHonests = bit.count();
            ans = max(ans, nHonests);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

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

cand = [[1]]
for i in range(N-1):
    tmp = []
    while cand:
        x = cand.pop()
        for i in range(x[-1], M + 1):
            tmp.append(x + [i])
    cand = tmp

ans = 0
for X in cand:
    score = 0
    for a, b, c, d in abcd:
        if X[b - 1] - X[a - 1] == c:
            score += d
    ans = max(ans, score)
print(ans)

Measured memory_bytes: 16484
#include <stdio.h>

int main(void){
    int n, i, max = 0, sum=0;
    scanf("%d", &n);
    int l[n];
    for(i=0; i<n; i++){
        scanf("%d", &l[i]);
        if(max<l[i]) max = l[i];
        sum += l[i];
    }
    if((sum-max)>max) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt(),k=sc.nextInt(),ans=0;
	int [] a = new int [n];
	for (int i=0;i<n;i++) a[i]=sc.nextInt();
	Arrays.sort(a);
	for (int i=0;i<k;i++) {
		ans+=a[i];
	}
	System.out.println(ans);
	sc.close();}}

Measured memory_bytes: 38768