akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <cmath>
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//~ const int mod = (int)1e9 + 7;
const int mod = 998244353;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){stringstream ss;ss << a;string str = ss.str();return str;}
string conv(char a){stringstream ss;ss << a;string str = ss.str();return str;}
int conv(string a){stringstream geek(a); int x = 0; geek >> x;   return x;}

bool color[N];
bool vis[N];
vector< pair<int,int> > g[N];


void add(int i, int j, int w){
		g[i].pb(mp(j,w));
		g[j].pb(mp(i,w));
}

void dfs(int i, int d){
	vis[i] = true;
	if(d%2 == 0)
		color[i] = true;
	rep(j,0,sz(g[i])-1){
		if(vis[g[i][j].f] == false){
			dfs(g[i][j].f,d+g[i][j].s);
		}
	}
}


int main(void) 
{	
	clr(color,false);
	int n; cin>>n;
	int x, y, w;
	rep(i,1,n-1){
		cin>> x >> y >> w;
		add(x,y,w);
	}
	dfs(1,0);
	rep(i,1,n)
		cout<<color[i]<<endl;
	return 0;
} 


Measured memory_bytes: 10624
/*
    A story which will never end
    A story which never began
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ll long long

int main(){
    int n;
    cin>>n;
    if(n == 1){
        cout<<"Hello World"<<endl;
    }
    else {
        int a, b;
        cin>>a>>b;
        cout<<a + b<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import deque
import bisect
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

Colors = deque()
Colors.append(A[0])

for i in range(1, N):
    if Colors[0] >= A[i]:
        Colors.appendleft(A[i])
    else:
        idx = bisect.bisect_left(Colors, A[i])
        Colors[idx-1] = A[i]
print(len(Colors))



Measured memory_bytes: 53720
import java.util.*;
import java.math.BigInteger;

public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    BigInteger A = sc.nextBigInteger();
    BigInteger B = sc.nextBigInteger();
 
    if(A.compareTo(B) > 0){
      System.out.println("GREATER");  
    }else if(A.compareTo(B) < 0){
      System.out.println("LESS");  
    }else{
      System.out.println("EQUAL"); 
    }
   
  }
}

Measured memory_bytes: 36056
#include<stdio.h>
#include<string.h>
int chk(int n){
    if(n==0)return 1;
    if(n==1)return 2;
    if(n==2)return 3;
}
int main(){
    char a[101],b[101],c[101];
    scanf("%s%s%s",a,b,c);
    int i=0,j=0,k=0,res=1;
    while(i<=strlen(a)&&j<=strlen(b)&&k<=strlen(c)){
        if(res==1){
            res=chk(a[i]-'a');
            i++;
            //printf("turn A done\n");
        }else if(res==2){
            res=chk(b[j]-'a');
            j++;
            //printf("turn B done\n");
        }else{
            res=chk(c[k]-'a');
            k++;
            //printf("turn C done\n");
        }
    }
    if(i==strlen(a)+1)printf("A");
    if(j==strlen(b)+1)printf("B");
    if(k==strlen(c)+1)printf("C");
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        if (N == 1) { Console.WriteLine("Hello World"); }
        else if (N == 2) {
            int A= int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            Console.WriteLine(A + B);
        }
    }
}

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

int main() {
  
  int a,b;
  cin >> a >> b;
  
  if ( ( a + b ) % 2 == 0 ){
    cout << ( a + b ) / 2 << endl;
  }else{
    cout << ( a + b ) / 2 + 1 << endl;
  }
  
  
}



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

int main() {
	long long N, A[2000], SUM = 0;
	static bitset<4000010> DP;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i], SUM += A[i];
	DP[0] = 1;
	for (int i = 0; i < N; i++) {
		DP = DP | (DP << A[i]);
	}
	for (long long i = (SUM + 1) / 2; i <= SUM; i++) {
		if (DP[i]) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 2176
L = list(map(int, input().split()))
X = L[:2]
Y = L[2:]

# ans = 0
ans_max = -10**20

for x in X:
    for y in Y:
        ans = x * y
        # print(x)
        # print(y)
        if ans > ans_max:
            ans_max = ans

print(ans_max)


Measured memory_bytes: 9152
#include<iostream>
using namespace std;
long long a[17][17];
long long gt[1<<17];
long long dp[1<<17];
int n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>a[i][j];
		}
	}	
	for(int S=0;S<(1<<n);S++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<i;j++)
			{
				if((S>>i)&1 && (S>>j)&1) gt[S]+=a[i][j];
			}
		}
	}
	for(int S=1;S<(1<<n);S++)
	{
		for(int k=S;k;k=(k-1)&S)
		{
			dp[S]=max(dp[S],gt[k]+dp[S^k]);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  vector<vector<int>> cost_and_time(n, vector<int> (2, 0));
  int mini = 10000;
  rep(i, n) {
      rep(j, 2) {
          cin >> cost_and_time[i][j];
      }
      mini = (t >= cost_and_time[i][1] &&
              min(cost_and_time[i][0], mini) != mini)
              ? cost_and_time[i][0] : mini;
  }
  if (mini == 10000) cout << "TLE" << endl;
  else cout << mini << endl;
}

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

int main()
{
		int n,k,a[100],m=0;cin>>n>>k;
		for(int i=0;i<n;i++)
		{
				cin>>a[i];
				m+=min(a[i],k-a[i]);
		}
		cout<<m*2<<endl;
		return 0;
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    if (A == B && B == C) {
        cout << -1 << endl;
        return 0;
    }
    bool flg = 1;
    int sum = 0;
    while (flg) {
        int A2, B2, C2;

        if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {
            cout << sum << endl;
            flg = 0;
        }

        A2 = A/2;
        B2 = B/2;
        C2 = C/2;

        A = B2 + C2;
        B = A2 + C2;
        C = A2 + B2;
        sum++;
    }

    return 0;
}


Measured memory_bytes: 256
#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, k;
  cin >> n >> k;
  vector<int> h(n+1);
  rep(i,n) cin >> h.at(i);
  ll dp[100010];
  rep(i,100010) dp[i] = LLONG_MAX;
  dp[0] = 0;
  for(int i = 1; i < n; i++) {
    for(int j = 1; i-j >= 0 && j <= k; j++) {
      dp[i] = min(dp[i], dp[i-j]+abs(h.at(i)-h.at(i-j)));
    }
  }
  cout << dp[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1408
# 個数を返す

n = int(input())
ps = list(map(int, input().split()))

_min = ps[0]
mins = []
for p in ps:
    if p < _min:
        _min = p
    mins.append(_min)

count = 0
for i in range(n):
    if ps[i] <= mins[i]:
        count+=1

print(count)

Measured memory_bytes: 26584
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(ll i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
ll n, a, b, c, d;
unordered_map<ll, ll>dp;
ll dfs(ll rt){
	//cout << rt << endl;
	if(rt == 1) return d;
	if(dp[rt]) return dp[rt];
	//dp[rt] = 1e18;
	rep(j, 0, 15){
		ll i = rt - j + 8;
		//cout << rt << " " << i << endl;
		if(i <= 0 || dp[i]) continue;
		dp[i] = 1e18;
		if(1e18 / i > d ) dp[i] = min(dp[i], d * i);
		if(i % 2 == 0){
			dp[i] = min(dp[i], dfs(i / 2) + a);
		}
		if(i % 3 == 0){
			dp[i] = min(dp[i], dfs(i / 3) + b);
		}
		if(i % 5 == 0){
			dp[i] = min(dp[i], dfs(i / 5) + c);
		}
	}
	rep(j, 0, 15){
		rep(k, 0, 15){
			ll i = rt - j + 8;
			ll t = rt - k + 8;
			if(i < 0 || t <  0) continue;
			dp[i] = min(dp[i], dp[t] + d * abs(t - i));
		}
	}
	return dp[rt];
	/*if(i % 2 == 0){
		dp[i] = min(dp[i], dfs(i / 2) + a);
	}
	if(i % 3 == 0){
		dp[i] = min(dp[i], dfs(i / 3) + b);
	}
	if(i % 5 == 0){
		dp[i] = min(dp[i], dfs(i / 5) + c);
	}
	i ++;
	dp[i] = 1e18;
	if(i % 2 == 0){
		dp[i] = min(dp[i], dfs(i / 2) + a);
	}
	if(i % 3 == 0){
		dp[i] = min(dp[i], dfs(i / 3) + b);
	}
	if(i % 5 == 0){
		dp[i] = min(dp[i], dfs(i / 5) + c);
	}
	i -= 2;
	if(i > 0){
		dp[i] = 1e18;
	if(i % 2 == 0){
		dp[i] = min(dp[i], dfs(i / 2) + a);
	}
	if(i % 3 == 0){
		dp[i] = min(dp[i], dfs(i / 3) + b);
	}
	if(i % 5 == 0){
		dp[i] = min(dp[i], dfs(i / 5) + c);
	}
	//i -= 2;
	}
	i ++ ;*/
	//dp[i] = min(dp[i], dfs(i + 1) + d);
	//dp[i] = min(dp[i], dfs(i - 1) + d);
	//return dp[rt];
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int T;
	cin >> T;
	while(T --){
		cin >> n >> a >> b >> c >> d;
		dp.clear();
		cout << dfs(n) << endl;
		/*rep(i, 0, 20){
			cout << i << " " << dp[i] << endl;
		}*/
		/*for(auto i : dp){
			cout << i.fi <<" " << i.se << endl;
		}*/
	}
	return 0;
}

