akhauriyash/Code-Regression huggingface dataset:
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<998244353>;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int sum = 0;
	modulo mul = 1;
	for (int i = 0; i < N; ++i) cin >> A[i], sum += A[i], mul *= 3;
	vector<modulo> dp(2 * sum + 1), dp2(2 * sum + 1);
	dp[sum] = 1;
	dp2[sum] = 1;
	for (int i = 0; i < N; ++i) {
		vector<modulo> ndp(2 * sum + 1);
		for (int j = 0; j <= 2 * sum; ++j) {
			if (j >= A[i]) ndp[j] += dp[j - A[i]];
			if (j <= 2 * sum - A[i]) ndp[j] += dp[j + A[i]] * 2;
		}
		dp = ndp;
	}
	for (int i = 0; i < N; ++i) {
		vector<modulo> ndp(2 * sum + 1);
		for (int j = 0; j <= 2 * sum; ++j) {
			if (j >= A[i]) ndp[j] += dp2[j - A[i]];
			if (j <= 2 * sum - A[i]) ndp[j] += dp2[j + A[i]];
		}
		dp2 = ndp;
	}
	modulo ans = mul;
	for (int i = sum; i <= 2 * sum; ++i) ans -= dp[i] * 3;
	ans += dp2[sum] * 3;
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 2376
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int INF = 1e9;
const int MAX = 100000;
const long long LINF = 1e18;



int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M);
  for(int i = 0; i < M; i++){
    cin >> X[i];
  }
  sort(X.begin(),X.end());
  int L = X[M-1] - X[0];
  int ans = 0;
  if(M > 1 && M >= N){
    if(N > 1){
      vector<int> l(M-1);
      for(int i = 0; i < M-1; i++){
        l[i] = X[i+1]-X[i];
      }
      sort(l.begin(),l.end(),greater<int>());
      int sum = 0;
      for(int i = 0; i < N-1; i++){
        sum += l[i];
      }
      ans = L - sum;
    }
    else ans = L;
  }

  cout << ans << endl;
}
  


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

