akhauriyash/Code-Regression huggingface dataset:
H,W = gets.split.map(&:to_i)
cnt = 0 # num of '.'
field = []
H.times do
  l = gets.chomp
  field << l
  cnt += l.count('.')
end

q = []
q << [0,0,1]
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
checked = Array.new(H) { Array.new(W, false) }
leng = -1
while !q.empty?
  x,y,d = q.shift
  checked[y][x] = true
  if x == W-1 && y == H-1
    leng = d
    break
  end
  4.times do |i|
    nx = x + dx[i]
    ny = y + dy[i]
    if 0 <= nx && nx < W && 0 <= ny && ny < H && field[ny][nx]=='.' && !checked[ny][nx]
      q << [nx, ny, d+1]
      checked[ny][nx] = true
    end
  end
end
puts leng > 0 ? cnt - leng : -1





Measured memory_bytes: 1788
#include <iostream>
#include <string>

using namespace std;

int main(){
    string S;
    cin >> S;
    int size;
    
    for (size = S.length()-2 ; size !=0; size -=2) {
        string front, back;
        front = S.substr(0, size/2);
        back = S.substr(size/2, size/2);
        if (front == back) {
            break;
        }

    }
    
    cout << size << endl;
    
    return 0;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            int caseCnt = 1;

            while (true)
            {
                int W = int.Parse(Console.ReadLine());
                if (W == 0) break;

                Nullable<int>[] dp = new Nullable<int>[W + 1];
                dp[0] = 0;

                int N = int.Parse(Console.ReadLine());
                int maxV = 0, resW = 0;

                for (int i = 0; i < N; i++)
                {
                    string[] input = Console.ReadLine().Split(',');
                    int v = int.Parse(input[0]);
                    int w = int.Parse(input[1]);

                    for (int j = W; j >= 0; j--)
                    {
                        if (dp[j] == null) continue;

                        int sumW = w + j;
                        if (sumW > W) continue;

                        int sumV = dp[j].Value + v;

                        if (dp[sumW] == null || dp[sumW] < sumV)
                        {
                            dp[sumW] = sumV;

                            if (maxV < dp[sumW].Value)
                            {
                                maxV = dp[sumW].Value;
                                resW = sumW;
                            }
                            else if (maxV == dp[sumW].Value)
                            {
                                resW = Math.Min(resW, sumW);
                            }
                        }
                    }
                }
                sb.AppendLine("Case " + caseCnt + ":");
                sb.AppendLine(maxV.ToString());
                sb.AppendLine(resW.ToString());
                caseCnt++;
            }
            Console.Write(sb);
        }
    }
}

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

typedef int i32;
typedef long long i64;
typedef unsigned int u32;
typedef unsigned long long u64;


template<typename First, typename Second, typename Third>
struct triple {
   First first;
   Second second;
   Third third;
};


#define debug(x)  cerr<<x<<"\n";
#define loop(i,n) for(i32 i = 0; i < n; ++i)
#define pi  pair<i32,i32>
#define ti  triple<i32,i32,i32>
#define mk  make_pair
#define vi  vector<i32>
#define vll vector<i64>
#define fastInOut ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pr(a) for(auto x:a) cout<<x<<" ";
#define prmap(m) for(auto x:m) cout<<x.first<<" "<<x.second<<"\n";
using namespace std;

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

vi V;
const i32 N=7e7+9;
bool prime[N]; 
void SieveOfEratosthenes(){ 
    for (int  p=2; p*p<=N; p++){ 
        if (prime[p] == false){ 
            for (int  i=p*p; i<=N; i += p) 
                prime[i] = true; 
        } 
    } 
    int u=0,mx=0;
    for (int p=2; p<=N; p++){ 
      if (!prime[p]) {
          V.push_back(p);
      }
    }
   
}

i64 c,k,n;
int main(){
    fastInOut
     cin>>n>>k;
     vector<i64>v(n);
     for(int i=0;i<n;i++)
        cin>>v[i];

      sort(v.begin(),v.end());
   
    if(k>=n)
       cout<<0;
    else {
       i64 t=n-k;
       i64 sum=0;
       for(int i=0;i<t;i++)
            sum+=v[i];
       cout<<sum; 
    }
      
    return 0;
}








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

int main() {
string s;
cin >> s;
int ans =10e6;
for(int i=2;i<s.size();i++){
int che =(s.at(i-2)-'0')*100+(s.at(i-1)-'0')*10+s.at(i)-'0';
ans =min(ans,abs(che-753));
}
cout << ans <<endl;
}