Measured memory_bytes: 7092
#include <iostream>
using namespace std;
int main(){
	int a[4],b[4];
	while(cin >> a[0]){
		int hit = 0,brow = 0;
		for(int i = 1; i < 4; i++){
			cin >> a[i];
		}
		for(int i = 0; i < 4; i++){
			cin >> b[i];
		}
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				if(a[i] == b[j]){
					i == j? hit++ : brow++;
				}
			}
		}
		cout << hit << " " << brow << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true){
        c -= b;
        if(c<=0){
            cout<<"Yes"<<endl;
            break;
        }
        a -= d;
        if(a<=0){
            cout<<"No"<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3040
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<math.h>
using namespace std;
int a[105];
int ans[105];
int sum[105];
int main()
{
    int n,nh=0;
    sum[0]=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        nh=nh+a[i];
        sum[i]=sum[i-1]+a[i];
    }
    for(int i=1;i<=n;i++)
    {
        ans[i]=fabs(2*sum[i]-nh);
    }
    sort(ans+1,ans+n+1);
    printf("%d\n",ans[1]);


}


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

#define ul unsigned long 
#define ull unsigned long long
#define li long long int

ul f(ul a,ul b) {
  ul ct=0;
  while (a|b) {
    a/=10;b/=10;
    ct++;
  }
  return ct;
}

int main()
{
  int a,b,c,x,y;
  cin >> a>>b>>c>>x>>y;
  int ans=INT_MAX;

  for (int i=0;i<=max(x,y);i++) {
    int cv=a*max(0,x-i)+b*max(0,y-i)+2*c*i;
    //cout <<cv <<endl;
    ans=min(ans,cv);
  }
  
  cout << ans <<endl;

  return 0;
}


Measured memory_bytes: 256
import math
source = input().split()
N, D = int(source[0]), int(source[1])
X = []
Y = []
validPoints = 0
for i in range(N):
    point = input().split()
    X.append(int(point[0]))
    Y.append(int(point[1]))

for j in range(len(X)):
    distance = math.sqrt(pow(X[j], 2) + pow(Y[j], 2))
    if distance <= D:
        validPoints += 1
print(validPoints)

Measured memory_bytes: 24956
#include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector> //動的配列

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

using namespace std;
int main() {
  string x;
  cin >> x;
  sort(x.begin(), x.end());
  if (x == "abc")
    cout << "Yes";
  else
    cout << "No";
  return 0;
}


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

int main()
{
	int a, b, c, d, e, k;
	std::cin >> a;
	std::cin >> b;
	std::cin >> c;
	std::cin >> d;
	std::cin >> e;
	std::cin >> k;


	if (e - a <= k)
		printf("Yay!\n");
	else
		printf(":(\n");

	system("pause");

	return 0;
}



Measured memory_bytes: 504
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

			int n = sc.nextInt();
			int v[] = new int[n];
			int c[] = new int[n];
			for (int i = 0; i < n; i++) {
				v[i] = sc.nextInt();
			}
			for (int i = 0; i < n; i++) {
				c[i] = sc.nextInt();
			}
			int result = 0;
			for (int i = 0; i < n; i++) {
				if (v[i] - c[i] > 0) {
					result += (v[i] - c[i]);
				}
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 24020
N = int(input())
ssum = 0
not10min = -1
for si in (int(input()) for _ in range(N)):
  ssum += si
  if si % 10 != 0:
    if not10min < 0:
      not10min = si
    else:
      not10min = min(not10min, si)

if ssum % 10 ==0:  
  if not10min >= 0:
    ssum -= not10min
  else:
    ssum = 0
print(ssum)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

ll apple[3*N];
bool cmp(ll a,ll b){
    return a>b;
}
int main(){
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    for(int i=0;i<a;i++){
        cin>>apple[i];
    }
    sort(apple,apple+a,cmp);
    for(int i=x;i<x+b;i++){
        cin>>apple[i];
    }
    sort(apple+x,apple+x+b,cmp);
    for(int i=x+y;i<x+y+c;i++){
        cin>>apple[i];
    }
    sort(apple,apple+x+y+c,cmp);
    ll sum=0;
    for(int i=0;i<x+y;i++) sum+=apple[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 2432
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            bool f = false;
            for (int i = 0; i <= n; i++)
            {
                if (n / 1.08 <= i && i < (n + 1) / 1.08)
                {
                    Console.WriteLine(i);
                    f = true;
                    break;
                }
            }
            if (!f) Console.WriteLine(":(");

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13140
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		int a,b;
		char t;
		cin>>a>>t>>b;
		long double aa=0.0,bb=0.0;
		aa=a*30.0;
		aa+=b/2.0;
		bb=b*6.0;
		long double ans=360.0;
		ans=min(abs(aa-bb),ans);
		ans=min(abs(aa+360-bb),ans);
		ans=min(abs(aa-bb-360),ans);
		if(0.0<=ans&&ans<30.0) cout<<"alert\n";
		else if(30.0<=ans&&ans<90.0) cout<<"warning\n";
		else cout<<"safe\n";
	}
}

Measured memory_bytes: 1124
N = int(input())
A = list(map(int, input().split()))

total_length = sum(A)
left_length = 0
for i in range(len(A)):
    left_length += A[i]
    if left_length * 2 >= total_length:
        break
cost_from_left = left_length * 2 - total_length

right_length = 0
for j in reversed(range(len(A))):
    right_length += A[j]
    if right_length * 2 >= total_length:
        break
cost_from_right = right_length * 2 - total_length

print(min(cost_from_left, cost_from_right))


Measured memory_bytes: 26060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> p(n * n);
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n * n; i++) {
        cin >> p[i];
        p[i]--;
        a[p[i] / n][p[i] % n] = i;
    }
    int cur;
    vector<vector<int>> d(n + 2, vector<int>(n + 2));
    for (int i = 1; i < n + 1; i++) {
        for (int j = 1; j < n + 1; j++) {
            d[i][j] = min({i, j, n + 1 - i, n + 1 - j});
        }
    }
    debug(d);
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, 1, -1};
    function<void(int, int)> bfs = [&](int i, int j) {
        deque<pair<int, int>> que;
        que.emplace_back(i, j);
        while (!que.empty()) {
            tie(i, j) = que.front();
            que.pop_front();
            for (int k = 0; k < 4; k++) {
                int ni = i + dx[k], nj = j + dy[k];
                if (0 < ni && ni <= n && 0 < nj && nj <= n) {
                    if (a[ni - 1][nj - 1] < cur) {
                        if (d[ni][nj] > d[i][j]) {
                            d[ni][nj] = d[i][j];
                            que.emplace_front(ni, nj);
                        }
                    } else {
                        if (d[ni][nj] > d[i][j] + 1) {
                            d[ni][nj] = d[i][j] + 1;
                            que.emplace_back(ni, nj);
                        }
                    }
                }
            }
        }
    };
    int ans = 0;
    for (int k = 0; k < n * n; k++) {
        int i = p[k] / n + 1, j = p[k] % n + 1;
        ans += d[i][j] - 1;
        for (int l = 0; l < 4; l++) {
            int ni = i + dx[l], nj = j + dy[l];
            d[i][j] = min(d[i][j], d[ni][nj]);
        }
        cur = k;
        bfs(i, j);
        debug(d);
    }
    debug(a);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 7140
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string S;
int cnt;
bool fl = true;
int idxC = -1;

