akhauriyash/Code-Regression huggingface dataset:
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
//end of libraries ;
#define INF 9999999999
#define N 300003
#define F first
#define S second
#define pb push_back
#define ll long long
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll x , c , ans , c1;
int main(){
fcin;
	cin>>x;
	c = x / 500;
	c1 = x%500;
	ans += c*1000;
	c1 /=5;
	c1*=5;
	ans+=c1;
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int s = sc.nextInt();
      int w = sc.nextInt();
      if(w>=s){
      	System.out.println("unsafe");
      }else{
        System.out.println("safe");
      }
    }
}


Measured memory_bytes: 35684
#include <iostream>
#include <string>
using namespace std;
    int main(){
    string a,b;
    cin >> a >> b;
    if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    }

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

int main() {
  string s;
  cin >> s;
  if (s == "ABC"){
    cout << "ARC" << endl;
  }else {
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 3628
import java.util.*;
 
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] S = sc.next().toCharArray();

        long ans = 0;
        int up = 0;
        int down = 0;
        for (int i = 0; i < S.length; i++) {

            if (S[i] == '<') {
                up++;
            } else {
                down++;
            }

            if (i == S.length-1 || S[i] == '>' && S[i+1] == '<') {
                if (up == down) {
                    ans += sum(up) + sum(down) - up;
                } else if (up < down) {
                    ans += sum(up-1) + sum(down);
                } else {
                    ans += sum(up) + sum(down-1);
                }
                up = 0;
                down = 0;
            }
        }
        System.out.println(ans);
    }

    private static long sum(int n) {
        return (long)n*(n+1)/2;
    }
}


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

using namespace std;

int main(){
    int A,B,Q; cin>>A>>B>>Q;
    int sw,se,tw,te;
    int64_t s[100005];//神社座標
    int64_t t[100005];//寺座標
    int64_t x[100005];//Q個の問の出発座標

    for(int i=1;i<=A;i++) cin>>s[i];
    for(int i=1;i<=B;i++) cin>>t[i];
    for(int i=1;i<=Q;i++) cin>>x[i];
    s[0]=-1000000000000;
    s[A+1]=1000000000000;
    t[0]=-1000000000000;
    t[B+1]=1000000000000;

    for(int i=1;i<=Q;i++){
        //x[i]より西にある一番東の(と東にある一番西の)を探す

        int l=0,r=A+1;
        while(r-l!=1){//まずは神社
            int c=(l+r)/2;
          	if(s[c]<x[i]) l=c;
            else r=c;
        }
        sw=l;
        se=r;

        l=0,r=B+1;
        while(r-l!=1){//まずは神社
            int c=(l+r)/2;
          	if(t[c]<x[i]) l=c;
            else r=c;
        }
        tw=l;
        te=r;
      
      	int64_t SW=s[sw],SE=s[se],TW=t[tw],TE=t[te],X=x[i];

        printf("%lld\n",min({abs(X-SW)+abs(SW-TW),abs(X-SW)+abs(SW-TE),abs(X-SE)+abs(SE-TW),abs(X-SE)+abs(SE-TE),abs(X-TW)+abs(TW-SW),abs(X-TW)+abs(TW-SE),abs(X-TE)+abs(TE-SW),abs(X-TE)+abs(TE-SE)}));   
    }
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <limits.h>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t;
string s;

vector<ll> v;

int main() {
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == '0') {
			v.push_back(0);
		}
		else if (s[i] == '1') {
			v.push_back(1);
		}
		else if (s[i] == 'B') {
			if (v.size()) {
				v.pop_back();
			}
		}
	}
	REP(i, v.size()) {
		cout << v[i];
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}