Measured memory_bytes: 256
s = input()
t = input()
letters_s = []
letters_t = []
for i in range(len(s)):
  letters_s.append(s[i])
letters_s.sort()
for i in range(len(t)):
  letters_t.append(t[i])
letters_t.sort(reverse=True)
ss = "".join(letters_s)
tt = "".join(letters_t)
if ss < tt:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long v = sc.nextLong();
		long b = sc.nextLong();
		long w = sc.nextLong();
		long t = sc.nextLong();
		if (v != w) {
			if (b > a) {
				double temp = (b-a) * 1.0/(v-w);
				if (t* (v-w) >= (b-a) && temp >=0) {
					System.out.println("YES");
					return;
				}
			} else {
				double temp = (a-b) * 1.0/(v-w);
				if (t* (v-w) >= (a-b) && temp >=0) {
					System.out.println("YES");
					return;
				}
			}
		}
		System.out.println("NO");
		return;

	}

}


Measured memory_bytes: 35840
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String in1 = sc.nextLine().trim();
		double d = Double.parseDouble(in1);
		double ans = Math.sqrt(d);
		int n = (int)(ans / 10.0 * 10);
		System.out.println(n * n);
	}
}

Measured memory_bytes: 20948
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

#include <bits/stdc++.h>
using namespace std;






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


    int a, b; cin >> a >> b;

    if (a == 1) {
    	if (b == 2) {
    		cout << 3;
    	} else {
    		cout << 2;
    	}
    } else if (a == 2) {
    	if (b == 1) {
    		cout << 3;
    	} else {
    		cout << 1;
    	}
    } else if (b == 2) {
    	cout << 1;
    } else {
    	cout << 2;
    }


    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()