int main()
{
  std::cin >> S;

  fl &= S[0] == 'A';

  fl &= std::count( S.begin()+2, S.end()-1, 'C' ) == 1;

  repi( i, 1, S.size() ) if( S[i] != 'C' )
    fl &= S[i] >= 'a' && S[i] <= 'z';

  puts( fl ? "AC" : "WA" );

  return 0;
}

Measured memory_bytes: 256
import sys
import math
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
s = ns()

if s[:(n//2)] ==s[(n//2):]:
    print("Yes")
else:
    print("No")

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 10){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input();

  string s;
  cin >> s;

  int q = input();
  while (q--) {
    int k = input();

    int64 ans = 0;
    int64 d = 0, m = 0, dm = 0;

    range(i, 0, N) {
      if (s[i] == 'C') ans += dm;
      if (s[i] == 'D') d++;
      if (s[i] == 'M') {
        dm += d;
        m++;
      }

      if (i - k + 1 < 0) continue;

      if (s[i - k + 1] == 'M') m--;
      if (s[i - k + 1] == 'D') {
        dm -= m;
        d--;
      }
    }

    cout << ans << endl;
  }
}

signed main(int argc, char *argv[]) {
  solver();
}



Measured memory_bytes: 1948
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b) f(i,0,n){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/


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

	int n;
	st a, b, c;
	cin >> n >> a >> b >> c;
	LL ans = 0;
	f(i, 0, n) {
		if (a[i] == b[i] && b[i] == c[i]) {
			continue;
		}
		if (a[i] == b[i] && b[i] != c[i]) {
			ans++;
			continue;
		}
		if (a[i] != b[i] && b[i] == c[i]) {
			ans++;
			continue;
		}
		if (a[i] == c[i] && b[i] != c[i]) {
			ans++;
			continue;
		}
		if (a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]) {
			ans += 2;
			continue;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n;
  cin >> n;
  double res = 0;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  res += a[0];
  for(int i = 1;i < n;i++)res += a[i],res /= 2;
  cout << fixed << setprecision(10) << res << endl;
}

Measured memory_bytes: 3704
#include<stdio.h>
#pragma GCC optimize(2)
short x[16],y[16];
int p[16];
long long ans[16];
short mi[16],m1[16];
short px[16][16],py[16][16];
int ppk,st;
short cnt,now;
int main(void)
{
 
	char n;
	scanf("%hd",&n);
	for(char i=0;i<n;i++) scanf("%hd%hd%d",&x[i],&y[i],&p[i]);
	int ma=1;
	for(char i=0;i<=n;++i) ans[i]=1000000000000000;
	for(char i=0;i<n;++i) ma*=3;
	for(char i=0;i<n;++i)
	{
		short x1=x[i]>0?x[i]:-x[i],y1=y[i]>0?y[i]:-y[i];
		m1[i]=x1>y1?y1:x1;
	}
	for(char i=0;i<n;++i)
	{
		for(char j=0;j<n;++j)
		{
			px[i][j]=x[i]-x[j];
			py[i][j]=y[i]-y[j];
			if(px[i][j]<0) px[i][j]=-px[i][j];
			if(py[i][j]<0) py[i][j]=-py[i][j];
		}
	}
	for(int zhu=0;zhu<ma;++zhu)
	{
		ppk=zhu,cnt=n,st=ma/3;
		for(char i=0;i<n;i++) mi[i]=m1[i];
		for(char i=0;i<n;i++,st/=3)
		{
			now=ppk/st;
			switch(now)
			{
				case 2:for(char j=0;j<n;++j) if(mi[j]>px[i][j]) mi[j]=px[i][j];break;
				case 1:for(char j=0;j<n;++j) if(mi[j]>py[i][j]) mi[j]=py[i][j];break;
				case 0:cnt--;
			}
			ppk-=st*now;
		}
		long long sum=0;
		for(char i=0;i<n;++i) sum+=(long long)mi[i]*p[i];
		if(ans[cnt]>sum) ans[cnt]=sum;
	}
	for(char i=0;i<=n;i++) printf("%lld\n",ans[i]);
}


Measured memory_bytes: 3148
use proconio::{fastout, input};

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        x: isize,
        n: usize,
        p: [isize; n],
    }

    let mut dp = [false; 102];
    let mut ans = 42;

    for e in &p {
        dp[*e as usize] = true;
    }

    let mut hoge = 10000;
    for i in (0..=101).rev() {
        if !dp[i] {
            let fuga = (x - i as isize).abs();
            if fuga <= hoge {
                ans = i;
                hoge = fuga;
            }
        }
    }

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


