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

int main() {
  int n,l,w;
  cin >> n >> l >> w;
  l--;
  w--;
  vector<vector<int>> list(n,vector<int> (1,-1));
  for(int i=0;i<n-1;i++) {
    int n1,n2;
    cin >> n1 >> n2;
    if(list.at(n1-1).at(0)==-1) {
      list.at(n1-1).at(0)=n2-1;
    }
    else {
      list.at(n1-1).push_back(n2-1);
    }
    
    if(list.at(n2-1).at(0)==-1) {
      list.at(n2-1).at(0)=n1-1;
    }
    else {
      list.at(n2-1).push_back(n1-1);
    }
  }
  vector<int> numw(n,1e9);
  vector<int> numl(n,1e9);
  
  /*for(int i=0;i<n;i++) {
    for(int j=0;j<list.at(i).size();j++) {
      cout << list.at(i).at(j) << " ";
    }
    cout << endl;
  }*/
  
  queue<int> q;
  q.push(w);
  numw.at(w)=0;
  while(q.size()) {
    int temp=q.front();
    q.pop();
    for(int i=0;i<list.at(temp).size();i++) {
      if(numw.at(list.at(temp).at(i))==1e9) {
        numw.at(list.at(temp).at(i))=numw.at(temp)+1;
        q.push(list.at(temp).at(i));
      }
    }
  }
  q.push(l);
  numl.at(l)=0;
  while(q.size()) {
    int temp=q.front();
    q.pop();
    for(int i=0;i<list.at(temp).size();i++) {
      if(numl.at(list.at(temp).at(i))==1e9) {
        numl.at(list.at(temp).at(i))=numl.at(temp)+1;
        q.push(list.at(temp).at(i));
      }
    }
  }
  int end=0;
  for(int i=0;i<n;i++) {
    //cout << numw.at(i) << endl;
    if(numw.at(i)>numl.at(i)) {
      end=max(end,numw.at(i));
    }
  }
  cout << end-1 << endl;
}

Measured memory_bytes: 6912
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

class Tree{
public:
    int N;
    vector<vector<int>> G;

    Tree(int _N){
        N = _N;
        G.resize(N);
    }

    void make_edge(int s, int t){
        G[s].push_back(t);
    }

    int dfs(int n, int par){
        vector<int> v;
        for(int i = 0; i < (int) G[n].size(); i++){
            int nx = G[n][i];
            if(nx != par){
                v.push_back(dfs(nx, n));
            }
        }

        int sz = v.size();
        int ret;
        if(sz == 0) ret = 0;
        else {
            sort(v.begin(), v.end(), greater<int>());
            for(int i = 0; i < sz; i++){
                v[i] += i;
            }
            ret = *max_element(v.begin(), v.end());
        }

        //cout << n << endl;
        //for(int i = 0; i < sz; i++) cout << v[i] << " ";
        //cout << endl << ret << endl << endl;

        return ret + 1;
    }
};

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

    Tree tr = Tree(N);
    for(int i = 0; i < N - 1; i++){
        int a;
        cin >> a;
        tr.make_edge(a - 1, i + 1);
    }

    cout << tr.dfs(0, -1) - 1 << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 100000;


int main() {
    vector<int> a(4);;
    int k;
    int i=0;
    cin >> k;
    while(k>0){
        a[3-i] = k%10;
        k /=10;
        i++;
    }

    int n = 3;

    vector<char> ord(n);
    bool flag =false;
    for(int i=0; i < (1<<n); i++){
            int count = 0;
        vector<char> ord(n);
        count += a[0];
        for(int j=0; j < n ; j++){
            if(i & (1<<j)){
                count += a[j+1];
                ord[j] = '+';
            }else{
                count -= a[j+1]; 
                ord[j] = '-';
            }
        }
        if(count==7){
            rep(i,n) cout << a[i] << ord[i];
            cout << a[3] << '=' << 7 << endl;
            break;
        }
    }

}



Measured memory_bytes: 256
while 1:
    r,n = map(int,raw_input().split())
    if r == 0: break

    h = {i:0 for i in xrange(-21,21)}
    for loop in xrange(n):
        xl,xr,hi = map(int,raw_input().split())
        for i in xrange(xl,xr):
            h[i] = max(h[i],hi)

    for i in xrange(20,-21,-1):
        h[i] = min(h[i-1],h[i])

    y,d,u = 0,-r,h[0]-r
    for loop in xrange(30):
        if any(x**2+(y-h[x])**2 < r**2 for x in xrange(-20,21)):
            u = y
        else:
            d = y
        y = (d+u)/2.
    print "%.4f"%abs(y+r)

Measured memory_bytes: 4308
def getval():
    n,m = map(int,input().split())
    a = [int(input()) for i in range(m)]
    return n,m,a

def main(n,m,a):
    dp = [0 for i in range(n+1)]
    mod = 10**9 + 7
    dp[0] = 1
    it1 = iter(a)
    it2 = iter(a)
    d = dict(zip(it1,it2))
    for i in range(1,n+1):
        if i in d:
            continue
        if i==1:
            dp[1] = dp[0]
        else:
            dp[i] = (dp[i-1] + dp[i-2]) % mod

    print(dp[n])
    #print(dp)