using namespace std;

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

  vector<string> ws;

  rep(i,n){
    string w;
    cin >> w;

    if(i != 0 && (v_exists(w, ws) == true || ws[i-1].at(ws[i-1].length()-1)!=w.at(0))){
      cout << "No" << endl;
      return 0;
    }

    ws.push_back(w);
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    long double a, b, c;
    cin >> a >> b >> c;

    if ( (a+b+2*(sqrt(a)*sqrt(b))< c) ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::io::BufRead;

fn main() {
    let stdin = io::stdin();
    for(i, line) in stdin.lock().lines().enumerate() {
        let x: u16 = line.unwrap().trim().parse().unwrap();
        match x {
            0 => break,
            _ => println!("Case {}: {}", i+1, x),
        }
    }
}


Measured memory_bytes: 5044
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
 const ll INF = 1e18;
//const ll MOD = 1e9+7;
//const double pi = 3.14159265358979;
using vl = vector<ll>;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define all(x) (x).begin(), (x).end()

ll N, K;

int Main() {
    cin >> N;
//    vl A(N);
    ll ichi = N%10;
    if(ichi == 2 || ichi == 4 || ichi == 5 || ichi == 7 || ichi == 9) {
        cout << "hon" << endl;
    } else if(ichi == 0 || ichi == 1 || ichi == 6 || ichi == 8) {
        cout << "pon" << endl;
    } else {
        cout << "bon" << endl;
    }
    
    return 0;
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)


int A, B;

void solve() {
    int ans = 0;
    int nums[5];
    FOR(i, A, B + 1) {
        int temp = i;
        REP(j, 5) {
            nums[j] = temp % 10;
            temp /= 10;
        }
        REP(j, 5) {
            if (nums[j] != nums[4 - j]) break;
            if (j == 4) ans++;
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> A >> B;
    solve();
    return 0;
}

Measured memory_bytes: 256
//file_name:ABC89_A.cpp
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // int scan
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // matrix scan
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // string scan
    /*
    string s;
    cin >> s;
    */


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



    int ans = 0;

    ans = n/3;

    cout << ans << endl;
    return 0;
}



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

int cnt[11];
int dgt[11];
int n;
string s;

void printans(){
	for (int i=1;i<=n;i++){
		cout << (char)(dgt[i]+96);
	}
	cout << endl;
	return;
}

void dfs(int x){
	cnt[x]=cnt[x-1];
	for (int i=1;i<=cnt[x];i++){
		dgt[x]=i;
		if (x==n)printans();
		else dfs(x+1); 
	}
	dgt[x]=++cnt[x];
	if (x==n)printans();
	else dfs(x+1); 
}

int main(){
	cin >> n;
	dfs(1);	
}

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

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    int a[100000];
    int c[100000];
    int b=0;
    int ma=0;
    c[0]=0;
    int d=1;
    if(s.at(0)=='0'){
        b++;
        a[0]=0;
    }
    for(int i=1;i<n;i++){
        if(s.at(i)=='1'&&s.at(i-1)=='0'){
            c[d]=i;
            d++;
        }
        if(s.at(i)=='0'&&s.at(i-1)=='1'){
            a[b]=i;
            if(b>=k){
                ma=max(ma,a[b]-c[d-k-1]);
            }
            b++;
        }
    }
    if(ma==0){
        cout << s.size() << endl;
        return 0;
    }
    int l=s.size();
    if(s.at(l-1)=='1'){
    ma = max(ma,l-c[d-k-1]);}
    if(s.at(l-1)=='0'){
        ma=max(ma,l-c[d-k]);
    }
    cout << ma << endl;
}

Measured memory_bytes: 640
/*
Owner: darkxeon
Problem: DDCC Finals
Date: 23/11/2019
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 8;
const int logN = 20, BL = 400;
const double EPS = 3e-16;

int main(){
//	freopen("ex.in", "r", stdin);
//	freopen("ex.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	long long x, y; cin >> x >> y;
	long long sum = 0;
	if(x <= 3){
		sum += (4 - x) * 100000;
	}
	if(y <= 3){
		sum += (4 - y) * 100000;
	}
	
	if(sum == 600000){
		sum += 400000;
	}
	cout << sum;
	return 0;
}


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

typedef long int lint;
typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<long, long> pll;

#define EACH(t, c) for (auto&& t : c)
#define ALL(c) begin(c), end(c)
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl '\n'
#define fk first
#define sv second

const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  llint q, h, s, d;
  int n;

  cin >> q >> h >> s >> d;
  cin >> n;

  llint c = min(q * 4, min(h * 2, s));
  llint res = min(c * n, n / 2 * d + n % 2 * c);
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int R = sc.nextInt();
		sc.close();
		
		if(R < 1200){
			System.out.println("ABC");
		}else if(R < 2800){
			System.out.println("ARC");
		}else{
			System.out.println("AGC");
		}		
	}
}

Measured memory_bytes: 25172
#include <iostream>
#include <climits>
using namespace std;
int main() {
    int n , k;
    cin >> n >> k;
    int arr[n];
    for (int i = 0; i < n; ++i) cin >> arr[i];

    int* dp = new int[n]();
    dp[1] = abs(arr[1]-arr[0]);
    for (int i = 2; i < n; ++i) {
        int minAns = INT_MAX;
        for (int j = 1; j <= k && j <= i; ++j) {
            int x =  dp[i-j] + abs(arr[i]-arr[i-j]);
            minAns = min(minAns , x);
        }

        dp[i] = minAns;
    }

    cout<<  dp[n-1];
}


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

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

    if (a == b) {
        cout << a + b << endl;
    } else if (a > b) {
        cout << a*2 - 1 << endl;
    } else {
        cout << b*2-1 << endl;
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N + 1);
  int ctr = 0;
  for (int i = 1; i < N + 1; i++){
    vec.at(i) = i;
    string s = to_string(vec.at(i));
    if (s.size() % 2 == 1) {
      ctr++;
    }
  }
  cout << ctr << endl;
}

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

using ll = long long;
#define f(a) (a*a*a*a)
#define g(a) (a*a*a)
#define h(a) (a*a)

bool check(ll x, ll n) {
	ll value = n/x;
	ll lim = sqrt(value);
	for (ll a=0; h(a) <= lim; a++) {
		ll b = a-x;
		ll expression = f(a) + g(a)*b + h(a)*h(b) + a*g(b) + f(b);
		if (expression == value) {
			cout << a << " " << b;
			return true;
		}
		b = -a-x;
		expression = f(a) + g(a)*b + h(a)*h(b) + a*g(b) + f(b);
		if (expression == value) {
			cout << -a << " " << b;
			return true;
		} 
	}
	return false;
}

int main() 
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    ll n;
    cin >> n;
    for (ll x=1; h(x) <= n; x++) {
    	if (n%x > 0) continue;
    	if (check(x,n)) return 0;
    	if (check(-x,n)) return 0;
	}
	return 0;
}


Measured memory_bytes: 3720
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    int a, b;
    cin >> a >> b;
    int maxi = max(a+b,a-b);
    maxi = max(maxi,a*b);
    cout << maxi;
    cout << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;


void Main()
{
	int N;
	std::cin >> N;
	std::vector<int> diff(N);
	for (auto& d : diff)
	{
		std::cin >> d;
	}
	boost::sort(diff);
	auto min = diff[N / 2 - 1] + 1;
	auto max = diff[N / 2] + 1;
	std::cout << std::max(0, max - min) << std::endl;

}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 640
#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<ll, ll>;
const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<std::vector<long long>> D) {
    ll loup = 0;
    ll ans = 0;
    rep(i, N) {
        if (D[i][0] == D[i][1]) {
            loup++;
        } else {
            loup = 0;
        }
        ans = max(ans, loup);
    }
    if (ans >= 3) {
        cout << YES << endl;
    } else {
        cout << NO << endl;
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<std::vector<long long>> D(N, std::vector<long long>(2));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 2; j++) {
            scanf("%lld", &D[i][j]);
        }
    }
    solve(N, std::move(D));
    return 0;
}


Measured memory_bytes: 3692
#!/usr/bin/env python3
import sys, math, fractions, itertools, collections, copy, heapq


def solve(Q: int, H: int, S: int, D: int, N: int):
    H = min(H, 2*Q)
    S = min(S, 2*H)
    if 2 * S <= D:
        print(N*S)
    else:
        print(N//2 * D + (N % 2) * S)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    Q = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(Q, H, S, D, N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5048
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=(int)(1e5)+5;
int a[maxn];
int n;

int solve() {
    int w=1,x=0;
    REP(i,1,n) w^=(a[i]-1)&1,x+=a[i]&1;
    if(!w) return 1;
    if(x==1) {
        REP(i,1,n) if(a[i]&1) {
            if(a[i]<3) return 0;
            a[i]--;
        }
        int g=0;
        REP(i,1,n) g=__gcd(g,a[i]);
        REP(i,1,n) a[i]/=g;
        if(solve()) return 0;return 1;
    } return 0;
}

int main() {
    read(n);
    REP(i,1,n) read(a[i]);
    if(solve()) printf("First\n"); else printf("Second\n");
    return 0;
}

Measured memory_bytes: 768
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var input = Console.ReadLine().Split();
            var total = new int[int.Parse(input[1]) + 1];
            for(int i = int.Parse(input[0]); i > 0; --i) {
                var line = Console.ReadLine();
                var array = line.Split().Select(int.Parse).ToArray();
                for (int l = 0; l < total.Length - 1; total[l] += array[l++]);
                var sum = array.Sum();
                total[total.Length - 1] += sum;
                Console.WriteLine("{0} {1}", line, sum);
            }
            Console.WriteLine(String.Join(" ", total.Select(q => q.ToString()).ToArray()));
        }
    }
}

Measured memory_bytes: 6196
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

int main(void){
  string s,s0="",s1="";
  int ans_0=0,ans_1=0;
  cin>>s;
  for(int i=0;i<s.length();i++){
    if(i%2==0){
      if(s[i]!='0'){
        ans_0++;
      }else{
        ans_1++;
      }
    }else{
      if(s[i]!='1'){
        ans_0++;
      }else{
        ans_1++;
      }
    }
  }
  cout<<min(ans_0,ans_1)<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fr(i,n) for(int i=0;i<n;++i)
constexpr int N=200000;
vector<int> e[N];
long long a,b,n,c[N],sz[N],ans[N]={},C[N]={};
auto f=[](auto a){return a*(a+1)/2;};
void dfs(int i,int p=-1){
    auto tmp = C[c[i]];
    for(auto j:e[i]) if(j!=p){
        C[c[i]]=0;
        dfs(j,i);
        sz[i]+=sz[j];
        ans[c[i]]-=f(sz[j]-C[c[i]]);
    }
    C[c[i]]=tmp+sz[i];
}
int main(){
    cin>>n;
    fr(i,n) cin>>c[i],--c[i],sz[i]=1;
    fr(i,n-1){
        cin>>a>>b;--a,--b;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    dfs(0);
    fr(i,n) cout<<ans[i]+f(n)-f(n-C[i])<<'\n';
}

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

int main(){
  int a,b; cin>>a >>b;
  if(a%3 ==  0 || b%3 == 0 || (a+b)%3 == 0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
}

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

typedef long long int LLI;

int N;
LLI S, Q, W;
LLI a[114514];
LLI m[114514];
LLI dp[114514][30];
map<LLI, LLI> cnt;
map<LLI, LLI> cnt2;

void GenerateA() {
  LLI g = S;
  for(int i=0; i<N; i++) {
    a[i] = (g/7) % 10;
    if (g%2 == 0) g = (g/2);
    else g = (g/2) ^ W;
  }
}

int main() {
  while (1) {
    scanf("%d%lld%lld%lld", &N, &S, &W, &Q);
    if ((N|S|W|Q) == 0) return 0;
    GenerateA();
    if (Q <= 30) {
      fill(dp[0],dp[N+1], 0);

      LLI ans = 0;
      for (int i=0; i<N; i++) {
        for (LLI j=0; j<Q; j++) {
          dp[i+1][(j*10+a[i])%Q] += dp[i][j];
        }
        if (a[i]) dp[i+1][a[i]%Q]++;
        ans += dp[i+1][0];
      }

      printf("%lld\n", ans);
    } else {
      cnt.clear();
      m[N-1] = a[N-1] % Q;

      LLI ans = 0;
      if (a[N-1]) {
        ans += cnt[m[N-1]];
        //if (a[N-1]%Q == 0) ans++;
        if (m[N-1] == 0) ans++;
      }
      cnt[m[N-1]]++;

      LLI B = 10;
      for (int i=N-2; i>=0; i--) {
        m[i] = (m[i+1] + a[i]*B) % Q;
        if (a[i]) {
          ans += cnt[m[i]];
          //if (a[i]%Q == 0) ans++;
          if (m[i] == 0) ans++;
        }
        cnt[m[i]]++;
        B = (B*10) % Q;
      }

      printf("%lld\n", ans);
    }
  }
}

Measured memory_bytes: 33828
#include <stdio.h>

int heap[251];

int main(void)
{
    int i, n;
    scanf("%d", &n);

    for(i = 1; i <= n; i++)
        scanf("%d", heap + i);

    for(i = 1; i <= n; i++){
        printf("node %d: key = %d, ", i, heap[i]);
        if(i != 1)
            printf("parent key = %d, ", heap[i / 2]);
        if(2 * i <= n)
            printf("left key = %d, ", heap[2 * i]);
        if(2 * i + 1 <= n)
            printf("right key = %d, ", heap[2 * i + 1]);

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 600
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;


int main(void)
{
	int x, y, a, b;
	scanf("%d %d", &x, &y);
	if (y % 2 == 0)
	{
		b = y / 2 - x;
		a = x - b;
		if (a < 0 || b < 0 || a > x || b > x)
			printf("No\n");
		else
			printf("Yes\n");
	}
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 1660
#include<iostream>
#include<cstdio>
using namespace std;
int a[150];
int f(int n,int k){
    int ans = n-(k+1);
    if(ans < 0) return 0;
    else return ans;
}
int main(){
    int K,T;
    while(scanf("%d%d",&K,&T)!=EOF){
        for(int i = 0;i < T;++i) scanf("%d",&a[i]);
        int ans = 0;
        for(int i = 0;i < T;++i) ans = max(ans,f(a[i],K-a[i]));
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  int x;
  cin >> x;
  if(x>=30)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define    sz    100110
#define    ll    long long int
ll n,c=0,p,q;
ll num[sz];
ll vis[sz];
ll dp[sz];

ll tani(int pos)
{

  if(pos>=n)return 0;
  if(vis[pos]==1)return dp[pos];
  vis[pos]=1;

  return  dp[pos]=min(abs(num[pos]-num[pos+1])+tani(pos+1),abs(num[pos]-num[pos+2])+tani(pos+2));

}

int main()
{
    ll t,i;

    for(i=1;i<sz;i++)num[i]=1000000;

    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>num[i];
    }
    t=tani(1);
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
#include <iterator>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  int ans=1;
  while(ans*2<=N){
    ans*=2;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl cum(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    cum[i + 1] = cum[i] + a;
  }
  ll ans = 1e18;
  rep2(k, 2, n - 1) {
    vl v(4);
    ll in =
        lower_bound(cum.begin(), cum.begin() + k + 1, cum[k] / 2) - cum.begin();
    ll p1 = cum[in], p2 = cum[in - 1], q1 = cum[k] - cum[in],
       q2 = cum[k] - cum[in - 1];
    if(abs(p1 - q1) > abs(p2 - q2)) {
      v[0] = p2;
      v[1] = q2;
    } else {
      v[0] = p1;
      v[1] = q1;
    }
    in = lower_bound(cum.begin() + k + 1, cum.end(), (cum[n] + cum[k]) / 2) -
         cum.begin();
    p1 = cum[in] - cum[k], p2 = cum[in - 1] - cum[k];
    q1 = cum[n] - cum[in], q2 = cum[n] - cum[in - 1];
    if(abs(p1 - q1) > abs(p2 - q2)) {
      v[2] = p2;
      v[3] = q2;
    } else {
      v[2] = p1;
      v[3] = q1;
    }
    // rep(i, 4) cout << v[i] << ' ';
    // cout << endl;
    sort(all(v));
    ans = min(ans, v[3] - v[0]);
  }
  cout << ans << endl;
}

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

const int N = 110;

char str[N];
int cut1,cut2,n;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>str[i];
	for(int i=1;i<=n;i++)
	{
		if(str[i]=='(')	cut1++;
		if(str[i]==')')
		{
			cut1--;
			if(cut1<0) cut2++,cut1 = 0;
		}
	}
	for(int i=1;i<=cut2;i++)
		cout<<"(";
	for(int i=1;i<=n;i++)
		cout<<str[i];
	for(int i=1;i<=cut1;i++)
		cout<<")";
	cout<<"\n";
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ok = false;
    rep(i, s.size())
    {
        if (s[i] == '-')
        {
            ok = true;
            if (i != a)
            {
                No;
                return;
            }
        }
    }
    if (ok)
        Yes;
    else
        No;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;


int main(){
  ll a, b, x;
  cin >> a >> b >> x;

  cout << (a == 0 ? b / x + 1 : b / x - (a - 1) / x) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

int n, k, a[5005], ans;

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	std::sort(a, a + n);
	ans = n;
	for (int i = 0; i < n; i++) {
		long long sum = a[i];
		for (int j = 0, l = 0; l <= n;) {
//			printf("%d - %d + %d: sum %lld\n", a[j], a[l], a[i], sum);
			if (sum < k) {
				if (l == i) l++;
				sum += a[l++];
			}
			else if (sum <= k + a[i] - 1) {
				ans--;
//				printf("a[i] = %d\n", a[i]);
				break;
			}
			else {
				if (j == i) j++;
				sum -= a[j++];
			}
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

struct Mod {
    static ll gcd(ll x, ll y, ll* out_cx, ll* out_cy) {
        if (x < 0) {
            ll d = gcd(-x, y, out_cx, out_cy);
            if (out_cx) {
                *out_cx *= -1;
            }
            return d;
        }
        if (y < 0) {
            ll d = gcd(x, -y, out_cx, out_cy);
            if (out_cy) {
                *out_cy *= -1;
            }
            return d;
        }
        if (x > y) {
            return gcd(y, x, out_cy, out_cx);
        }
        if (x == 0) {
            if (out_cx && out_cy) {
                *out_cx = 0;
                *out_cy = 1;
            }
            return y;
        }
        ll q = y / x;
        ll r = y % x;
        ll d = gcd(r, x, out_cy, out_cx);
        if (out_cx) {
            *out_cx -= q * *out_cy;
        }
        return d;
    }
};

int main() {
    ll A, B;
    cin >> A >> B;
    cout << A * B / Mod::gcd(A, B, nullptr, nullptr) << endl;
}



Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using vi = vector<int>;

#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MAX_SUM = 16000;

bool dp1[8000][MAX_SUM];
bool dp2[8000][MAX_SUM];
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string s;
  int x, y;
  cin >> s >> x >> y;
  int N = s.length();

  vi v[2];
  int count = 0;
  int turn = 0;
  rep(i, N) {
    if (s[i] == 'F')
      ++count;
    else {
      v[turn].push_back(count);
      turn = 1 - turn;
      count = 0;
    }
  }
  v[turn].push_back(count);

  dp1[0][MAX_SUM/2+v[0][0]] = true;
  loop(i, 1, v[0].size()) rep(sum, MAX_SUM) {
    if (!dp1[i-1][sum])
      continue;
    if (sum+v[0][i] < MAX_SUM)
      dp1[i][sum+v[0][i]] = dp1[i-1][sum];
    if (sum - v[0][i] >= 0)
      dp1[i][sum-v[0][i]] = dp1[i-1][sum];
  }

  dp2[0][MAX_SUM/2] = true;
  rep(i, v[1].size()) rep(sum, MAX_SUM) {
    if (!dp2[i][sum])
      continue;
    if (sum+v[1][i] < MAX_SUM)
      dp2[i+1][sum+v[1][i]] = dp2[i][sum];
    if (sum - v[1][i] >= 0)
      dp2[i+1][sum-v[1][i]] = dp2[i][sum];
  }

  if (dp1[v[0].size()-1][x+MAX_SUM/2] && dp2[v[1].size()][y+MAX_SUM/2])
    printf("Yes\n");
  else
    printf("No\n");


  return 0;
}


Measured memory_bytes: 125824
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int maxn=200020,mod=998244353;
#define MP make_pair
#define PB push_back
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn];
vector<PII> v;
bool add(int x,int upr){
	if(!x) return false;
	if(!v.empty()) assert(x>=v.back().first);
	if(!v.empty() && x==v.back().first){
		v.back().second++;
		if(v.back().second>upr){
			v.pop_back();
			return add(x-1,upr);
		}
	}
	else v.PB(MP(x,2));
	return true;
}
bool check(int upr){
	v.clear();
	FOR(i,1,n) if(a[i]<=a[i-1]){
		while(!v.empty() && v.back().first>a[i]) v.pop_back();
		if(!add(a[i],upr)) return false;
	}
	return true;
}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	bool flag=true;
	FOR(i,1,n-1) flag&=a[i]<a[i+1];
	if(flag) return puts("1"),0; 
	int l=2,r=n;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%d\n",l);
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)
 

def makebin(arr):
    ret = 0
    for num in arr:
        ret += 2 ** (num - 1)

    return ret

def main():
    n, m = getList()
    dp = [INF] * (2 ** n)
    dp[0] = 0
    for i in range(m):
        a, b = getList()
        tgt = getList()
        kagi = makebin(tgt)
        for i, d in enumerate(dp):
            if d != -1:
                dp[i|kagi] = min(dp[i|kagi], d + a)
        # print(dp, kagi)

    if dp[-1] == INF:
        print(-1)
        return 
    print(dp[-1])
    # print(0&1)?






 
if __name__ == "__main__":
    main()
   

Measured memory_bytes: 74896
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
  int n, weight;
  std::cin >> n >> weight;
  std::vector<std::vector<int> > dp(n + 1, std::vector<int>(weight + 1, 0));
  std::vector<int> v(n), w(n);
  for (int i = 0; i < n; i++) {
    std::cin >> v[i] >> w[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= weight; j++) {
      if(j + w[i] <= weight){
        dp[i + 1][j + w[i]] = std::max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
      }
      dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
    }
  }
  std::cout << dp[n][weight] << std::endl;
  return 0;
}

Measured memory_bytes: 6724
package main

import (
	"fmt"
)

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

	length := len(str)

	for i := 0; i < length-2; i++ {
		if str[i] == str[i+2] {
			fmt.Printf("%d %d\n", i+1, i+3)
			return
		}
		if str[i] == str[i+1] {
			fmt.Printf("%d %d\n", i+1, i+2)
			return
		}
	}
	if str[length-2] == str[length-1] {
		fmt.Printf("%d %d", length-1, length)
	} else {
		fmt.Println("-1 -1")
	}
}

Measured memory_bytes: 2580
#include <stdio.h>

int isPrime(int p) {
  int i;

  if(p > 2 && p % 2 == 0)
    return 0;

  for(i = 3;i * i <= p;i += 2) {
    if(p % i == 0)
      return 0;
  }

  return 1;
}

int main() {
  int n, i, t, cnt = 0;

  scanf("%d", &n);
  for(i = 0;i < n;i++) {
    scanf("%d", &t);
    if(isPrime(t))
      cnt++;
  }

  printf("%d\n", cnt);

  return 0;
}



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

using namespace std;
using namespace std::chrono;

#define rep(i,a,b) for(int i = a;i<(b);++i)
#define trav(a,v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,T,k,q,p;

ll mul[3][3] = {0};

int main()
{
   // freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    mul[0][1] = 3;
    mul[0][2] = 6;
    mul[1][1] = 2;
    mul[1][2] = 2;
    mul[2][1] = 1;
    mul[2][2] = 3;
    ll state = 0;
    ll ans = 1;
    cin >> n;
    string s1;
    string s2;
    cin >> s1 >> s2;
    ll c1 = 0;
    while(c1 < n){
        ll nstate = 2;
        if(s1[c1] == s2[c1]){
            nstate = 1;
        }
        ans *= mul[state][nstate];
        ans %= big;
        c1 += nstate;
        state = nstate;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    X,Y = input_number_list()
    print(X+Y//2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#define MAX 20001
#define nNIL -1
 
typedef struct{
  int p, l, r;
}Tree;
Tree node[MAX];
int n;
 
void preParse(int u) {
    if (u == nNIL) return;
    printf(" %d", u);
    preParse(node[u].l);
    preParse(node[u].r);
}
 
void inParse(int u) {
    if (u == nNIL ) return;
    inParse(node[u].l);
    printf(" %d", u);
    inParse(node[u].r);
}
 
void postParse(int u) {
    if (u == nNIL ) return;
    postParse(node[u].l);
    postParse(node[u].r);
    printf(" %d", u);
}
 
int main(int argc, char const* argv[])
{
    int i, v, l, r, root;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        node[i].p = nNIL;
    }
 
    for ( i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        node[v].l = l;
        node[v].r = r;
        if(l != nNIL) node[l].p = v;
        if(r != nNIL) node[r].p = v;
    }
 
    for ( i = 0; i < n; i++) {
        if (node[i].p == nNIL) {
            root = i;
        }
    }
 
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");
    return 0;
}



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

#define pb push_back
#define F first
#define S second
#define fo(i,a,b)  for(int i = a; i < b; i++)

using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
#define Mosta     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ReadFile            freopen("input.in","r",stdin)
#define WriteFile           freopen("output.txt","w",stdout)
const ll mod7 = 1000000007,mod = 1000000000,OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi=acos(-1);
const ld rad=Pi/180.0;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll nCr (ll n,ll m)
{
    return(m == 0)?1:n*nCr(n-1,m-1)/m;
}
/*****************************************************/

int main()
{
    ll n , x = 1;
    char a[100005];
    cin >> n;

    for(int i = 0; i < n; ++i)
        cin >> a[i];

    for(int i = 0; i < n-1; ++i)
        if(a[i] != a[i+1])
            x++;

    cout << x << "\n";

	return 0;
}


Measured memory_bytes: 384
from collections import Counter as c
N = int(input())

dup = {}
ans = dict(c(list(input())))
for _ in range(N-1):
	s = dict(c(list(input())))
	tmp = {}
	for ansk, ansv in ans.items():
		tmp[ansk] = min([ansv, s.get(ansk, 0)])
	ans = tmp

for c in sorted(list(ans.items()), key=lambda x: x[0]):
	print(c[0]*c[1], end= '')
print()

Measured memory_bytes: 3316
#include <stdio.h>

int main(void) 
{
	
	char hiduke[10]; 
	scanf("%s",hiduke);
	hiduke[0] = '2';
	hiduke[1] = '0';
	hiduke[2] = '1';
	hiduke[3] = '8';

	printf ("%s",hiduke);
	return 0;
	
	
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc155() {
	ll a, b, c;
	ll ans = 0;
	string str;

	cin >> a >> b >> c;

	if (a == b) {
		if (a != c) {
			// a == b != c
			str = "Yes";
		}
		else {
			// a == b == c
			str = "No";
		}
	}
	else {
		// a != b
		if (b == c) {
			// a != b == c
			str = "Yes";
		}
		else if (a == c) {
			// a == c != b
			str = "Yes";
		}
		else {
			// a != b != c
			str = "No";
		}
	}

	cout << str << "\n";
}

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

	solve_abc155();

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ans = 0;
    rep(i, n) {
        if (i % 2 == 0 && a[i] % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  double a,b,c;
  double S,L2, L, h;

  scanf("%lf %lf %lf",&a,&b,&c);

  S = 0.5*a*b*sin(c*3.14159265359/180);
  L2 = a*a+b*b-2*a*b*cos(c*3.1415926359/180);
  L = sqrt(L2)+a+b;
  h = 2*S/a;

  printf("%.11lf\n%.11lf\n%.11lf\n",S ,L,h); 

  return 0;
}



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

int main() {
    int N; cin >> N;
    vector<long long> dp(N+1, N);
    dp[0] = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = 1; i+j <= N; j *= 6) dp[i+j] = min(dp[i+j], dp[i] + 1);
        for(int j = 1; i+j <= N; j *= 9) dp[i+j] = min(dp[i+j], dp[i] + 1);
    }
    
    cout << dp[N] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	int x[n], y[n];
	rep(i, n) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y, y + n);
	int p = y[n / 2 - 1], q = y[n / 2];
	rep(i, n) {
		if (x[i] <= p)
			cout << q << endl;
		else
			cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 3712
def resolve():
    A, B, K = map(int, input().split())
    if 2*K > B-A+1:
        for _ in range(B-A+1):
            print(A+_)
    else:
        for i in range(K):
            print(A+i)
        for j in range(K):
            print(B-K+j+1)
resolve()

Measured memory_bytes: 3060
from math import sin, cos, pi, sqrt
a, b, c = map(int, input().split())
s = a*b*sin(pi*c/180)/2
c = sqrt(a**2 + b**2 -a*b*2*cos(pi*c/180))
h = 2*s/a
print(s)
print(a+b+c)
print(h)


Measured memory_bytes: 5708
n=int(input())
seq=list(map(int,input().split()))
p=1
f=1
c=int(1e18)
if 0 in seq:
    print(0)
else:
    for i in range(n):
        p*=seq[i]
        if p>c:
            print(-1)
            f=0
            break
            
    if f==1:
        print(p)



Measured memory_bytes: 21772