Measured memory_bytes: 2172
import sys

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N, U, V = rl()
edges = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b = rl()
    edges[a].append(b)
    edges[b].append(a)

def dfs(v):
    dist = [-1] * (N+1)
    dist[v] = 0
    stack = []
    stack.append(v)
    while stack:
        s = stack.pop()
        for t in edges[s]:
            if dist[t] >= 0:
                continue
            dist[t] = dist[s] + 1
            stack.append(t)
    return dist

DU, DV = dfs(U), dfs(V)
answer = 0
for u, v in zip(DU[1:], DV[1:]):
    if v > u:
        x = v - 1
        if x > answer:
            answer = x

print(answer)



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N, K; cin >> N >> K;
  bool ok[N] = {};
  rep(i,K) {
    int d; cin >> d;
    rep(j,d) {
      int A; cin >> A; A--;
      ok[A] = true;
    }
  }
  int result = 0;
  rep(i,N) result += !ok[i];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    long sum = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
      sum += a[i];
    }
    long t = ((long)n * (long)(n + 1)) / (long)2;
    String ans = "NO";
    if((sum % t) == 0) {
      long k = sum / t;
      int p = 0;
      for(int i = 0; i < n; i++) {
        long c = 0;
        if(i == 0) {
          c = a[i] - a[n - 1] - k;
        } else {
          c = a[i] - a[i - 1] - k;
        }
        if(!((c <= 0) && ((c % (long)n) == 0))) p++;
      }
      if(p == 0) ans = "YES";
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 56040
#include"bits/stdc++.h"
using namespace std;
int main(){
	bool ans=false;
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	vector<int> a,b;
	for(int i=0;i!=n;++i){
		int z;
		cin>>z;
		a.push_back(z);
	}
	for(int i=0;i!=m;++i){
		int z;
		cin>>z;
		b.push_back(z);
	}
	for(int z=-100;z<=100;++z){
		bool t=(x<z),u=(z<=y),v=true,w=true;
		for(auto i:a){
			if(i>=z)
				v=false;
		}
		for(auto i:b){
			if(i<z)
				w=false;
		}
		if(t&&u&&v&&w)
			ans=true;
	}
	cout<<(ans ? "No War":"War");
}


Measured memory_bytes: 256
#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;
  cin >> N;
  vector<int> ss(N);
  int sum = 0;
  rep(i, N) {
    cin >> ss[i];
    sum += ss[i];
  }
  if (sum%10) {
    cout << sum << endl;
    return 0;
  }
  sort(ss.begin(), ss.end());
  int num = 0;
  rep(i, N) {
    int s = ss[i];
    if (s%10) {
      sum -= s;
      break;
    }
    if (i == N-1) {
      sum = 0;
    }
  }
  cout << sum << endl;
  return 0;
}


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