if __name__=="__main__":
    n,m,a = getval()
    main(n,m,a) 

Measured memory_bytes: 99640
#include<bits/stdc++.h>
using namespace std;
long long a[10000][10000];
long long b[10000][10000];
int inf=(1<<31)-1;
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            a[i][j]=inf;
            b[i][j]=inf;
        }
        b[i][i]=0;
        a[i][i]=0;
    }
    for(int i=1;i<=m;i++)
    {
        long long x,y,z;
        cin>>x>>y>>z;
        a[x][y]=min(z,a[x][y]);
        a[y][x]=min(z,a[y][x]);
        b[x][y]=min(z,b[x][y]);
        b[y][x]=min(z,b[y][x]);
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                a[i][j]=min(a[i][k]+a[k][j],a[i][j]);
              //  cout<<a[i][j]<<" "<<i<<" "<<j<<" "<<k<<endl;
            }
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1+i;j<=n;j++)
        {
            if(b[i][j]!=inf&&a[i][j]!=b[i][j])
            {
                sum++;
                //cout<<i<<" "<<j<<endl;
               // cout<<a[i][j]<<" "<<b[i][j]<<endl;
            }
        }
    }
    cout<<sum<<endl;
   // cout<<b[1][2]<<endl;
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;

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

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();

        int i = 1;
        Set<Long> set = new HashSet<>();
        long val = A % B;
        boolean found = false;
        while (!set.contains(val)) {
            if (val == C) {
                found = true;
                break;
            }
            set.add(val);
            i++;
            val = (A * i) % B;
        }

        System.out.println(found ? "YES" : "NO");
        return;
    }

}

Measured memory_bytes: 23892
import collections
n,x,y = map(int,input().split())
li = []
for i in range(1,n):
  for j in range(i+1,n+1):
    i_x = abs(x-i)
    y_j = abs(j-y)
    li.append(min(j-i,i_x + y_j + 1))
c = collections.Counter(li)
for k in range(1,n):
  print(c[k])
  

Measured memory_bytes: 67748
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N,ans,res;

int main()
{
	in >> N;
	LL tmp = 1;
	while (ans+tmp <= N)
	{
		ans += tmp;
		tmp *= 2;
		++res;
	}
	out << res << std::endl;
	return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}
const int mod = 1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int>p(n);
    vector<int>c(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) {
        cin >> c[i];
    }
    ll ans = -1001001001;
    rep(i,n) {
        vector<int>s;
        int x = p[i];
        ll tot = 0;
        while(true) {
            s.push_back(c[x]);
            tot += c[x];
            if(x==i) break;
            x = p[x];
        }
        ll sum = 0;
        int l = s.size();
        rep(j,l) {
            if(j+1 > k) break;
            sum += s[j];
            ll now = sum;
            if(tot > 0) {
                ll e = (k-j-1)/l;
                now += tot*e; // 周期をとれるだけとって加算
            }
            ans = max(ans,now);
        }
    }
    cout << ans << endl;
}

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

int main()
{
  int M, D;
  cin >> M >> D;
  int count = 0;
  for (int i = 1; i <= D; i++)
  {
    int d1 = i / 10;
    int d10 = i - d1 * 10;
    if (d1 < 2 || d10 < 2)
      continue;
    if (d1 * d10 <= M)
      count++;
  }
  cout << count << endl;
}


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

int gcd(int a, int b, int c) {
  if (!(b%a) && !(c%a)) {
    return a;
  } else {
    for (int i = a/2; i > 0; i--) {
      if (a%i) continue;
      if (!(b%i) && !(c%i)) return i;
    }
    return 1;
  }
}

