akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0, y = 0;
	REP(i, s.length()) {
		if (s[i] >= 'A' && s[i] <= 'M') {
			x++;
		}
		else if (s[i] >= 'N' && s[i] <= 'Z') {
			x--;
		}
		else if (s[i] >= 'a' && s[i] <= 'm') {
			y--;
		}
		else {
			y++;
		}
	}
	cout << abs(x) + abs(y) << endl;
	REP(i, x) {
		cout << "A";
	}
	REP(i, -x) {
		cout << "Z";
	}
	REP(i, y) {
		cout << "z";
	}
	REP(i, -y) {
		cout << "a";
	}
	cout << endl;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
#define pi  3.141592653589793238462643383279


void solve(){
double a,b,h,m;
cin >> a >> b >> h >> m;


cout << setprecision(21) << sqrt ( a*a + b*b - 2*a*b*cos(( 0.5*(m + 60*h ) -  6*m)*(pi/180)));



}

int main(){

solve();
return 0;


}


Measured memory_bytes: 4208
from collections import Counter
s = sorted(list(Counter(list(input())).values()))[::-1]
if len(s)==1:
  if s[0]!=1:
    print("NO")
    exit()
  else:
    print("YES")
    exit()
a = s[0]
if len(s)==2:
  if s[0]==1 and s[1]==1:
    print("YES")
    exit()
  else:
    print("NO")
    exit()
for i in s:
  if a==i or a==i+1:
    continue
  else:
    print('NO')
    exit()
else:
  print("YES")


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