int main(){
    string s[50];
    int h, w;
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }
    const int dx[8] = {1, 1, 1, 0, 0, -1, -1, -1};
    const int dy[8] = {1, 0, -1, 1, -1, 1, 0, -1};

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(s[i][j] == '#') continue;
            int tmp = 0;
            for(int d = 0; d < 8; d++){
                const int x = j + dx[d];
                const int y = i + dy[d];

                if(x < 0 || w <= x || y < 0 || h <= y) continue;
                if(s[y][x] == '#') tmp++;
            }
            s[i][j] = tmp + '0';
        }
    }
    for(int i = 0; i < h; i++){
        cout << s[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
s = gets.chomp.to_i

x_1 = 0
x_2 = 1
x_3 = 1

y_1 = 0
y_2 = 1
y_3 = s + 1

if s > 10**9
  #sの桁数を調べる
  s_size = s.to_s.length
  y_3 = 10**9
  x_2 = s.to_s[0, s_size - 9].to_i
  x_2 += 1 if x_2 != 10 **9
  x_3 = x_2 * y_3 - s
end
print("#{x_1} #{y_1} #{x_2} #{y_2} #{x_3} #{y_3}\n")

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "test"
using namespace std;
const ll N = 1e6 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
char a[N];
ll h,w,k,n,d[N],x1,x2,Y1,Y2;
ll scr,dest;
ll trans(ll x,ll y){
    return (x - 1)*w + y;
}
bool chk(ll n){
    return (n > 0&&n <= h*w&&a[n] != '@');
}
void BFS(ll scr){
    queue<ll> q;
    fill(d,d + N + 1,inf);
    d[scr] = 0;
    q.push(scr);
    while(!q.empty()){
        ll t = q.front(); q.pop();
        ll p = ceil((ld) t/w);
        for (ll i = t + 1;i <= t + k;i++){
            if (chk(i)&&i <= p*w){
                if (d[i] > d[t] + 1){
                    d[i] = d[t] + 1;
                    q.push(i);
                }
                else if (d[i] == d[t] + 1) continue;
                else break;
            }
            else break;
        }
        for (ll i = t - 1;i >= t - k;i--){
            if (chk(i)&&i > (p - 1)*w){
                if (d[i] > d[t] + 1){
                    d[i] = d[t] + 1;
                    q.push(i);
                }
                else if (d[i] == d[t] + 1) continue;
                else break;
            }
            else break;
        }
        for (ll i = 1;i <= k;i++){
            if (chk(t + i*w)){
                if (d[t + i*w] > d[t] + 1){
                    d[t + i*w] = d[t] + 1;
                    q.push(t + i*w);
                }
                else if (d[t + i*w] == d[t] + 1) continue;
                else break;
            }
            else break;
        }
        for (ll i = 1;i <= k;i++){
            if (chk(t - i*w)){
                if (d[t - i*w] > d[t] + 1){
                    d[t - i*w] = d[t] + 1;
                    q.push(t - i*w);
                }
                else if (d[t - i*w] == d[t] + 1) continue;
                else break;
            }
            else break;
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>h>>w>>k>>x1>>Y1>>x2>>Y2;
    for (ll i = 1;i <= h*w;i++) cin>>a[i];
    scr = trans(x1,Y1); dest = trans(x2,Y2);
    BFS(scr);
    if (d[dest] != inf) cout<<d[dest];
    else cout<<-1;
}


Measured memory_bytes: 13124
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stdlib.h>

using namespace std;

const int maxn=500100;

int t[maxn],a[maxn];

int c=0;

void merge_sort(int *a,int x,int y,int *t){
	if(y-x>1){
		int m=(x+y)/2;
		int p=x,q=m,i=x;
		merge_sort(a,x,m,t);
		merge_sort(a,m,y,t);
		while(p<m || q<y){
			if(q>=y || (p<m && a[p]<=a[q]))
			{
				c++;
				t[i++]=a[p++];
			}
			else
			{
				c++;
				t[i++]=a[q++];
			}
		}
	for(i = x;i<y;i++)
		a[i]=t[i];
	}
}

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF){
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
		}
		int l=0,r=n;
		merge_sort(a,l,r,t);
		for(int i=0;i<n;i++)
		{
			if(i!=0)
				printf(" ");
			printf("%d",a[i]);
		}
		printf("\n");
		printf("%d\n",c);
	}
	return 0;
}



Measured memory_bytes: 7092
import java.util.*;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		long N = scanner.nextLong();
		String S = scanner.next();

		long ans = 0;
		for (int i = 0; i < N - 2; i++) {
			boolean a = S.charAt(i) == 'A';
			boolean b = S.charAt(i + 1) == 'B';
			boolean c = S.charAt(i + 2) == 'C';
			if (a && b && c) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

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

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

    int cost[N+1];
    cost[0] = 0;
    for(int i=1; i<N+1; i++){
        cost[i] = INF;
    }

    for(int i=1; i<N+1; i++){
        cost[i] = min(cost[i], cost[i-1]+1);
        int tmp = 6;
        while(i-tmp >= 0 && tmp <= N){
            cost[i] = min(cost[i], cost[i-tmp]+1);
            tmp *= 6;
        }
        tmp = 9;
        while(i-tmp >= 0 && tmp <= N){
            cost[i] = min(cost[i], cost[i-tmp]+1);
            tmp *= 9;
        }
    }

    cout << cost[N] << endl;
    return 0;
}

Measured memory_bytes: 640
import java.io.*;
class Main{
    public static void main(String[]args){
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
      	int S;
        try{
            S = Integer.parseInt(bf.readLine());
        }catch(Exception e){
          	S = 0;
        }
        int H,M,s;
        H = (int) S / 3600;
        M = (int) (S%3600) / 60;
        s = (int) (S%3600) % 60;
        System.out.print(H + ":");
        System.out.print(M + ":" + s);
        System.out.println();
    }
}


Measured memory_bytes: 24464
from collections import deque
n,k=map(int,input().split())
s=list(map(int,list(input())))
cnt=0
q=deque()
prev=1
ans=[]
for i in s:
    if i==0 and prev==1:
        cnt+=1
    q.append(i)
    prev=i
    if cnt>k:
        #print(q)
        ans.append(len(q)-1)
        prev1=1
        while len(q)>0:
            if q[0]==1 and prev1==0 and cnt<=k:
                break
            if q[0]==0 and prev1==1:
                cnt-=1
            prev1=q[0]
            q.popleft()
ans.append(len(q))
print(max(ans))

Measured memory_bytes: 5780
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32, a: i32, b: i32,
    }
    let mut ans = 0;
    for i in 1..n+1 {
        let mut count = 0;
        let mut num = i;
        for _ in 0..5 {
            count += num % 10;
            num /= 10;
        }
        
        if a <= count && count <= b {
            ans += i;
        }
    }

    println!("{}", ans);
}


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

#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define i64 long long int
#define MEM(a,x) memset(a,x,sizeof(x))
#define INF 1000000000
#define mod 998244353

using namespace std ;

typedef pair<int,int> pi ;

#define maxn 1000005

i64 a[maxn] ;

int main()
{
    i64 i , j , k , l , m , n ;

    scanf("%lld",&n) ;

    for(i=0 ; i<n ; i++) scanf("%lld",&a[i]) ;

    i64 sum = 0LL ;
    for(i=0 ; i<n ; i++) sum += a[i] ;

    if( sum%((n*(n+1))/2) != 0 )
    {
        printf("NO\n") ;
        return 0 ;
    }

    i64 t = sum/((n*(n+1))/2) ;

    i64 fl = 1 ;

    a[n] = a[0] ;

    for(i=0 ; i<n ; i++)
    {
        i64 deli = a[i] - a[i+1] ;

        if( deli+t < 0 || (deli+t)%n !=0 ) fl = 0 ;
    }

    if(fl) printf("YES\n") ;
    else printf("NO\n") ;

    return 0 ;
}


