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

int main() {
  int N;
  cin >> N;
  
  bool isOK = true;
  string word;
  set<string> used;
  char beforelast;
  for(int i = 0; i < N; ++i) {
    cin >> word;
    if(i != 0) {
      // 使ったことがある言葉か
      if(used.find(word) != used.end()) {
        isOK = false;
        break;
      }
      // 最初の文字が直前の言葉の最後の文字と同じか
      if(word[0] != beforelast) {
        isOK = false;
        break;
      }

    }
    used.insert(word);
    beforelast = word[word.size()-1];
  }
  if(isOK) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


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

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	int ab = abs(x - a);
	int bb = abs(x - b);

	if (ab < bb) {
		cout << "A";
	}
	else {
		cout << "B";
	}
}

Measured memory_bytes: 256
<?php
  
$input_line = fgets(STDIN);
$array = explode(" ", $input_line);
$age = $array[0];
$price = $array[1];

if ($age >= 13) {
  echo $price;
} else if ($age <= 12 && $age >= 6) {
  echo $price / 2;
} else {
  echo 0;
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
int d, g;
vector<int> p, c;

int rec(int cur, bool partially_solved, int solved_number, int score)
{
    if (cur == d)
    {
        return (score >= g ? solved_number : INFINITY);
    }

    int point = (cur + 1) * 100;
    int question_number = p.at(cur);
    int comp_bonus = c.at(cur);

    int res;
    res = rec(cur + 1, partially_solved, solved_number, score); // 解かない
    res = min(res,
              rec(cur + 1, partially_solved, solved_number + question_number,
                  score + point * question_number + comp_bonus)); // 全部解く

    if (partially_solved == false)
    {
        rep(i, 1, question_number)
        {
            res = min(res,
                      rec(cur + 1, true, solved_number + i,
                          score + point * i)); // 部分的に解く
        }
    }
    return res;
}

int main()
{
    cin >> d >> g;

    p.resize(d);
    c.resize(d);

    rep(i, 0, d)
    {
        cin >> p.at(i) >> c.at(i);
    }
    cout << rec(0, false, 0, 0) << endl;
    return 0;
}

/*
base case

cur == d
得点g以上なら問題数を返す

他
各分岐のreturnのminを返す

部分的に解いたかどうかに関わらず、
問題を0/p問解く

部分的に解く場合、
問題を1～p-1問解く

引数
cur
部分的に解いたか
問題数
得点
*/

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    struct Edge
    {
        internal int u, v, cost;
    }

    class Union_Find
    {
        internal int[] parents, rank;

        public Union_Find(int n)
        {
            parents = Enumerable.Range(0, n).ToArray();
            rank = new int[n];
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);

            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            List<Edge> es = new List<Edge>();

            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Trim().Split(' ');
                Edge temp;

                for (int j = 0; j < n; j++)
                {
                    int cost = int.Parse(input[j]);

                    if (cost != -1)
                    {
                        temp.u = i;
                        temp.v = j;
                        temp.cost = cost;
                        es.Add(temp);
                    }
                }
            }
            Console.WriteLine(Kruskal(es, n));
        }

        static int Kruskal(List<Edge> es, int n)
        {
            es.Sort((a, b) => a.cost - b.cost);
            Union_Find uf = new Union_Find(n);

            int res = 0;

            for (int i = 0; i < es.Count; i++)
            {
                Edge e = es[i];

                if (!uf.Same(e.u, e.v))
                {
                    uf.Unite(e.u, e.v);
                    res += e.cost;
                }
            }
            return res;
        }
    }
}

Measured memory_bytes: 9832
IDENTIFICATION DIVISION.
      PROGRAM-ID.  090A.
      DATA DIVISION.
      WORKING-STORAGE SECTION.
      01 INP PIC X(10).
      01 C1.
      	03 C11 PIC X(1).
      	03 C12 PIC X(1).
      	03 C13 PIC X(1).
      01 C2.
      	03 C21 PIC X(1).
      	03 C22 PIC X(1).
      	03 C23 PIC X(1).
      01 C3.
      	03 C31 PIC X(1).
      	03 C32 PIC X(1).
      	03 C33 PIC X(1).
      
      01 OUT PIC X(3).
      
      PROCEDURE DIVISION.
      ACCEPT INP.
	  MOVE INP TO C1.
            
      ACCEPT INP.
	  MOVE INP TO C2.
            
      ACCEPT INP.
	  MOVE INP TO C3.
      
	  STRING C11 C22 C33 DELIMITED BY SIZE
      INTO OUT.
      
      DISPLAY OUT.
      
      STOP RUN.

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;
ll sum = 0;