int main(){
    string s; cin >> s;
    int a[4];
    int sum = 0;
    rep(i,4){
        a[i] = s[i]-'0';
        sum += a[i];
    }


    
    for(int bit =0;bit<(1<<3);bit++){
        bool op[4]={1,1,1,1};
        int x = sum;
        
        for(int i=1;i<=3 ;i++){
            if(bit & (1<<(i-1))){
                op[i]=0;
                x -= 2*a[i];
            }
        }
        if(x == 7){
            char op1 = (op[1] ? '+' : '-');
            char op2 = (op[2] ? '+' : '-');
            char op3 = (op[3] ? '+' : '-');
            
            printf("%d%c%d%c%d%c%d=7\n",a[0],op1,a[1],op2,a[2],op3,a[3]);
            return 0;
            
        }
    }
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char s[N];
int main(){
	scanf("%s",s); int len=strlen(s),cnta=0;
	long long ans=0;
	for(int i=0; i<len;){
		if(s[i]=='A')++cnta,++i;
		else if(s[i]=='B'&&s[i+1]=='C')ans+=cnta,i+=2;
		else cnta=0,++i;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main(int argc, char const *argv[])
{
	int a, b, c, answer;
	
	answer = 0;
	std::cin >> a >> b >> c;
	for (int i = a;i <= b;i++) {
		if ((c % i) == 0) {
			answer++;
		}
	}
	std::cout << answer << std::endl;
	
	return 0;
}

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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N; cin >> N;
    vector<P> as(N);
    int ai;
    rep(i, N) {
        cin >> ai;
        as[i] = make_pair(ai, i+1);
    }
    sort(as.begin(), as.end());
    rep(i, N) {
        cout << as[i].second << " ";
    }
    cout << endl;
    return 0;
}

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

int main(void){
    char sa[101], sb[101], sc[101]; 
    int cnt_a = 0, cnt_b = 0, cnt_c = 0;
    char now; // 1 = a, 2 = b, 3 = cさん
    now = 'a';

    scanf("%s%s%s", sa, sb, sc);

    while(1){  
        if(now == 'a'){
            now = sa[cnt_a];
            cnt_a++;
            if(cnt_a > strlen(sa)){
                printf("A\n");
                break;
            }
        }else if(now == 'b'){
            now = sb[cnt_b];
            cnt_b++;
            if(cnt_b > strlen(sb)){
                printf("B\n");
                break;
            }
        }else if(now == 'c'){
            now = sc[cnt_c];
            cnt_c++;
            if(cnt_c > strlen(sc)){
                printf("C\n");
                break;
            }
        }
//        printf("now = %c cnta=%d cntb=%d cntc=%d\n", now, cnt_a, cnt_b, cnt_c);
    }

    return 0;

} 


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

const int maxn = 200010;
char s[maxn];
stack<int> st;

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'S') {
            st.push(1);
        } else {
            if (st.size()) st.pop();
            else ans++;
        }
    }
    printf("%d\n", ans + st.size());
    return 0;
}

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

using namespace std;

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

    vector<vector<int>> x(n);

    for (int i = 0; i < n; ++i)
    {
        x[i].resize(d);

        for (int j = 0; j < d; ++j)
        {
            cin >> x[i][j];
        }
    }

    double temp;
    int ans = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (i == j) break;

            temp = 0.0;

            for (int k = 0; k < d; ++k)
            {
                temp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }

            if (sqrt(temp) == floor(sqrt(temp)))
            {
                ++ans;
            }
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD				1000000007
#define MOD1			998244353
#define EPS				1e-9
#define fore(i, b, e)	for(ll i = b; i < e; i++)
#define forg(i, b, e, m)	for(ll i = b; i < e; i+=m)

