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

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7 || n == 8 || n == 9 ||
        n == 2 || n == 6 || n == 8 || n == 10 || n == 12 || n == 14 || n == 16 || n == 18 ||
        n == 4 || n == 9 || n == 12 || n == 15 || n == 18 || n == 21 || n == 24 || n == 27 ||
        n == 6 || n == 12 || n == 16 || n == 20 || n == 24 || n == 28 || n == 32 || n == 36 ||
        n == 8 || n == 15 || n == 20 || n == 25 || n == 30 || n == 35 || n == 40 || n == 45 ||
        n == 10 || n == 18 || n == 24 || n == 30 || n == 36 || n == 42 || n == 48 || n == 54 ||
        n == 12 || n == 21 || n == 28 || n == 35 || n == 42 || n == 49 || n == 56 || n == 63 ||
        n == 14 || n == 24 || n == 32 || n == 40 || n == 48 || n == 56 || n == 64 || n == 72 ||
        n == 16 || n == 27 || n == 36 || n == 45 || n == 54 || n == 63 || n == 72 || n == 81) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        
    }
}


Measured memory_bytes: 23252
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 100000000000000;

ll dp[2005][2005];

int main()
{
    ll n;
    cin >> n;
    P p[2005];
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        p[i] = P(a, i);
    }
    sort(p, p + n, greater<P>());
    for(int j = 1; j <= n; j++) dp[0][j] = -INF;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= i; j++){
            dp[i][j] = max(dp[i - 1][j] + p[i - 1].first * (p[i - 1].second - (i - 1 - j)),
                           dp[i - 1][j - 1] + p[i - 1].first * (n - j - p[i - 1].second));
        }
        dp[i][0] = dp[i - 1][0] + p[i - 1].first * (p[i - 1].second - (i - 1));
    }
    ll ans = 0;
    for(int j = 0; j <= n; j++) ans = max(ans, dp[n][j]);
    cout << ans << endl;
}


Measured memory_bytes: 26300
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    N = II()
    ans = [0,0,0,0]
    for i in range(N):
        S = IS()
        if S == 'AC': ans[0]+=1
        elif S == 'WA': ans[1]+=1
        elif S == 'TLE': ans[2]+=1
        elif S == 'RE': ans[3]+=1

    print("AC x {}".format(ans[0]))
    print("WA x {}".format(ans[1]))
    print("TLE x {}".format(ans[2]))
    print("RE x {}".format(ans[3]))

if __name__ == '__main__':
    main()

Measured memory_bytes: 9228
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    fix20;
    double l;
    cin >> l;
    cout << (l*l*l)/27.0 << endl;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll d;
    cin>>d;
    string s  = "Christmas";
    while(25-d >0){
        s += " Eve";
        d++;
    }
    cout<<s<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int N;
    std::cin >> N;
    std::vector<int> v(N);
    for (auto& e : v) std::cin >> e;

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int l, m, r;
        std::cin >> l >> m >> r;
        std::rotate(v.begin() + l, v.begin() + m, v.begin() + r);
    }

    for (int i = 0; i < v.size(); ++i) {
        std::cout << v[i] << " \n"[i == v.size() - 1];
    }
}


Measured memory_bytes: 3140
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from collections import deque

n = int(sys.stdin.readline())
ai = list(map(int, sys.stdin.readline().split(' ')))

bi = deque()

for i in range(n):
	if i % 2 == 0:
		bi.append(ai[i])
	else:
		bi.appendleft(ai[i])

if n % 2 == 0:
	bi.reverse()

o = ""
while len(bi) > 0:
	o += str(bi.pop()) + " "

o = o[:-1]

print(o)

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

class Main {


  

  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int N = in.nextInt();

    double[] p = new double[N];
    for (int i = 0; i < N; i++) {p[i] = in.nextDouble();}

    double[][] dp = new double[N +  1][N + 1];
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
      for (int j = 0; j <= i; j++) {
        dp[i][j] = (j == 0 ? 0 : (dp[i - 1][j - 1] * p[i - 1])) + dp[i - 1][j] * (1 - p[i - 1]);
      }
    }

    double ans = 0;
    for (int i = N / 2 + 1; i <= N; i++) {
      ans += dp[N][i];
    }




    System.out.println(ans);
  }

}

Measured memory_bytes: 124948
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int n;
LL h[101010], dp[101010];