Measured memory_bytes: 1024
/*
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineerin College
    Date:07/03/2020
*/
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
#define ld long double
#define ff first
#define ss string 
#define se second
#define alt(v) v.begin(),v.end()
#define pb emplace_back
#define mp make_pair
#define tc(t) cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fab(i,a,b) for(ll i=(a);i<(b);i++)
#define fba(i,a,b) for(ll i=(b);i>=(a);i--)
#define arr(i,n) fab(i,0,n)

ll test=0;
void solve()
{

    int i,j,f=0,k,x1,x2,y,q,m,n;
    string s;
    cin>>s;
    int c1=0,c2=0;
    fab(i,0,3){
    if(s[i]=='A')
    c1++;
    else
    c2++;
    
    }
    if(c1==2 && c2==1)
    cout<<"Yes"<<endl;
    else if(c1==1 && c2==2)
     cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}














int main()
{
    ll t=1,s;
    if(test)
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <limits.h>
#include <math.h>

int qsort_int(const void *a, const void *b)
{
    return *(int *) a - *(int *) b;
}

int push(int n, int v[], int count, int l, int r)
{
    int a[50];
    int i, p;
    int sum;

    p = 0;
    for (i = 0; i < l; i++) {
        a[p++] = v[i];
    }
    for (i = 0; i < r; i++) {
        a[p++] = v[n - i - 1];
    }

    qsort(a, p, sizeof(int), qsort_int);

    sum = 0;
    for (i = 0; i < p; i++) {
        if (count == 0) {break;}
        if (a[i] < 0) {
            sum += a[i];
            count--;
        }
    }

    return sum;
}

int main(int argc, char *argv[])
{
    int n, k;
    int v[50];
    int l[51]; // 左からn個取り出した時のスコアl[i]
    int r[51]; // 右
    int i, j;
    int points;
    int max;
    int ans;

    scanf("%d %d", &n, &k);

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

    l[0] = 0;
    r[0] = 0;
    for (i = 0; i < n; i++) {
        l[i + 1] = l[i] + v[i]; 
        r[i + 1] = r[i] + v[n - i - 1];
    }

    max = 0;
    // solve
    for (i = 0; i <= n; i++) {
        for (j = 0; i + j <= n; j++) {
            if (i + j > k) {continue;}
            points = l[i] + r[j];

            points -= push(n, v, k - (i + j), i, j);

            if (max < points) {
                max = points;
            }
        }
    }

    printf("%d\n", max);

    return 0;
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!
import math

def main():
    a, b, h, m = map(int, input().split())
    arg_a = 360 * (h * 60 + m) / (12 * 60)
    arg_b = 360 * m / 60
    arg = min(abs(arg_a - arg_b), 360 - abs(arg_a - arg_b))
    # print(arg)
    c = math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(math.radians(arg)))
    
    print(c)
    
main()

Measured memory_bytes: 9372
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        long[] x = new long[N];
        long[] y = new long[N];
        for (int i = 0; i < N; i++)
        {
            x[i] = NextInt();
            y[i] = NextInt();
        }
        long ans = INFINITY;
        for (int x1 = 0; x1 < N; x1++)
            for (int x2 = 0; x2 < N; x2++)
                for (int y1 = 0; y1 < N; y1++)
                    for (int y2 = 0; y2 < N; y2++)
                    {
                        long xl = x[x1], xr = x[x2];
                        long yl = y[y1], yr = y[y2];
                        int count = 0;
                        for (int i = 0; i < N; i++)
                        {
                            if (xl <= x[i] && x[i] <= xr && yl <= y[i] && y[i] <= yr) count++;
                        }
                        if (count >= K)
                        {
                            long rect = (Math.Max(xl, xr) - Math.Min(xl, xr)) *
                                (Math.Max(yl, yr) - Math.Min(yl, yr));
                            ans = Math.Min(ans,rect);
                        }
                    }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int max_num = Math.max(A,B);
    ArrayList<Integer> num = new ArrayList<Integer>();
    
    for(int i=1;i<=max_num;i++){
     if(B%i==0&&A%i==0){
      num.add(i);
     }
    }
    
    int size=num.size();
    System.out.println(num.get(size-C));
  }
}

Measured memory_bytes: 21716
def f(s):
    sx=[0]*26
    for i in range (len(s)):
        p=ord(s[i])-ord("a")
        sx[p]+=1
    string=""
    for i in range(26):
        for _ in range(sx[i]):
            string+=chr(i+ord("a"))
    return string
s=input()
t=input()
print("Yes" if f(s)<f(t)[::-1] else "No")



Measured memory_bytes: 3060
import java.util.*;
public 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();
		// // 文字列の入力
		// String s = sc.next();
		// // 出力
    // System.out.println((a+b+c) + " " + s);
    int X = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    System.out.println((X - A) % B);
	}
}