int main() {
  int k; cin>>k;
  int sum = 0;
  vector<int> list = {0,0,0};
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= k; j++) {
      for (int j2 = 1; j2 <= k; j2++) {
        list.at(0) = i;list.at(1) = j;list.at(2) = j2;
        sort(list.begin(),list.end());
        sum += gcd(list.at(0),list.at(1),list.at(2));
      }
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 3612
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

double EPS = 1.0e-10;

int main()
{
    for(;;){
        int n, l;
        cin >> n >> l;
        if(n == 0)
            return 0;

        vector<int> t(2*n+2, 0), u(2*n+1, 0);
        for(int i=0; i<n; ++i)
            cin >> t[i*2+1] >> t[i*2+2] >> u[2*i+1];
        t[2*n+1] = 86400;

        double left = 0.0;
        double right = 1000000;
        while(left < right - EPS){
            double mid = (left + right) / 2;

            bool ng = false;
            vector<double> tank(3);
            tank[0] = l;
            for(int k=1; k<3; ++k){
                tank[k] = tank[k-1];
                for(int j=0; j<2*n+1; ++j){
                    tank[k] += (t[j+1] - t[j]) * (mid - u[j]);
                    tank[k] = min(tank[k], (double)l);
                    if(tank[k] < 0){
                        ng = true;
                        break;
                    }
                }
            }

            if(!ng && abs(tank[1] - tank[2]) < EPS)
                right = mid;
            else
                left = mid;
        }

        printf("%.10f\n", left);
    }
}

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

#define REP(i, n, N) for(int i=(n); i<(N); i++)
#define RREP(i, n, N) for(int i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N, M, C;
int B[100];
int A[100][100];
int ans;
int main() {
	cin>>N>>M>>C;
	REP(i,0,M) cin>>B[i];
	REP(i,0,N){
		REP(j,0,M){
			cin>>A[i][j];
		}
	}
	REP(i,0,N){
		int sum=C;
		REP(j,0,M){
			sum+=A[i][j]*B[j];
		}
		if(sum>0){
			ans++;
		}
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

n = int(input())
l = list(map(int, input().split()))
l.sort()
triangle = 0
for i in range(n-2):
  for j in range(i+1, n-1):
    index = bisect_left(l, l[i] + l[j], j + 1, n) - 1
    triangle += index - j
print(triangle)

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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;

const int MOD = 10000;

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

    while (true) {
        int a, b, n;
        cin >> a >> b;
        if (a == 0 and b == 0) { break; }
        cin >> n;

        VVI ng(b + 1, VI(a + 1, 0));
        FOR(i, 0, n) {
            int x, y;
            cin >> x >> y;
            ng[y][x] = 1;
        }

        VVI dp(b + 1, VI(a + 1, 0));
        dp[1][1] = 1;

        FOR(i, 0, b + 1) {
            FOR(j, 0, a + 1) {
                if (i + 1 < dp.size() and ng[i + 1][j] == 0) {
                    dp[i + 1][j] += dp[i][j];
                }
                if (j + 1 < dp[0].size() and ng[i][j + 1] == 0) {
                    dp[i][j + 1] += dp[i][j];
                }
            }
        }

        print(dp[b][a]);
    }

}




Measured memory_bytes: 3204
#include <bits/stdc++.h>
#include <string>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define jai_shree_ram  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i, a, b, d) for (int i = a; i <= b; i += d)
#define brep(i, a, b, d) for (int i = a; i >= b; i -= d)
#define pb push_back
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define endl '\n'
const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;
////////////////////////////////

int dp[1005][1005];

int32_t main(){
    jai_shree_ram
    int n, m;
    cin >> n >> m;
    dp[1][1] = 1;
    rep(i,1,n,1){
        rep(j,1,m,1){
            char c;
            cin >> c;
            if(c == '.') {
                dp[i][j] += dp[i][j-1];
                dp[i][j]%=MOD;
                dp[i][j] += dp[i-1][j];
                dp[i][j]%=MOD;
            }
        }
    }
    cout << dp[n][m] << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[101];
  scanf("%s",s);
  int half=n/2;
  int flg=1;
  
  for(int i=0;i<half;i++){
    if(s[i]!=s[i+half])flg=0;
  }
  if(flg && n!=1 && n%2==0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return(0);
  
}

Measured memory_bytes: 128
using System;
namespace kozaiyApp
{
    public class dubiousDocument2
    {
        static void Main(string[] args)
        {
            string ans = "UNRESTORABLE";
            char[] S = Console.ReadLine().ToCharArray(); // 一部'?'の状態
            char[] T = Console.ReadLine().ToCharArray();

            if (S.Length < T.Length)
            {
                Console.WriteLine(ans);
                return;
            }

            // Sが7文字、Tが5文字の場合、i=2からはじまり、i=0まで
            for (int i = S.Length - T.Length; i >= 0; i--)
            {
                // S差替え済み
                if (ans == "SUCCESS") break;

                for (int j = 0; j < T.Length; j++)
                {
                    if (S[j+i] == T[j] || S[j+i] == '?')
                    {
                        // Tの最後の一文字まで合致(j最終回)
                        if (j == T.Length - 1)
                        {
                            // SをTに差替える
                            for (int t = 0; t < T.Length; t++)
                            {
                                S[i+t] = T[t];
                            }
                            ans = "SUCCESS";
                        }
                        continue; // 続ける
                    }
                    else
                    {
                        break; // 抜ける
                    }
                }
            }

            // Tが合致しなかったので終了
            if (ans == "UNRESTORABLE")
            {
                Console.WriteLine(ans);
                return;
            }

            // Sの'?'を'a'に差替え
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == '?')
                {
                    S[i] = 'a';
                }
            }

            ans = string.Join("", S);
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
import math
def isprime(x):
 if x == 2:
  return True
 elif x < 2 or x % 2 == 0:
  return False
 else:
  for i in range(3, int(math.sqrt(x)) + 1,2):
   if x % i == 0:
    return False 
  return True

n = int(input())
cnt = 0
for i in range(n):
 x = int(input())
 if isprime(x):
  cnt += 1
print(str(cnt))

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

double PI = M_PI;
double ER = 1e-8;

double calc(int a, int b, double theta){
    double rad = theta*PI/180;
    double ans;
    if(a*tan(rad) <= b){
        ans = a*a*b;
        ans -= a*a*a*tan(rad)/2;
        return ans;
    }
    else{
        ans = b*b*a/(tan(rad)*2);
        return ans;
    }
}

int main(){
    int a,b;
    cin >> a >> b;
    double water;
    cin >> water;
    double l=0;
    double r=90;
    while(l+ER < r){
        double mid=(l+r)/2;
        if(calc(a,b,mid) >= water){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    cout << fixed << setprecision(7) << l << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, c;
  cin >> r >> c;
  int a[r + 1][c + 1] = {};
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      cin >> a[i][j];
      cout << a[i][j] << ' ';
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
    cout << a[i][c] << '\n';
  }
  for (int i = 0; i < c; i++) {
    cout << a[r][i] << ' ';
  }
  cout << a[r][c] << '\n';
  return 0;
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
int main(){
  string S;
  cin >> S;
  int K;
  cin >> K;

  for( int i=0;i<min((int)S.length(), K); i++ )
    {
      if(S[i] != '1')
	{
	  cout << S[i] << endl;
	  return 0;
	}
    }
  cout << '1' << endl;

}


Measured memory_bytes: 256
s=input()
g,p=0,0
w,l=0,0
t=""
for c in s:
    if c == 'g' and p < g:
        w += 1
        p += 1
        t += 'p'
    else:
        g += 1
        t += 'g'
        if c == 'p':
            l += 1
for i in range(len(s)-1, -1, -1):
    if t[i] == 'g' and s[i] == 'p':
        if p+1 <= g-1:
            l -= 1
            p += 1
            g -= 1
print(w-l)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    map<string,int> mp;
    int n; cin >> n;
    rep(i,n) {
        string s; cin >> s;
        mp[s]++;
    }
    cout << "AC" << " " << 'x' << " " << mp["AC"] << endl;
    cout << "WA" << " " << 'x' << " " << mp["WA"] << endl;
    cout << "TLE" << " " << 'x' << " " << mp["TLE"] << endl;
    cout << "RE" << " " << 'x' << " " << mp["RE"] << endl;
}

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

class Dice {
  private:
    int *numbers;
  public:
    Dice(int *numbers) {
      this->numbers = numbers;
    }

    int getCurrentNumber() {
      return this->numbers[0];
    }

    void turn(char direction) {
      switch (direction) {
        case 'N':
          this->turnNorth();
          break;
        case 'S':
          this->turnSouth();
          break;
        case 'E':
          this->turnEast();
          break;
        case 'W':
          this->turnWest();
          break;
      }
    }

    void turnNorth() {
      swap(this->numbers[0], this->numbers[1]);
      swap(this->numbers[1], this->numbers[5]);
      swap(this->numbers[5], this->numbers[4]);
    }

    void turnSouth() {
      swap(this->numbers[0], this->numbers[4]);
      swap(this->numbers[4], this->numbers[5]);
      swap(this->numbers[5], this->numbers[1]);
    }

    void turnEast() {
      swap(this->numbers[0], this->numbers[3]);
      swap(this->numbers[3], this->numbers[5]);
      swap(this->numbers[5], this->numbers[2]);
    }

    void turnWest() {
      swap(this->numbers[0], this->numbers[2]);
      swap(this->numbers[2], this->numbers[5]);
      swap(this->numbers[5], this->numbers[3]);
    }

    int getRightNumberFrom(int top, int front) {
      int rightIndexes[6][6] = {
        { -1, 2, 4, 1, 3, -1 },
        { 3, -1, 0, 5, -1, 2 },
        { 1, 5, -1, -1, 0, 4 },
        { 4, 0, -1, -1, 5, 1 },
        { 2, -1, 5, 0, -1, 3 },
        { -1, 3, 1, 4, 2, -1 }
      };
      int topIndex, frontIndex;
      for(int i = 0; i < 6; i++) {
        if (this->numbers[i] == top) topIndex = i;
        if (this->numbers[i] == front) frontIndex = i;
      }
      return this->numbers[rightIndexes[topIndex][frontIndex]];
    }
};

int main() {
  int numbers[6], n, top, front;
  int ans[24];

  for (int i = 0; i < 6; i++) {
    cin >> numbers[i];
  }
  cin >> n;
  Dice dice(numbers);
  for (int i = 0; i < n; i++) {
    cin >> top >> front;
    ans[i] = dice.getRightNumberFrom(top, front);
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    vi h(n);
    //vector<pii> h(n);
    REP(i,n) {
        int tmp;
        cin>>tmp;
        //h[i] = pii(tmp,i+1);
        h[i] = tmp;
    }

    //sort(ALL(h),greater<pii>());
    //REP(i,n) DEBUG2(h[i].first,h[i].second);

    vector<bool> isgood(n, true);
    int ans=0;
    REP(i,m){
        int a,b;
        cin>>a>>b;
        a--; b--;
        if(h[a] < h[b]){
            isgood[a]=false;
        }
        else if(h[a] > h[b]){
            isgood[b]=false;
        }
        else
        {
            isgood[a]=false;
            isgood[b]=false;
        }
    }

    REP(i,n){
        if(isgood[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3700
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)

A = 0
B = 100001

for a, b in zip(L, R):
    A = max(A, a)
    B = min(B, b)


if B-A < 0:
    print(0)
else:
    print(B-A+1)

Measured memory_bytes: 10996
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(void)
{
    int n;
    scanf("%d",&n);
    if(n==25)
        printf("Christmas\n");
    else if(n==24)printf("Christmas Eve\n");
    else if(n==23)printf("Christmas Eve Eve\n");
    else if(n==22)printf("Christmas Eve Eve Eve\n");
    return 0;
}



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

int main(){

    float A, B;
    cin >> A >> B;

    int ans = 0;
    rep(i,50000){
        if(floor(i*0.08) == A && floor(i*0.1) == B){
            ans = i;
            break;
        }
    }

    if(ans != 0) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
while True:
  m, f, r = map(int, input().split())
  if m == -1 and f == -1 and r == -1:
    break
  if  m == -1 or f == -1:
    print("F")
  elif m+f >= 80:
    print("A")
  elif 65 <= m+f:
    print("B")
  elif 50 <= m+f:
    print("C")
  elif 30 <= m+f:
    if r >= 50:
      print("C")
    else:
      print("D")
  else:
    print("F")
    


Measured memory_bytes: 5588
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ll n;
	ll x, m;
	cin>>n>>x>>m;
	vector<ll> v, v0{x};
	bool used[100010]={};
	used[x]=1;
	for(int i=1; i<=m; i++){
		x=x*x%m;
		if(used[x]){
			break;
		}
		used[x]=1;
		v0.push_back(x);
	}
	while(!v0.empty()){
		ll x1=v0.back(); v0.pop_back();
		v.push_back(x1);
		if(x1==x) break;
	}
	reverse(v.begin(), v.end());
	if(v0.size()>=n){
		ll ans=0;
		for(int i=0; i<n; i++){
			ans+=v0[i];
		}
		cout<<ans<<endl;
		return 0;
	}
	ll ans=0;
	for(auto x:v0) ans+=x;
	n-=(ll)v0.size();
	ll s=0;
	for(auto x:v) s+=x;
	ll l=v.size();
	ans+=s*(n/l);
	for(int i=0; i<n%l; i++) ans+=v[i];
	cout<<ans<<endl;
	return 0;
}



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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


int main() {

    int n, h;
    cin >> n >> h;

    vector<int> knife_throw(n), knife_saw(n);
    rep(i, n) cin >> knife_saw[i] >> knife_throw[i];

    ll m = *max_element(knife_saw.begin(), knife_saw.end());

    vector<int> need_knife_throw;
    for (ll a :knife_throw) if (a > m) need_knife_throw.push_back(a);
    sort(need_knife_throw.rbegin(), need_knife_throw.rend());

    ll ans = 0;
    ll hit = 0;
    for (int i = 0; i < need_knife_throw.size(); i++) {
        ans++;
        hit += need_knife_throw[i];
        if (hit >= h) {
            cout << ans << endl;
            ret();
        }
    }

    ll nokori = h - hit;

    ans += ((nokori + m - 1) / m);
    cout << ans << endl;


}


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

int main() {
    int n, t, a;
    std::cin >> n >> t >> a;
    std::vector<int> h(n);
    int ret = 0;
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
        if (std::abs(t - h[ret] * 0.006 - a) > std::abs(t - h[i] * 0.006 - a)) ret = i;
    }

    std::cout << ret + 1 << std::endl;

    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heapreplace

n = int(input())
a = sorted(map(int, input().split()), reverse=True)
h = [-a[0]]
c = 0
for i in range(1, n):
    c += heapreplace(h, -a[i])
    heappush(h, -a[i])
print(-c)

Measured memory_bytes: 31780
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

constexpr ll mod = 1000000007;

ll modpow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a % m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

void solve(){
  ll x, y; cin >> x >> y;
  if((x+y)%3!=0){
    cout << 0 << endl;
    return;
  }
  if(x<y) swap(x,y);
  ll mvt, mvdf, mvy;
  mvt = (x+y)/3;
  mvdf = x-y;
  if(mvt < mvdf){
    cout << 0 << endl;
    return;
  }
  mvy = (mvt - mvdf)/2;
  vector<ll> fract(mvt+10);
  fract[0] = 1;
  for(ll i = 0; i<mvt+5; ++i) fract[i+1] = ((i+1)*fract[i] )%mod;
  ll ans = (fract[mvt] * modpow(fract[mvy],mod-2,mod))%mod;
  ans = ans * modpow(fract[mvt-mvy],mod-2,mod) % mod;
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 5504
#include <iostream>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<15;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N;
  string S;
  cin >> N >> S;
  int black = 0;
  for (int i=0; i<N; i++){
    if (S[i] == '#') black++;
  }

  int now = 0, ans, tmp;
  ans = min(black, N-black);
  for (int i=0; i<N; i++){
    if (S[i] == '#'){
      now++;
      tmp = now-1 + (N-i-1) - (black - now);
      ans = min(tmp, ans);
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

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

  int a[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  int X, Y; cin >> X >> Y;
  cout << (a[X] == a[Y] ? "Yes" : "No") << endl;
}

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

using namespace std;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    for (int s = 0; s <= k; ++s) {
        for (int t = 0; t <= k; ++t) {
            for (int w = 0; w <= k; ++w) {
                if (s + t + w > k) continue;
                int A = a, B = b, C = c;
                for (int j = 1; j <= s; ++j) A *= 2;
                for (int j = 1; j <= t; ++j) B *= 2;
                for (int j = 1; j <= w; ++j) C *= 2;
                if (A < B && B < C) {
                    cout << "Yes";
                    exit(0);
                }
            }
        }
    }
    cout << "No" << '\n';
    return 0;
}



Measured memory_bytes: 3644
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int N, M;

int main() {
    map<string, int> m;
    string s;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> s;
        if (m.count(s) > 0) {
            m[s]++;
        } else
            m.insert({s, 1});
    }

    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> s;
        if (m.count(s) > 0) {
            m[s]--;
        } else
            m.insert({s, -1});
    }

    int ans = 0;
    for (auto n : m) ans = max(ans, n.second);
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i--)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

int IN_int(){
    int x;
    scanf("%d",&x);
    return x;
}

//library----------------------------------------------

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

const int NMAX = 25;
bool flag;

int main(){
    SCIN(s);
    flag=false;
    if(s[2]==s[3]&&s[4]==s[5]) flag=true;
    printf(flag?"Yes":"No");
    

    return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[[0]*n for _ in range(n)]
for i in range(n):
	r=input()
	for j in range(n):
		if r[j]=="1":
			s[i][j]=1
ans=0
from collections import deque
for i in range(n):
	queue=deque([i])
	num=[-1]*n
	num[i]=0
	while queue:
		r=queue.popleft()
		for j in range(n):
			if s[r][j]==1 and num[j]==-1:
				num[j]=num[r]+1
				queue.append(j)
	MAX=max(num)
	p=[[]for _ in range(MAX+1)]
	for i in range(n):
		p[num[i]].append(i)
	ok=1
	for i in range(MAX+1):
		for x in p[i]:
			for y in p[i]:
				if s[x][y]==1:
					ok=0
					break
			if ok==0:
				break
		if ok==0:
			break
	if ok:
		ans=max(ans,MAX+1)
print(ans if ans else -1)

Measured memory_bytes: 9824
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int toi = Integer.parseInt(scanner.nextLine());
		String bin = "";

		while( toi != 0) {
			if(toi % -2 == 0) {
				bin = "0" + bin;
			}else if(toi % -2 != 0) {
				bin = "1" + bin;
				toi--;
			}

			toi /= -2;
		}

		if(bin.equals("")) {
			bin = "0";
		}

		System.out.println(bin);


	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

int main(){
    int n; cin>>n;
    int s[n]; rep(i,n) cin>>s[i];
    bool dp[n+1][101*n]; rep(i,n+1)rep(j,101*n) dp[i][j]=0;
    dp[0][0]=1;
    int ans=0;
    for(int i=1;i<n+1;i++)rep(j,101*n){
        if(j-s[i-1]>=0) dp[i][j]=(dp[i-1][j]||dp[i-1][j-s[i-1]]);
        else dp[i][j]=dp[i-1][j];
        if(dp[i][j]&&j%10!=0){
            ans=max(ans,j);
        }
    }
    // rep(i,n+1){
    //     rep(j,31){
    //         cout<<dp[i][j];
    //     }
    //     cout<<endl;
    // }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ms(x,y) memset(x, y, sizeof(x))
#define lowbit(x) ((x)&(-x))
#define sqr(x) ((x)*(x))
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const LL MOD = 998244353;

void run_case() {
    int n;
    cin >> n;
    vector<pll> a(n), sta;
    for(auto &x: a) cin >> x.first >> x.second;
    sort(a.begin(), a.end());
    vector<LL> dp(n+1);
    dp[n] = 1;
    sta.emplace_back(n, 3e9);
    for(int i = n-1; i >= 0; --i) {
        while(sta.back().second < a[i].first + a[i].second)
            sta.pop_back();
        dp[i] = dp[sta.back().first];
        sta.emplace_back(i, a[i].first);
        dp[i] = (dp[i] + dp[i+1]) % MOD;
    }
    cout << dp[0];
}


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    cout.flags(ios::fixed);cout.precision(9);
    //int t; cin >> t;
    //while(t--)
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 7156
import math
a,b,x=map(int,input().split())
if x<=(a*a*b/2):
    l=(a*b*b)/(2*x)
    atan = math.degrees(math.atan(l))
    print(atan)
else:
    l=(2*a*a*b-2*x)/(a**3)
    atan = math.degrees(math.atan(l))
    print(atan)

Measured memory_bytes: 3060
//Osenbei
#include <stdio.h>
#include <string.h>
int A[10001];

int main(){
  int C, R, tmp, mask, ans, a, b, i, j;
  while(1){
    scanf("%d %d", &C, &R);
    if((C | R) == 0){
      break;
    }
    memset(A, 0, sizeof(A));
    for(i = 0; i < C; ++i){
      for(j = 0; j < R; ++j){
        scanf("%d", &tmp);
        A[j] += tmp << i;
      }
    }
    ans = 0;
    for(mask = 0; mask < (1 << C); ++mask){
      //printf("mask = %d \n", mask);
      a = 0;
      for(i = 0; i < R; ++i){
        tmp = A[i] ^ mask;
        //printf("%d", tmp);
        b = 0;
        while(tmp != 0){
          if((tmp & 1) == 1){
            b++;
          }
          tmp = tmp >> 1;
        }
        a += b > C - b ? b : C - b;
      }
      //printf(" a = %d \n", a);
      if(ans < a){
        ans = a;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

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

int a[110];

int main(){
    int n,v,j;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=1;i<n;i++){
        for(int o=0;o<n;o++){
            if(o==n-1) cout<<a[o]<<endl;
            else cout<<a[o]<<" ";
        }
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
    }
    for(int o=0;o<n;o++){
        if(o==n-1) cout<<a[o]<<endl;
        else cout<<a[o]<<" ";
    }
    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>                
using namespace std;
#define REP(i,n) for(auto i = 0; i < (n); ++i)
#define REP1(i,n) for(auto i = 0; i <= (n); ++i)
#define REPO(i,o,n) for(auto i = (o); i < (n); ++i)
#define REPR(i,n) for(auto i = (n)-1; i >= 0; --i)
#define REPI(itr,v) for(auto itr=v.begin(); itr != v.end(); ++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin(); itr != v.rend(); ++itr)
#define ALL(v) v.begin(), v.end()
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}
#define push_back pb;
#define push_front pf; 
#define make_pair mp;
#define first fi;
#define second se;
typedef long long ll;

int A, B;
char func(int inp){
	if(inp==1||inp==3||inp==5||inp==7||inp==8||inp==10||inp==12) return 'a';
	else if(inp==4||inp==6||inp==9||inp==11) return 'b';
	else return 'c';
} 
int main(void){
	cin >> A >> B;
	if(func(A) == func(B))cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
char str[100005];
char c[100005];
int n;
int k;
bool have[256];
int nxt[100005][26];

int main()
{
//	freopen("input.txt","r",stdin);
	scanf("%s",str);
	scanf("%s",c);
	n=strlen(str);
	k=strlen(c);
	for(int i=0;i<n;i++)
	{
		have[str[i]]=true;
		for(int j=0;j<26;j++)
		{
			nxt[i][j]=-1;
		}
	}
	for(int j=0;j<26;j++)
	{
		nxt[n][j]=-1;
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<26;j++)
		{
			if(str[i]-'a'==j)
			{
				nxt[i][j]=i;
			}
			else
			{
				nxt[i][j]=nxt[i+1][j];
			}
		}
	}
	for(int i=0;i<k;i++)
	{
		if(!have[c[i]]) over("-1");
	}
	int res=0;
	int cur=0;
	for(int i=0;i<k;i++)
	{
		if(nxt[cur][c[i]-'a']==-1)
		{
			cur=0;
			res++;
		}
		cur=nxt[cur][c[i]-'a']+1;
	}
	cout<<1LL*res*n+cur<<endl;
	return 0;
}

Measured memory_bytes: 10624
class UnionFind():
    def __init__(self,size):
        self.table=[-1]*size
    def root(self,x):
        while self.table[x]>=0:
            x=self.table[x]
        return x
    def unite(self,x,y):
        s1=self.root(x)
        s2=self.root(y)
        if s1!=s2:
            if self.table[s1]>self.table[s2]:
                s1,s2=s2,s1
            self.table[s1]+=self.table[s2]
            self.table[s2]=s1
        return
    def same(self,x,y):
        return self.root(x)==self.root(y)
    def size(self,x):
        return -self.table[self.root(x)]
n,*z=map(int,open(0).read().split())
u=UnionFind(10**5*2+1)
for x,y in zip(*[iter(z)]*2):
    u.unite(x,10**5+y)
d=[[0,set(),set()]for _ in range(10**5*2+1)]
for x,y in zip(*[iter(z)]*2):
    t=d[u.root(x)]
    t[0]+=1
    t[1].add(x)
    t[2].add(y)
print(sum(len(x)*len(y)-a for a,x,y in d))

Measured memory_bytes: 109228
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main{
    public static void main(String args[]){
	try{
	    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str;
	    String strary[] = new String[6];
	    double x[] = new double[3];
	    double y[] = new double[3];
	    int count = Integer.parseInt(br.readLine());
	    double c[] = new double[10]; // keisan you
	    double a,b,r;
	    while((count--) != 0){
		str = br.readLine();
		strary = str.split(" ");
		int tmp = 0;
		for (int i = 0; i < 3; i++) {
		    x[i] = Double.parseDouble(strary[tmp]);
		    y[i] = Double.parseDouble(strary[tmp+1]);
		    tmp+=2;
		}
		c[0] = 2*(x[1]-x[0]);
		c[1] = 2*(y[1]-y[0]);
		c[2] = x[0]*x[0]-x[1]*x[1]+y[0]*y[0]-y[1]*y[1];
		c[3] = 2*(x[2]-x[0]);
		c[4] = 2*(y[2]-y[0]);
		c[5] = x[0]*x[0]-x[2]*x[2]+y[0]*y[0]-y[2]*y[2];
		a = (c[1]*c[5]-c[4]*c[2])/(c[0]*c[4]-c[3]*c[1]);
		b = (c[2]*c[3]-c[5]*c[0])/(c[0]*c[4]-c[3]*c[1]);
		r = Math.sqrt((x[0]-a)*(x[0]-a)+(y[0]-b)*(y[0]-b));
		System.out.printf("%.3f %.3f %.3f\n",a,b,r);
	    }
	}
	catch(Exception e){
	    System.out.println("error");
	    System.exit(0);
	}
    }
}

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

class Maze {
public:
    static Maze from_cin(const int w, const int h) {
        auto data = std::vector<std::vector<char> >();
        data.reserve(h);

        for(int h1 = 0; h1 < h; ++h1) {
            auto row = std::vector<char>();
            row.reserve(w);

            for(int w1 = 0; w1 < w; ++w1) {
                char c;
                std::cin >> c;
                row.push_back(c);
            }

            data.push_back(row);
        }

        return Maze(data, h, w);
    }

    char at(int w, int h) const {
        if(w < 0 || h < 0 || w >= width || h >= height) {
            return '#';
        }
        return data[h][w];
    }

private:
    Maze(std::vector<std::vector<char> > data, const int h, const int w):
        data(data),
        height(h),
        width(w)
    { }

    std::vector<std::vector<char> > data;
    int height, width;
};

struct SearchData {
    int w, h, distance;

    bool operator < (const SearchData &other) const {
        if(w == other.w) {
            return h < other.h;
        }
        return w < other.w;
    }
};

void process(const SearchData sd, std::set<SearchData> &searched, std::queue<SearchData> &que, Maze &maze) {
    if(maze.at(sd.w, sd.h) == '.' && searched.find(sd) == searched.end()) {
        searched.insert(sd);
        que.push(sd);
    }
}

int main() {
    int w, h;
    std::cin >> h >> w;

    auto maze = Maze::from_cin(w, h);

    int answer = 0;

    for(int h1 = 0; h1 < h; ++h1) {
        for(int w1 = 0; w1 < w; ++w1) {
            if(maze.at(w1, h1) == '#') {
                continue;
            }

            const auto start = SearchData { w1, h1, 0 };

            auto searched = std::set<SearchData>();
            searched.insert(start);

            auto que = std::queue<SearchData>();
            que.push(start);

            while(!que.empty()) {
                const auto d = que.front();
                que.pop();

                auto d1 = SearchData{ d.w, d.h - 1, d.distance + 1 };
                process(d1, searched, que, maze);

                d1 = SearchData{ d.w, d.h + 1, d.distance + 1 };
                process(d1, searched, que, maze);

                d1 = SearchData{ d.w - 1, d.h, d.distance + 1 };
                process(d1, searched, que, maze);

                d1 = SearchData{ d.w + 1, d.h, d.distance + 1 };
                process(d1, searched, que, maze);
            }

            int max_distance = 0;

            for(const auto sd: searched) {
                max_distance = std::max(max_distance, sd.distance);
            }

            answer = std::max(max_distance, answer);
        }
    }

    std::cout << answer << std::endl;

    return 0;
}


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

int main()
{
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> Sd;
    for(auto &p : S) Sd.push_back(p);
    bool rev = false;
    for(int i = 0; i < Q; ++i) {
        int T, F; char C;
        cin >> T;
        if(T == 1) { rev = !rev; continue; }
        cin >> F >> C;
        if(F == 1) { if(!rev) Sd.push_front(C); else Sd.push_back(C); }
        else { if(!rev) Sd.push_back(C); else Sd.push_front(C); }
    }
    if(!rev) {
        for_each(Sd.begin(), Sd.end(), [](char &c) {
            cout << c;
        });
    }
    else {
        for(int i = 0, i_len = Sd.size(); i < i_len; ++i) {
            cout << Sd.back();
            Sd.pop_back();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
N, K = map(int,input().split())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

x10 = N
output = int(Base_10_to_n(x10, K))

count = 1



while output>=10:
    count+=1
    output/=10

print(count)


Measured memory_bytes: 3060