int main() {
    int x, y;
    cin >> x >> y;

    vector<vector<int>> group(3);
    for(int i = 1; i <= 12; i++){
        if(i == 2) group.at(0).push_back(i);
        else if(i == 4 || i == 6 || i == 9 || i == 11) group.at(1).push_back(i);
        else group.at(2).push_back(i);
    }
  
  	bool flag1 = false;
  	bool flag2 = false;

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < group.at(i).size(); j++){
            if(x == group.at(i).at(j)){
              x = i;
              flag1 = true;
            }
          if(flag1 == true) break;
        }
      if(flag1 == true) break;
    }
  
  	for(int i = 0; i < 3; i++){
        for(int j = 0; j < group.at(i).size(); j++){
            if(y == group.at(i).at(j)){
              y = i;
              flag2 = true;
            }
          if(flag2 == true) break;
        }
      if(flag2 == true) break;
    }

    if(x == y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N>=1000){
		printf("ABD");
	}else{
		printf("ABC");
	}
}

Measured memory_bytes: 256
program main
  implicit none

  integer :: n,x,i, a(100), b=1, p=0

  read(*,*)n,x
  read(*,*)(a(i), i = 1, n)
  
  do i = 1, n
    p = p + a(i)
    if (p <= x) then
      b = b + 1
    else
      write(*,*)b
      stop
    end if
  end do

  write(*,*)b