int main(){
    INIT;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> h[i];
        dp[i] = HINF<LL>();
    }
    dp[1] = 0;
    for(int i = 1;i <= n;i++){
        if(i >= 2)dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i >= 3)dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n] << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n,m;
    while(cin>>n>>m, n || m){
        vector<vector<int>> p(m+1);
        for(int i=0;i<n;i++){
            int d,v;cin>>d>>v;
            p[d].push_back(v);
        }
        int res=0;
        for(int i=1;i<=m;i++){
            sort(p[i].rbegin(),p[i].rend());
            res += p[i][0];
        }
        cout<<res<<endl;
    }
}



Measured memory_bytes: 3216
using System;
using System.Collections.Generic;
using System.Linq;

class E
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var d = new Dictionary<long, int>();
		foreach (var x in a)
			foreach (var o in Factorize(x).GroupBy(p => p).Select(g => new { p = g.Key, c = g.Count() }))
				if (!d.ContainsKey(o.p) || d[o.p] < o.c) d[o.p] = o.c;

		var lcm = d.Select(p => ((MInt)p.Key).Pow(p.Value)).Aggregate((MInt)1, (x, y) => x * y);
		Console.WriteLine(a.Select(x => lcm / x).Aggregate((x, y) => x + y));
	}

	static long[] Factorize(long n)
	{
		var r = new List<long>();
		for (long rn = (long)Math.Ceiling(Math.Sqrt(n)), x = 2; x <= rn && n > 1; ++x)
			while (n % x == 0) { r.Add(x); n /= x; }
		if (n > 1) r.Add(n);
		return r.ToArray();
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);
	public override string ToString() => $"{V}";

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 20700
import java.util.Scanner;

class Main {
    public static void main (String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] A = new int[n];
        int max = 0;
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
            if (A[i] > max) {
                max = A[i];
            }
        }

        int[] B = countingSort(A, max);

        StringBuilder sb = new StringBuilder("");
        sb.append(B[0]);
        for (int i = 1; i < B.length; i++) {
            sb.append(" ").append(B[i]);
        }
        System.out.println(sb);
    }

    public static int[] countingSort(int[] A, int k) {
        int[] B = new int[A.length];
        int[] C = new int[k + 1];
        int i;
        for (i = 0; i < A.length; i++) {
            C[A[i]]++;
        }
        for (i = 1; i <= k; i++) {
            C[i] += C[i - 1];
        }
        for (i = A.length - 1; i >= 0; i--) {
            B[C[A[i]] - 1] = A[i];
            C[A[i]]--;
        }
        return B;
    }
}

Measured memory_bytes: 508904
program main
  implicit none
  integer(8),parameter::M=1000000007
  integer(8) h,w,a,b,i,asize
  integer(8),allocatable::fact(:),invf(:)
  integer(16)::i16=0

  read*,h,w,a,b
  asize=h+w
  allocate(fact(asize+1),invf(asize+1))

  fact(1:2)=1
  do i=1,asize
     fact(i+1)=mod(fact(i)*i,M)
  enddo
  invf(asize+1)=powmod(fact(asize+1))
  do i=asize,1,-1
     invf(i)=mod(invf(i+1)*i,M)
  enddo
  
  print*,mod(dot_product(&
       i16+mod(fact(h-a+b:h-a+w-1)*invf(b+1:w),M),mod(fact(w-b+a-1:a:-1)*invf(w-b:1:-1),M))*mod(invf(h-a)*invf(a),M),M)

  !end program main
contains
  function powmod(t) result(r)
    integer(8),intent(in)::t
    integer(8)x,i,r
    i=M-2
    x=t
    r=1
    do
       if ( i .eq. 0 ) exit
       if ( iand(i,1).eq.1 )then
          r=mod(r*x,M)
       endif
       x=mod(x*x,M)
       i=ishft(i,-1)
    end do
  end function powmod
end program main

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
const ll mod=1e9+7;
const ll INF = 1e9;

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b); 
}

bool is_prime(ll x){
    if(x==1) return false;
    for(ll i=2; i*i<=x;i++){
        if(x%i == 0) return false;
    }
    return true;
}