Measured memory_bytes: 21844
N,M=list(map(int,input().split()))
S=[list(map(str,input().split())) for i in range(M)]
D={}
D2={}
D3={}
for i in S:
    if D.get(i[0],0)!='AC':
        D[i[0]]=i[1] 
        D2[(i[0],i[1])]=D2.get((i[0],i[1]),0)+1
ans=[0,0]
for i in D.items():
    if i[1]=='AC':
        ans[1]+=D2.get((i[0],'WA'),0)
        ans[0]+=D2.get((i[0],'AC'),0)

print(*ans)

Measured memory_bytes: 101080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cerr<<#x<<" -> "<<x<<'\n'
#define debug2(x,y) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<'\n'
#define debug3(x,y,z) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<" "<<#z<<" -> "<<z<<'\n'

 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

using ordered_set = tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
struct CMP {
	bool operator() (const T& lhs, const T& rhs) const{
		return lhs < rhs;
	}
};

template <typename T>
T power(T a, T n){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a);
		a = (a * a);
		n >>= 1;
	}
	
	return res;
}

template <typename T>
T power(T a, T n, long long mm){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a) % mm;
		a = (a * a) % mm;
		n >>= 1;
	}
	
	return res;
}

const ll N = 2e5+7;
const ll MOD = 1e9+7;
const ll INF = 2e14+7;

double prob[3005];
double dp[3005][3005];
int n;


double solve(int pos, int heads){
	if(pos >= n){
		if(heads > pos - heads){
			return 1;
		}
		
		return 0;
	}
	
	if(dp[pos][heads] != -1) return dp[pos][heads];
	
	double ans = prob[pos] * solve(pos + 1, heads + 1);
	double ans2 = (1.0 - prob[pos]) * solve(pos + 1, heads);
	
	return dp[pos][heads] = ans + ans2;
	
}

void testcase(){
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>prob[i];
	}
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			dp[i][j] = -1.0;
		}
	}
	
	double ans = solve(0, 0);
	
	cout<<setprecision(15)<<ans<<'\n';
	
}

signed main(){
	fast;
	
	int t = 1;
	//cin>>t;
	while(t--){
		testcase();
	}
	
	return 0;
}


Measured memory_bytes: 70912
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]

b = []
for i in range(n+1):
    b.append(abs(a[i+1] - a[i]))

c = []
for i in range(n):
    c.append(abs(a[i+2] - a[i]))
c = c + [0]    

sum_b = sum(b)
for i in range(n):
    print(sum_b - sum(b[i:i+2]) + c[i])

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	rep(i, S.size()){
		char a = S[i] + N;
		if (a - 'A' >= 26) a -= 26;
		cout << a; 
	}
	cout << endl;
	//cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
