akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		long count = 0;
		for (int i = 1; i <= k; i++) {
			for (int j = 1; j <= k; j++) {
				for (int l = 1; l <= k; l++) {
					int a = i;
					int b = j;
					int c = l;
					int min = Math.min(a, Math.min(b, c));
					int res = 0;
					for (int m = 1; m <= min; m++) {
						if (a % m == 0 && b % m == 0 && c % m == 0) {
							res = m;
						}
					}
					count += res;
				}
			}
		}
		System.out.println(count);
	}
}


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

long long count(int l, int d) {
    if (l == 1) return 1;
    long long ans = 0;
    for (int e = max(0, d-1); e <= min(9, d+1); e++)
        ans += count(l-1, e);
    return ans;
}

long long construct(int k, int l, int d) {
    long long ans = d;
    while (--l) {
        for (int e = max(0, d-1); e <= min(9, d+1); e++) {
            long long t = count(l, e);
            if (t >= k) { ans = 10 * ans + e; d = e; break; }
            else k -= t;
        }
    }
    return ans;
}

long long solve(int k) {
    long long sum = 0;
    for (int l = 1; ; l++)
        for (int d = 1; d < 10; d++) {
            long long t = count(l, d);
            if (sum + t >= k) return construct(k - sum, l, d);
            else sum += t;
        }
}


int main() {
    int k; cin >> k;
    cout << solve(k) << endl;
}


Measured memory_bytes: 256
N = int(input())
F = []
P = []
for i in range(N):
    a = list(map(int,input().split()))
    c = 0
    for i in range(10):
        c += a[i]*(2**(9-i))
    F.append(c)
for i in range(N):
    P.append(list(map(int,input().split())))
ans = []
for i in range(1,2**10):
    an = 0
    for j in range(len(F)):
        count = 0
        for k in range(10):
            if ((i&F[j]) >> k) & 1 == 1:
                count += 1
        an += P[j][count]
    ans.append(an)
print(max(ans))