using namespace std;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<ll, ll>  ii;
typedef vector<ll>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const ll tam = 10000010;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	//freopen("asd.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	ll a, b, q;
	ll x;
	cin>>a>>b>>q;
	set<ll> a1,a2, b1, b2;
	while(a--)
	{
		cin>>x;
		a1.insert(x);
		a2.insert(-x);
	}
	while(b--)
	{
		cin>>x;
		b1.insert(x);
		b2.insert(-x);
	}
	while(q--)
	{
		cin>>x;
		ll res = 1e15;
		if(a1.lower_bound(x) != a1.end())
		{
			ll x1 = *a1.lower_bound(x);
			if(b1.lower_bound(x1) != b1.end())
			{
				res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1)));
			}
			if(b2.lower_bound(-x1) != b2.end())
			{
				res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1)));
			}
		}
		if(a2.lower_bound(-x) != a2.end())
		{
			ll x1 = -*a2.lower_bound(-x);
			if(b1.lower_bound(x1) != b1.end())
			{
				res = min(res, abs(x - x1) + abs(x1 - *b1.lower_bound(x1)));
			}
			if(b2.lower_bound(-x1) != b2.end())
			{
				res = min(res, abs(x - x1) + abs(x1 + *b2.lower_bound(-x1)));
			}
		}
		if(b1.lower_bound(x) != b1.end())
		{
			ll x1 = *b1.lower_bound(x);
			if(a1.lower_bound(x1) != a1.end())
			{
				res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1)));
			}
			if(a2.lower_bound(-x1) != a2.end())
			{
				res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1)));
			}
		}
		if(b2.lower_bound(-x) != b2.end())
		{
			ll x1 = -*b2.lower_bound(-x);
			if(a1.lower_bound(x1) != a1.end())
			{
				res = min(res, abs(x - x1) + abs(x1 - *a1.lower_bound(x1)));
			}
			if(a2.lower_bound(-x1) != a2.end())
			{
				res = min(res, abs(x - x1) + abs(x1 + *a2.lower_bound(-x1)));
			}
		}
		cout<<res<<'\n';
	}
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constralls?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs ll?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 20096
use std::cmp::{max, min};

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//usage
//input! {
//  h: i32;
//  v: [i32; n]
//  x: [[i32; n]; m]
//  f: chars <- Vec<char>
//}

fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        x: i64,
        y: i64
    }
    let min_a = min(a, c * 2);
    let min_b = min(b, c * 2);
    let min_ab = min(a + b, c * 2);
    let mut ans = min_ab * min(x, y);
    if x > y {
        ans += (x - y) * min_a;
    } else if x < y {
        ans += (y - x) * min_b;
    } else {}
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = input()
K = int(input())
N = len(s)

ans = []

for i in range(min(K, N)):
  for j in range(N-i):
    ans.append(s[j:j+i+1])
  
ans.sort()
count = 0
now = '0'
for i in range(len(ans)):
  if ans[i] != now:
    count += 1
    now = ans[i]
    if count == K:
      print(now)
      exit()
    


Measured memory_bytes: 4340
package main

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

func main() {
	N, D := getStdinInt2()
	ans := 0
	for i := 0; i < N; i++ {
		X, Y := getStdinInt2()
		if dis(X, Y) <= float64(D) {
			ans++
		}
	}
	fmt.Printf("%d\n", ans)
}

func dis(x, y int) float64 {
	return math.Sqrt((float64)(x*x + y*y))
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 15220
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s,t;
  cin >> s >> t;
  int s_l = s.size();
  int t_l = t.size();
  /*if(s_l<t_l){
    cout << "UNRESTORABLE" << '\n';
    return 0;
  }*/
  vector<int> ok_pos;
  REP(i,s_l-t_l+1){
    bool flag = true;
    REP(j,t_l){
      if(s[i+j]!='?' && s[i+j]!=t[j]){
        flag = false;
        break;
      }
    }
    if(flag) ok_pos.push_back(i);
  }
  if(ok_pos.size()==0){
    cout << "UNRESTORABLE" << '\n';
  }else{
    int pos = ok_pos.back();
    REP(i,t_l) s[pos+i] = t[i];
    REP(i,s_l) if(s[i]=='?') s[i] = 'a';
    cout << s << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		

      
		for(int i = 1;i <= 5 ; i++){
          int x = sc.nextInt();
          if(x==0){
          	System.out.println(i);
          }
        }
		
	}
}

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

using namespace std;