int main(){
    int n;
    bool flg = false;
    cin >> n;
    for (int i = 0;i < 3;i++){
        if (n % 10 ==7){
            flg = true;
            break;
        }else{
            n = n / 10;
        }
    }
    if (flg){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 3640
#include <stdio.h>
#include<math.h>

int main(void) {
	int d, f,g,h,i;
	double e;

	scanf("%d", &d);
	e = d / 1.08;
	f = e;
	g = f * 1.08;
	h = (f + 1 )*1.08;
	i = (f - 1)*1.08;
	//printf("e:%lf, f:%d, f:%d\n", e, f,g);
	if (g == d)
		printf("%d\n", f);
	else if (h == d)
		printf("%d\n", f+1);
	else if (i == d)
		printf("%d\n", f-1);
	else
		printf(":(\n");

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
enum TheDay {
	Monday = 0, 
	Tuesday = 1,
	Wednesday = 2,
	Thursday = 3,
	Friday = 4,
	Saturday = 5,
	Sunday = 6
};
string getTheDayString(TheDay d){
	switch(d){
	case Monday:	return "Monday";
	case Tuesday:	return "Tuesday";
	case Wednesday: return "Wednesday";
	case Thursday:	return "Thursday";
	case Friday:	return "Friday";
	case Saturday:	return "Saturday";
	case Sunday:	return "Sunday";
	}
	return "";
}
int main()
{
	int MD[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	int MK[12] = {};
	MK[0] = 3;
	for(int i = 1; i < 12; ++i)
		MK[i] = (MK[i - 1] + MD[i - 1]) % 7;

	int m, d;
	while(cin >> m >> d){
		if(0 == m && 0 == d) break;
		TheDay a = (TheDay)((MK[m-1] + d - 1) % 7);
		cout << getTheDayString(a) << "\n";
	}
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

#define N 13
#define M 14

bool skillEnough(int num, int b[][M], int n, int m, int x, int *cost) {
	*cost = 0;
	int skill[m+1] = {0};

	for (int i = 0; i < n; i++) {
		if ((num >> i) & 1) {
			*cost += b[i][0];

			for (int j = 1; j <= m; j++)
				skill[j] += b[i][j];
		}
	}

	for (int i = 1; i <= m; i++) {
		if (skill[i] < x)
			return false;
	}

	return true;
}

int findMinMoney(int b[][M], int n, int m, int x) {

	int mm = INT_MAX, cost;

	for (int num = 1; num < (2 << n); num++) {
		if (skillEnough(num, b, n, m, x, &cost))
			mm = min(mm, cost);
	}

	return mm == INT_MAX ? -1 : mm;
}

int main() {

	IOS

	int n, m, x;
	cin >> n >> m >> x;

	int b[N][M];

	for (int i = 0; i < n; i++)
		for (int j = 0; j <= m; j++)
			cin >> b[i][j];

	cout << findMinMoney(b, n, m, x) << endl;

	return 0;
}

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

namespace ABC061A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a,b,c;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);
            if (a <= c && c <= b)
                Console.WriteLine("Yes");

            else
               Console.WriteLine("No");
            Console.ReadKey();

            



        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
int h,w,d;
char s[]="RGBY";
int main(){
	scanf("%d%d%d",&h,&w,&d);
	if(d&1){
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j)putchar(s[i+j&1]);
			putchar(10);
		}
	}else{
		for(int i=0;i<h;++i){
			for(int j=0;j<w;++j){
				int x=i+j,y=i-j+10000;
				putchar(s[(x/d&1)+(y/d&1)*2]);
			}
			putchar(10);
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    int K, S;
    cin>>K>>S;
    int k;
    int ans = 0;
    for(int i=0;i<=K;++i){
        for(int j=0;j<=K;++j){
            k = S - i - j;
            if((0<=k) & (k<=K)) ans++;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

int64 d[21][11];

void solve(int) {
  for (int i = 0; i < 10; ++i) {
    d[0][i] = 1;
  }
  for (int i = 0; i < 20; ++i) {
    d[i + 1][0] = d[i][0] + d[i][1];
    for (int j = 1; j < 10; ++j) {
      d[i + 1][j] = d[i][j - 1] + d[i][j] + d[i][j + 1];
    }
  }
  int64 n;
  cin >> n;
  int i = 0;
  int j = 1;
  int64 c = 0;
  while (c + d[i][j] < n) {
    c += d[i][j];
    ++j;
    if (j == 10) {
      j = 1;
      ++i;
    }
  }

  for (; i > 0; --i) {
    cout << j;
    n -= c;
    j = max(0, j - 1);
    c = 0; 
    while (c + d[i - 1][j] < n) {
      c += d[i - 1][j];
      ++j;
    }
  }
  cout << j << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-6;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
int N, T;
ll c[200],t[200];

void solve()
{
	ll ans = INF;
	for(int i=0;i<N;++i)if(t[i]<=T)ans=min(ans, c[i]);
	if(ans == INF) cout << "TLE" << endl;
	else cout << ans << endl;
}

int main()
{
	cin >> N >> T;
	for(int i=0;i<N;++i)cin >> c[i] >> t[i];
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int no_of_input,no_of_ticket;
  int input;
  priority_queue<int> q1;
  cin >> no_of_input >> no_of_ticket;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    q1.push(input);
  }
  while(no_of_ticket--){
    int a = q1.top();
    q1.pop();
    a/= 2;
    q1.push(a);
  }
  int ans = 0;
  while(q1.size()!=0){
    ans += q1.top();
    q1.pop();
  }
  cout << ans;
}

Measured memory_bytes: 1400
def dfs(i, func):
    if i == len(S) - 1:
        return eval(func)

    ret = 0
    ret += dfs(i + 1, func + S[i + 1])
    ret += dfs(i + 1, func + '+' + S[i + 1])
    return ret


S = input().strip()

print(dfs(0, S[0]))


Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
  char c1,c2;
  int a,b;
  int cup[3]={1,0,0};
  while((scanf("%c,%c",&c1,&c2))!=EOF){
    int temp;
    while((getchar())!='\n');
      a=c1-'A';
      b=c2-'A';
      temp = cup[a];
      cup[a] = cup[b];
      cup[b] = temp;
  }
  if(cup[0]==1) printf("A\n");
  if(cup[1]==1) printf("B\n");
  if(cup[2]==1) printf("C\n");
  return 0;
}


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

int main() {
  string S, T;
  cin >> S >> T;
  
  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == T.at(i)) {
      count++;
    }
  }
  
  if ( count == S.size() ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int sum = 0;
  rep(i,3){
    int x;
    cin >> x;
    sum += x;
  }
  if(sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  }



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

using namespace std;

const int mod = (int )(1e9) + 7;

vector<int> E[10001];
int sz[10001];
int f[5001][5001];
int tmp[10001];
int n;
int g[10001];
void add(int u, int v) {
	E[u].push_back(v);
	E[v].push_back(u);
}

void upd(int& x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

void dfs(int x, int fa) {
	sz[x] = f[x][1] = 1;
	for (int i = 0; i < (int )E[x].size(); i ++) {
		int v = E[x][i];
		if (v == fa) continue;
		dfs(v, x);
		for (int j = 1; j <= sz[x] + sz[v]; j ++) tmp[j] = 0;
		for (int j = 1; j <= sz[x]; j ++)
			for (int k = 1; k <= sz[v]; k ++) {
				upd(tmp[j + k], 1LL * f[x][j] * f[v][k] % mod);
				if (k & 1 ^ 1) {
					upd(tmp[j], mod - 1LL * f[x][j] * f[v][k] % mod * g[k] % mod);
				}
			}
		sz[x] += sz[v];
		for (int j = 1; j <= sz[x]; j ++) {
			f[x][j] = tmp[j];
		}
	}
}


int main( ){
	int x, y;
	int ans = 0;
	scanf("%d", &n);
	for (int i = 1; i < n; i ++) {
		scanf("%d %d", &x, &y);
		add(x, y);
	}
	for (int i = 2; i <= n; i += 2) {
		g[i] = 1;
		for (int j = i - 1; j >= 1; j -= 2) g[i] = 1LL * g[i] * j % mod;
	}

	dfs(1, 0);
	for (int i = 2; i <= n; i += 2) upd(ans, 1LL * f[1][i] * g[i] % mod);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 97536
var
	n:Longint;
function f(x:int64;a,b,c:Longint):Longint;
begin
	f:=0;
	if x<=n then f:=a*b*c+f(x*10+3,1,b,c)+f(x*10+5,a,1,c)+f(x*10+7,a,b,1);
end;
begin
	read(n);
	if n>700000000 then writeln(17656+f(7,0,0,1))
	else if n>300000000 then writeln(5556+f(3,1,0,0))
	else writeln(f(0,0,0,0));
end.

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

using namespace std;

const int INF = 1 << 30;

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

  vector< int > proc(26, INF);
  for(int i = 0; i < N; i++) {
    string S;
    cin >> S;
    vector< int > sum(26, 0);
    for(auto &c : S) sum[c - 'a']++;
    for(int j = 0; j < 26; j++) proc[j] = min(proc[j], sum[j]);
  }

  string s;
  for(int i = 0; i < 26; i++) {
    s += string(proc[i], i + 'a');
  }

  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back

int main(){
	boost ;
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int a,b,c,ans,x[101];


int main(){
    cin>>a>>b>>c;
    x[a]++;
    x[b]++;
    x[c]++;
    rep(i,101){
        if(x[i])ans++;
    }
    out(ans);
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  string s;
  cin>>s;
  if(int(s.size()) >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
const int MAX_DIGIT = 50;

int main(){
    int n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n);
    for(auto& v:a){cin >> v;}
    vector<vector<ll>> dp(51, vector<ll>(2, -1));
    dp[0][0] = 0;
    for(int d = 0; d < MAX_DIGIT; d++){
        ll mask = 1LL<<(MAX_DIGIT - 1 - d);
        int num = 0;
        for(int i = 0; i < n; i++) if (a[i] & mask) num++;
        ll score0 = mask * num;
        ll score1 = mask * (n - num);
        // fit to fit
        if(k & mask){
            dp[d+1][0] = dp[d][0] + score1;
        }
        else{
            dp[d+1][0] = dp[d][0] + score0;
        }
        // loose to loose
        if(dp[d][1] != -1){
            dp[d+1][1] = max(dp[d][1] + score0, dp[d][1] + score1);
        }
        // fit to loose
        if(k & mask){
            dp[d+1][1] = max(dp[d+1][1], dp[d][0] + score0);
        }
    }
    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
    return 0;
}

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

int main() {
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

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

int main () {
    string a;
    cin >> a;
    vector<int> ai(4);
    rep (i, 4) {
        ai.at(i) = a.at(i) - '0';
    }
    for (int i = 0; i < 8; i++) {
        string ans;
        ans += a.at(0);
        int ansi = ai.at(0);
        for (int j = 0; j < 3; j++) {
            if(i & (1 << j)) {
                ans += '+';
                ans += a.at(j+1);
                ansi += ai.at(j+1);
            }
            else {
                ans += '-';
                ans += a.at(j+1);
                ansi -= ai.at(j+1);
            }
        }
        if (ansi == 7) {
            ans += "=7";
            cout << ans << endl;
            break;
        }
    }
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  xs <- filter (/= "") . lines <$> getContents
  solve xs

solve :: [String] -> IO ()
solve [] = return ()
solve xs = do
  putStrLn $ figure fld
  solve $ drop 8 xs
  where
    fld = take 8 xs

figure :: [String] -> String
figure xs = s
  where
    rmr0 = filter (not . all (== '0')) xs
    ts = transpose rmr0
    rmc0 = filter (not . all (== '0')) ts
    Just s = lookup rmc0 tbl

tbl :: [([String],String)]
tbl = [(["11","11"],"A"),(["1111"],"B"),(["1","1","1","1"],"C"),(["011","110"],"D"),(["10","11","01"],"E"),(["110","011"],"F"),(["01","11","10"],"G")]

Measured memory_bytes: 3936
import java.util.Scanner;

/**
 * @author yoshizaki
 *
 */
public class Main {
 
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        double target = scanner.nextDouble();
    //    long start = System.currentTimeMillis(); 
        long ans = calc(target);
    //    long end = System.currentTimeMillis(); 
    //    long time = end - start;
        System.out.println(ans );
    //    System.out.println(time +"ms");
    }
    
    /**
     * @param target
     * @return
     */
    public static  long calc(double target){
        long targetNum = (long)target;
        long root = 0;
        long divNum = 0;
        long ansNum = 0;
        long sumNum = 0;
        root = (long) Math.sqrt(target);
        for (long i = root; i > 0; i--) 
        {
            if (targetNum % i == 0 ) {
                divNum = i;
                break;
            }
        }
        ansNum = targetNum / divNum;
        sumNum = ansNum + divNum -2;
        return sumNum;
    }
}

Measured memory_bytes: 24916
from functools import reduce

def binom(n, r):
    if n < r or n < 0 or r < 0: return 0
    
    if n - r < r: r = n - r
    if r == 0: return 1
    elif r == 1: return n

    numerator = [n - r + 1 + k for k in range(r)]  # (n-r+1)*(n-r+2)*...*(n-1)*n
    denominator = [1 + k for k in range(r)]         # 1*2*...*(r-1)*r

    # reduce prod(numerator)//prod(denominator)
    for p in range(2, r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    
    # calculate nCr
    return reduce(lambda x, y: x*y, numerator)

S = input()
cnt = [0] * 2019; cnt[0] += 1
t = 0
for i, s in enumerate(S[::-1]):
    t += int(s) * pow(10, i, 2019); t %= 2019
    cnt[t] += 1
ans = 0
for i in range(2019):
    if cnt[i] >= 2: ans += binom(cnt[i], 2)
print(ans)

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

int W, a, b;

int main() {
    cin >> W >> a >> b;

    if (a < b) {
        if (b - (a+W) > 0) {
            cout << b - (a+W) << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    else {
        if (a - (b+W) > 0) {
            cout << a - (b+W) << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#define ll long long
ll n,x;
ll gcd(ll a,ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
int main(){
	scanf("%lld%lld",&n,&x);
	printf("%lld",3*(n-gcd(n,x)));
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long m = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        long max = lcm(n,m);
        long spow = max/n;
        long tpow = max/m;
        for(int i = 0; i < n; i++){
            long index = i*spow;
            if(i == 0 || index % tpow == 0){
                if(s.charAt(i) != t.charAt((int)(index/tpow))){
                    System.out.println(-1);
                    return;
                }
            }else{
                continue;
            }
        }
        System.out.println(max);
    }
    
    private static long gcd(long a, long b){
        while (b > 0){
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }
    
    private static long lcm(long a, long b){
        return a * (b / gcd(a, b));
    }

}


Measured memory_bytes: 28620
N = gets.to_i
A = gets.chomp.split(" ").map(&:to_i)

a_sum_half = A.inject(:+) / 2
other_sum = 0
1.step(N - 1, 2){|i| other_sum += A[i]}

mnt_h = a_sum_half - other_sum
A.each_with_index{|a, idx|
  printf("#{mnt_h * 2} ")
  mnt_h = a - mnt_h if idx < N - 1
  mnt_h = A[0] - mnt_h if idx == N - 1
}
printf("\n")


Measured memory_bytes: 13316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;

const LL inf = 1000000000000000;
const LL mod = 1000000007;

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

	vector<LL> a(n);

	for(auto &e : a) {
		cin >> e;
	}

	sort(a.begin(), a.end());


	LL cnt = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			
			LL add = upper_bound(a.begin(), a.end(), a[i]+a[j]-1) - a.begin() -j-1;

			cnt += add;
		}
	}
	cout << cnt << endl;
	 
}

Measured memory_bytes: 256
#include <stdio.h>

int main (void)

{

int a,b;

scanf("%d",&a);

scanf("%d",&b);

if(a<b)

{

printf("a < b\n");

}

if(a>b)

{

printf("a > b\n");

}

if(a==b)

{

printf("a == b\n");

}

return 0;

}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int sum(int a){
  if(a<10) return a;
  return a%10+sum(a/10);
}

int main(){
  
  int n,a,b;
  cin >> n >> a >> b;
  int ans = 0;
  rep1(i,n) if(a<=sum(i) && sum(i)<=b) ans+=i;
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
H,W = map(int,input().split())
listMap = [[i for i in input()] for j in range(H)]
listPatA = [-1,0,0,1]
listPatB = [0,-1,1,0]

def dfs(a,b):
    # 4方向確認
    for i in range(4):
        # 現在地a,bにpatternのiを足した値を設定
        A = a + listPatA[i]
        B = b + listPatB[i]

        # A,BがMAP範囲内　かつ　W出現で再帰
        if 0 <= A < H and 0 <= B < W and listMap[A][B] == '#':
            return True
    # 結果的になければFalse
    return False

for i in range(H):
    for j in range(W):
        # 初めのWを見つける
        if listMap[i][j] == '#':
            # 見つけたら周囲8方向検索
            if dfs(i,j) == False:
                print("No")
                sys.exit()
# 全探索終了でYes
print("Yes")

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int main()
{
    int a,num=1;

    while(scanf("%d",&a)!=EOF){
            num=1;
        while(num<=a/2){
            num*=2;
        }
        printf("%d\n",num);

    }
    return 0;
}


Measured memory_bytes: 256
X = int(input())
N = [1]
j = 2

while True:
  i = 2
  flag = False
  while True:
    n = i ** j
    if n <= X:
      N.append(n)
      flag = True
      i += 1
    else:
      break
  if flag:
    j += 1
  else:
    break
print(max(N))

Measured memory_bytes: 3060
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nms = lambda: map(str, sys.stdin.readline().split())
nl = lambda: list(nm())

n, m = nm()
a = nl()
lis = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1 for _ in range(n + 1)]
dp[0] = 0
for i in range(1, n + 1):
    for j in a:
        if i - lis[j] >= 0:
            dp[i] = max(dp[i], dp[i - lis[j]] * 10 + j)
print(dp[n])


Measured memory_bytes: 14444
#include <bits/stdc++.h>
using namespace std;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m;
  cin >> n >> m;
  vector<string> str(n);
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  vector<vector<vector<int> > > dp(n, vector<vector<int> >(n, vector<int>(m)));
  for (int l = m - 1; l >= 0; l--) {
    for (int u = 0; u < n; u++) {
      for (int d = u; d < n; d++) {
        if (d != u && str[d][l] != str[d - 1][l]) {
          break;
        } else if (l + 1 == m || str[u][l] != str[u][l + 1]) {
          dp[u][d][l] = 1;
        } else {
          dp[u][d][l] = dp[u][d][l + 1] + 1;
        }
      }
    }
  }
  int answer = 0;
  while (dp[0][n - 1][0] < m) {
    vector<vector<vector<int> > > nxt(n, vector<vector<int> >(n, vector<int>(m)));
    for (int u = 0; u < n; u++) {
      for (int d = u; d < n; d++) {
        vector<int> bit(m);
        auto lowbit = [&] (int val) {
          return val & -val;
        };
        auto modify = [&] (int pos, int val) {
          for (; pos < m; pos += lowbit(pos + 1)) {
            bit[pos] = max(bit[pos], val);
          }
        };
        auto query = [&] (int pos) {
          int result = 0;
          if (pos >= m) {
            pos = m - 1;
          }
          for (; pos >= 0; pos -= lowbit(pos + 1)) {
            result = max(result, bit[pos]);
          }
          return result;
        };
        for (int l = m - 1; l >= 0; l--) {
          if (dp[u][d][l]) {
            modify(l, dp[u][d][l] + l);
          }
          nxt[u][d][l] = max(dp[u][d][l], query(dp[u][d][l] + l) - l);
          int left = u, right = d - 1, result = d;
          while (left <= right) {
            int mid = (left + right) / 2;
            if (dp[u][mid][l] > dp[mid + 1][d][l]) {
              left = mid + 1;
            } else {
              result = mid;
              right = mid - 1;
            }
          }
          if (result > u && result <= d) {
            nxt[u][d][l] = max(nxt[u][d][l], min(dp[u][result - 1][l], dp[result][d][l]));
          }
          if (result >= u && result < d) {
            nxt[u][d][l] = max(nxt[u][d][l], min(dp[u][result][l], dp[result + 1][d][l]));
          }
        }
      }
    }
    swap(dp, nxt);
    answer++;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 54364
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9+7;

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	vector<int> v(13);
	string s;
	cin >> s;
	reverse(s.begin(),s.end());
	int n = s.size();
	if(s[0] == '?'){
      for (int i=0; i<10; ++i) v[i] = 1;
   }
   else v[s[0]-'0'] = 1;
   int r = 10;
	for (int i=1; i<n; ++i){
		vector<int> v2(13);
		if (s[i] == '?'){
			for(int j=0; j<10; ++j){
            for(int k=0; k<13; ++k){
					v2[(k+j*r)%13] += v[k];
				}
			}
		}
		else{
		  int j = s[i]-'0';
        for(int k=0; k<13; ++k) v2[(k+j*r)%13] += v[k];	
		}
		r = (r*10)%13;
		v = v2;
		for (int j=0; j<13; ++j){
			v[j] %= MOD;
		}
	}
	cout <<  v[5]%MOD;
	return 0;
}


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

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w, k; cin >> h >> w >> k;
	vector<string>c(h); rep(i, h)cin >> c[i];
	int ans = 0;
	rep(bit, 1 << h) {
		rep(bit2, 1 << w) {
			vector<vector<bool>>r(h, vector<bool>(w));
			rep(i, h) {
				if (bit & (1 << i)) {
					rep(j, w)r[i][j] = true;
				}
			}
			rep(j, w) {
				if (bit2 & (1 << j)) {
					rep(i, h)r[i][j] = true;
				}
			}
			int cnt = 0;
			rep(i, h)rep(j, w) {
				if (!r[i][j] && c[i][j] == '#')cnt++;
			}
			if (cnt == k) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3612
//I love Nnanami Chiaki
#include<bits/stdc++.h>
using namespace std;
const int maxn=307;
int n,k,m;
int dp[maxn][maxn],sum[maxn][maxn],c[maxn][maxn];
void init(){
	c[0][0]=1;
	for (int i=1;i<=n;i++){
		c[i][0]=1;
		for (int j=1;j<=i;j++) c[i][j]=(c[i-1][j-1]+c[i-1][j])%m;
	}
}
int main(){
	scanf("%d%d%d",&n,&k,&m);
	init();
	for (int i=k;i>=0;i--) dp[1][i]=1;
	for (int i=k;i>=0;i--) sum[1][i]=(sum[1][i+1]+dp[1][i])%m;
	for (int i=2;i<=n+1;i++){
		for (int j=0;j<=k;j++){
			for (int sz=1;sz<i;sz++) dp[i][j]=(dp[i][j]+1ll*dp[i-sz][j]*c[i-2][sz-1]%m*sum[sz][j+1]%m)%m;
		}
		for (int j=k;j>=0;j--) sum[i][j]=(sum[i][j+1]+dp[i][j])%m;
	}
	printf("%d\n",dp[n+1][0]);
	return 0;
} 

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define powerof2 ()
#define mp make_pair
#define pi acos(-1)
using ll = long long;
const ll M = 1000000007;
const ll M1= 998244353;
using vl = vector<ll>;
using pll =  pair<ll,ll>;
ll power(ll x,ll y){
	if(y==0)
		return 1;
	ll res=power(x,y/2);
	res=(res*res);
	if(y&1)
		res=(res*x);
	return res;
}
 
ll powermod(ll x,ll y,ll mod){
	if(y==0)
		return 1;
	ll res=powermod(x,y/2,mod);
	res=(res*res)%mod;
	if(y&1)
		res=(res*x)%mod;
	return res;
}
/*ll binarysearch(ll va)
{
	ll n=1;
	ll l=va+1,u=n;
	ll st=num.order_of_key(va);
	while(l+1<u)
	{
		m=(l+u)/2;
		ll in=num.order_of_key(m);
		if(in-st==m-va)
		{
			l=m;
		}
		else
		{
            u=m;
		}
	}
	if(num1.find(l)==num1.end())
		return l;
	return u;
}*/
void solve(){
	int n;
	cin>>n;
	cout<<n*n*n<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    // cin>>t;
 
    for(int i=1;i<=t;i++)
    {//cout<<"Case #"<<i<<": ";
    solve();}
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define N 1000005
using namespace std;
bool prime[N];
set<int> p;
int n,ans;


int main(){
  for(int i=0;i<N;i++)prime[i]=true;
  prime[0]=prime[1]=false;
  for(int i=0;i*i<N;i++){
    if(!prime[i])continue;
    for(int j=i*2;j<N;j+=i)prime[j]=false;
  }
  for(int i=0;i<N;i++)
    if(prime[i])p.insert(i);
  while(1){
    cin>>n;
    if(!n)break;
    ans=0;
    set<int>::iterator ite;
    for(ite=p.begin();ite!=p.end();ite++){
      int key=n-(*ite);
      if((*ite)>key)continue;
      if(p.count(key))ans++;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5844
#include<stdio.h>
#include<string.h>
#define MAX 21
char str[MAX];
int main() {
	int len;
	char temp;
	scanf("%s",str);
	len = strlen(str);
	for (int i = 0;i < len / 2;i++) {
		temp = str[i];
		str[i] = str[len - 1 - i];
		str[len - 1 - i] = temp;
	}
	printf("%s\n",str);
}

Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
vector<pair<int,int>> arm;
int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, l;
		cin >> x >> l;
		arm.emplace_back(make_pair(x + l, x - l));
	}
	sort(arm.begin(), arm.end());
	int max = -1000000007;
	int ans = 0;
	for (int j = 0; j < n; j++) {
		if (max <= arm[j].second) {
			ans++;
			max = arm[j].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair <int,int> P;
int n;
P book[1001];

int solve(){
  int sumf=0,sums=0;
  for(int i=0;i<n;i++)sumf+=book[i].f,sums+=book[i].s;

  int d=max(0,2*book[0].f-sumf),dp[3000]={1};
  for(int i=1;i<n;i++)
    for(int j=d-book[i].s;j>=0;j--) dp[j+book[i].s]|=dp[j];

  int cnt=0;
  while(!dp[d--])cnt++;
  return sumf+sums+cnt;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++) cin>>book[i].f>>book[i].s;
    sort(book,book+n,greater<P>());
    cout <<solve()<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s,a,b;
    cin >> s ; 
    int n=sz(s); 
    for (int i=0;i<n;i++){
        if (s[i] != 'x') a.insert(a.end(),s[i]);
    }
    b=a;
    reverse(b.begin(), b.end());
    if (a != b) {
        cout << -1 << endl;
        return;
    }
    int ans=0;
    for (int i=0,j=n-1;i<j;){
        if (s[i]==s[j]) i++,j--;
        else {
            i += (s[i]=='x');
            j -= (s[j]=='x');
            ans++;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0;i < N;i++){
        cin >> a.at(i);
    }
    int button = 1;
    int count = 0;
    for (int j=0;j < N+10;j++){
        button = a.at(button - 1);
        count++;
        if(button == 2){
            cout << count << endl;
            break;
        }else if(j>N){
            cout << -1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int x;
    cin >>x;
    if(x<1200) cout <<"ABC" << endl;
    else cout << "ARC"<<endl;



}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int n, x, count;
    while (1) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        count = 0;
        for (int i = 1; i <= n; i++)
            for (int j = i + 1; j <= n; j++)
                for (int k = j + 1; k <= n; k++)
                    if (i + j + k == x) count++;
        cout << count << endl;
    }
}

Measured memory_bytes: 3080
#include <stdio.h>
int comp(int* x, int* y)
{
  int i;

  i = *x;
  *x = *y;
  *y = i;
}

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

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

  printf("%d %d %d\n",a,b,c);
  return(0);
}

Measured memory_bytes: 2688
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n,W;
    cin>>n>>W;
    vector<ll> dp(W+1,0);
    for(int i=0;i<n;i++){
        ll v,w,m;
        cin>>v>>w>>m;
        for(int t=0;m>0;t++){
            ll k=min(m,(ll)1<<t);
            m-=k;
            ll vd=v*k;
            ll wd=w*k;
            for(ll h=W-wd;h>=0;h--){
                dp[h+wd]=max(dp[h+wd],dp[h]+vd);
            }
        }
    }
    ll mx=0;
    for(int i=0;i<=W;i++){
        mx=max(mx,dp[i]);
    }
    cout<<mx<<endl;
    
    return 0;
}


Measured memory_bytes: 3180
X=input()
c=list(input())
result=0
i=0
while i<len(c)-2:
    if c[i]=='A':
        if c[i+1]=='B' and c[i+2]=='C':
            result+=1
            i+=3
        else:
            i+=1
    else:
        i+=1
print(result)

Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
	
	double a, b;
	int x, y;
	scanf("%lf %lf", &a, &b);
	x = a;
	y = b;
	printf("%d %d %.5lf\n", x/y, x%y, a/b);
	return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3
#define MAX_N 50

struct union_find {
    int rank[MAX_N], par[MAX_N];

    union_find(int n) { rep(i, n) rank[i] = 1, par[i] = i; }

    int find(int x) {
        if(x == par[x]) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;
        if(rank[x] > rank[y]) par[y] = x;
        else {
            par[x] = y;
            if(rank[x] == rank[y]) rank[y]++;
        }
    }
    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }
};

int main(){
    cin.sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<P> v;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v.pb(P(a, b));
    }
    int ans = 0;
    rep(i, m) {
        union_find uf(n);
        rep(j, m) {
            if (i == j) continue;
            uf.unite(v[j].fi, v[j].se);
        }
        bool ok = true;
        rep(j, n) if (!uf.same(0, j)) ok = false;
        if (!ok) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vb reach(const string& str, int loc, bool asc) {
    vb res(str.size());
    assert(str[loc] == '.');
    res[loc] = true;
    if (asc) for (int i = loc + 1; i < str.size(); i++) {
        if (str[i] == '#') continue;
        res[i] = res[i-1] | (i >= 2 ? res[i-2] : false);
    }
    else for (int i = loc - 1; i >= 0; i--) {
        if (str[i] == '#') continue;
        res[i] = res[i + 1] | (i + 2 < str.size() ? res[i+2] : false);
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N, A, B, C, D;
    string str;
    cin >> N >> A >> B >> C >> D >> str;

    A--, B--, C--, D--;
    vb rA = reach(str, A, true), rB = reach(str, B, true);
    vb rC = reach(str, C, false), rD = reach(str, D, false);

    bool good = false;
    if (C > D) {
        for (int sw = 1; sw < N - 1; sw++) {
            good |= rA[sw - 1] && rB[sw] && rD[sw] && rC[sw + 1];
        }
    } else {
        good = rB[D] && rC[A];
    }

    cout << (good ? "Yes": "No") << "\n";

    return 0;
}



Measured memory_bytes: 592
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp.map(r => r.split(' ').map(n => Number(n)))
  let ans = 0
  for (let i = 0; i < N; i++) {
    let j = inp[0][i]
    ans += inp[1][j-1]
    if (i !== N - 1 && inp[0][i+1] - 1 === j) {
      ans += inp[2][j-1]
    }
  }
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int X,N;
    cin >> X >> N;
    set<int> p;
    REP(i,N) {
        int x; cin >> x;
        p.insert(x);
    }
    int mini = INF;
    int ans = -1;
    REP(i,102)  if( !(p.count(i)) && chmin(mini,abs(X-i)) ) ans = i;
    cout << ans << endl;
}

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


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

using namespace std;

int main(){
	ios::sync_with_stdio(false);
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	string ans;
	for(int i=0; i<(ty-sy); i++)
		ans += 'U';
	for(int i=0; i<(tx-sx); i++)
		ans += 'R';
	for(int i=0; i<(ty-sy); i++)
		ans += 'D';
	for(int i=0; i<(tx-sx); i++)
		ans += 'L';
	ans += 'L';
	for(int i=0; i<(ty-sy)+1; i++)
		ans += 'U';
	for(int i=0; i<(tx-sx)+1; i++)
		ans += 'R';
	ans += "DR";
	for(int i=0; i<(ty-sy)+1; i++)
		ans += 'D';
	for(int i=0; i<(tx-sx)+1; i++)
		ans += 'L';
	ans += 'U';
	cout << ans << endl;
	return 0;
}


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

using Int = int;

int main(){
	Int n;
	std::cin >> n;
	std::vector<Int> v(n);
	for(Int &i : v) std::cin >> i;
	std::sort(v.begin(), v.end());
	std::vector<std::pair<Int, Int>> a(n * (n - 1) / 2);
	for(int i = 0; i < n; ++i) for(int j = 0; j < i; ++j){
		a[i * (i - 1) / 2 + j].first = v[i] - v[j];
		a[i * (i - 1) / 2 + j].second = v[j];
	}
	std::sort(a.begin(), a.end(), [](std::pair<Int, Int> &l, std::pair<Int, Int> &r){
		if(l.first < r.first) return true;
		else if(l.first == r.first){
			Int lr = l.second % r.first;
			Int rr = r.second % r.first;
			if(lr < rr) return true;
			else if(lr == rr) return l.second < r.second;
			else return false;
		}
		else return false;
	});
	
	std::cout << [&a](){
	//	for(auto i : a) std::cout << i.first << ',' << i.second << std::endl;
		std::pair<Int, Int> prev(0, 0);
		Int cnt = 0;
		Int max = 0;
		for(auto i : a){
			if(i.first == prev.first && i.second == prev.first + prev.second){
				++cnt;
				if(max < cnt) max = cnt;
			}else{
				cnt = 0;
			}
			prev = i;
		}
		return max + 2;
	}() << std::endl;
}



Measured memory_bytes: 100564
use std::collections::BTreeSet;
fn main() {
    let mut sc = Scanner::new();
    let n = sc.read();
    let w: Vec<String> = sc.read_vec(n);
    let mut set = BTreeSet::new();
    for w in w.iter() {
        if set.contains(w) {
            println!("No");
            return;
        }
        set.insert(w.clone());
    }

    let w: Vec<Vec<char>> = w.iter().map(|w| w.chars().collect()).collect();
    for i in 1..n {
        if w[i][0] != w[i - 1][w[i - 1].len() - 1] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
unsigned long long MOD = 1000000007;
long long INF = 1000000000000000;

typedef long long ll;
typedef unsigned long long ull;

ull powMod(ull x, ull n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  ull tmp = powMod(x, n / 2);
  if (n % 2 == 0) return (tmp * tmp) % MOD;
  return ((ull)2) * (tmp * tmp) % MOD;
}

int main(void) {
  ull cnt[65] = {};
  ull a[300010];

  ull n; cin >> n;
  ull y = 2;
  rep(i, n) cin >> a[i];

  rep(i, n) {
    int j = 0;
    ull b = a[i];
    while (b > 0) {
      cnt[j++] += (b % y);
      b /= y;
    }
  }

  ull ans[65] = {};
  rep(i, n) {
    int j = 0;
    while (j < 62) {
      if ((a[i] % y) == 0) {
	ans[j] += cnt[j];
      } else {
	ans[j] += n - cnt[j];
      }
      a[i] /= y;
      j++;
    }
  }
  //rep(i, 6) cout << ans[i];
  //cout << endl;
  ull x = 1;
  ull r = 0;
  rep(i, 62) {
    r += (ans[i] % MOD) * ((x << ull(i)) % MOD) % MOD;
    r %= MOD;
  }

  cout << r * powMod(y, MOD - y) % MOD << endl;

  return 0;
}

  


Measured memory_bytes: 2560