int main(){
    fast_io
    
    int n;
    cin>>n;
    vector<ll> a(n);
    ll ans = 100100100100;
    bool eq=true;
    rep(i, n){
        cin>>a[i];
    }
    ans=a[n-1];
    rep(i,n){
        ans=gcd(ans, a[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
int n,m,d;
inline void work1() {
    for(int i=1;i<=n;i++) {
	for(int j=1;j<=m;j++) putchar((i+j)&1?'R':'B');
	puts("");
    }
}
inline char C(int x,int y) {
    x/=d,y/=d;
    if(x%2==0) return y%2?'R':'B';
    else return y%2?'G':'Y';
}
inline void work2() {
    for(int i=1;i<=n;i++) {
	for(int j=1;j<=m;j++) putchar(C((i+j+10000)/2,(i-j+10000)/2));
	puts("");
    }
}
int main() {
    cin>>n>>m>>d;
    if(d&1) work1();
    else d>>=1,work2();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n,m;
cin >> n >> m;
int ans;
ans+=n*(n-1)/2;
ans+=m*(m-1)/2;
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  string S;
  std::cin >> S;
  int rcount=0, lcount=0, mode=0, last_r=0, first_l=0;
  std::vector<int> ans(S.size(), 0);
  for(int i=0;i<S.size();i++){
    if(mode==0&&S[i]=='R') rcount++;
    else if(mode==0&&S[i]=='L') mode=1, lcount++, last_r=i-1, first_l=i;
    else if(mode==1&&S[i]=='L') lcount++;
    else if(mode==1&&S[i]=='R'){
      if(rcount%2==0) ans[last_r]+=rcount/2, ans[first_l]+=rcount/2;
      else ans[last_r]+=rcount/2+1, ans[first_l]+=rcount/2;
      if(lcount%2==0) ans[last_r]+=lcount/2, ans[first_l]+=lcount/2;
      else ans[last_r]+=lcount/2, ans[first_l]+=lcount/2+1;
      mode=0;
      lcount=0;
      rcount=1;
    }
    if(i==S.size()-1){
      if(rcount%2==0) ans[last_r]+=rcount/2, ans[first_l]+=rcount/2;
      else ans[last_r]+=rcount/2+1, ans[first_l]+=rcount/2;
      if(lcount%2==0) ans[last_r]+=lcount/2, ans[first_l]+=lcount/2;
      else ans[last_r]+=lcount/2, ans[first_l]+=lcount/2+1;
    }
  }
  for(int i=0;i<S.size();i++) std::cout << ans[i]  << " ";
  std::cout << '\n';
  return 0;
}


Measured memory_bytes: 1088
#include<bits/stdc++.h>
using namespace std;
struct node{
	int a,b;
}w[200002];
int n;
bool cmp(node x,node y){
	return x.b<y.b;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&w[i].a,&w[i].b);
	sort(w+1,w+n+1,cmp);
	int now=0;
	for(int i=1;i<=n;i++){
		now+=w[i].a;
		if(now>w[i].b){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;
using namespace std;
#define LARGE 1000000007

int main(){
  ll n,k,ans;
  scanf("%lld %lld",&n, &k);

  ans=0;
  REP(ll,i,0,n-k+2){
    ans = (ans+i*n-i*(i-1)+1)%LARGE;
  }
  
  printf("%lld",ans);
}

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

void solve(string a,string b){
    vector<int> m(4),n(4),o(4);
    int x=0,y=0,z=0;
    string c="mcxi";
    for(auto i=a.begin();i!=a.end();i++){
        if(*i>='0'&&*i<='9'){
            m[c.find(*(i+1))]=*i-'0';
        }
    }
    for(int i=0;i<c.size();i++){
        if(a.find(c[i])!=string::npos&&!m[i])m[i]++;
    }
    for(int i=0;i<m.size();i++){
        x+=m[i]*pow(10,3-i);
    }
        for(auto i=b.begin();i!=b.end();i++){
        if(*i>='0'&&*i<='9'){
            n[c.find(*(i+1))]=*i-'0';
        }
    }
    for(int i=0;i<c.size();i++){
        if(b.find(c[i])!=string::npos&&!n[i])n[i]++;
    }
    for(int i=0;i<n.size();i++){
        y+=n[i]*pow(10,3-i);
    }
    z=x+y;
    for(int i=0;i<o.size();i++){
        o[i]=(z/(int)pow(10,3-i))%10;
    }
    for(int i=0;i<o.size();i++){
        if(o[i]){
            if(o[i]!=1)cout<<o[i];
            cout<<c[i];
        }
    }
    cout<<endl;
}

int main(void){
    int n;
    cin>>n;
    string a,b;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        solve(a,b);
    }
}



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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout << "Yes" << '\n';
    else cout << "No" << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

string s, t;
int cnt=0, l, k;
bool ans;

int main()
{

cin >> s >> t;

k = s.size()-1;
l = t.size()-1;

if(l>k)return 0*printf("UNRESTORABLE");

for(int i =k-l; i>=0; i--){
    cnt=0;
    ans = false;
    for(int j =0; j<=l; j++){
        if(s[i+j]==t[j] || s[i+j]=='?'){
            cnt++;
        }
    }
    //cout << cnt << endl;
    if(cnt-1==l)ans=true;
    if(ans){
        for(int j =0; j<=l; j++){
            s[i+j]=t[j];
        }
        break;
    }
}
for(int i =0; i<=k; i++){
    if(s[i]=='?')s[i]='a';
}
if(!ans)cout << "UNRESTORABLE";
else
cout << s ;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
typedef long long ll;
using namespace std;
ll inf = 1000000007;
ll c[55];
int main() {
	int n, m;
	cin >> n >> m;
		int k;
	vector<vector<ll>>s(m);
	for (int i = 0; i < m; i++) {
		cin >> k;
		s[i].resize(k);
		for (int j = 0; j < k; j++) {
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	vector<ll>p(m);
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	ll ans = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		bool ok = true;
		for (int i = 0; i < m; i++) {
			int count = 0;
			for (auto id : s[i]) {
				if (bit & (1 << id)) {
					count++;
				}
			}
			if (count % 2 != p[i]) {
				ok = false;
			}
		}
		if (ok)ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
n = int(input())
a1 = [ int(x) for x in input().split() ]
a2 = [ int(x) for x in input().split() ]

candy_max = 0

for i in range(n+1):
    candies = sum(a1[0:i+1]) + sum(a2[i:n])
    if candy_max < candies:
        candy_max = candies

print(candy_max)


Measured memory_bytes: 9144
IDENTIFICATION                   DIVISION.
       PROGRAM-ID.                      PracticeA.
       ENVIRONMENT                      DIVISION.
       DATA                             DIVISION.
       WORKING-STORAGE                  SECTION.
       01 WORK                          PIC 9(3).
       01 WORK-R  REDEFINES  WORK.
          03 WORK-R-A                  PIC 9(2).
          03 WORK-R-B                  PIC 9(1).
       PROCEDURE DIVISION.
       MAIN-SECTION.
           ACCEPT    WORK  FROM  SYSIN.
           EVALUATE  TRUE
           WHEN WORK-R-B = 2 OR 4 OR 5 OR 7 OR 9
      	       DISPLAY "hon"
           WHEN WORK-R-B = 0 OR 1 OR 6 OR 8
      	       DISPLAY "pon"
           WHEN WORK-R-B = 3
               DISPLAY "bon"
           END-EVALUATE.
           STOP RUN.      


Measured memory_bytes: 3744
if __name__ == '__main__':

	while True:
		try:
			A = []

			for i in range(8):
				tmp = list(map(int,input()))
				if tmp.count(1) > 0:
					A.append(tmp)

			if len(A) == 1:
				print("C")
			elif len(A) == 4:
				print("B")
			else:
				if len(A) == 2:#A,E,G
					if A[0].index(1) < A[1].index(1):
						print("E")
					elif A[0].index(1) > A[1].index(1):
						print("G")
					else:
						print("A")
				elif len(A) == 3:#D,F
					if A[0].index(1) < A[2].index(1):
						print("F")
					else:
						print("D")
			input()

		except EOFError:
			break




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



int main (){
    int N;
    cin>>N;
    unordered_map<string, int> Words;
    long long Sum=0;
    for(int i=0; i<N; i++){
        string S;
        cin>>S;
        sort(S.begin(), S.end());
        Sum+=Words[S];
        Words[S]++;
    }
    cout<<Sum<<endl;
}

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

int main(){
    int n;
    cin >> n;
    ve<ll> a(n), b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    ll ans;
    if(n%2==1){
        int mid = (n-1)/2;
        ans = b[mid]-a[mid]+1;
    }else{
        int mid1 = n/2;
        int mid0 = mid1-1;
        ans = b[mid0] + b[mid1] - a[mid0] - a[mid1] + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6428
n=int(input())
a=list(map(int,input().split()))
flg=True
c=0
while flg==True:
  for i in range(n):
    if a[i]%2==1:
      flg=False
      
  if flg == True:
    c+=1
    a=[int(i/2) for i in a]
    
print(c)

Measured memory_bytes: 2940
N, M = (int(i) for i in input().split())
H = list(map(int,input().split()))
ans = [1]*N
for m in range(M):
    a, b = (int(i) for i in input().split())
    if H[a-1] < H[b-1]:
        ans[a-1] = 0
    elif H[a-1] > H[b-1]:
        ans[b-1] = 0
    else:
        ans[a-1] = 0
        ans[b-1] = 0
print(ans.count(1))

Measured memory_bytes: 20004
n = int(input())
edge = [[] for _ in range(n)]
for _ in range(n-1):
  a, b = map(int, input().split())
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)

group = [False] * n
parent = list(range(n))
stack = [0]
while stack:
  v = stack.pop()
  while edge[v]:
    u = edge[v].pop()
    if parent[v] != u:
      group[u] = not group[v]
      parent[u] = v
      stack.append(u)

three = 3
p = [0] * n
if group.count(False) <= n // 3:
  other = 1
  for i in range(n):
    if group[i] and other <= n:
      p[i] = other
      other += other % 3
    else:
      p[i] = three
      three += 3
elif group.count(True) <= n // 3:
  other = 1
  for i in range(n):
    if not group[i] and other <= n:
      p[i] = other
      other += other % 3
    else:
      p[i] = three
      three += 3
else:
  one, two = 1, 2
  for i in range(n):
    if group[i] and one <= n:
      p[i] = one
      one += 3
    elif not group[i] and two <= n:
      p[i] = two
      two += 3
    else:
      p[i] = three
      three += 3
print(' '.join(map(str, p)))

Measured memory_bytes: 58200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

vb seen;

bool possible = true;
vi pos;

void dfs(const vector<vector<P>> &G, int v) {
  seen[v] = true;

  for (auto p : G[v]) {
    int nv, d;
    tie(nv, d) = p;

    if (seen[nv]) {
      if (pos[nv] - pos[v] == d) continue;
      else {
        possible = false;
        return;
      }
    }

    pos[nv] = pos[v] + d;

    dfs(G, nv);

    if (!possible) return;
  }
}

int main() {
  int N, M; cin >> N >> M;

  vector<vector<P>> G(N);
  rep(i,M) {
    int L, R, D;
    cin >> L >> R >> D;
    --L; --R;
    G[L].push_back(P(R,D));
    G[R].push_back(P(L,-D));
  }

  seen.assign(N, false);
  pos.resize(N);

  rep(i,N) {
    if (seen[i]) continue;
    pos[i] = 0;
    dfs(G, i);
    if (!possible) break;
  }

  if (possible) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 12032
N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = list(input())
J = {"r": P, "s": R, "p": S}

ans = 0
for i in range(K):
  c = 1
  t = T[i]
  for j in range(i + K, N, K):
    if T[j] == t:
      c += 1
    else:
      ans += J[t] * ((c + 1) // 2)
      c = 1
      t = T[j]
  ans += J[t] * ((c + 1) // 2)

print(ans)

Measured memory_bytes: 4084
import java.util.Scanner;
 
public class Main {
 
    public static final int BIG_NUM  = 2000000000;
    public static final int MOD  = 1000000007;
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
        int H,W;
 
        H = sc.nextInt();
        W = sc.nextInt();
 
        int table[][] = new int[H+1][W+1];
 
        for(int row = 0; row < H; row++){
            for(int col = 0; col < W; col++){
                table[row][col] = sc.nextInt();
            }
        }
 
        for(int row = 0; row < H; row++){
            table[row][W] = 0;
            for(int col = 0; col < W; col++){
                table[row][W] += table[row][col];
            }
        }
 
        for(int col = 0; col <= W; col++){
            table[H][col] = 0;
            for(int row = 0; row < H; row++){
                table[H][col] += table[row][col];
            }
        }
 
        for(int row = 0; row <= H; row++){
            System.out.printf("%d", table[row][0]);
            for(int col = 1; col <= W; col++){
                System.out.printf(" %d", table[row][col]);
            }
            System.out.printf("\n");
        }
    }
}


Measured memory_bytes: 55040
#include <stdio.h>

int main(void)
{
  int n, m;
  int a;
  int b;
  int c[51] = {0};
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    c[a]++;
    c[b]++;
  }
  for (int i = 1; i <= n; i++)
    printf("%d\n", c[i]);
}


Measured memory_bytes: 128
#include <stdio.h>

#define MODULUS  (1000 * 1000 * 1000 + 7)  /* Note that it is prime. */
#define N_FACT   30   /* 10**9 \sim 2**30 */

int fact[N_FACT];
int n_fact = 0;

void factorized(int M)
{
    n_fact = 0;
    int d = 2;
    while (d <= M) {
        int count = 0;
        while (M % d == 0) {
            M /= d;
            count++;
        }
        if (count > 0) {
            fact[n_fact++] = count;
        }
        d++;
    }
}

/* modular multiplicative inverse a^{-1} (mod m) */
long inverse(long a)
{
    /* a^{-1} == a^{m-2} mod m for a prime m by Euler's theorem. */
    long powa = a;  /* a^{2^i} (mod m) */
    long x = 1;
    int i;
    for (i = 0; i < 30; i++) {
        if ((MODULUS - 2) & (1 << i)) {
            x = x * powa % MODULUS;
        }
        powa = powa * powa % MODULUS;
    }
    return x;
}

long tetra(int n, int m)
{
    long x = 1;
    long y = 1;
    int i;
    for (i = 1; i < n; i++) {
        x = x * (m + i - 1) % MODULUS;
        y = y * i           % MODULUS;
    }
    return x * inverse(y) % MODULUS;
}

int main()
{
    int N, M;
    long x;
    int i;

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

    factorized(M);
    x = 1;
    for (i = 0; i < n_fact; i++) {
        x *= tetra(N, fact[i] + 1);
        x %= MODULUS;
    }

    printf("%ld\n", x);
    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

long foo (long arg) {
  long ret = 0;
  while (arg) {
    ret += arg % 10;
    arg /= 10;
  }
  return ret;
}

void solve() {
  long N;
  cin >> N;
  if (N % foo(N)) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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


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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<ll>());
    // for(int i=0;i<n;i++){
    //     cerr << a[i] << " ";
    // }
    // cerr << endl;
    ll low=-1,up=n,mid;
    while(up-low>1){
        mid=(up+low)/2;
        ll now = a[mid] + m;
        ll sum = v*m;
        ll cnt = 0;
        for(int i=0;i<n;i++){
            if(a[i] <= now){
                if(cnt < p-1){
                    cnt++;
                    sum -= m;
                }
                else sum -= min(m,now-a[i]);
            }
            else if(a[i]>now) {
                cnt++;
                sum -= m;
            }
        }
        //cerr << mid << " " << sum << " " << cnt << endl;
        if(sum <= 0 && cnt<p){
            low=mid;
        }
        else{
            up=mid;
        }
    }
    cout << low + 1 << endl;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&... tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&... args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N;
  ll ans = 0;

  scanf("%d", &N);

  for (int i = 1; i <= N; i++) {
    ll t = N / i;
    ans += t * (t + 1) / 2 * i;
  }

  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
const long long INF = 1LL << 60;
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false;}
//cout << fixed << setprecision(10);

ll dp[100010];

int main(){
    ll n; cin>>n;
    vector<ll>v(n);
    rep(i,n) cin>>v[i];
    rep(i,100010) dp[i]=INF;
    dp[0]=0;
    dp[1]=dp[0]+abs(v[1]-v[0]);
    FOR(i,2,n){
        chmin(dp[i], dp[i-1]+abs(v[i]-v[i-1]));
        chmin(dp[i], dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
bool solve(string s,string t){
	for(unsigned int i=0;i<s.length();i++){
		if(s==t)
			return 1;
		s=s.back()+s.substr(0,s.length()-1);
	}
	return 0;
}


int main(){
	string s,t;
	cin>>s>>t;
	if(solve(s,t))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>

int main(void) {
    std::string str;
    std::cin >> str;
    char prev = str[0];
    int res=0;
    for(char c : str) {
        if(prev != c)
            res++;
        prev = c;
    }
    std::cout << res << std::endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = x / 500;
		x %= 500;
		int z = x / 5;
		System.out.println(y * 1000 + z * 5);

	}

}


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


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

  if (a >= b) {
    cout << "delicious" << endl;
    return 0;
  }

  if (a + x >= b) {
    cout << "safe" << endl;
    return 0;
  }

  cout << "dangerous" << endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x,c=0,c1=0;
    cin>>n;
    int ar[n+5];
    for(int i=0;i<n;i++)
    {
        cin>>ar[i];
        if(ar[i]%2==0)
            c++;
    }
    for(int i =0; i <n;i++)
    {
        if(ar[i]%2==0)
        {
            if(ar[i]%3==0 || ar[i]%5==0)
            {
                c1++;
            }
        }
    }
    if(c1==c)
        cout<<"APPROVED"<<endl;
    else
        cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	var a, b Point
	a.x = 0.0
	a.y = 0.0
	b.x = 100.0
	b.y = 0.0

	//koch()の引数にする両端の座標は出力されないので、自分でprint文を書く
	fmt.Println(a.x, a.y)
	koch(n, a, b)
	fmt.Println(b.x, b.y)
}

type Point struct {
	x float64
	y float64
}

func koch(n int, a Point, b Point) {
	//nが0になったら再帰処理から抜ける
	if n == 0 {
		return
	}
	var s, t, u Point
	cos60 := 1.0 / 2.0
	sin60 := (math.Sqrt(3)) / 2.0

	//線分abを1:2に内分する点s
	s.x = (2.0*a.x + 1.0*b.x) / 3.0
	s.y = (2.0*a.y + 1.0*b.y) / 3.0
	//線分abを2:1に内分する点t
	t.x = (1.0*a.x + 2.0*b.x) / 3.0
	t.y = (1.0*a.y + 2.0*b.y) / 3.0
	//tを起点に、sを反時計回りに60度回転した点u
	u.x = (t.x-s.x)*cos60 - (t.y-s.y)*sin60 + s.x
	u.y = (t.x-s.x)*sin60 + (t.y-s.y)*cos60 + s.y

	//再帰処理
	//koch()の引数にする両端の座標は出力されないので、自分でprint文を書く
	koch(n-1, a, s)
	fmt.Println(s.x, s.y)
	koch(n-1, s, u)
	fmt.Println(u.x, u.y)
	koch(n-1, u, t)
	fmt.Println(t.x, t.y)
	koch(n-1, t, b)
}



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

// 等差数列の和の公式
int calc_sum(int l, int r){
    return (l+r)*(r-l+1)/2;
}

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    if(S < K){
        ans = calc_sum(1, S+1);
    }else if(S <= 2*K){
        ans = calc_sum(2*K-S+1, K+1) + calc_sum(-K+S+1, K);
    }else{
        ans = calc_sum(1, 3*K-S+1);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x = (a+d-1)/d;
    int y = (c+b-1)/b;
    if(x>=y){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3604
s = input()
n = len(s)
ans = n
for j in range(2):
    cnt = 0
    for i in range(n):
        if((i%2==j and s[i]=="0") or (i%2!=j and s[i]=="1")):
            cnt += 1
    ans = min(ans,cnt)
print(ans)
        

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define vsort(v) sort((v).begin(), (v).end())
#define vrsort(v) sort((v).rbegin(), (v).rend())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 2000000009
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  ll n,i;cin>>n;vll a(n);ain(i,n,a);
  //caricurate
  deque<ll> deq;
  vsort(a);rep(i,n){deq.pb(a[i]);}
  deque<ll> ans;vll la(0);
  ll s=deq.front();deq.pop_front();ans.pb(s);
  while(!deq.empty()){
    s=deq.back();deq.pop_back();ans.push_front(s);
    if(!deq.empty()){s=deq.back();deq.pop_back();ans.pb(s);}else{continue;}
    if(!deq.empty()){s=deq.front();deq.pop_front();ans.push_front(s);}else{continue;}
    if(!deq.empty()){s=deq.front();deq.pop_front();ans.pb(s);}
  }
  while(!ans.empty()){
    ll k=ans.front();ans.pop_front();la.pb(k);
  }
  ll ri=0;rep(i,n-1){ri+=abs(la[i+1]-la[i]);}
  
  deque<ll> deqi;
  vrsort(a);rep(i,n){deqi.pb(a[i]);}
  deque<ll> ansi;vll lai(0);
  ll si=deqi.front();deqi.pop_front();ansi.pb(si);
  while(!deqi.empty()){
    si=deqi.back();deqi.pop_back();ansi.push_front(si);
    if(!deqi.empty()){si=deqi.back();deqi.pop_back();ansi.pb(si);}else{continue;}
    if(!deqi.empty()){si=deqi.front();deqi.pop_front();ansi.push_front(si);}else{continue;}
    if(!deqi.empty()){si=deqi.front();deqi.pop_front();ansi.pb(si);}
  }
  while(!ansi.empty()){
    ll ki=ansi.front();ansi.pop_front();lai.pb(ki);
  }
  ll rii=0;rep(i,n-1){rii+=abs(lai[i+1]-lai[i]);}
  //output
  cout<<max(ri,rii)<<endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
 
  vector<string> mas(H);
  for(int i=0;i<H;i++)
    cin >> mas.at(i);
  
  vector<bool> row(H,false);
  vector<bool> col(W,false);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(mas.at(i).at(j) == '#'){
        row.at(i) = true;
        col.at(j) = true;
      }
      
    }
  }
  for(int i=0; i<H; i++){
    if(row.at(i)){
      for(int j=0; j<W; j++){
        if(col.at(j)){
          cout << mas.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n, k;
    cin >> n >> k;
    vec v[n];
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    bool visited[n];
    fill(visited, visited + n, false);
    queue<int> que;
    que.push(0);
    visited[0] = true;
    ll ans = k;
    bool init = true;
    while(que.size() > 0){
        int e = que.front();
        que.pop();
        int num;
        if(init){
            num = k - 1;
            init = false;
        }else{
            num = k - 2;
        }
        for (int i = 0; i < v[e].size(); i++){
            if(visited[v[e][i]]) continue;
            visited[v[e][i]] = true;
            ans *= num;
            ans %= mod;
            num--;
            que.push(v[e][i]);
            
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 9576
from itertools import permutations

N = int(input())
x, y = [], []
for _ in range(N):
    _x, _y = map(int, input().split())
    x.append(_x)
    y.append(_y)

al = list(permutations(range(N)))
ttmp = []
for a in al:
    tmp = 0
    h = a[0]
    for i in a[1:]:
        tmp += ((x[h] - x[i]) ** 2 + (y[h] - y[i]) ** 2) ** 0.5
        h = i
    ttmp.append(tmp)
print(sum(ttmp) / len(al))

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



int main(){
    int n;  cin >> n;
    vector<pair<ll, ll>> r(n);
    for(int i=0; i<n; i++){
        ll a, b;    cin >> a >> b;
        r.at(i) = {a-b, a+b};
    }
    sort(r.begin(), r.end());
    ll x=1e+15, cnt=0;
    for(int i=n-1; 0<=i; i--){
        if(r.at(i).second<=x){
            x = r.at(i).first;
            cnt += 1;
        }
    }
    cout << cnt << endl;
}




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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
}

int main()
{
    // FAST_IO;
    // #ifndef ONLINE_JUDGE 
      // OC;
    // #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

// #define ONLINE_JUDGE

#define V vector
#define P pair

using LL = long long;
#define FOR(i, x, y) \
    for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) \
    for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
    do {                                      \
        cerr << "\033[32;1m" << #x << " -> "; \
        err(x);                               \
    } while (0)
void err() { cerr << "\033[39;0m" << endl; }
template <template <typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) {
    for (auto v : a) cerr << v << ' ';
    err(x...);
}
template <typename T, typename... A>
void err(T a, A... x) {
    cerr << a << ' ';
    err(x...);
}
#else
#define dbg(...)
#endif
#define sz(x) (int)x.size()

LL bin(LL a, LL b, LL p) {
    LL res = 1;
    a = (a % p + p) % p;
    for (; b; b >>= 1, a = a * a % p)
        if (b & 1) res = res * a % p;

    return res;
}

const int N = 55;

int a[N];

int n, m, q;
int s[N], t[N], c[N], d[N];
int ans;
void dfs(int now, int la) {
    if (now > n) {
        int tans = 0;
        for (int i=1; i<=q; ++i) {
            if (a[t[i]] - a[s[i]] == c[i])
                tans += d[i];
        }
        ans = max(ans, tans);
        return;
    }
    for (int i=la; i<=m; ++i) {
        a[now] = i;
        dfs(now+1, i);
    }
}

void solve() {
    cin >> n >> m >> q;
    for (int i=1; i<=q; ++i) {
        cin >> s[i] >> t[i] >> c[i] >> d[i];
    }
    dfs(1, 1);
    cout << ans << endl;
}

int main() {

    // int t;
    // cin >> t;
    // while (t--) solve();

    solve();

    return 0;
}

Measured memory_bytes: 3596
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>*/
#define PII pair<int,int>
#define ll long long
#define ull unsigned long long
#define INFI 2147483647
#define INFL 9223372036854775807
#define INFU 18446744073709551615
using namespace std;
//using namespace __gnu_pbds;
const double PI=acos(-1.0);
const double eps=1e-6;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0' || ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
int ans[1000000];
int main()
{
	//ios_base::sync_with_stdio(false);
    //cin.tie(0);
    //cout.tie(0);
	int n=read();
	for(int i=2;i<=n;++i){
        int k=read();
        ans[k]++;
	}
    for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 4244
input = open(0).read

N, *A = [int(i) for i in input().split()]


def main():
    l = [abs(A[i + 1] - A[i]) for i in range(N - 1)]

    num = sum(l)

    print(num - l[0] + abs(A[1]) + abs(A[-1]))

    if N != 2:
        print("\n".join(
            [str(num - l[i] - l[i + 1]
                 + abs(A[i] - A[i + 2])
                 + abs(A[0]) + abs(A[-1])) for i in range(N - 2)]))

    print(num - l[-1] + abs(A[0]) + abs(A[-2]))
    return


main()


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

using namespace std;

const int N = int(2e5 + 10);
int v[N];
int a[N];

int main(){
	int k, n;

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

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

	int ans = int(1e9);

	for(int i = 0 ; i < n ; i++){
		int op1, op2;

		if(i < n - 1){
			op1 = a[i] + k - a[i + 1];
		}else{
			op1 = a[i] - a[0];
		}

		if(i != 0){
			op2 = k - a[i] + a[i - 1];
		}else{
			op2 = a[n - 1] - a[0];
		}

		ans = min(ans, min(op1, op2));
	}

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

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
  int a;
  int b;
  int c;

  scanf("%d %d %d",&a,&b,&c);

  if(a < b && b < c ){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
    return 0;
} 



Measured memory_bytes: 2036