int main()
{
    string s;
    cin >> s;

    res = "yes";
    set<char> a;
    for (char c : s)
    {
        if (a.count(c))
        {
            res = "no";
        }

        a.insert(c);
    }

    println(res);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;
struct state { ull x; int zero, pre, dist, remain; };
bool operator<(const state& s1, const state& s2) { return s1.dist + s1.remain > s2.dist + s2.remain; }
int a, cz, dist[16][16]; ull s, goal = 1147797409030816545;
int goals[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0 };
int goals2[] = { 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };
int goals3[] = { 15, 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11 };
int dir[4] = { 1, 0, -1, 0 };
inline int getheuri(ull x) {
	int ret1 = 0; cz++;
	for (int i = 0; i < 16; i++) {
		int ww = ((x >> (i * 4)) & 15);
		if (!ww) continue;
		ret1 += dist[i][goals2[ww]];
	}
	int ret2 = 0, ret3 = 0;
	for (int i = 0; i < 16; i++) {
		for (int j = i + 1; j < 16; j++) {
			int ww1 = ((x >> (i * 4)) & 15);
			int ww2 = ((x >> (j * 4)) & 15);
			if (goals2[ww1] > goals2[ww2]) ret2++;
			if (goals3[ww1] > goals3[ww2]) ret3++;
		}
	}
	ret2 = ret2 / 3 + ret2 % 3;
	ret3 = ret3 / 3 + ret3 % 3;
	int ret = max(ret1, ret2 + ret3);
	return ret1;
}
int solve() {
	if (s == goal) return 0;
	int zz = -1;
	for (int i = 0; i < 16; i++) {
		if (!((s >> (i * 4)) & 15)) zz = i;
	}
	int rr = getheuri(s);
	priority_queue<state> que;
	que.push(state{ s, zz, -99, 0, rr });
	while (!que.empty()) {
		state a = que.top(); que.pop();
		ull v = a.x; int z = a.zero;
		for (int i = 0; i < 4; i++) {
			if (abs(i - a.pre) == 2) continue;
			int dx = dir[i], dy = dir[i ^ 1];
			int e = z + dy * 4 + dx;
			int g = ((v >> (e << 2)) & 15);
			if (0 <= e && e < 16 && (e & 3) - (z & 3) == dx) {
				ull w = v;
				w -= ((1ULL * g) << (e << 2));
				w += ((1ULL * g) << (z << 2));
				int xx = getheuri(w);
				if (w == goal) return a.dist + 1;
				que.push(state{ w, e, i, a.dist + 1, xx });
			}
		}
	}
	return -1;
}
int main() {
	for (int i = 0; i < 16; i++) {
		for (int j = 0; j < 16; j++) {
			dist[i][j] = abs((i >> 2) - (j >> 2)) + abs((i & 3) - (j & 3));
		}
	}
	for (int i = 0; i < 16; i++) {
		cin >> a;
		s += ((1ULL * a) << (i * 4));
	}
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 52068
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll h,w,r,m,tmp,rans,ans,MIN=1e9,ok;
string s[10];
vector<ll> v[1001],u;
int main(void){
    cin>>h>>w>>r;
    for(int i=0;i<h;i++)cin>>s[i];
    for(int i=0;i<(1<<(h-1));i++){
        ok=1;
        rans=0;
        ans=0;
        for(int k=0;k<(h-1);k++){
            if((i>>k)&1)rans++;
        }
        for(int i=0;i<1001;i++)v[i]={};
        for(int k=0;k<w;k++){
            tmp=0;
            if(s[0][k]=='1')tmp++;
            for(int j=0;j<(h-1);j++){
                if((i>>j)&1){
                    v[k].push_back(tmp);
                    //cout<<tmp<<" ";
                    if(tmp>r)ok=0;
                    tmp=0;
                    if(s[j+1][k]=='1')tmp++;
                }
                else{
                    if(s[j+1][k]=='1')tmp++;
                }
            }
            v[k].push_back(tmp);
            //cout<<tmp<<endl;
            //cout<<endl;
            if(tmp>r)ok=0;
        }
        //cout<<v[0][0]<<"WWWWW"<<endl;
        if(ok==0)continue;
        u={};
        for(int k=0;k<(rans+1);k++)u.push_back(0);
        for(int k=0;k<w;k++){
            for(int j=0;j<(rans+1);j++){
                //cout<<v[k][j]<<" "<<u[j]<<j<<endl;
                if(v[k][j]+u[j]>r){
                    ans++;
                    for(int tt=0;tt<(rans+1);tt++){
                        u[tt]=v[k][tt];
                    }
                    break;
                }
                else{
                    u[j]+=v[k][j];
                }
            }
        }
        //cout<<ans<<" "<<rans<<"W"<<endl;
        MIN=min(MIN,rans+ans);
    }
    cout<<MIN<<endl;
}


Measured memory_bytes: 512
/*input
4 3 90
*/
macro_rules! input_vec {
    () => {
        input!()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    ($delimiter:expr) => {
        input!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! input {
    () => {{
        let mut return_ = String::new();
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let v: Vec<f64> = input_vec!();
    print!(
        "{:.10}\n{:.10}\n{:.10}\n",
        v[0] * v[1] * v[2].to_radians().sin() / 2.0,
        v[0] + v[1]
            + ((v[0] * v[0]) + (v[1] * v[1]) - (2.0 * v[0] * v[1] * v[2].to_radians().cos()))
                .sqrt(),
        2.0 * (v[0] * v[1] * v[2].to_radians().sin() / 2.0) / v[0]
    );
}



Measured memory_bytes: 5184
N, K = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

def calc(n):
  return sum(range(1, n + 1)) / n

sums = [0]
s = 0
for i in range(N):
  s += calc(P[i])
  sums.append(s)

max_value = -1
max_index = -1

# print(sums)
for i in range(N - K + 1):
  s = sums[i+K] - sums[i]
  # print(i)
  # print(i+K)
  max_value = max(max_value, s)
  if max_value == s:
    max_index = i

print(max_value)
# print(sum([calc(P[i]) for i in range(max_index, max_index + K)]))

Measured memory_bytes: 76936
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
using namespace std;

const int mod = 2019;

int main() {
	int N;
	cin >> N;
	vector<int> cnt(N);
	for (int i = 2; i <= N; i++) {
		int A;
		cin >> A;
		cnt[A - 1]++;
	}
	for (int i = 0; i < N; i++) {
		cout << cnt[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 3648
# AOJ 1111: Cyber Guardian
# Python3 2018.7.15 bal4u

import re

while True:
	n, m = map(int, input().split())
	if (n|m) == 0: break
	rule, ans = [], []
	for i in range(n):
		g, s, d = input().split()
		rule.append((g[0] == 'p', re.compile((s+d).replace("?", "\d"))))
	for i in range(m):
		s, d, m = input().split()
		sd = s+d
		for G, SD in rule[::-1]:
			if re.match(SD, sd):
				if G: ans.append((s, d, m))
				break
	print(len(ans))
	for a in ans: print(*a)



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

string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main(){
	ll n;
	cin >> n;
	vector<int> s;
	while(n > 0){
		s.push_back(n%26);
		if(n % 26 == 0){
			n /= 26;
			n--;
		}else{
			n /= 26;
		}
	}
	reverse(s.begin(),s.end());
	string ans = "";
	rep(i,s.size()){
		if(s[i] == 0){
			ans.push_back('z');
		} else{
			ans.push_back(alphabet[s[i]-1]);
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3620
*c=0,2,5,5,4,5,6,3,7,6;eval"N,_,*A="+`dd`.split*?,;d=[0];1.upto(N){|i|q=A.map{|x|i>=c[x]&&d[t=i-c[x]]?d[t]*10+x:p}.compact;d.<<q[0]&&q.max};p d[N]

Measured memory_bytes: 36096
#include <bits/stdc++.h>
#define ll long long
using namespace std;
string s,t;
ll arr[3009][3009];
string ans;

void rec(ll x, ll y){
    if(x==0||y==0) return;
    if(s[x-1]==t[y-1]){
        ans+=s[x-1];
        rec(x-1,y-1);
        return;
    }
    else{
        if(arr[x][y]==arr[x-1][y]){
            rec(x-1,y);
            return;
        }
        else{
            rec(x,y-1);
            return;
        }
    }
}

int main()
{
    cin>>s>>t;
    for(int i=1;i<=s.length();i++){
        for(int j=1;j<=t.length();j++){
            if(s[i-1]==t[j-1]){
                arr[i][j]=arr[i-1][j-1]+1;
            }
            else{
                arr[i][j]=max(arr[i-1][j],arr[i][j-1]);
            }
        }
    }
    /*
    for(int i=0;i<=s.length();i++){
        for(int j=0;j<=t.length();j++){
            cout<<arr[i][j]<<' ';
        }
        cout<<endl;
    }
    */
    rec(s.length(),t.length());
    reverse(ans.begin(),ans.end());
    cout<<ans;
    return 0;
}


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

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

    vector<int> B(n - 1);
    rep(i, n - 1) { cin >> B.at(i); }
    int sum = 0;

    sum = B.at(0) + B.at(n - 2);  // initialvalue;

    rep(i, n - 2) { sum += min(B.at(i), B.at(i + 1)); }
    cout << sum << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
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;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
//int dp[100050];

int main(){
    int N;
    string S;
    cin >> N >> S;//Wが左、Eが右
    int W = 0;
    int E = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'W') W++;
        else E++;
    }
    int hoge = E,ans = E;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'W') hoge++;
        else hoge--;
        ans = min(ans,hoge);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int n,check = 1;;
	string s;
	cin >> n >> s;
	if(n%2 != 0){
		cout << "No";
		return 0;
	}
	for(int i = 0;i < n/2;i++){
		if(s[i] != s[i+n/2]){
			check = 0;
		}
	}
	if(check == 1)cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
//Flip,Flip, and Flip......

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    ll n,m;cin>>n>>m;
    if(n==1&&m==1){cout<<1<<nnn;return 0;}
    if(n==1||m==1){cout<<n*m-2<<nnn;return 0;}
    cout<<(n-2)*(m-2)<<nnn;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()

typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<int> LArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

int itiv;
inline int getInt() { return (cin >> itiv, itiv); }
void readAll(Array& vec, int n) { for (int i = 0; i < n; i++) cin >> vec[i]; }
inline bool between(int first, int last, int n) { return first <= n && n <= last; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int m, n;
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };


int main(void)
{
	while(cin >> n && n)
	{
		for (int i = 0; i < n; i++)
		{
			vector<int> arr(3);
			for (int i = 0; i < 3; i++)
			{
				cin >> arr[i];
			}
			sort(ALL(arr));
			cout << (arr[2] * arr[2] == arr[0] * arr[0] + arr[1] * arr[1] ? "YES" : "NO") << endl;
		}
	}
	return 0;
}

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

int n;

int main(){
  cin >> n;
  int num1 = 0, num2 = 0, num4 = 0;
  rep(i, n){
    int tmp; cin >> tmp;
    if(tmp % 4 == 0){
      num4++;
    }else if(tmp % 2 == 0){
      num2++;
    }else{
      num1++;
    }
  }
  if(n == 1){
    if(num4){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else if(num2 == 0){
    if(num4 >= num1 - 1){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(num4 >= num1){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


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

int main(void)
{
  long long X;

  scanf("%lld", &X);

  long long money = 100;
  int year = 0;

  while (1)
  {
    if (money >= X)
    {
      printf("%d", year);
      return 0;
    }
    money = (long long)(money * 1.01);
    year++;
  }

  return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define inf 1e9
#define mod 1000000007
#define ff first
#define ss second

void solve()
{
	int n, k;
	cin >> n >> k;
	int reach[n + 1], arr[n + 1];

	memset(reach, -1, sizeof(reach));
	for (int i = 1; i <= n; i++)
		cin >> arr[i];

	int cnt = 0, pos = 1;
	while (true)
	{
		if (reach[pos] != -1)
			break;
		if (k == cnt)
		{
			cout << pos << "\n";
			return;
		}
		reach[pos] = cnt;
		pos = arr[pos];
		cnt++;
	}

	k -= reach[pos];
	cnt -= reach[pos];
	k = k % cnt;
	for (int i = 0; i < k; i++)
		pos = arr[pos];

	cout << pos << "\n";
}

signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> a(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++)
      cin >> a.at(i).at(j);
  }
  
  for(int i=0;i<h;i++){
    int k=0;
    for(int j=0;j<w;j++){
      if(a.at(i).at(j)=='#')
        k++;
    }
    if(k==0){
      for(int j=0;j<w;j++)
        a.at(i).at(j)=' ';
    }
  }
  
  for(int i=0;i<w;i++){
    int k=0;
    for(int j=0;j<h;j++){
      if(a.at(j).at(i)=='#')
        k++;
    }
    if(k==0){
      for(int j=0;j<h;j++)
        a.at(j).at(i)=' ';
    }
  }
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a.at(i).at(j)!=' ')
        cout << a.at(i).at(j);
    }
    int k=0;
    for(int j=0;j<w;j++){
      if(a.at(i).at(j)==' ')
        k++;
    }
    if(k!=w)
      cout << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
yes = 'Possible'
no = 'Impossible'

if N == 2:
    if a[0] != 1 and a[1] != 1:
        print(no)
        exit()
    else:
        print(yes)
        exit()
if a[-1] != (a[0] + 1) // 2:
    print(no)
    exit()
else:
    if a[0] % 2 == 0:
        if a[-2] == a[-1]:
            print(no)
            exit()
    else:
        if a[-3] == a[-1]:
            print(no)
            exit()

ok = [0] * N
for i in range(N):
    ok[a[i]] += 1
for i in range(a[-1] + 1, a[0] + 1):
    if ok[i] < 2:
        print(no)
        exit()

print(yes)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
 {  
    FIO
    int a,b,k; cin>>a>>b>>k;
    
    int i = min(a,b);
    while(k) {
        if (a % i == 0 and b % i == 0)
        {
            k--;
            if(k == 0) break;
        }
        i--;
    }

    cout<<i;
    
    return 0;
}



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

int main(){
    int count = 0;
    string S;
    cin >> S;
    for(int i=0;i<(S.size()-1)/2;i++){
        if(S[i]!=S[S.size()-i-1]){
            count++;
        }
    }
    for(int i=0;i<(S.size()-1)/4;i++){
        if(S[i]!=S[(S.size()-3)/2-i]){
            count++;
        }
    }
    if(count == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	T := nextString()
	t := strings.ReplaceAll(T, "?", "D")
	ans := strings.Count(t, "D")
	ans += strings.Count(t, "PD")
	fmt.Println(t)
}

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

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

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

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 310, M = 1010;

int n, m, k, d;
int g[N][N];
PII p[N * N];
vector<vector<LL> > s;

int main()
{
	scanf("%d%d%d", &n, &m, &d);
	
	for (int i = 1; i <= n; i ++ )
		for (int j = 1; j <= m; j ++ )
		{
			cin >> g[i][j];
			p[g[i][j]] = {i, j};
		}
	
	s.resize(d + 10);
	for (int i = 0; i < d; i ++ )
	{
		s[i].resize((n * m + d - 1) / d + 10);
		s[i][0] = 0;
		for (int j = 0; (j + 1) * d + i <= n * m; j ++ )
		{
			PII st = p[j * d + i], ed = p[(j + 1) * d + i];
			LL sum = abs(st.F - ed.F) + abs(st.S - ed.S);
			s[i][j + 1] = s[i][j] + sum;
		}
	}
	
	scanf("%d", &k);
	while (k -- )
	{
		int l, r;
		scanf("%d%d", &l, &r);
		
		int t = l % d;
		printf("%lld\n", s[t][r / d] - s[t][l / d]);
	}
    return 0;
}

Measured memory_bytes: 14760
import java.util.*;
public class Main{
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		// get a integer
		int a = sc.nextInt();
      	int[] input = new int[a];
      	for(int i=0; i<a ; i++){
        	input[i] = sc.nextInt();
        }
      	int[] arr = new int[input.length];
    	arr[0] = 0;
    	arr[1] = Math.abs(input[0] - input[1]);
    	for (int i = 2; i < arr.length; i++) {
      		arr[i] = Math.min(arr[i - 1] + Math.abs(input[i - 1] - input[i]),
          	arr[i - 2] + Math.abs(input[i - 2] - input[i]));
    	}
   		System.out.println(arr[arr.length - 1]);
    }
}

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

const int HMAX=3001;
const int WMAX=3001;

int X[HMAX][WMAX];
int Y[HMAX][WMAX];

int main(){
    int H, W;
    cin >> H >> W;
    string S[H], T[W];
    for(int i=0; i<H; i++){
        cin >> S[i];
    }
    for(int j=0; j<W; j++){
        string Ttmp(H,'a');
        for(int i=0; i<H; i++){
            Ttmp[i]=S[i][j];
        }
        T[j]=Ttmp;
    }

    for(int i=0; i<H; i++){ // counting S -> X;
        int count=0;
        for(int j=0; j<W; j++){
            if( S[i][j]=='#' ){
                X[i][j]=0;
                count=0;
            }else{
                count++;
                X[i][j]=count;
            }
        }
        for(int j=W-1; j>=1; j--){
            if( X[i][j-1]>0 && X[i][j-1]<X[i][j] ){
                X[i][j-1]=X[i][j];
            }
        }
    }

    for(int j=0; j<W; j++){ // counting T -> Y;
        int count=0;
        for(int i=0; i<H; i++){
            if( S[i][j]=='#' ){
                Y[i][j]=0;
                count=0;
            }else{
                count++;
                Y[i][j]=count;
            }
        }
        for(int i=H-1; i>=1; i--){
            if( Y[i-1][j]>0 && Y[i-1][j]<Y[i][j] ){
                Y[i-1][j]=Y[i][j];
            }
        }
    }

    int ans=0;
    int tmp;

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            tmp = X[i][j]+Y[i][j]-1;
            ans = max(ans,tmp);
            //cout << tmp << " ";
        }
        //cout << endl;
    }

    cout << ans << endl;

    return 0;
}

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


int main() {
  string s;
  cin>>s;
  cout<<s.at(0)<<s.at(1)<<s.at(2)<<endl;
  
}



Measured memory_bytes: 3628
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

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

using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    vector<ll> as;
    as.resize(n);
    for(int i = 0;i < n;i++)
    {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    
    set<ll> s;
    s.insert(0);
    int r = n;
    for(int i = n-1;i >= 0;i--)
    {
        set<ll> t;
        for(auto e:s)
        {
            auto next = e + as[i];
            if(next >= k)
            {
                r = i;
                break;
            }
            else
            {
                t.insert(next);
            }
        }
        for(auto e: t)
        {
            s.insert(e);
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

ll hexa2int(char c) {
    if (c >= '0' && c <= '9') return (ll)(c - '0');
    else return (ll)(c - 'a') + 10;
}

ll get_int(string s) {
    reverse(s.begin(), s.end());
    ll res = 0;
    for (int i = 0; i < s.size(); i++) {
        res += (hexa2int(s[i]) << (4 * i));
    }
    return res;
}

string int2hexa(ll num) {
    if (num == 0) return "0";
    string res;
    while (num > 0) {
        ll mod = num % 16;
        if (mod < 10) res += (char)(mod + '0');
        else res += (char)(mod - 10 + 'a');
        num /= 16;
    }
    reverse(res.begin(), res.end());
    return res;
}

void solve() {
    vector<ll> com(9);
    string s;
    for (int i = 0; i < 9; ++i) {
        cin >> s;
        com[i] = get_int(s);
    }
    ll up = 0;
    ll ans = 0;
    for (int i = 0; i < 32; ++i) {
        ll sum = up;
        for (int j = 0; j < 8; ++j) {
            sum += ((com[j] >> i) & 1) ^ 1;
        }
        if ((sum % 2) == (((com[8] >> i) & 1) ^ 1)) {
            ans += (1LL << i);
            up = sum / 2;
            continue;
        }
        sum = up;
        for (int j = 0; j < 8; ++j) {
            sum += ((com[j] >> i) & 1) ^ 0;
        }
        up = sum / 2;
    }
    cout << int2hexa(ans) << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S;
    cin >> S;
    for (int i = 0; i < S; ++i) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3232
#include <stdio.h>

using namespace std;

int main(){
	int n,m,tmp;
	scanf("%d %d",&n,&m);
	int** A = new int*[n];
	for(int i = 0; i < n; i++) A[i] = new int[m];
	int b[m];

	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			scanf("%d",&tmp);
			A[i][j] = tmp;
		}
	}
	for(int i = 0; i < m; i++){
		scanf("%d",&tmp);
		b[i] = tmp;
	}
	long long int sum;
	for(int i = 0; i < n; i++){
		sum = 0;
		for(int j = 0; j < m; j++){
			sum += A[i][j] * b[j];
		}
		printf("%lld\n",sum);
	}

	for(int i = 0; i < n; i++){
		delete[] A[i];
	}
	delete A;
}


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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    LL a,b;
    cin >> a;
    cin >> b;
    LL c = a*b;

      if(a<b){
   LL tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  LL r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

    cout << c/b << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, a[100];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if ((i + 1) % 2 == 1 && a[i] % 2 == 1) {
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct EDG
{
	long long x,y,num;
}a[100001];
bool operator <(EDG a,EDG b) {
 	if(a.x==b.x) return a.y<b.y;
	 return a.x<b.x; 
 }
long long n,m,ans1[100001],ans2[100001],flag[100001],flg[100001];
#undef int
int main()
{
	#define int long long
	for(int i=1;i<=100000;i++) flag[i]=6,flg[i]=6;
	cin>>n>>m;
	for(int i=1;i<=m;i++) 
	{
		cin>>a[i].x>>a[i].y;
		a[i].num=i;
	}
	sort(a+1,a+m+1);
	for(int i=1;i<=m;i++)
	{
		if(a[i].x==a[i-1].x)
		{
			ans1[a[i].num]=a[i].x;
			ans2[a[i].num]=ans2[a[i-1].num]+1;
		}
		else
		{
			ans1[a[i].num]=a[i].x;
			ans2[a[i].num]=1;
		}
	}
	int x,y;
	for(int i=1;i<=m;i++)
	 {
	 	x=ans1[i],y=ans2[i];
	 	while(x)
		 {
		 	x/=10;
		 	flag[i]--;
			 }	
			while(y)
		 {
		 	y/=10;
		 	flg[i]--;
			 }	
	 }
	for(int ii=1;ii<=m;ii++)
	 {
	 	for(int i=1;i<=flag[ii];i++) cout<<"0";
	 	cout<<ans1[ii];
	 	for(int i=1;i<=flg[ii];i++) cout<<"0";
	 	cout<<ans2[ii]<<endl;
	 }	 
}

Measured memory_bytes: 7040
#!/usr/bin/env python3
import sys
from collections import Counter
sys.setrecursionlimit(10**8)
INF = float("inf")


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    B, C = [0]*Q, [0]*Q
    for i in range(Q):
        B[i], C[i] = map(int, input().split())
    # 個数を持つ
    # Biの個数 O(1),C[i]の個数 O(1) 更新 O(1) 総和O(1)

    group = [None]*(10**5+1)
    uf = UnionFind(N)

    # union_find
    # N個の数に対して、i番目の数がどのグループに属するのかを示す
    # group
    # j (< 10**5)に対して、jがつけられているグループの根の番号を示す

    for i, a in enumerate(A):
        # グループにつけられている番号がaであるようなグループはあるか？
        # なければ自信のグループにつけられている番号として保持
        # あればそこに合流
        if group[a] is None:
            group[a] = i
        else:
            uf.union(i, group[a])
            group[a] = uf.find(i)
    # print(A)
    # print(group)
    # print(uf.parents)

    tot = sum(A)
    for i in range(Q):
        if group[B[i]] is None:
            b = 0
        elif group[C[i]] is None:
            b = uf.size(group[B[i]])
            group[C[i]] = uf.find(group[B[i]])
            group[B[i]] = None
        else:
            b = uf.size(group[B[i]])
            uf.union(group[B[i]], group[C[i]])
            group[C[i]] = uf.find(group[B[i]])
            group[B[i]] = None
        tot = tot - B[i]*b + C[i]*b
        print(tot)
        # print(group)
        # print(uf.parents)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 88136
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 1;
    for(int i=0;i<N-1;i++){
        if(S[i] != S[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3756
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = [0]*m
x = [0]*m
for i in range(m):
    p[i], x[i] = map(int, input().split())

ts = sum(t)
for i in range(m):
    ans = ts - t[p[i]-1] + x[i]
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
template <typename T>
T pow(T a, ll n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
 
template <int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) {
        if ((x = x_ % mod + mod) >= mod) x -= mod;
    }
    ModInt& operator+=(ModInt rhs) {
        if ((x += rhs.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(ModInt rhs) {
        if ((x -= rhs.x) < 0) x += mod;
        return *this;
    }
    ModInt& operator*=(ModInt rhs) {
        x = (unsigned long long)x * rhs.x % mod;
        return *this;
    }
    ModInt& operator/=(ModInt rhs) {
        x = (unsigned long long)x * rhs.inv().x % mod;
        return *this;
    }
 
    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }
 
    friend ostream& operator<<(ostream& s, ModInt<mod> a) {
        s << a.x;
        return s;
    }
    friend istream& operator>>(istream& s, ModInt<mod>& a) {
        s >> a.x;
        return s;
    }
};
 
using mint = ModInt<1000000007>;
using Graph = vector<vector<int>>;
Graph G;
/*------------------------------------------------------------------*/
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s, t; cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int dp[n + 1][m + 1];
    rep(i, n + 1)rep(j, m + 1) dp[i][j] = 0;
    rep(i, n)rep(j, m){
        if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
        else dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
    }

    int i = n, j = m;
    string ans = "";
    while(i > 0 and j > 0){
        if(dp[i][j] == dp[i][j - 1]) j--;
        else if(dp[i][j] == dp[i - 1][j]) i--;
        else{
            ans += s[i - 1];
            i--, j--;
        }
    } 
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 38772
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second
 
//#include <boost/unordered_map.hpp>
//using namespace boost;
 
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/
 
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
//using i128 = i64;
//using u128 = u64;
 
ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}
 
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}

ll gcd(ll a, ll b)
{
	return b ? gcd(b, a%b) : a;
}
 
template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}
 
template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}

template<class T>
void print(const T &a)
{
	for (auto x : a) printf("%d ", x); puts("");
}

const int MAXN = 500010;
//const int MAXM = 100010;
const int MAXK = 30;
//const i64 INF = 1000000000000000000LL;
const int INF = 1000000000;
//const int MOD = 998244353;
const int B = 31;
const int MOD = 1000000007;
//const int INV2 = (MOD+1)/2;
const ld pi = 3.1415926535897932384626433;

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

#define rep(i,a,b) for (int i = (a), I = (b); i <= I; ++ i)

int days[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool leap(int y)
{
	return y%4 == 0 && y%100 != 0 || y%400 == 0;
}

int n, m;
//int a[MAXN];

string a[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

void solve()
{
	/*
	scanf("%d", &n);
	for (int i = 1; i <= n; ++ i)
		scanf("%d", &a[i]);
	*/
	string s;
	cin >> s;
	for (int i = 0; i < 7; ++ i)
		if (a[i] == s)
		{
			cout << 7-i << endl;
			return;
		}
}

int main()
{
	
	int T;
	T = 1;
	//scanf("%d", &T);
	while (T --)
	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
int aa[N+2],dp[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  long n;cin>>n;
  cout<<(n*(n-1))/2<<endl;
  return 0;
}


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


namespace _004_Simultaneous_Equation
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int[] tmp = inputStr.Split (' ').Select (str => int.Parse (str)).ToArray ();
				int a = tmp[0];
				int b = tmp[1];
				int c = tmp[2];
				int d = tmp[3];
				int e = tmp[4];
				int f = tmp[5];

				int divide = (a * e - b * d);
				double X = (double) (c * e - b * f) / divide;
				double Y = (double) (f * a - c * d) / divide;
				Console.WriteLine ("{0:0.000} {1:0.000}", X, Y);
			}
		}
	}
}

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

int dist (int x,int y,int a,int b)
{
	a = -a;
	b = -b;
//	cout<<abs(x+a)<<"--"<<abs(y+b)<<endl;
	return abs(x+a)+abs(y+b);
}

int main() {
	int n,m,x[100],y[100],a[100],b[100];
	int vis[100];
	for(int i=0;i<100;i++)
		vis[i] = 0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	
	for(int i=0;i<m;i++)
		cin>>a[i]>>b[i];
	
	for(int i=0;i<n;i++)
	{
		int mini = 1e9,pos = -1;
		for(int j=0;j<m;j++)
		{
		//	if(!vis[j])
			{
				int dis = dist(x[i],y[i],a[j],b[j]);
			//	cout<<x[i]<<" "<<y[i]<<" "<<a[j]<<" "<<b[j]<<" "<<dis<<endl;
				if(dis<mini) 
					mini = dis,pos = j;
			}
		}
	//	vis[pos]=1;
		cout<<pos+1<<endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int n,a=0,b=0;
  cin >> n;
  vector<int> u(n),v(n),w(n);
  for(int i = 0;i < n;i++)cin >> u[i];
  for(int j = 0;j < n;j++)cin >> v[j];
  for(int i = 0;i < n;i++)w[i] = i+1;
  int i = 0;
  do{
    if(w == u)a = i;
    if(w == v)b = i;
    i++;
  }while(next_permutation(w.begin(),w.end()));
  cout << abs(b-a);
  return 0;
}

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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;
    map<int,int> m;

    for (int i = 0; i < n; i++){
        int ai;
        cin  >> ai;

        m[ai-1]++;
        m[ai]++;
        m[ai+1]++;

    }

    for(auto p:m){
        ans =max((ll)p.se,ans);
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 4736
N=int(input())
H = list(map(int,input().split()))

dp=[1000000000000]*N

dp[0]=0
i=1
def chmin(a,b):
    if a>b:
        dp[i]=b

while i < N :
    chmin(dp[i],abs(H[i]-H[i-1])+dp[i-1])
    if i>1:
        chmin(dp[i],abs(H[i]-H[i-2])+dp[i-2])
    i+=1

print(dp[N-1])        

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

int main() {
	int N,K,X,Y;
	cin>>N>>K>>X>>Y;
	int count;
	if(N-K>=0){
		count=K*X+(N-K)*Y;
	}
	else count=N*X;
	cout<<count<<endl;

}



Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var s string
	fmt.Scan(&s)

	var x int
	min := 1000
	for i := 0; i+2 < len(s); i++ {
		x, _ = strconv.Atoi(s[i : i+3])
		if v := abs(x - 753); v < min {
			min = v
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 512
N = int(input())
h = list(map(int,input().split()))
dp = [0]*(N+1)
for i in range(1,N):
    if i>=2:
        dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]) ,dp[i-1]+abs(h[i]-h[i-1]))
    else:
        dp[i] = dp[0]+abs(h[0]-h[i])

print(dp[N-1])



Measured memory_bytes: 13928
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = Integer.MAX_VALUE;
        for (int i = 1; i < n; i++) {
            int v = i;
            int b = n - i;
            int count = 0;
            while (v > 0) {
                count += v % 10;
                v /= 10;
            }
            while (b > 0) {
                count += b % 10;
                b /= 10;
            }
            ans = Math.min(count, ans);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e11;

struct D{
  ll lj=INF,rj=INF,lt=INF,rt=INF;
};

typedef pair<ll,int> P;

int main(){
  int A,B,Q;
  cin>>A>>B>>Q;
  int N = A + B + Q;
  vector<ll> s(A),t(B),x(Q);
  vector<D> dist(N);
  vector<P> p(N);
  vector<char> type(N);
  for(int i=0;i<A;i++) cin>>s[i];
  for(int i=0;i<B;i++) cin>>t[i];
  for(int i=0;i<Q;i++) cin>>x[i];
  for(int i=0;i<A;i++){
    type[i] = 'J';
    p[i].first = s[i];
    p[i].second = i;
  }
  for(int i=0;i<B;i++){
    type[i+A] = 'T';
    p[i+A].first = t[i];
    p[i+A].second = i+A;
  }
  for(int i=0;i<Q;i++){
    type[i+A+B] = 'C';
    p[i+A+B].first = x[i];
    p[i+A+B].second = i+A+B;
  }
  sort(p.begin(),p.end());
  ll jp = -INF;
  ll tp = -INF;
  for(int i=0;i<N;i++){
    ll d = p[i].first;
    int id = p[i].second;
    if(type[id] == 'J') jp = d;
    else if(type[id] == 'T') tp = d;
    else{
      dist[id].lj = d - jp;
      dist[id].lt = d - tp;
    }
  }
  jp = INF;
  tp = INF;
  for(int i=N-1;i>=0;i--){
    ll d = p[i].first;
    int id = p[i].second;
    if(type[id] == 'J') jp = d;
    else if(type[id] == 'T') tp = d;
    else{
      dist[id].rj = jp - d;
      dist[id].rt = tp - d;
    }
  }

  for(int i=A+B;i<N;i++){
    ll ltmp = max(dist[i].lj,dist[i].lt);
    ll rtmp = max(dist[i].rj,dist[i].rt);
    ll dis = min(ltmp,rtmp);
    ll tmp = dist[i].lj + dist[i].rt + min(dist[i].lj,dist[i].rt);
    ll tmp2 = dist[i].lt + dist[i].rj + min(dist[i].lt,dist[i].rj);
    ll ans = min(dis,tmp);
    ans = min(ans,tmp2);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 18048