struct node
{
	 int a,b,c,d;

};
int a[1000][1000]={0};
int main()
{
	 int n,m;
	 cin>>n>>m;
	 vector<node>q;
	 
	 for(int i=1;i<=n;i++)
	 {
	 	 for(int j=1;j<=m;j++)
	 	  cin>>a[i][j];
	 	  for(int j=1;j<m;j++)
	 	   {
	 	   	 if(a[i][j]&1)
	 	   	   {a[i][j+1]++;
	 	   	   	 q.push_back(node{i,j,i,j+1});
	 	   	   	 
	 	   	   	 
				   }
				   
			}
	 }
	 
 for(int i=1;i<n;i++)
	 {
	 	 if(a[i][m]&1)
	 	 {a[i+1][m]++;
	 	 	q.push_back(node{i,m,i+1,m});
	 	 //	a[i][m-1]--;
	 	 	
		  }
	 }
		/* printf("\n");
	 for(int i=1;i<=n;i++)
	 {
	 	for(int j=1;j<=m;j++)
	 	 printf("%d ",a[i][j]);
	 	 printf("\n");
	 }*/
	 cout<<q.size()<<endl;
	 for(int i=0;i<q.size();i++)
	  printf("%d %d %d %d\n",q[i].a,q[i].b,q[i].c,q[i].d);
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
int A,B,C,X,Y;
int solve(int x,int y){
    long long int ans = 0;
    while(x<X || y<Y){
        if(A+B >= 2*C && (x<X) && y<Y){
            x++;
            y++;
            ans += 2*C;
        }
        else if(X<=x && y<Y){
            if(2*C<=B){
                ans += 2*C;
                x++;
                y++;
            }
            else {
                ans += B;
                y++;
            }
        }
        else if(Y<=y && x<X){
            if(2*C<=A){
                ans += 2*C;
                x++;
                y++;
            }
            else {
                ans += A;
                x++;
            }
        }
        else{
            ans += A*(X-x) + B*(Y-y);
            x = X;
            y = Y;
        }
    }
    return ans;
}


int main(){
    cin>>A>>B>>C>>X>>Y;
    long long int ans = solve(0,0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからbまで
#define print(x) cout<<x<<endl  //xを改行付きで出力
#define scan(x) cin>>x //xを入力
const int INF = 1e9 + 7;  //最大値兼MOD
typedef long long ll;
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; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
/*
./a.exe
*/
ll ans = 1;
int n;cin>>n;
rep1(i,n+1)ans = (ans * i) % INF;
cout<< ans <<endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

vector<ll> fac;
int N;
typedef struct {
    vector<pair<int, ll>> edge;
    int par = 0;
    ll ans = 0;
    ll siz = 1;
    ll dp = 1;
    bool vi1 = 0, vi2 = 0;
}node_t;
vector<node_t> node;

long long mypow(long long k, long long n) {
    long long temp = 1;

    k = k % DIV;
    while (n) {
        if (n % 2) temp = temp * k % DIV;
        k = k * k % DIV;
        n = n / 2;
    }
    return temp % DIV;
}

ll dfs(int x) {
    int n = node[x].edge.size();
    ll nuri = 1;
    ll deno = 1;
    for (int i = 0; i < n; i++) {
        int to = node[x].edge[i].first;
        if (node[to].vi1) continue;
        node[to].vi1 = true;
        node[to].par = x;
        node[x].edge[i].second = dfs(to);
        node[x].siz += node[to].siz;
        nuri *= node[x].edge[i].second;
        nuri %= DIV;
        deno *= fac[node[to].siz];
        deno %= DIV;

    }

    ll as = nuri * (fac[node[x].siz - 1]);
    as %= DIV;
    node[x].dp = as * mypow(deno, DIV - 2);
    node[x].dp %= DIV;
    return node[x].dp;
}

void dfs2(int self, int par) {
    int n = node[self].edge.size();
    if (par == -1) node[self].ans = node[self].dp%DIV;
    else {
        ll nuri = 1;
        ll deno = 1;
        for (int i = 0; i < n; i++) {
            int to = node[self].edge[i].first;
            int S = node[to].siz;
            if (to == par) {
                S = N - node[self].siz;
                ll temp = node[par].ans * mypow(fac[N - 1], DIV - 2);
                temp %= DIV;
                temp *= fac[S - 1];
                temp %= DIV;
                temp *= fac[node[self].siz];
                temp %= DIV;
                temp *= mypow(node[self].dp, DIV - 2);
                node[self].edge[i].second = temp;
            }
          	node[self].edge[i].second %=DIV;
            nuri *= node[self].edge[i].second;
            nuri %= DIV;
            deno *= fac[S];
            deno %= DIV;
        }
        ll as = nuri * fac[N - 1];
        as %= DIV;
        node[self].ans = as * mypow(deno, DIV - 2);
        node[self].ans %= DIV;
    }

    for (int i = 0; i < n; i++) {
        int to = node[self].edge[i].first;
        if (node[to].vi2) continue;
        node[to].vi2 = true;
        dfs2(to, self);
    }

}


int main() {

    cin >> N;

    node = vector<node_t>(N + 1);
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        node[a].edge.push_back(make_pair(b, 0));
        node[b].edge.push_back(make_pair(a, 0));
    }

    fac = vector<ll>(N + 1, 1);
    for (ll i = 2; i <= N; i++) {
        fac[i] = fac[i - 1] * i;
        fac[i] %= DIV;
    }


    node[1].vi1 = true;
    dfs(1);
    node[1].vi2 = true;
    dfs2(1,-1);
    for (int i = 1; i <= N; i++) {
      cout << node[i].ans << endl;
    }
   
}


Measured memory_bytes: 27136
N=input()

if N[-1]=="2" or \
N[-1]=="4" or \
N[-1]=="5" or \
N[-1]=="7" or \
N[-1]=="9":
  print("hon")
elif N[-1]=="0" or \
N[-1]=="1" or \
N[-1]=="6" or \
N[-1]=="8":
  print("pon")
else:
  print("bon")

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

typedef long long ll;
typedef long double ld;
#define Cin(x) cin >> x
#define Cin2(x,y) cin >> x >> y
#define Cin3(x,y,z) cin >> x >> y >> z
#define Cin4(w,x,y,z) cin >> w >> x >> y >> z
#define Cout(x) cout << x << "\n"
#define Cout2(x,y) cout << x << y << "\n"
#define Cout3(x,y,z) cout << x << y << z << "\n"
#define Cout4(w,x,y,z) cout << w << x << y << z << "\n"
#define Kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define Size(n) (n).size()
#define EPS (1e-7)
#define INF (1e9)

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

    ll n,a,b;
    Cin3(n,a,b);
    if(n*a<=b){
        Cout(n*a);
    }else{
        Cout(b);
    }
    return 0;
}

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

int main()
{
    int n, a;
    double r = 0;
    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> a;
        r += 1.0 / a;
    }
    r = 1.0 / r;
    //cout << trunc(r) << endl;
    printf("%0.5f\n", r);
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

class Main{
	public static void main(String[] args) {
		int INF=1000000007;
		Scanner sc=new Scanner(System.in);
		int V=sc.nextInt();
		ArrayList<ArrayList<Integer>> v=new ArrayList<ArrayList<Integer>>();
		for(int i=0; i<=V; i++) {
			v.add(new ArrayList<Integer>());
		}
		for(int i=0; i<V-1; i++) {
			int a=sc.nextInt();
			int b=sc.nextInt();
			(v.get(a)).add(b);
			(v.get(b)).add(a);
		}
		int[] Fe=new int[V+1];
		int[] Su=new int[V+1];
		boolean[] Fe_V=new boolean[V+1];
		boolean[] Su_V=new boolean[V+1];
		Arrays.fill(Fe, INF);
		Arrays.fill(Su, INF);
		Fe[1]=0;
		Su[V]=0;
		Stack<Integer> Q=new Stack<Integer>();
		Q.add(1);
		while(!Q.isEmpty()) {
			int tmp=Q.pop();
			for(int i=0; i<v.get(tmp).size(); i++) {
				if(!Fe_V[v.get(tmp).get(i)] && Fe[tmp]+1<Fe[v.get(tmp).get(i)]) {
					Fe_V[v.get(tmp).get(i)]=true;
					Fe[v.get(tmp).get(i)]=Fe[tmp]+1;
					Q.push(v.get(tmp).get(i));
				}
			}
		}

		Q.add(V);
		while(!Q.isEmpty()) {
			int tmp=Q.pop();
			for(int i=0; i<v.get(tmp).size(); i++) {
				if(!Su_V[v.get(tmp).get(i)] && Su[tmp]+1<Su[v.get(tmp).get(i)]) {
					Su_V[v.get(tmp).get(i)]=true;
					Su[v.get(tmp).get(i)]=Su[tmp]+1;
					Q.push(v.get(tmp).get(i));
				}
			}
		}
		int Su_w=0;
		int Fe_w=0;
		for(int i=1; i<=V; i++) {
			if(Fe[i]<=Su[i]) {
				Fe_w++;
			}
			else {
				Su_w++;
			}
		}
		if(Su_w>=Fe_w) {
			System.out.println("Snuke");
			System.out.flush();
		}
		else {
			System.out.println("Fennec");
			System.out.flush();
		}
	}
}

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

#define debug(n) cerr << #n << ':' << n << endl;

using namespace std;

using  ll = long long;

template<class T,class U>
using umap = unordered_map<T,U>;

template<class T>
using uset = unordered_set<T>;

template<class T>
inline bool change_max(T&a, const T&b){
  if(b > a){
    a = b;
    return true;
  }
  return false;
}

template<class T>
inline bool change_min(T&a, const T&b){
  if(a > b){
    a = b;
    return true;
  }
  return false;
}


int main(){
  int n; cin >> n;
  cout << pow(n,3) << endl;
  return 0;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	long K;
	int N;

	public void solve() {
		K = nextLong();
		N = 50;

		long[] a = new long[N];

		for(int i = 0;i < 50;i++){
			a[i] = i;
		}

		long x = K / N;
		long y = K % N;

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

			a[i] += N * x;
			a[i] -= (N-1)* x;
			a[i] -= y;
			if(i < y){
				a[i] += N+1;
			}
		}

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

			if(i != 0)out.print(" ");
			out.print(a[i]);
		}
		out.println();
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

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

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

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

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

Measured memory_bytes: 22740
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl;exit(0);}else return;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int H, W; cin >> H >> W;
	V<V<int>> c(10, V<int>(10));
	V<V<int>> A(H, V<int>(W));
	REP(i, 10) REP(j, 10) cin >> c[i][j];
	REP(k, 10)REP(i, 10)REP(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
	REP(i, H) REP(j, W) cin >> A[i][j];
	int ans = 0;
	REP(i, H) REP(j, W) if (A[i][j] != -1) ans += c[A[i][j]][1];
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 384
inf = 10**16
n=int(input())
h=list(map(int,input().split()))
s1,s2=abs(h[1]-h[0]),inf
if n ==2:
    print(s1)
else:
    dp=[0]+[inf]*(n-1)
    for i in range(1,n):
        dp[i] = min(abs(h[i-1]-h[i]) + dp[i-1],dp[i])
        if i>1:
            dp[i] = min(dp[i],abs(h[i-2]-h[i]) + dp[i-2])
    print(dp[n-1])

Measured memory_bytes: 13908
//Created by Kira

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

#define IOS cin.sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pii pair<int,int> 
#define pb push_back
#define vi vector<int> 
using ll = long long;

const int mod = 1e9 + 7;

ll pwr(ll a, ll b);
    
const int nax = 305;
 double p[nax][nax][nax], ev[nax][nax][nax];

//p[a][b][c] - P-bability to go to (a, b, c) state

int main(){
   IOS

   int n; cin>>n;

    vi cnt(4);
   for(int i = 0; i < n; i++){
       int x; cin>>x;
       cnt[x]++;
   }

   //Initial State = (cnt[1], cnt[2], cnt[3])

    p[cnt[1]][cnt[2]][cnt[3]] = 1.0;
   for(int c = n; c >= 0; --c){
       for(int b = n; b >= 0; --b){
           for(int a = n; a >= 0; --a){
               
               if(a==0 and b == 0 and c ==0)
                    continue;
                if(a+b+c > n)   continue;

               double p_waste = (double)(n-a-b-c)/n;
               
               double ev_waste = 1 / (1 - p_waste );

               ev[a][b][c] += ev_waste * p[a][b][c];

                //remove 1 --> dp[a-1][b][c]

               if(a != 0){
                   double p_go = (double)a / (a+b+c);
                   p[a-1][b][c] += p[a][b][c] * p_go;
                   ev[a-1][b][c] += ev[a][b][c] * p_go;
               }
               
               if(b != 0){
                   double p_go = (double) b/ (a+b+c);
                   p[a+1][b-1][c] += p[a][b][c] * p_go;
                   ev[a+1][b-1][c] += ev[a][b][c]*p_go;
               }

               //Remove 3 -> dp[a][b+1][c-1]
               if(c != 0){
                   double p_go = (double)c / (a+b+c);
                   p[a][b+1][c-1] += p[a][b][c]*p_go;
                   ev[a][b+1][c-1] += ev[a][b][c] * p_go;
               }
            }
       }
   }

   cout<<fixed<<setprecision(10)<<ev[0][0][0]<<"\n";





  



}

ll pwr(ll a, ll b){
   a %= mod;	//Remove mod if not required
   ll res = 1;
   while(b > 0){
    if(b&1)
        res = res * a % mod;
        a = a * a % mod;
    b >>= 1;
    }

    return res;
}



Measured memory_bytes: 438528
// https://atcoder.jp/contests/abc139/submissions/7298310

#include <iostream>
#include <vector>
#pragma GCC optimize("O3")

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

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int a[1010][1010] = {};
    int head[1010] = {};
    rep(i,n){
        rep(j,n-1){
            int x;
            cin >> x;
            x--;
            a[i][j] = x;
        }
    }
    register int turn = 0;
    int used[1010] = {};
    for (int &i : used) i = -1;
    while(true){
        register bool ng = true;
        register int empty_cnt = 0;
        rep(i,n){
            if (head[i] == n-1) {
                empty_cnt++;
                continue;
            }
            int j = a[i][head[i]];
            if (used[i] == turn || used[j] == turn) continue;
            if (a[j][head[j]] == i) {
                head[i]++;
                head[j]++;
                used[i] = used[j] = turn;
                ng = false;
            }
        }
        if (empty_cnt == n) break;
        if (ng) {
            cout << -1 << endl;
            return 0;
        }
        turn++;
    }
    cout << turn << endl;

    return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n;cin>>n;
  string s; cin>>s;
  int r=0,w=0;
  for(int i=0;i<n;i++){
    if(s[i] == 'W')
      w++;
    if(s[i] == 'R')
      r++;
  }
  string newS="";
  while(r--)
    newS+="R";
  while(w--)
    newS+="W";

  int ans=0;
  for(int i=0;i<n;i++)
    if(s[i] != newS[i])
      ans++;

  cout<<ans/2<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3844
n,m = map(int,input().split())
check = []
for i in range(m):
    l = list(map(int,input().split()))
    check.append(l[1:])
p = list(map(int,input().split()))
count = 0

for i in range(2**n):
    check2 = [0]*m
    for j in range(n):
        if ((i>>j) & 1):
            for k in range(m):
                
                if j+1 in check[k]:
                    check2[k] += 1
                    
    check3 = True
    for l in range(m):
        if check2[l]%2 != p[l]:
            check3 = False
    if check3 :
        count += 1
        

print(count)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
bool check(vl A){ // 全て偶数ならTrue, いずれかが奇数ならfalse
    ll N = A.size();
    bool isok = true;
    rep(i,N){
        if(A[i]%2){
            isok = false;
            break;
        }
    }
    return isok;
}
int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    cout << (check(A) ? "second" : "first") << endl;

}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int s1,s2,s4;
int n;
int main()
{
	scanf("%d",&n);
	int i,a;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(a%4==0)	s4++;
		else	if(a%2==0)	s2++;
		else	s1++;
	}
	if(!s2&&s1<=s4+1)	printf("Yes");
	else	if(s1<=s4)	printf("Yes");
	else	if(!s1)	printf("Yes");
	else	printf("No");
	return 0;
}


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