Measured memory_bytes: 3064
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int a, b;
    scan(a, b);

    auto d = new int[][](a + 1, b + 1);

    iota(1, a + 1).each!(i => d[i][1 .. $] = readln.split.to!(int[]));

    debug {
        writefln("%(%(%s %)\n%)", d);
    }

    auto c = new int[][](101, 101);

    foreach (i ; 0 .. 101) {
        foreach (j ; 0 .. 101) {
            foreach (x ; 1 .. a + 1) {
                foreach (y ; 1 .. b + 1) {
                    c[i][j] = max(c[i][j], d[x][y] - i*x - j*y);
                }
            }
        }
    }

    foreach (x ; 1 .. a + 1) {
        foreach (y ; 1 .. b + 1) {
            int dt = 101;

            foreach (i ; 0 .. 101) {
                foreach (j ; 0 .. 101) {
                    dt = min(dt, i*x + j*y + c[i][j]);
                }
            }

            if (d[x][y] != dt) {
                writeln("Impossible");
                return;
            }
        }
    }

    writeln("Possible");
    writeln(202, " ", 100 + 100 + 101*101);

    foreach (i ; 0 .. 100) {
        writeln(i + 1, " ", i + 2, " ", 'X');
        writeln(102 + i, " ", 102 + i + 1, " ", 'Y');
    }

    foreach (i ; 0 .. 101) {
        foreach (j ; 0 .. 101) {
            writeln(1 + i, " ", 202 - j, " ", c[i][j]);
        }
    }

    writeln(1, " ", 202);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N),B(N),ABdif(N);
    ll sumA=0,sumB=0;
    rep(i,N) {
        cin >> A[i];
        sumA+=A[i];
        ABdif[i] = A[i];
    }
    rep(i,N){
        cin >> B[i];
        sumB += B[i];
        ABdif[i]-=B[i];
    }
    bool f = true;
    rep(i,N){
        if(A[i]<B[i]) f = false;
    }
    if(f){
        cout << 0 << endl;
        return 0;
    }
    if(sumA<sumB){
        cout << -1 << endl;
        return 0;
    }
    sort(ABdif.rbegin(),ABdif.rend());
    int ix = 0;
    ll st = 0;
    ll cnt = 0;
    rep(i,N){
        ll d = B[i]-A[i];
        if(d>0){
            while(d>st){
                st+=ABdif[ix];
                cnt++;
                ix++;
            }
            st-=d;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include<stack>
#include <unordered_map>

int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
int abs(int a) { return a < 0 ? -a : a; }

using namespace std;

int main() {
	string S;
	cin >> S;
	int min = 1000;
	for (int i = 0; i < S.size() - 2; i++) {
		int a = atoi(S.substr(i, 3).c_str());
		int s = abs(753 - a);
		if (min > s)min = s;
	}
	cout << min;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< int > p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    cout << p[n / 2] - p[n / 2 - 1] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int D, N;

int ord(int a, int b)
{
	int ret = 0;
	while (a % b == 0) {
		++ret;
		a /= b;
	}
	return ret;
}

int main()
{
	scanf("%d%d", &D, &N);

	for (int i = 1;; ++i) {
		if (ord(i, 100) == D) {
			if (--N == 0) {
				printf("%d\n", i);
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
n = raw_input()
n = int(n)
minv = raw_input()
minv = int(minv)
maxv = -1000000000
  
for j in range(n-1):
  num = raw_input()
  num = int(num)  
  diff = num - minv
  if maxv < diff:
    maxv = diff
  if num < minv:
    minv = num
  
print maxv

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

const int N = 300;

pair<int,long long> dat[N+5][N+5];

int main() {
    for (int i=0; i<N+3; i++) for (int j=0; j<N+3; j++) {
        dat[i][j] = make_pair((int)1e9, (long long)1e18);
    }
    for (int i=0; i<N+3; i++) dat[i][i] = make_pair(0,0);

    int n,m,l; scanf("%d %d %d", &n, &m, &l);
    for (int i=1; i<=m; i++) {
        int u,v,w; scanf("%d %d %d", &u, &v, &w);
        if (w > l) continue;
        dat[u][v] = make_pair(1,w);
        dat[v][u] = make_pair(1,w);
    }

    for (int xxx=0; xxx<3; xxx++) {
        for (int k=1; k<=n; k++) for (int i=1; i<=n; i++) {
            for(int j=1; j<=n; j++) {
                pair<int,long long> temp;
                temp.first = dat[i][k].first + dat[k][j].first;
                temp.second = dat[i][k].second + dat[k][j].second;
                if (temp.second <= l) temp.first = 1;

                dat[i][j] = min(dat[i][j], temp);
            }
        }
    }

    for (int i=1; i<=n; i++) for(int j=1; j<=n; j++) {
        if (dat[i][j].first == (int)1e9) dat[i][j].first = 0;
    }

    int q; scanf("%d", &q);
    for (int qq=1; qq<=q; qq++) {
        int s,t; scanf("%d %d", &s, &t);
        printf("%d\n", dat[s][t].first - 1);
    }
    return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define printjudge(cond) {if(cond) printf("Yes\n"); else printf("No\n");}
#define printans(ans) {printf("%d\n",(ans));}
#define intscan(x) {scanf("%d", &x);}
#define Ntimes(N) for(int i=0; i<N; i++)
#define min(x,y) (((x)<(y)) ? (x) : (y))
#define max(x,y) (((x)>(y)) ? (x) : (y))
typedef int* intarray;
typedef char* string;

int main(){
    int A, B, K;
    scanf("%d%d%d", &A, &B, &K);
    for(int n=min(A,B); n>0; n--){
        if(A%n==0 && B%n==0) K--;
        if(K==0){
            printans(n); break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int N, K;
    cin >> N;
    cin >> K;
    int sum, x;
    for(int i=0;i<N;i++)
    {
        cin >> x;
        sum += min(K-x, x);
    }
    cout << sum * 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N;
  cin >> N;
  long count = 0, a, up, down, flag;
  vector<vector<long>> data(9, vector<long> (9));
  for(int i = 1; i <= N; i++){
    a = i;
    flag = 0;
    up = 0;
    down = -1;
    while(a != 0){
      if(down == -1)down = (a % 10);
      up = a % 10;
      a /= 10;
    }
    if(down == 0)continue;
    data.at(up - 1).at(down - 1)++;
  }
  for(int i = 0; i < 9; i++){
    for(int j = 0; j < 9; j++){
      count += data.at(i).at(j) * data.at(j).at(i);
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <fstream>
#include <queue>
#include <cstdio>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)
#define db(a) cout << a<< endl;
typedef pair <int,int>P;
using namespace std;

int main(){
    vector <int>a;
    int n;
    cin >>n;
    fol(i,n){
        int b;
        cin >> b;
        a.push_back(b);
    }
    sort(a.begin(),a.end());
    cout << a[n-1]-a[0]<<endl;
    return 0;
}

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

int main(void){
    int n, m;
    cin >> n >> m;

    //student coordinate
    vector<vector<int>> student(n, vector<int>(2));
    for(int i = 0; i< n; i++){
        for(int j = 0; j < 2; j++){
            cin >> student.at(i).at(j);
        }
    }

    //checkpoint coordinate
    vector<vector<int>> checkpoint(m, vector<int>(2));

    for(int i = 0; i< m; i++){
        for(int j = 0; j < 2; j++){
            cin >> checkpoint.at(i).at(j);
        }
    }


    for(int i = 0; i < n; i++){
      int ans = -1;
      long long comp = pow(10, 9.0);
        for(int j = 0; j < m; j++){
            long long xdis = abs(student.at(i).at(0) - checkpoint.at(j).at(0));
            long long ydis = abs(student.at(i).at(1) - checkpoint.at(j).at(1));
            long long distance = xdis + ydis;
            if(distance < comp) {
              ans = j + 1;
              comp = distance;
            }
        }
        cout << ans << endl;
    }

    return 0;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin>>s;
  int l=s.length();
 if((s[2]==s[3])&&(s[4]==s[5]))
 cout<<"Yes"<<endl;
 else
 cout<<"No"<<endl;
  
  
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string a;
    string b;
    cin >> a >> b;
    int result = stoi(a + b);
    for(int i = 1; i < 1000; i++){
        if(i * i == result){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
using ll = long long;

typedef long long ll;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999

int a[100],b[100],c[100],N,sum=0;

int main(){
  scanf("%d",&N);
  REP(i,N){scanf("%d",&a[i]);}
  REP(i,N){scanf("%d",&b[i]);}
  REP(i,N-1){scanf("%d",&c[i]);}
  int t=-2;
  REP(i,N)a[i]=a[i]-1;
  REP(i,N){
    sum+=b[a[i]];
    if(a[i]==t+1){
      sum+=c[t];
    }
    t=a[i];
}

printf("%d\n",sum);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int ret = A + B;
        while (ret >= 24) {
            ret -= 24;
        }
        System.out.println(ret);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() {
            try {
                return Integer.parseInt(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public double nextDouble() {
            try {
                return Double.parseDouble(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }

        public long nextLong()  {
            try {
                return Long.parseLong(next());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return -1;
        }
    }
}


Measured memory_bytes: 24916
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dl double long
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rrep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); --i)
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;

int n, a[20];

bool solve(int i, int m){
    if(m == 0) return true;
    else if(i >= n) return false;

    bool res = solve(i+1, m) || solve(i+1, m-a[i]);
    return res;
}

int main(void){
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    int q;
    cin >> q;
    rep(i, 0, q){
        int m;
        cin >> m;
        cout << ((solve(0, m))? "yes":"no") << endl;
    }    
    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//#define int long long


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

  cout << max(max(a,b),c)-min(min(a,b),c) << endl;
  
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class CODEFESTIVAL_2016_FINALA
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var H = NN;
            var W = NN;
            var output = "";
            for (var i = 1; i <= H; i++)
            {
                var ch = 'A';
                for (var j = 0; j < W; j++)
                {
                    if (NS == "snuke")
                    {
                        output = $"{ch}{i}";
                    }
                    ++ch;
                }
            }
            Console.WriteLine(output);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 12768
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

//2分以上の木に変換
struct node{
  string s = "";
  int sz = 0;
  map<char, pair<node*, ll>> nx;
  bool unuse = false;
  node(string t):s(t){}
  node(){}
};

node top("");
node ed("");

void dfs(node* now){
  if(now->unuse) return;
  for(auto to:now->nx) dfs(to.second.first);
  if(now->nx.size()==1){
    pair<node*, ll> to = (*(now->nx.begin())).second;
    to.first->unuse = true;
    now->sz += to.first->sz;
    now->nx = to.first->nx;
  }
}
int main(int argc, char const *argv[]) {
  ed.unuse = true;
  ll n;std::cin >> n;
  vector<string> s(n);
  re(i, n) std::cin >> s[i];
  vector<node> z(400001);
  ll num = 0;
  for(auto t:s){
    ll j = 0;
    node* now = &top;
    while(j<t.size()){
      auto itr = now->nx.find(t[j]);
      if(itr==now->nx.end()) {
        z[num].s += t[j];
        z[num].sz = 1;
        now->nx.emplace(t[j], make_pair(&z[num], 1));
        now = &z[num];
        num++;
      }else now = (*itr).second.first, (*itr).second.second++;
      j++;
    }
    // end ?
    auto end_h = now->nx.find('?');
    if(end_h==now->nx.end()) now->nx.emplace('?', make_pair(&ed, 1));
    else (*end_h).second.second++;
  }
  dfs(&top);
  ll q;std::cin >> q;
  re(Q, q){
    ll a;std::cin >> a;a--;
    string t;std::cin >> t;
    node* now = &top;
    ll j = 0, cnt = 0;

    while(true){
      j += now->sz;

      if(j>=s[a].size()) break;
      char nowc = s[a][j];
      // small
      for(int i=0;t[i]!=nowc;i++){
        auto itr = now->nx.find(t[i]);
        if(itr!=now->nx.end()) cnt += (*itr).second.second;
      }
      auto itr = now->nx.find('?');
      if(itr!=now->nx.end()) cnt += (*itr).second.second;
      // equal
      itr = now->nx.find(nowc);
      now = (*itr).second.first;
    }
    std::cout << cnt+1 << '\n';
  }
  return 0;
}


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

int main(void)
{
    long a, b, k;
    cin >> a >> b >> k;
    
    if (k <= a){
        cout << a - k << ' ' << b << endl;
    }
    else if (k > a && k <= a+b){
        cout << 0 << ' ' << a + b - k << endl; 
    }
    else{
        cout << 0 << ' ' << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ans = new int[10001];
        int min = (int)Math.sqrt(n) + 1;
        for (int x=1; x<=min; x++){
            for(int y=1; y<=min; y++) {
                for(int z=1; z<=min; z++) {
                    int value = x*x + y*y + z*z + x*y + y*z + x*z;
                    if (value<=10000) ans[value]++;
                }
            }
        }
        for(int i=1; i<=n; i++) {
            System.out.print(ans[i]);
            System.out.print("\n");
        }
    }
}

Measured memory_bytes: 39860
<?php
list($s) = strs();
$n = strlen($s);
if (isKaibun($s)) exit('0');
$l = 0;
$r = $n - 1;
$cnt = 0;
while (true) {
    if ($s[$l] === $s[$r]) {
        ++$l;
        --$r;
    } else {
        if ($s[$l] !== 'x' && $s[$r] !== 'x') exit('-1');
        if ($s[$l] !== 'x') --$r;
        else ++$l;
        ++$cnt;
    }
    if ($l >= $r) break;
}
echo $cnt;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function isKaibun($s)
{
    $n = strlen($s);
    for ($i = 0; $i < intdiv($n, 2); $i++) {
        if ($s[$i] !== $s[$n - $i - 1]) return false;
    }
    return true;
}


Measured memory_bytes: 16464
n = int(input())
words = []
for i in range(n):
  word = str(input())
  word = "".join(sorted(word))
  words.append(word)

ans=""

for i in range(26):#chr(i+97)
  max_num = 50
  for word in words:
    num = word.count(chr(i+97))
    max_num = min(max_num,num)
  ans += chr(i+97) * max_num

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define N 200000
using namespace std;
int n;
struct dat{int h,i;};

int calc(int A[]){
  stack <dat> S;
  int res = 0;
  for(int i=0;i<=n;i++){
    int h = A[i];
    if(S.empty() || S.top().h < h) S.push((dat){h,i});
    else if(S.top().h > h){
      int ni = i;
      while(!S.empty() && S.top().h > h){
        dat t = S.top(); S.pop();
        ni = t.i;
        int area = (i - t.i) * t.h;
        res = max(res,area);
      }
      res = max(res,(i-ni)*h);
      S.push((dat){h,ni});
    }
  }
  return res;
}

int A[N];
signed main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>A[i];
  cout<<calc(A)<<endl;
  return 0;
}

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

int hour(string s){
    return stoi(s.substr(0,2));
}
int minute(string s){
    return stoi(s.substr(3,2));
}
int sec(string s){
    return stoi(s.substr(6,2));
}
int hms(string s){
    int ss=hour(s);
    int tt=minute(s);
    int uu=sec(s);
    return ss*3600+tt*60+uu;
}

int main(){

    while(1){
        int n;
        cin >> n;
        if(n==0)break;
        vector<pair<int,int>> se(n);
        rep(i,n){
            string s,t;
            cin >> s >> t;
            se[i].first=hms(s);
            se[i].second=hms(t);
        }
        vector<int> ti(86400,0);
        for(int i=0;i<n;i++){
            ti[se[i].first]++;
            ti[se[i].second]--;            
        }
        int ma=ti[0];
        for(int i=0;i<86400-1;i++){
            ti[i+1]+=ti[i];
            ma=max(ma,ti[i+1]);
        }
        cout << ma << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;

lli dp[e5][2];
lli n,p;
lli a[e5];

int main(){
	cin >> n >> p;
	for(lli i = 1;i <= n;i++) cin >> a[i];
	dp[0][0] = 1;
	for(lli i = 1;i <= n;i++){
		if(a[i]%2 == 0) dp[i][0] += dp[i-1][0]+dp[i-1][0], dp[i][1] += dp[i-1][1]+dp[i-1][1];
		else dp[i][0] += dp[i-1][0]+dp[i-1][1], dp[i][1] += dp[i-1][1]+dp[i-1][0];
	}
	cout << dp[n][p] << endl;
}


Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
struct edge{int to, cost;};
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int V;
vector<edge> G[201];
int d[201];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V + 1, INF);
    d[s] = 0;
    que.push(P(0, s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i, G[v].size()){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    int n, m, R;
    cin >> n >> m >> R;
    V = n;
    vector<int> r;
    REP(i, R){
        int tmp;
        cin >> tmp;
        r.pb(tmp);
    }
    SORT(r);
    REP(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        edge e;
        e.cost = c; e.to = b;
        G[a].pb(e);
        e.to = a;
        G[b].pb(e);
    }
    int dr[201][201];
    REP(i, R){
        dijkstra(r[i]);
        REP(j, R){
            dr[r[i]][r[j]] = d[r[j]];
        }
    }
    int ans = INF;
    do{
        int cost = 0;
        REP(i, R - 1){
            cost += dr[r[i]][r[i + 1]];
        }
        ans = min(ans, cost);
    }while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

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

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int ab[][] = new int[n][2];
            int playermin = 1100000000;
            int playermax = -1;
            int point = 1100000000;
            for (int i = 0; i < n; i++) {
                ab[i][0] = Integer.parseInt(in.next());
                ab[i][1] = Integer.parseInt(in.next());
                playermin = Math.min(playermin, ab[i][0]);
                playermax = Math.max(playermax, ab[i][0]);
                point = Math.min(point, ab[i][1]);
            }
            int ans = playermax - playermin + 1;
            for (int i = 1; i < playermin; i++) ans++;
            for (int i = 0; i < point; i++) ans++;

            // 出力
            out.println(ans);

        }

    }
}



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

int a[16][16], b[16][16];
int map[16][16];
int gx, gy;
int rec(int x, int y)
{
    if (map[x][y] != -1)return map[x][y];
    if (x == 0) {
        map[x][y] = a[x][y - 1] * rec(x, y - 1);
    }
    else if (y == 0) {
        map[x][y] = b[x - 1][y] * rec(x - 1, y);
    }
    else {
        map[x][y] = a[x][y - 1] * rec(x, y - 1) + b[x - 1][y] * rec(x - 1, y);
    }
    return map[x][y];
}
int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        for (int i = 0; i < 16; i++) {
            for (int j = 0; j < 16; j++) {
                a[i][j] = 1; 
                b[i][j] = 1;
                map[i][j] = -1;
            }
        }
        map[0][0] = 1;
        cin >> gx >> gy;
        double p;
        cin >> p;
        while (p--) {
            int l, m, n, o;
            cin >> l >> m >> n >> o;
            if (l == n)
                a[l][min(m, o)] = 0;
            else
                b[min(l, n)][m] = 0;
        }
        if (rec(gx, gy) != 0) {
            cout << rec(gx, gy) << endl;
        }
        else {
            cout << "Miserable Hokusai!" << endl;
        }
    }
    return 0;
}

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

vector<int> frog;
int n,k;
long long int mem[100005];

long long int dp(int n){
	
	if(n<=0)
	{
		return 0;
	}
	
	if(mem[n]!=-1){
		return mem[n];
	}
	
	long long int cost=10000000005;
	for(int i=1;i<=min(k,n);i++){
		cost = min(cost,dp(n-i)+abs(frog[n-i]-frog[n]));
	}
	mem[n]=cost;
	return cost;
	
}

int main(){
	cin>>n>>k;
	memset(mem,-1,sizeof(mem));
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		frog.push_back(x);
	}
	cout<<dp(n-1);
	return 0;
}

Measured memory_bytes: 12464
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N;
        cin >> N;
        string S;
        cin >> S;
        vector<char> vc;
        for (int i = 0; i < N; ++i) {
            if (vc.size() == 0 || vc.back() != S[i]) {
                vc.push_back(S[i]);
            }
        }
        cout << vc.size() << endl;
    }
};


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

    Solve().solve();


    return 0;
}


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

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        var inp2 = Console.ReadLine().Split(' ');

        int k = int.Parse(inp[0]);
        string s = inp2[0];

        if(s.Length <= k) {
            Console.WriteLine(s);
        } else {
            Console.WriteLine(s.Substring(0,k)+"...");
        }
    }
}

Measured memory_bytes: 27396
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 1e5+5;

void solve(){
	int n;
	cin>>n;
	int a[n],b[n];
	rep(i,n){
		cin>>a[i];
		b[i]=0;
	}
	for(int j=0;j<10000;j++){
		bool ok=1;
		rep(i,n){
			if(b[i]^a[i])ok=0;
		}
		if(ok){
			cout<<j;
			return;
		}
		rep(i,n){
			if(a[i]^b[i]){
				while(a[i]^b[i] && i<n){
					b[i]++;
					i++;
				}
				break;
			}
		}
	}

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a<=8&&b<=8) cout <<"Yay!" <<endl;
    else cout << ":(" <<endl;
    return 0; 

}

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

using namespace std;
using ll = long long;

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int k;
    cin >> k;
    if (k < 10) {
        cout << k << '\n';
        return 0;
    }
    queue<ll> q;
    for (int i = 1; i <= 9; i++) {
        q.push(1LL * i);
    }
    ll x;
    for (int i = 0; i < k; i++) {
        x = q.front();
        q.pop();
        if (x % 10LL != 0) {
            q.push(10LL * x + (x % 10LL) - 1LL);
        } 
        q.push(10LL * x + (x % 10LL));
        if (x % 10LL != 9LL) {
            q.push(10LL * x + (x % 10LL) + 1LL);
        }
    }
    cout << x << '\n';
}

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

using namespace std;

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


int main(){
    int n, m;
    cin >> n >> m;
    int l[m], r[m];
    rep(i, m) cin >> l[i] >> r[i];
    sort(l, l + m);
    sort(r, r + m);
    int ans = max(r[0] - l[m-1] + 1, 0);
    cout << ans << endl;

    
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int maxn = 110;
char str[maxn];

int main()
{
    scanf("%s", str);
    int len = strlen(str);
    printf("%c%d%c\n", str[0], len - 2, str[len - 1]);
    return 0;
}


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

int main() {
 int N, A, B ;
  
  cin >> N >> A >> B;
  
  if (N * A <  B ) {
    cout << N * A << endl;
  }
 else {
    cout << B << endl;
  }
  
  
  
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

    int r;
    cin>>r;

    double ans = 2*pi*r;
    cout<<ps(ans,12);
    
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int a[1000];
int c[1000];
int dp[1000][1 << 12];

int main()
{
	int N, M, b, ALL;

	cin >> N >> M;

	ALL = (1 << N) - 1;

	rep(i, M) {
		int c_out = 0;
		cin >> a[i] >> b;

		rep(j, b) {
			int c_in;
			cin >> c_in;
			c_out |= (1 << (c_in - 1));
		}

		c[i] = c_out;
	}

	rep(i, M) {
		repc(j, 0, ALL) {
			if (j == 0) dp[i][j] = 0;
			else dp[i][j] = 1000000000;
		}
	}

	rep(i, M) {
		repc(j, 1, ALL) {
			if (i == 0) {
				if ((c[i] & j) == j) dp[i][j] = a[i];
				continue;
			}

			dp[i][j] = min(dp[i - 1][j], dp[i - 1][j & (~c[i])] + a[i]);
		}
	}

	if (dp[M - 1][ALL] == 1000000000) dp[M - 1][ALL] = -1;
	cout << dp[M - 1][ALL] << endl;

	return 0;
}


Measured memory_bytes: 16256
#include <stdio.h>

int main(void)
{
  int n;
  for(;;){
    scanf("%d",&n);
    if(n==0)break;
    int zero=0;
    while(n>=5){
      n/=5;
      zero+= n;
    }
    printf("%d\n",zero);
  }

  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N;
vector<int> a;
int f(int b) {
    int ret = 0;
    for (auto v : a) {
        ret += (v - b) * (v - b);
    }
    return ret;
}
int main() {
    cin >> N;
    a.resize(N);
    rep(i, N) cin >> a[i];
    int ans = INF;
    for (int i = -100; i <= 100; i++) {
        ans = min(ans, f(i));
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int q; cin>>q;
	vector<bool>sv(MAX,true); sv.at(0)=sv.at(1)=false;
	for(int i=2;i*i<MAX;++i){
		if(sv.at(i)){
			int j=i*i;
			while(j<MAX){
				sv.at(j)=false;
				j+=i;
			}
		}
	}
	vector<int>v(MAX,0);
	for(int i=4;i<MAX;++i){
		v.at(i)=v.at(i-1);
		if(sv.at(i-1)&&sv.at(i/2))++v.at(i);
	}
	for(int i=0;i<q;++i){
		int l,r; cin>>l>>r;
		cout<<v.at(r+1)-v.at(l-1)<<"\n"s;
	}
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

#define MAX_V 100010
struct edge{int to,cost;};
typedef pair<int,int> pii;

int V;
vector<edge> G[MAX_V];
int d1[MAX_V];
void dijkstra1(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d1,d1+V,INF);
    d1[s] = 0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p = que.top();que.pop();
        int v = p.se;
        if(d1[v] < p.fi) continue;
        rep(i,G[v].size()){
            edge e = G[v][i];
            if(d1[e.to] > d1[v]+e.cost){
                d1[e.to] = d1[v] + e.cost;
                que.push(pii(d1[e.to],e.to));
            }
        }
    }
}
int d2[MAX_V];
void dijkstra2(int s){
    priority_queue<pii,vector<pii>,greater<pii>> que;
    fill(d2,d2+V,INF);
    d2[s] = 0;
    que.push(pii(0,s));
    while(!que.empty()){
        pii p = que.top();que.pop();
        int v = p.se;
        if(d2[v] < p.fi) continue;
        rep(i,G[v].size()){
            edge e = G[v][i];
            if(d2[e.to] > d2[v]+e.cost){
                d2[e.to] = d2[v] + e.cost;
                que.push(pii(d2[e.to],e.to));
            }
        }
    }
}

/*----------------------------------------------------------------*/
signed main(){

	int n,u,v;
	cin >> n >> u >> v;
	u--;v--;

	//こんな感じに入力
    V = n;
    rep(i,n-1){//m は edge数
        int a,b,c=1;
        cin >> a >> b;
      	a--;
      	b--;
      	edge e1 = {a,c};
      	edge e2 = {b,c};
        G[b].pb(e1);
        G[a].pb(e2);
    }

	dijkstra1(v);
	dijkstra2(u);

	int ans = -1;
	rep(i,n){
		if(d1[i] > d2[i])ans = max(ans,d1[i]);
	}
	cout << ans - 1 << endl;











	 
	   
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc148.contest.atcoder.jp/tasks/abc148_b

Measured memory_bytes: 11680
program c177

implicit none
integer(16) :: n, ans, i, j, sum
integer(16), allocatable :: a(:), p(:)

read *, n
allocate(a(1:n))
allocate(p(1:n))

read *, a(:)

ans = 0
p(:) = 0

do i = n-1, 1, -1
 p(i) = p(i+1) + a(i+1)
end do

!print *, p(:)

do i = 1, n-1
 ans = ans + a(i) * p(i)
 !print *, a(i)*p(i)
end do

print *, mod(ans,1000000007)

end program c177

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

typedef long long ll;
#define OO 1e9
using namespace std;

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int h[n];
  for(int i = 0;i < n;i++)
    scanf("%d", h + i);
  int dp[n];
  dp[n - 1] = 0;
  dp[n - 2] = abs(h[n - 1] - h[n - 2]);

  for(int i = n - 3;i >= 0;i--)
    dp[i] = min(dp[i + 1] + abs(h[i] - h[i + 1]), dp[i + 2] + abs(h[i] - h[i + 2]));
  cout << dp[0];
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int n,m;
    char s[101][11],t[101][11];
    int cnt[100]={0};
    int max;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",s[i]);
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        scanf("%s",t[i]);
    }
    for(int i=0;i<n;i++){
        cnt[i]++;
        for(int j=0;j<m;j++){
            if(strcmp(s[i],t[j])==0){
                cnt[i]--;
            }
        }
        for(int j=0;j<n;j++){
            if(i==j)continue;
            if(strcmp(s[i],s[j])==0){
                cnt[i]++;
            }
        }
    }
    max=0;
    for(int i=0;i<n;i++){
        if(max<cnt[i])max=cnt[i];
    }
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;

int main()
{
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    if(s1[s1.length()-1]==s2[0]&&s3[0]==s2[s2.length()-1])
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


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

namespace AtCoder
{
	public class ABC
	{
		private const int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); stopwatch.Start();
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//string s = Console.ReadLine();
			int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			Dictionary<string, int> count = new Dictionary<string, int>();
			int max = 0;
			for (int i = 0; i < n; i++) {
				string s = Console.ReadLine();
				if (count.ContainsKey(s)) {
					count[s]++;
				} else {
					count.Add(s, 1);
				}
				max = Math.Max(max, count[s]);
			}
			//System.Diagnostics.Debug.WriteLine(max);
			string[] keys = count.Where(p => p.Value == max).Select(p => p.Key).OrderBy(p => p, StringComparer.Ordinal).ToArray();
			//Array.Sort(keys, StringComparer.Ordinal);
			foreach (var s in keys) {
				//System.Diagnostics.Debug.WriteLine($"{s} {count[s]}");
				Console.WriteLine(s);
			}


			Console.Out.Flush();
			System.Diagnostics.Debug.WriteLine(stopwatch.Elapsed);
		}
	}
}


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

int main() {
    int a[3];
    int n,m,l;
    int tmp;
    cin >> a[0] >> a[1] >> a[2];
    for ( int i = 0; i < 3; i++ )
    {
        for ( int j = i; j < 3; j++ )
        {
            if( a[i] > a[j] )
            {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
    cout << a[0] << " " << a[1] << " " << a[2] << endl;

}


Measured memory_bytes: 3100