void dfs(int u, const vector<vector<pair<int, int>>> &g, vector<int> &vis) {
    vis[u] = 1;
    for (const auto p : g[u]) {
        int v = p.first, c = p.second;
        if (!vis[v]) {
            dfs(v, g, vis);
        }
    }
}
int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);

    int N, M, P;
    cin >> N >> M >> P;
    vector<vector<pair<int, int>>> g(N);
    for (int i = 0; i < M; ++i) {
        int A, B, C;
        cin >> A >> B >> C;
        g[A - 1].emplace_back(B - 1, -(C - P));
    }
    vector<int> rem(N, 0);
    for (int u = 1; u < N; ++u) {
        vector<int> vis(N, 0);
        dfs(u, g, vis);
        if (!vis[N - 1]) {
            rem[u] = 1;
        }
    }
    {
        vector<int> vis(N, 0);
        dfs(0, g, vis);
        for (int u = 1; u < N; ++u) {
            if (!vis[u]) {
                rem[u] = 1;
            }
        }
    }

    vector<int> dist(N, 1'000'000'000), par(N, -1);
    dist[0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int u = 0; u < N; ++u) {
            if (rem[u]) continue;
            for (const auto p : g[u]) {
                int v = p.first, c = p.second;
                if (rem[v]) continue;
                if (dist[u] + c < dist[v]) {
                    dist[v] = dist[u] + c;
                    par[v] = u;
                }
            }
        }
    }
    for (int u = 0; u < N; ++u) {
        if (rem[u]) continue;
        for (const auto p : g[u]) {
            int v = p.first, c = p.second;
            if (rem[v]) continue;
            if (dist[u] + c < dist[v]) {
                cout << -1 << "\n";
                return 0;
            }
        }
    }
    cout << max(-dist[N - 1], 0) << "\n";

    return 0;
}

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

int main() {
    int N ,K;
    cin >> N >> K;
    int ketasu = 0;
    int X = 0;
    
    while(true){
        int Y = 1;
        for(int i=0; i<ketasu; i++){
            Y = Y*K;
        }
        Y = Y*(K-1);
        X += Y;
        if(N  > X){
            ketasu ++;
        }
        else {
            break;
        }
    }
    cout << ketasu + 1 << endl;
}

Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll n = inp1;
    string s = inp1, t = inp1;
    REP(i, n) {
        cout << s[i] << t[i];
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x),end(x)

#define forn(i, n) for (int i = 0; i < n; ++i)
#define rforn(i, n) for (int i = n - 1; i >= 0; --i)

const int N = 2e5 + 5, M = 1e9 + 7; // 998244353
const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};
const ll INF = 1e18 + 10LL;
const ld PI = 4.0 * atan((ld) 1.0), EPS = 1e-6;
const char nl = '\n';

template <typename T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> inline T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void ckmin(T& a, T b) { a = min(a, b); }
template <class T> void ckmax(T& a, T b) { a = max(a, b); }
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string YN(bool x) { return x ? "YES" : "NO"; }

void solve(int tcn) {
	ll n;
	cin >> n;
	ll psum = 26LL;
	int len = 1;
	while (n > psum) {
		n -= psum;
		psum *= 26LL;
		++len;
	}
	string ans(len, '0');
	--n;
	for (int i = len - 1; i >= 0; --i) {
		ans[i] = n % 26 + 'a';
		n /= 26;
	}
	cout << ans << nl;
}

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

	int t = 1; //cin >> t;
	for (int i = 1; i <= t; ++i) {
		solve(i);
	}
	return 0;
}


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

int main() {
    int n; cin >> n;
    vector<long long> a(n+1), b(n);
    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long e = min(b[i], a[i]);
        b[i] -= e; a[i] -= e; ans += e;
        long long ee = min(b[i], a[i+1]);
        a[i+1] -= ee; ans += ee;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys
import math
from fractions import gcd
import bisect
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 属している県ごとに年代をソートする
# ソート後、元の年代が属している位置を二分探索で見つける

N, M =  map(int, sys.stdin.readline().split())

org =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(M)]