long long int a, b, x;
int main(){
	scanf("%lld %lld %lld", &a, &b, &x);
	long long int ans = 0;
	ans = b / x;
	
	if (a == 0){
		ans++;
		if (b == 0){
		ans = 1;
		}
	}
	else{
		ans -= (a - 1) / x;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int A[2000001],B[2000001],C[10001],i,j,k=10000;
void CountingSort(int A[],int B[],int n){
  for(i=0;i<=k;i++){
    C[i]=0;
  }for(j=1;j<=n;j++){
    C[A[j]]++;
  }for(i=0;i<=k;i++){
    C[i] = C[i] + C[i-1];
  }for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}
  
int main(){
  int n;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
     scanf("%d",&A[i]);
  }
  CountingSort(A,B,n);
  for(i=1;i<n;i++){
  printf("%d ",B[i]);
  }
  printf("%d\n",B[n]);
  return 0;
}



Measured memory_bytes: 17408
#include <bits/stdc++.h>
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{	
	int N, j, k;
	cin >> N;
	vector<int> v(N);
	REP(i, N) cin >> v[i];
	int ans = INF;

	REP(i, N-1){
		int S1 = 0;
		int S2 = 0;
		for(j = 0; j < i+1; j++) S1 += v[j];
		for(k = j; k < N; k++) S2 += v[k];
		ans = min(ans,abs(S1-S2));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define int long long int
#define float double
#define pb push_back
#define FF first
#define SS second
#define N 100005
#define MOD 1000000007
#define fn(i,n) for(int i=0;i<n;i++)
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define pii pair<int,int>
#define mp make_pair
#define INF 1000000000000000000
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

signed main() 
{
    speed;
    //freopen("input.tXt","r",stdin);
    //freopen("output.tXt","w",stdout);
    
    int k,n;
    cin>>k>>n;
    int A[n+1];
    for(int i=1;i<=n;i++) cin>>A[i];
    int minn=INT_MAX;
    for(int i=1;i<=n;i++) 
    {
        if(i==n) minn=min(minn,min(A[n]-A[1],k+A[n-1]-A[n]));
        else minn=min(minn,min(k-A[i+1]+A[i],2*(A[i]-A[1])+(A[n]-A[i])));
    }
    cout<<minn<<endl;
}   

Measured memory_bytes: 5256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1

//{
#pragma GCC optimize ("O3","unroll-loops")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
#define hi cerr<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1
#define sysp system("pause")
#define PI acos(-1)
#define ins insert

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

//}

int n,m,k,h,w,ans,dx[]={0,1,0,-1},dy[]={-1,0,1,0};
string s;
set<string> aa;

main(){
	cin>>s;
	n=s.size();
	for(int i=0;i<n;i++){
		for(int j=0;j<=n-i;j++){
			string t=s;
			t.erase(i,j);
			aa.ins(t);
		}
	}
	//for(auto x:aa)debug(x);
	if(aa.count("keyence"))dump("YES");
	else dump("NO");
}


Measured memory_bytes: 768
import java.util.*;

public class Main {
	
	static int zeroCheck(int[][] p){
		int count=0;
		for(int i[]: p)
			for(int j : i) if(j==0) count++;
		return count;
	}
	
	static int max(int[][] p){
		int max=0;
		for(int i[] : p)
			for(int j:i) if(max<j) max = j ;
		return max;
	}
	
	static boolean judge(int x,int y){
		if(x>=0 && x<=9 && y>=0 && y<=9)
			return true;
		else return false;
	}
	
	static int[][] dropS(int[][] p,int x,int y){
		if(judge(x,y)) p[y][x]++;
		if(judge(x+1,y)) p[y][x+1] ++;
		if(judge(x-1,y)) p[y][x-1] ++;
		if(judge(x,y+1)) p[y+1][x] ++;
		if(judge(x,y-1)) p[y-1][x] ++;
		return p;
	}
	
	static int[][] dropM(int[][] p,int x,int y){
		for(int i=-1; i<=1; i++){
			for(int j=-1; j<=1; j++){
				if(judge(x+i,y+j)) p[y+j][x+i]++;
			}
		}
		return p;
	}
	
	static int[][] dropL(int[][] p,int x,int y){
		p = dropM(p,x,y);
		if(judge(x+2,y)) p[y][x+2] ++;
		if(judge(x-2,y)) p[y][x-2] ++;
		if(judge(x,y+2)) p[y+2][x] ++;
		if(judge(x,y-2)) p[y-2][x] ++;
		return p;
	}
	
	public static String[] kommmaReader(String sc) {
		String line= sc;
		String[] array = line.split(",");
		return array;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] p = new int[10][10];
		do{
			String[] str = kommmaReader(sc.nextLine());
			int x = Integer.parseInt(str[0]);
			int y = Integer.parseInt(str[1]);
			int size = Integer.parseInt(str[2]);
			
			switch(size){
			case 1: p = dropS(p,x,y); break;
			case 2: p = dropM(p,x,y); break;
			case 3: p = dropL(p,x,y); break;
			}
		} while(sc.hasNext());
		System.out.println(zeroCheck(p));
		System.out.println(max(p));
		
	}

}

Measured memory_bytes: 12000