end program main

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            decimal iL = decimal.Parse(sS[0]);
            decimal iR = decimal.Parse(sS[1]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            decimal iOut = decimal.MaxValue;
            decimal iNow = 0;
            for (decimal i = iL; i < iR; i++)                               // A
            {
                for (decimal j = i + 1; j <= iR; j++)                       // B   A-Bで全ての組合せ
                {
                    iNow = (i * j) % 2019;                                  // A*Bの2019の余り
                    if (iNow == 0) { iOut = 0; break; }
                    if (iOut > iNow) { iOut = iNow; }
                }
                if (iOut == 0) { break; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

namespace Sunuke
{
    class Program
    {
        private static char[] c;
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            c = n.ToCharArray();

            for(int i = 0; i < n.Length; i++)
            {
                if (c[i] == '1')
                {
                    c[i] = '9';
                }
                else
                {
                    c[i] = '1';
                }
            }
            Console.WriteLine(c);
        }
    }
}


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

int main(){
   int n,k;
   cin >> n >> k;
   vector<int> a(n);
   vector<int> b(n+1);
   rep(i,n){
      cin >> a.at(i);
      b.at(a.at(i))++;
   }
   int count=0;
   rep(i,n+1){
      if(b.at(i)!=0)count++;
   }
   if(count<=k){
      cout << 0 << endl;
      return 0;
   }
   int ans=0;
   k=count-k;
   sort(b.begin(),b.end());
   rep(i,n){
      if(b.at(i)!=0){
         k--;
         ans+=b.at(i);
      }
      if(k==0){
         cout << ans << endl;
         return 0;
      }
   }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll H,W; cin>>H>>W;
  vector<vector<ll>>X(10, vector<ll>(10));
  for(int i=0; i<=9; i++){
    for(int j=0; j<=9; j++){
      ll c; cin>>c;
      X[i][j]=c;
    }
  }
  for(int k=0; k<=9; k++){
    for(int i=0; i<=9; i++){
      for(int j=0; j<=9; j++){
        if(i==j || j==k || k==i) continue;
        X[i][j]=min(X[i][j],X[i][k]+X[k][j]);
      }
    }
  }
  ll ans=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      ll a; cin>>a;
      if(a==-1) continue;
      ans+=X[a][1];
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 3168
import java.util.*;

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

        if(n == s){
            System.out.println(n+1);
            return;
        }

        for(int i=2; i<(int)(Math.sqrt(n) + 10); i++){
            if(f(n, i) == s){
                System.out.println(i);
                return;
            }
        }

        long bmin = Long.MAX_VALUE;
        for(int i=1; i<=(int)(Math.sqrt(n)+ 10); i++){
            long b = (n-s) / i + 1;
            if(b <= 1) continue;
            if(f(n, b) == s){
                bmin = Math.min(b, bmin);
            }
        }

        if(bmin == Long.MAX_VALUE){
            System.out.println(-1);
        }else{
            System.out.println(bmin);
        }

    }

    static long f(long n, long b){
        long ret = 0;
        while(n != 0){
            ret += n % b;
            n /= b;
        }
        return ret;
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	int res=0;
	for(int i=1; i<n-1; i++){
		if((a[i]>=a[i-1] && a[i]<=a[i+1]) || (a[i]<=a[i-1] && a[i]>=a[i+1])) res++;
	}
	cout << res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl "\n"
#define inf 1000000007
//#define for(i, a, b) for(int i=a; i<b; i++)
void solve(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++) cin>>arr[i];
  	int dp[n] = {0};
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	//for(int i=0;i<n;i++) cout<<dp[i]<<endl;
	cout<<dp[n-1];
}
signed main(){
	#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
 
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

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

    ll h; cin >> h;

    ll cnt = 0;
    while(h != 1){
        cnt++;
        h /= 2;
    }

    cnt++;

    ll ans = 0, n = 1;
    while(cnt--){
        ans += n;
        n *= 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  string s;
  cin>>s;
  set<string> s1,s2;
  for(Int i=0;i<100;i++){
    for(Int j=1;j<=12;j++){
      string a=to_string(i);
      string b=to_string(j);
      if(a.size()==1u) a='0'+a;
      if(b.size()==1u) b='0'+b;
      s1.emplace(a+b);
      s2.emplace(b+a);
    }
  }
  if(s1.count(s)&&!s2.count(s)){
    cout<<"YYMM"<<endl;
  }
  if(!s1.count(s)&&s2.count(s)){
    cout<<"MMYY"<<endl;
  }
  if(s1.count(s)&&s2.count(s)){
    cout<<"AMBIGUOUS"<<endl;
  }
  if(!s1.count(s)&&!s2.count(s)){
    cout<<"NA"<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

typedef long long int ll;

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

int main() 
{
    ll n;
    cin >> n;
    
    int ans = to_string(n).size();
    
    for(ll i=1 ; i*i<=n ; i++)
    {
        if(n%i == 0)
        {
            int temp = max(to_string(i).size() , to_string(n/i).size());
            ans = min(ans , temp);
        }
    }
    
    cout << ans;
    return 0;
}

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

int H, W;

string S[22];
int visit[22][22];
queue< pair<int, int> > Q;

int isGood(int a, int b)
{
    if(a < 0 || a >= H || b < 0 || b >= W || S[a][b] == '#' || visit[a][b])
        return 0;
    
    return 1;
}

int bfs(int x, int y)
{
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            visit[i][j] = 0;
    
    int ans = 0;
    Q.push({x, y});
    visit[x][y] = 1;

    while(!Q.empty())
    {
        int q = Q.size();

        while(q--)
        {
            auto pr = Q.front();
            Q.pop();
            int a = pr.first, b = pr.second;

            if(isGood(a-1, b))
            {
                Q.push({a-1, b});
                visit[a-1][b] = 1;
            }
            if(isGood(a+1, b))
            {
                Q.push({a+1, b});
                visit[a+1][b] = 1;
            }
            if(isGood(a, b-1))
            {
                Q.push({a, b-1});
                visit[a][b-1] = 1;
            }
            if(isGood(a, b+1))
            {
                Q.push({a, b+1});
                visit[a][b+1] = 1;
            }
        }

        ans++;
    }

    return ans - 1;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    cin >> H >> W;

    for(int i=0; i<H; i++)
        cin >> S[i];
    
    int ans = 0;

    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
        {
            if(S[i][j] == '#')
                continue;
            
            ans = max(ans, bfs(i, j));
        }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from math import gcd

print('A' if input().isupper() else 'a')


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

typedef long long ll;

ll C2(int x){
    return (ll)x * (x-1) / 2LL;
}

set<int> S, T;

int a[200005];
int pos[200005];
int n;

void input(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        pos[a[i]] = i;
    }
    S.insert(0);
    S.insert(n+1);
    T.insert(0);
    T.insert(-n-1);
}

void pro(){
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        auto It = S.lower_bound(pos[i]);
        auto Jt = T.lower_bound(-pos[i]);
        int r = *It, l = -(*Jt);
        //printf("i = %d, l = %d, r = %d\n",i,l,r);
        ans += (ll)(r-pos[i]) * (pos[i]-l) * i;
        S.insert(pos[i]);
        T.insert(-pos[i]);
    }
    cout << ans << '\n';
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    input();
    pro();
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
 
int run_test(){
      int r,c,k;
      cin >> r >> c >> k;
      int arr[r][c];
      for(int i =0; i<r; i++){
            for(int j = 0; j<c; j++){
                  char t;
                  cin >> t;
                  if(t == '#'){
                        arr[i][j] = 1;
                  }
                  else{
                        arr[i][j] = 0;
                  }
            }
      }
      int ans = 0;
      for(int rmask = 0; rmask < (1 << r); rmask++){
            for(int cmask =0; cmask < (1 << c); cmask++){
                  int b = 0;
                  for(int i =0; i < r; i++){
                        for(int j=0; j<c; j++){
                             if(((rmask >> i) & 1) == 0 && ((cmask >> j) & 1)== 0 && arr[i][j] == 1) b++;
                        }
                  }
                  if(b == k) ans++;
            }
      }
      cout << ans;
      return 0;
}

       
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(){
  int x;
  scanf("%d", &x);
  int a[4]={0};
  char s[4];
  for(int i=0; i<x; i++){
    scanf("%s", s);
    if(s[0]=='A') a[0]++;
    else if(s[0]=='W') a[1]++;
    else if(s[0]=='T') a[2]++;
    else if(s[0]=='R') a[3]++;
  }
  printf("AC x %d\n", a[0]);
  printf("WA x %d\n", a[1]);
  printf("TLE x %d\n", a[2]);
  printf("RE x %d\n", a[3]);
}

Measured memory_bytes: 1700