d = {}

for o in org:
    d.setdefault(o[0], [])
    d[o[0]].append(o[1])

for l in d.values():
    l.sort()

for o in org:
    order = bisect.bisect_left(d[o[0]],o[1]) + 1
    print(str(o[0]).zfill(6) + str(order).zfill(6))

Measured memory_bytes: 102868
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	int t = 1;
	//cin >> t;
	while(t--){
		int a[5], ans = 0;
		for (int i = 0; i < 5; ++i)
		{
			cin >> a[i];
			if (a[i] == 0)
				ans = i + 1;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var S string
	fmt.Scanf("%s\n", &S)
	ok := true
	for idx, rs := range []rune(S) {
		s := string(rs)
		i := idx + 1
		if s == "U" || s == "D" {
			continue
		}
		if s == "R" && i%2 == 0 {
			ok = false
			break
		}
		if s == "L" && i%2 != 0 {
			ok = false
			break
		}
	}
	if ok {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  string s;
  cin >> s;
  int n = s.size();

  // cout << "test" << endl;

  if(s[0] == '0' || s[n-1] == '1') {
    cout << -1 << endl;
    return 0;
  }

  REP(i, n-1) {
    if(s[i] != s[n-2-i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int now = 1, tmp = 0;
  V<int> v(1, 0);
  FOR(i, 1, n) {
    if(s[i] == '1') {
      // now から v の集合につなぐ
      for(auto j: v) {
        cout << now+1 << " " << j+1 << endl;
        tmp++;
      }
      v.clear();
      v.PB(now);
    } else {
      v.PB(now);
    }
    now++;
  }
  cout << n << " " << n-1 << endl;

  return 0;
}


Measured memory_bytes: 2500
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		int ans = 0;

		for (Integer i = A; i <= B; i++) {
			String s = i.toString();
			StringBuffer sb = new StringBuffer(s);
			String sR = sb.reverse().toString();
			if (s.equals(sR))
				ans++;
		}

		System.out.println(ans);
	}
}

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

int a[4][4],b,vis[4][4],n;

int main()
{
	for(int i=1;i<=3;++i)
		for(int j=1;j<=3;++j)
			scanf("%d",&a[i][j]);
	scanf("%d",&n);
	for(int _=1;_<=n;++_) {
		scanf("%d",&b);
		for(int i=1;i<=3;++i)
			for(int j=1;j<=3;++j)
				if(a[i][j]==b) vis[i][j]=1;
	}
	int f,g;
	for(int i=1;i<=3;++i) {
		f=0,g=0;
		for(int j=1;j<=3;++j) {
			if(vis[i][j]) f++;
			if(vis[j][i]) g++;
		}
		if(f==3||g==3) {
			printf("Yes");
			return 0;
		}
	}
	f=0,g=0;
	for(int i=1;i<=3;++i) {
		if(vis[i][i]) f++;
		if(vis[4-i][i]) g++;
	}
	if(f==3||g==3){ 
		printf("Yes");
		return 0;
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static boolean[] primes;

	static void primeSet(final int MAX){
		primes = new boolean[MAX+1];

		primes[2] = true;
		for(int i=3;i<=MAX;i+=2){
			primes[i] = true;
		}
		int rt = (int) Math.sqrt(MAX);
		for(int i=3;i<=rt;i+=2){
			if(primes[i]){
				for(int j=i*2;j<=MAX;j+=i){
					primes[j] = false;
				}
			}
		}
	}

	@SuppressWarnings("unused")
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		primeSet(1000000);

		while(true){
			int a = stdIn.nextInt();
			int d = stdIn.nextInt();
			int n = stdIn.nextInt();
			int cnt = 0;

			if(a==0&&d==0&&n==0){
				break;
			}

			for(int i=a;;i+=d){
				if(primes[i]){
					cnt++;
				}
				if(cnt==n){
					System.out.println(i);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 13000
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int n;
bool check(int n){
    for(int i=2;i*i<=n;i++)if(n%i==0)return false;
    return true;
}
int main(){
    scanf("%d",&n);
    for(int i=n;;i++){
        if(check(i)){
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3

N, L = map(int, input().split())
a = list(map(int, input().split()))

sums = [a[i]+a[i+1] for i in range(N-1)]

maxind, maxval = max(enumerate(sums), key=lambda x:x[1])
if maxval >= L:
    print("Possible")
    for i in range(maxind):
        print(i+1)
    for j in reversed(range(maxind, N-1)):
        print(j+1)
else:
    print("Impossible")


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

int rabit[200000] = {};

int main()
{
	
	int r, N, cnt = 0;
	
	cin >> N;
	for(int i = 1 ; i <= N; i++){
		cin >> r;
		rabit[i] = r;
		
		if(rabit[r] == i) cnt++;
	}
	cout << cnt << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double A, V;
    cin >> A >> V;
    double B, W;
    cin >> B >> W;
    double T;
    cin >> T;
    if (A <= B) {
        double time = (B - A) / (V - W);
        if (time >= 0 && time <= T) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    } else {
        double time = (A - B) / (V - W);
        if (time >= 0 && time <= T) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3692
#include <cstdio>
#include <vector>
using namespace std;
 
int unko(int a, int k) {
        if (a < k) return 0;
        if (a % k == 0) return a / k;
        int hoge = a / k + 1;
        int fuga = a % k - 1;
        return unko(a - (fuga / hoge + 1) * hoge, k);
}
 
int main() {
        int n;
        scanf("%d", &n);
        long long ans = 0;
        for (int i = 0; i < n; i ++) {
                long long a, k;
                scanf("%lld%lld", &a, &k);
                ans ^= unko(a, k);
        }
        puts(ans ? "Takahashi" : "Aoki");
        return 0;
}


Measured memory_bytes: 128
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define mod (int)1000000007
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
constexpr double eps = DBL_EPSILON;
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b >> 1, m);
	return memo * memo % m;
}
int n;
string s;
map<string, int> mp;
vector<string> ans;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> s;
		mp[s]++;
	}
	int ma = 0;
	for (auto i : mp) {
		chmax(ma, i.second);
	}
	for (auto i : mp) {
		if (i.second == ma) {
			cout << i.first << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 25216
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n;cin>>n;
	ll a[n];For(i,0,n) cin>>a[i];
	ll index[n];For(i,0,n) index[i]=i+1;
	bool visited[n];
	memset(visited,0,sizeof(visited));
	vector<ll> ans;
	For(i,0,n){
		if(a[i]==index[i] && !visited[i]){
			bool check=1;
			For(j,i+1,n) if(index[j]-1<a[j] && !visited[j]) check=0;
			if(check){
				visited[i]=1;
				ans.pb(a[i]);
				For(j,i+1,n) index[j]--;
				i = -1;
				continue;
			}
		}
	}
	if(ans.size()!=n){
		cout<<-1<<endl;
	}else{
		reverse(ans.begin(),ans.end());
		for(ll x:ans){
			cout<<x<<endl;
		}
	}










	
}

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

int next_combination(int bit) {
  int x = bit & -bit;
  int y = bit + x;
  return (((bit & ~y) / x) >> 1) | y;
}

int main() {
  int n, k; cin >> n >> k;
  k--;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  if (k == 0) {
    cout << 0 << endl;
    return 0;
  }
  n--;
  long long res = 1001001001001;
  int bit = (1 << k) - 1;
  for (; bit < (1 << n); bit = next_combination(bit)) {
    long long highest = a[0];
    long long tmp = 0;
    for (int i = 0; i < n; i++) {
      if ((bit >> i) & 1) {
        if (a[i+1] <= highest) {
          tmp += (highest - a[i+1] + 1);
          highest += 1;
        } else {
          highest = a[i+1];
        }
      } else {
        if (highest < a[i+1]) {
          highest = a[i+1];
        }
      }
    }
    res = min(res, tmp);
  }
  cout << res <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
typedef long long ll;
const int MAXN = 100;
char S[MAXN + 5];
int main() {
	ll K; scanf("%s%lld", S + 1, &K);
	int n = strlen(S + 1);
	bool flag = true;
	for(int i=1;i<n;i++)
		if( S[i] != S[i+1] ) flag = false;
	if( flag ) {
		printf("%lld\n", n*K/2);
		return 0;
	}
	else {
		if( S[1] != S[n] ) {
			ll ans = 0;
			for(int i=1;i<=n;) {
				int j = i;
				while( S[j] == S[i] )
					j++;
				ans += (j - i) / 2;
				i = j;
			}
			printf("%lld\n", ans*K);
		}
		else {
			ll ans = 0, a = 0, b = 0;
			for(int i=1;i<=n;) {
				int j = i;
				while( S[j] == S[i] )
					j++;
				if( i == 1 ) a = j - i;
				else if( j == n + 1 ) b = j - i;
				else ans += (j - i) / 2;
				i = j;
			}
			printf("%lld\n", ans*K + a/2 + b/2 + (a + b)/2*(K-1));
		}
	}
}

Measured memory_bytes: 128
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n;
  	cin >> n;
  	int a[n],b[n];
  	for(int i=0;i<n;i++){
      cin >> a[i];
      b[a[i]-1] = i+1;}
  	for(int i=0;i<n;i++)
      cout << b[i] << " ";
  return 0;
}

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

using namespace std;

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

int h, w;
long long ans, cnt[2];
int a[Maxn][Maxn], vis[Maxn][Maxn];

inline void dfs(int x, int y)
{
    cnt[a[x][y]]++;
    vis[x][y] = 1;
    for(int i = 0, nx, ny; i < 4; ++i)
    {
        nx = x+dx[i]; ny = y+dy[i];
        if(nx < 1 || ny < 1 || nx > h || ny > w
        || vis[nx][ny] || a[x][y] == a[nx][ny]) continue;
        dfs(nx, ny);
    }
}

int main()
{
    cin >> h >> w;
    for(int i = 1; i <= h; ++i)
    {
        char c;
        for(int j = 1; j <= w; ++j)
        {
            cin >> c;
            if(c == '#') a[i][j] = 1;
            // else a[i][j] = 0;
        }
    }

    for(int i = 1; i <= h; ++i)
    {
        for(int j = 1; j <= w; ++j)
        {
            if(!vis[i][j])
            {
                cnt[0] = cnt[1] = 0;
                dfs(i, j);
                ans += cnt[0]*cnt[1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10240
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int convert(int base, int v) {
	vector<int> digits;
	while(v > 0) {
		if(v % base >= 10) return -1;
		digits.push_back(v % base);
		v /= base;
	}

	reverse(digits.begin(), digits.end());
	int ret = 0;
	for(int v: digits) ret = ret * 10 + v;
	return ret;
}

int main(void) {
	int a, b, c;
	while(scanf("%d %d %d", &a, &b, &c), a != -1) {
		int base = 16;
		while(base >= 2) {
			int converted = convert(base, a);
			if(converted == b) break;
			base--;
		}
		if(base == 1) {
			printf("-1\n");
			continue;
		}

		int ans;
		for(int i = a + 1; i <= c; i++) {
			base = 16;
			while(base >= 2) {
				int converted = convert(base, i);
				if(converted >= b) break;
				base--;
			}

			if(base == 1) {
				ans = -1;
				break;
			}

			b = ans = convert(base, i);
		}

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

	return 0;
}

Measured memory_bytes: 1040
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

int n;
vector<int> d;

int calc_diff(){
    int ret = INF;
    rep(n){
        reppp(j, i+1, n){
            int diff = abs(d[i]-d[j]);
            diff = min(diff, 24-diff);
            ret = min(ret, diff);
        }
    }
    return ret;
}

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

    cin >> n;

    if(n==1){
        int d;
        cin >> d;
        cout << d << endl;
        return 0;
    }

    d.push_back(0);
    rep(n){
        int tmp;
        cin >> tmp;
        d.push_back(tmp);
    }
    sort(all(d));

    for(int i=1;i<=n;i+=2){
        d[i] = 24 - d[i];
    }
    int ans1 = calc_diff();

    rep(n){
        d[i] = 24 - d[i];
    }
    int ans2 = calc_diff();

    cout << max(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl        '\n'
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define pf(x) 		push_front(x)
#define pb(x)       push_back(x)
#define eb(x)		emplace_back(x)
#define all(x)      (x).begin(), (x).end()
#define rall(x) 	(x).rbegin(), (x).rend()
#define sz(x) 		(int)x.size()
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0)

const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18; 

using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    int w, a, b;
    cin >> w >> a >> b;
    if(b > (a+w)) {
        cout << (b - (a + w)) << endl;
    }
    else if(a > (b+w)) {
        cout <<abs((b + w) - a )<< endl;
    }
    else
        cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    for (i in 1..10000) {
        val inStr: String? = readLine()
        val x: Int? = inStr?.toInt()
        if (x == null) {
            return
        }
        if (x == 0) {
            return
        }
        println("Case %d: %d".format(i, x))
    }
}



Measured memory_bytes: 56240
n = int(input())
a = list(map(int, input().split()))

a.insert(0, 0)
a.append(0)
dist = 0
for i in range(n+1):
    dist += abs(a[i+1] - a[i])

for i in range(1, n+1):
    print(dist - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]))

Measured memory_bytes: 85288
#pragma GCC optimize(30000000)
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x,y,ans,sum=0;
    cin>>x>>y;
    ans=((long long)(y/x));
    while(ans>=1)ans/=2,sum++;
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args){
		
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		String strLine = null;
		try {
			strLine = insBR.readLine();
			
		} catch (IOException e) {
			// TODO ????????????????????? catch ????????????
			e.printStackTrace();
		}
		//????????????????§£???????????????????´?
		char[] ary = strLine.toCharArray();
		//?°???????????????????????????§????????????????????????????´?
		for(int i = 0; i < ary.length; i++){
			if(Character.isLowerCase(ary[i])){
				ary[i] = Character.toUpperCase(ary[i]);
			}else{
				ary[i] = Character.toLowerCase(ary[i]);
			}
		}
		String strNewLine = new String(ary);
		System.out.println(strNewLine);
	}

}

Measured memory_bytes: 16876
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args)throws IOException  {
		// TODO ?????????????????????????????????????????????

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        double r = Double.parseDouble(in.readLine());
 
        double pi = Math.PI;
        double S = r * r * pi;
        double R = 2 * r * pi;
        System.out.printf("%.6f %.6f", S, R);

	}

}

Measured memory_bytes: 24776
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e5 + 3;
 
int main(){
    fast;
    ld n;
    ld o = 26.0;
    cin >> n;
    ll n1 = n; 
    string s;
    while(n > 26){
        ll g = n1 % 26;
        char a = g + 'a' - 1;
        if(g == 0){
            a = 'z';
            --n;
        }
        s.push_back(a);
        n = floor(n/o);
        n1 = n;
       // cout << n1 << ' ';
    }
    char b = n + 'a' - 1;
    s.push_back(b);
    for(int i = s.size() - 1; i >= 0; --i)
        cout << s[i];
    return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define eoi ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int main()
{
    eoi;
int t,a;
vector<int>v;
long long sum=0;
cin>>t;
while(t--){
    cin>>a;
    v.push_back(a);
}
for(int i=0;i<v.size()-1;i++){
    for(int h=i+1;h<v.size();h++){
        sum+=v[i]*v[h];
    }

}
cout<<sum;

}


Measured memory_bytes: 256