akhauriyash/Code-Regression huggingface dataset:
import java.io.*;

public class Main{
    public static void main(String[]args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String p = br.readLine();
        String ans=null;
        String res=null;
        for(int i=0;i<s.length();i++){
            if(i+p.length() <=s.length()){
                ans=s.substring(i, i+p.length());
            }else{
                ans=s.substring(i , s.length())+s.substring(0 , p.length()-(s.length()-i));
            }
            if(p.equals(ans)){
                res="Yes";
                break;
            }
                    
        }
        if(res=="Yes"){
            System.out.println(res);
        }else{
            System.out.println("No");
        }
 
        
    }

        
}

Measured memory_bytes: 17020
#include<iostream>
using namespace std;
void printAns(int arr[], int len) {
	using std::cout;
	using std::endl;
	for (int i = 0; i < len; i++)
	{
		if (i)
			cout << " ";
		cout << arr[i];
	}
	cout << endl;
}
int main() {
	int len;
	cin >> len;
	int* arr = new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	 for (int i = 0; i < len - 1; i++) {
		printAns(arr, len);
		for (int j = i + 1; j > 0; j--) {
			if (arr[j - 1] > arr[j])
				swap(arr[j - 1], arr[j]);
		}
	}
	printAns(arr, len);

	/*int step = 0;
	for (int i = 0; i < len - 1; i++) {
		for (int j = len - 1; j > i; j--) {
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;*/

	/*int step = 0;
	for (int i = 0; i < len - 1 ; i++) {
		if (arr[i] > arr[i + 1]) {
			swap(arr[i], arr[i + 1]);
			step++;
		}
		for(int j=i;j>0;j--){
			if (arr[j] < arr[j - 1]) {
				swap(arr[j], arr[j - 1]);
				step++;
			}
		}
	}
	printAns(arr, len);
	cout << step << endl;*/
	return 0;
}


Measured memory_bytes: 3096
combi :: Int -> Int
combi n = length [[a, b, c, d] |
    a <- [0 .. 9], b <- [0 .. 9], c <- [0 .. 9], d <- [0 .. 9],
        a + b + c + d == n]

main :: IO ()
main = putStr. unlines . map show . map combi . map read . lines =<< getContents

Measured memory_bytes: 4156
#include <stdio.h>

int pow2(int x);

int main(void)
{
    int side1, side2, diagonal;
    int cnt_rect = 0, cnt_lozen = 0;

    while (scanf("%d,%d,%d", &side1, &side2, &diagonal) != EOF) {
        if (pow2(side1) + pow2(side2) == pow2(diagonal)) {
            cnt_rect++;
        }
        if (side1 == side2) {
            cnt_lozen++;
        }
    }

    printf("%d\n%d\n", cnt_rect, cnt_lozen);

    return 0;
}

int pow2(int x)
{
    return x * x;
}

Measured memory_bytes: 596
<?php
while ($input = fgets(STDIN)) {
	list($a, $b) = explode(' ', trim($input));
	$gcd = gcd($a, $b);
	$lcm = $a / $gcd * $b;
	echo $gcd . " " . $lcm . "\n";
}

function gcd($m, $n) {
	while ($m % $n != 0) {
		$temp = $n;
		$n = $m % $n;
		$m = $temp;
	}
	return $n;
}

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

#include <iostream>


#define MOD 1000000007

typedef unsigned long long ull;
typedef long long ll;

using namespace std;
auto f=[]()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
};


int main()
{
	f();
	vector<set<int>> v(26);
	int n;cin>>n;
	for(auto i=1;i<=n;++i)
	{
		char c;cin>>c;
		v[c-'a'].insert(i);
	}
	
	int q;cin>>q;
	while(q--)
	{
		int t;cin>>t;
		if(t==1)
		{
			size_t id;
			char c;
			cin>>id>>c;
			
			for(auto j=0;j<26;++j)
				v[j].erase(id);
			
			v[c-'a'].insert(id);
		}
		else
		{
			size_t l,r;cin>>l>>r;
			size_t ans=0;
			for(auto i=0;i<26;++i)
			{
				auto it=v[i].lower_bound(l);
				if(it!=v[i].end() && *it<=r)
					ans++;
			}
			cout<<ans<<"\n";
		}
	}
	return 0;
}


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

typedef long long i64;
const int N = 100005;
const int MAXN = 32;

int main ()
{
    int A, B, C, X, Y;
    scanf("%d %d %d %d %d", &A, &B, &C, &X, &Y);
    if (A + B < 2 * C) {
        printf("%d\n", X * A + Y * B);
    }
    else {
        printf("%d\n", min(X, Y) * 2 * C + (X - min(X, Y)) * min(2*C, A) + (Y - min(X, Y)) * min(2*C,B));
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int chomp(char *str){
    int len = strlen(str);
    if(str[len-1]=='\n'){
        str[len-1] = '\0';
        len--;
    }
    return len;
}

int main(){
    int n;
    int i,j;
    int s1,s2,la,sm;
    char a1[102],a2[102],*pla,*psm,dummy[2];
    int carry,r;
    scanf("%d",&n);
    fgets(dummy,2,stdin);
    for(i=0;i<n;i++){
        fgets(a1,101,stdin);
        fgets(a2,101,stdin);
        s1 = chomp(a1);
        s2 = chomp(a2);
        if(s1>80||s2>80){
            printf("overflow\n");
            goto NEXT;
        }
        if(s1<s2){
            pla = a2;
            la = s2;
            psm = a1;
            sm = s1;
        }else{
            pla = a1;
            la = s1;
            psm = a2;
            sm = s2;
        }
        carry = 0;
        for(j=0;j<la;j++){
            r = (j<sm) ? (psm[sm-j-1]-'0') : 0;
            r += (pla[la-j-1]-'0')+carry;
            carry = r/10;
            pla[la-j] = '0' + r%10;
        }
        if(carry){
            pla[0] = '1';
        }else{
            pla = (s1<s2) ? &a2[1] : &a1[1];
        }
        if(j+carry>80){
                printf("overflow\n");
                goto NEXT;
        }
        printf("%s\n",pla);
NEXT:
        printf("");
    }
}

Measured memory_bytes: 1016
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

struct edge{
    int to, idx;
};

int par[60];
int idx[60];
int N, M, root = 1;
ll ans = 1;
vector<edge> G[60];
vector<int> ms[21];
vector<int> path(int u, int v){
    vector<int> us, vs;
    while(par[u] != 0){
        us.push_back(idx[u]);
        u = par[u];
    }

    while(par[v] != 0){
        vs.push_back(idx[v]);
        v = par[v];
    }
    reverse(us.begin(), us.end());
    reverse(vs.begin(), vs.end());
    int sz = min(us.size(), vs.size());
    int id = 0;
    for(; id < sz; id++){
        if(us[id] != vs[id]) break;
    }
    vector<int> res;
    for(int i = id; i < us.size(); i++) res.push_back(us[i]);
    for(int i = id; i < vs.size(); i++) res.push_back(vs[i]);
    return res;
}

void dfs(int v, int p, int id){
    par[v] = p;
    idx[v] = id;
    for(auto u : G[v]){
        if(u.to == p) continue;
        dfs(u.to, v, u.idx);
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i < N; i++){
        ans *= 2;
        int a, b;
        cin >> a >> b;
        G[a].push_back(edge{b, i});
        G[b].push_back(edge{a, i});
    }
    dfs(root, 0, -1);

    cin >> M;
    for(int i = 0; i < M; i++){
        int u, v;
        cin >> u >> v;
        ms[i] = path(u, v);
    }
    for(int i = 1; i < (1 << M); i++){
        bool used[50] = {};
        int co = 1;
        int cnt = 0;
        for(int k = 0; k < M; k++){
            if((i >> k) & 1){
                co *= -1;
                for(auto u : ms[k]) used[u] = true;
            }
        }
        for(int k = 1; k < N; k++) cnt += !used[k];
        ll num = 1LL << cnt;
        ans += num * co;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100;
static const int MAX_W = 100000;

int N, W;
int w[MAX_N], v[MAX_N];
ll memo[MAX_N + 1][MAX_W + 1];

int main(){
	scanf("%d %d", &N, &W);
	for(int i = 0; i < N; i++) scanf("%d %d", &w[i], &v[i]);
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= W; j++){
			if(j < w[i]) memo[i + 1][j] = memo[i][j];
			else memo[i + 1][j] = max(memo[i][j], memo[i][j - w[i]] + v[i]);
		}
	}
	printf("%lld\n", memo[N][W]);
	return 0;
}

Measured memory_bytes: 78336
# -*- coding: utf-8 -*-

import sys
import os


n, q = map(int, input().split())
scores = [0] * n

max_value = 0
max_index = 0
for i in range(q):
    a, v = map(int, input().split())

    # zero index
    a -= 1
    scores[a] += v

    # need speed than naive implementation

    if max_index == a and v < 0:
        max_value = max(scores)
        max_index = scores.index(max_value)

    elif max_value < scores[a]:
        max_index = a
        max_value = scores[a]

    elif max_value == scores[a] and a < max_index:
        max_index = a

    print(max_index + 1, max_value)

Measured memory_bytes: 15312
function Main(input) {
    input = input.split("\n");
    var people_num = Number(input[0]);
    var scores = input[1].split(' ');
    var ary = [];
    var pro = 0;
    var any = 0;
    for(var i = 0; i < scores.length; i++){
        scores[i] = Number(scores[i]);
        pro = Math.floor(scores[i] / 400);
        if(pro >= 8){
            any++;
        }else{
            ary.push(pro);
        }
    }
    var united = ary.filter(function(a,b,c){
        return c.indexOf(a) === b;
    });
    if(united.length){
        console.log(united.length + ' ' + (united.length + any));
    } else {
        console.log(1 + ' ' + any);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    if (S == "ABC") cout << "ARC";
    else cout << "ABC";
    return 0;
}


Measured memory_bytes: 3640
import std;
void main () {
	int n;
	while (readf !(" %s") (n) > 0) {
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto s = a.fold !(q{a ^ b});
		a[] = s ^ a[];
		writefln !("%(%s %)") (a);
	}
}



Measured memory_bytes: 7740
import sys
import time

t = time.time()

n = int(input())
a = list(map(int, input().split(' ')))
b = list(range(n))
b.sort(key=lambda x: -a[x])
# print("b after:", b)
# print(list(map(lambda x:a[x],b)))
# print(time.time()-t)

cache = [[-1 for x in range(n)] for y in range(n)]
# print(cache)


def dfs(left, right):
    if left > right:
        return 0
    if cache[left][right] != -1:
        return cache[left][right]
    which = n-(right-left+1)
    ans1 = dfs(left+1, right)+abs(left-b[which])*a[b[which]]
    ans2 = dfs(left, right-1)+abs(right-b[which])*a[b[which]]
    cache[left][right] = max(ans1, ans2)
    return cache[left][right]


sys.setrecursionlimit(2010)
print(dfs(0, n-1))


Measured memory_bytes: 175136
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i=1,i##_len=(n); i<=i##_len; ++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(obj) (obj).begin(), (obj).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 uni(x) x.erase(unique(rng(x)),x.end())
#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) vector<vector<T>>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
template <class T> inline istream& operator>>(istream&i,v(T)&v)
{ rep(j,sz(v))i>>v[j];return i;}
template <class T> string join(const v(T)&v)
{ stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template <class T> inline ostream& operator<<(ostream&o,const v(T)&v)
{ if(sz(v))o<<join(v); return o;}
template <class T1,class T2> inline istream& operator>>(istream&i ,pair<T1,T2>&v)
{ return i>>v.fi>>v.se;}
template <class T1,class T2> inline ostream& operator<<(ostream&o ,pair<T1,T2>&v)
{ return o<<v.fi<<","<<v.se;}
template <class T> inline ll suma(const v(T)& a) 
{ ll res(0); for(auto&& x:a) res += x; return res;}
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const double eps = 1e-10;
const int MX = 200005;
//----------------------------------------------------------------

#define fileio ifstream fio; if(argc>=2){fio.open(argv[1]); std::cin.rdbuf(fio.rdbuf());}
#define fastio ios_base::sync_with_stdio(false);
#define MOD 1000000007
//----------------------------------------------------------------

void Main(){
  int n;
  cin>>n;
  vi sc(1e5+5,0);
  rep(i,n){
    int a;
    cin>>a;
    sc[a  ]++;
    sc[a+1]++;
    sc[a+2]++;
  }
  cout<<*max_element(rng(sc))<<endl;;
} int main(int argc,char* argv[]){ 
    fastio; fileio; Main();}

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

bool check(int n, vector<bool>& d){
	while(n > 0){
		if(d[n % 10])
			return false;
		n/=10;
	}
	return true;
}

int solve(int n, vector<bool>& d){
	int res = n;
	while(!check(res,d)){
		res++;
	}
	return res;
}

int main(){
	int n,k;
	cin >> n >> k;
	vector<bool> d(10,false);
	for(int i = 0; i < k; i++){
		int tmp; cin >> tmp;
		d[tmp] = true;
	}
	cout << solve(n,d) << endl;
}



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

int main(int argc, char* argv[])
{
  char x,y;

  std::cin >> x >> y;
  if (x < y) {
    std::cout << '<' << std::endl;
  } else if (x > y) {
    std::cout << '>' << std::endl;
  } else {
    std::cout << '=' << std::endl;
  }

  return 0;
}


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


void solve(long long X, long long Y){
  if(X % Y == 0) {
    cout << -1 << endl;
    return;
  }

  for(long long i = 2; i < LLONG_MAX; i++){
    if((X*i)%Y != 0) {
      cout << (X*i) << endl;
      break;
    }
  }
}

// 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 X;
  scanf("%lld",&X);
  long long Y;
  scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

string s;
int S, E;
int main(void){
    cin >> s;
    S = atoi(s.substr(0, 2).c_str());
    E = atoi(s.substr(2, 2).c_str());

    if(1 <= S and S <= 12 and 1 <= E and E <= 12) cout << "AMBIGUOUS" << endl;
    else if (1 <= S and S <= 12) cout << "MMYY" << endl;
    else if (1 <= E and E <= 12) cout << "YYMM" << endl;
    else cout << "NA" << endl;
    return 0;
}



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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	int r; cin >> r;
	cout << 3 * r * r << endl;

    return 0;
}


Measured memory_bytes: 256
#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 mod 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  vector<int> vec;
  rep(i, n){
    int num;
    cin >> num;
    vec.push_back(num);
  }
  sort(all(vec));
  long long sum = 0;
  int res = 0;
  rep(i, n){
    if(sum*2 >= vec[i]) res++;
    else res = 1;
    sum += vec[i];
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
//const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  string s;
  cin >> s;
  vl num(26);
  rep (i, s.size()) {
    num[s[i] - 'a']++;
  }
  ll n = s.size();
  ll ans = n * (n - 1) / 2 + 1;
  rep (i, 26) {
    ans -= num[i] * (num[i] - 1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

        final String S = sc.next();
        int day = 0;

        switch (S) {
            case "SUN":
                day = 7;
                break;
            case "MON":
                day = 6;
                break;
            case "TUE":
                day = 5;
                break;
            case "WED":
                day = 4;
                break;
            case "THU":
                day = 3;
                break;
            case "FRI":
                day = 2;
                break;
            case "SAT":
                day = 1;
                break;
            default:
                break;
        }

        System.out.print(day);
    }
}

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

std::string s1, s2, s3;

int main()
{
in >> s1 >> s2 >> s3;

std::transform(s1.begin(),s1.end(),s1.begin(),::toupper);
std::transform(s2.begin(),s2.end(),s2.begin(),::toupper);
std::transform(s3.begin(),s3.end(),s3.begin(),::toupper);

out << s1[0] << s2[0] << s3[0] << std::endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++)cin >> s[i];
    int ans = 0;
    for(int i = 0; i < h; i++)for(int j = 0; j < w; j++){
        for(int k = 0; k < h; k++)for(int l = 0; l < w; l++){
            if(s[i][j] == 'B' && s[k][l] == 'B'){
                ans = max(ans, abs(i-k) + abs(j-l));
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 3180
#include "bits/stdc++.h"
using namespace std;
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
typedef long long ll;

int main() {
	// fios;
	ll n;
	cin >> n;
	ll n3 = n / 3;
	ll n5  = n/5;
	ll n15 = n/15;
	ll ans = n*(n+1)/2 - (3*n3*(1+n3)/2) - (5*n5*(1+n5)/2) + (15*n15*(1+n15)/2);
	cout << ans << endl;
}

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

int main()
{
    long long int n,i,h[100005],dp[100005],j,k;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    cin>>h[i];
    dp[1] = 0;
    for(i=2;i<=n;i++)
    {
        dp[i] = 1e15;
        // cout<<" i = "<<i<<"\n";
        for(j=i-1;j>=i-k && j>=1;j--)
        {
            // cout<<" j = "<<j<<" dp = "<<dp[j]<<endl;
            dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
        }
        // cout<<" i = "<<i<<" dp = "<<dp[i]<<endl<<endl;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 1792
#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++)
 


int main(){
  string s;
  cin >> s;
 int n;
  n=s.size();
  int sum0=0;
  int sum1=0;
  rep(i,n){
    if(s.at(i)=='0')sum0++;
    else if(s.at(i)=='1')sum1++;
  }
  int sum=min(sum0,sum1);
  cout << sum*2 << endl;
  
}

Measured memory_bytes: 512
N,M=map(int,input().split())
X=[]
Y=[]
Z=[]
G1=[]
G2=[]
G3=[]
G4=[]
G5=[]
G6=[]
G7=[]
G8=[]

for i in range(N):
    x,y,z=map(int,input().split())
    G1.append(-(x+y+z))
    G2.append(-(x+y)+z)
    G3.append(-x+y-z)
    G4.append(-x+(y+z))
    G5.append(x-(y+z))
    G6.append(x-y+z)
    G7.append(x+y-z)
    G8.append(x+y+z)
G1.sort(reverse=True)
G2.sort(reverse=True)
G3.sort(reverse=True)
G4.sort(reverse=True)
G5.sort(reverse=True)
G6.sort(reverse=True)
G7.sort(reverse=True)
G8.sort(reverse=True)
ans=0
val1=0
val2=0
val3=0
val4=0
val5=0
val6=0
val7=0
val8=0
for i in range(M):
    val1+=G1[i]
    val2+=G2[i]
    val3+=G3[i]
    val4+=G4[i]
    val5+=G5[i]
    val6+=G6[i]
    val7+=G7[i]
    val8+=G8[i]

ans=max(val1,val2,val3,val4,val5,val6,val7,val8)
print(ans)

Measured memory_bytes: 3440
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int f[10000];
char a[200004];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    int p = gi();
    scanf("%s", a);
    ll res = 0;

    if (p == 2 || p == 5) {
        for (int i = 0; i < n; i++)
            if ((a[i]-'0')%p == 0)
                res += i+1;
    } else {
        memset(f, 0, sizeof(f));
        int m = 1, r = 0; f[0]++;
        for (int i = n-1; i >= 0; i--) {
            r += (a[i] - '0') * m; r %= p;
            m *= 10; m %= p;
            res += f[r];
            f[r]++;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;
const int MOD=1000000007;

int H,W,N;
int A[100010];
int C[110][110];

signed main(){
	cin>>H>>W>>N;
	REP(i,N){
		cin>>A[i];
	}
	int cnt=0,s=0,num=1;
	for(int i=0;i<H;i++){
		if(i%2==0){
			for(int j=0;j<W;j++){
				cnt++;
				C[i][j]=num;
				if(cnt==A[s]){
					cnt=0;
					s++;
					num++;
				}
			}
		}
		else{
			for(int j=W-1;0<=j;j--){
				cnt++;
				C[i][j]=num;
				if(cnt==A[s]){
					cnt=0;
					s++;
					num++;
				}
			}
		}
	}
	REP(i,H){
		REP(j,W){
			cout<<C[i][j];
			if(j!=W-1){
				cout<<" ";
			}
		}
		if(i!=H-1){
			cout<<endl;
		}
	}
	return 0;
}


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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	Long n;
	cin >> n;
	Long a[n + 1], b[n];
	for (int i = 0; i <= n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	Long answer = 0LL;
	for (int i = 0; i < n; i++) {
		Long aux = min(a[i], b[i]);
		answer += aux;
		a[i] -= aux;
		b[i] -= aux;
		aux = min(a[i + 1], b[i]);
		answer += aux;
		a[i + 1] -= aux;
		b[i] -= aux;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF MOD
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

bool ans[220000];

int main() {
    int n, k;
    cin >> n >> k;
    Int a[n];
    rep(i,n) cin >> a[i];
    for (int i = k; i < n; i++) {
        if (a[i] > a[i - k]) ans[i] = true;
    }
    for (int i = k; i < n; i++) {
        if (ans[i]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

int main() {
	int x;
	cin >> x;
	for(int i=0; i*100<=x;i++){
		if (x - i * 100 <= 5 * i) {
			cout << 1 << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    N = I()
    print(pow(N, 3))
    return


# B
def B():
    return


# C
def C():
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    A()
    return


# Solve
if __name__ == "__main__":
    A()


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

// int/long:            -2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:      -9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define MOD 1000000007

#define Rep0(i, n)      for (auto i=0; i<n; i++)
#define Rep1(i, n)      for (auto i=1; i<=n; i++)
#define Sort(P) sort(P.begin(), P.end())
#define Rev(P)  reverse(P.begin(), P.end())

int     main() {
        ll N=150;
        vector<ll> A(N+1, 0);
        Rep1(i, N)
                A.at(i)=pow(i, 5);
        ll X;
        cin >>X;
        for (auto i=0; i<=N; i++)
                for (auto j=0; j<=N; j++) {
                        if (X==A.at(i)+A.at(j)) {
                                cout <<i <<' ' <<-j <<endl;
                                return 0;
                        }
                        if (X==A.at(i)-A.at(j)) {
                                cout <<i <<' ' <<j <<endl;
                                return 0;
                        }
                }
        return 0;
}


Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N, M;
  std::cin >> N >> M;
  std::cout << N * (N - 1) / 2 + M * (M - 1) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  for (int i = 0; i < S.length() - 1; i++){
    if (S[i] == S[i + 1]){
     N--; 
    }
  }
  
  
   cout << N << endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc =  new Scanner(System.in);
		int n = sc.nextInt();
		int num[][] = new int [n][3];
		int ten[] = new int [n];
		int cnt = 0;
		for(int i = 0; i < n; i++){
			for(int k = 0; k < 3; k++){
				num[i][k] = sc.nextInt();//num?????\???
			}
			ten[i] = 0;//ten????????????
		}
		for(int i = 0; i < 3; i++){
			for(int k = 0; k < n; k++){
				cnt = 0;
				for(int j = 0; j < n; j++){
					if(num[k][i] == num[j][i] && k != j) cnt++;
				}
				if(cnt == 0) ten[k] += num[k][i];
			}
		}
		for(int i = 0; i < ten.length; i++){
			System.out.println(ten[i]);
		}
	}
}

Measured memory_bytes: 28684
import java.util.Arrays;
import java.util.Scanner;

//ICPC: Intelligent Congruent Partition of Chocolate
public class Main{

	int w, h, si, sj, ti, tj, N, c;
	int[][] a;
	int[] sum;
	boolean[][] u;
	int[][] d = {{-1,0},{0,1},{1,0},{0,-1}};

	void p(){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++)System.out.printf("%3d", a[i][j]);
			System.out.println();
		}
		System.out.println();
	}
	
	boolean dfs(int i, int j, int rot, int rev, int num){
//		System.out.println(i+" "+j+" "+num);
		if(num==(N>>1)){
//			p();
			for(boolean[]v:u)Arrays.fill(v, false);
			c = 0;
			check(si, sj, -1);
//			System.out.println("C:"+c+" N:"+N);
			if(c!=(N>>1))return false;
			c = 0;
			check(ti, tj, -2);
//			System.out.println("C2:"+c+" N:"+N);
			return c==(N>>1);
		}
		if(i==h || (N>>1)-num > sum[i*w+j])return false;
		if(j==w)return dfs(i+1, 0, rot, rev, num);
		if(a[i][j]==1){
			a[i][j] = -1;
			int di = i-si, dj = j-sj;
			int ni, nj;
			if(rot==0){
				ni = di; nj = dj;
			}
			else if(rot==1){
				ni = dj; nj = -di;
			}
			else if(rot==2){
				ni = -di; nj = -dj;
			}
			else{
				ni = -dj; nj = di;
			}
			if(rev==1)nj*=-1;
			int ki = ti+ni, kj = tj+nj;
			if(0<=ki&&ki<h&&0<=kj&&kj<w&&a[ki][kj]==1){
				a[ki][kj] = -2;
				if(dfs(i, j+1, rot, rev, num+1))return true;
				a[ki][kj] = 1;
			}
			a[i][j] = 1;
		}
		return dfs(i, j+1, rot, rev, num);
	}
	
	void check(int i, int j, int x){
		if(u[i][j])return;
		u[i][j] = true;
		c++;
		for(int k=0;k<4;k++){
			int ni = i+d[k][0], nj = j+d[k][1];
			if(ni < 0 || h <= ni || nj < 0 || w <= nj || a[ni][nj]!=x)continue;
			check(ni, nj, x);
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			w = sc.nextInt(); h = sc.nextInt();
			if((w|h)==0)break;
			N = 0;
			a = new int[h][w];
			u = new boolean[h][w];
			sum = new int[h*w+1];
			si = sj = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++){
				a[i][j] = sc.nextInt();
				if(a[i][j]==1){
					N++;
					if(si==-1){
						si = i; sj = j;
					}
				}
			}
			if((N&1)==1){
				System.out.println("NO"); continue;
			}
			for(int i=h-1;i>=0;i--)for(int j=w-1;j>=0;j--)sum[i*w+j] = sum[i*w+j+1]+a[i][j];
			boolean res = false;
			a[si][sj] = -1;
			for(int i=0;i<h;i++)for(int j=0;j<w;j++)if(a[i][j]==1){
				ti = i; tj = j;
				a[i][j] = -2;
				for(int rot=0;rot<4;rot++)for(int rev=0;rev<2;rev++){
//					System.out.println("TI:"+i+" TJ:"+j+" ROT:"+rot+" REV:"+rev);
					if(dfs(0, 0, rot, rev, 1)){
//						System.out.println(si+" "+sj+" "+i+" "+j+" "+rot+" "+rev);
						res = true;
					}
					if(res)break;
				}
				a[i][j] = 1;
			}
			System.out.println(res?"YES":"NO");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
import sys

n = int(input())
a = [int(i) for i in input().split()]
prd = 1
if 0 in a:
  print(0)
  sys.exit()
for i in range(n):
  prd*=a[i]
  if prd > 10**18:
    print(-1)
    sys.exit()
print(prd)

Measured memory_bytes: 21600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> l_l;
struct UnionFind{
vector<int> par,depth;
UnionFind(int n){
par.resize(n); depth.resize(n);
for(int i=0; i<n; i++){
par[i]=i;
depth[i]=0;
}
}
int find(int x){
if(par[x]==x){
return x;
}
else{
return par[x]=find(par[x]);
}
}
bool same(int x, int y){
return find(x)==find(y);
}
void unite(int x, int y){
x=find(x); y=find(y);
if(x==y) return;
if(depth[x]<depth[y]) swap(x,y);
if(depth[x]==depth[y]) depth[x]++;
par[y]=x;
}
};
struct Edge{
    ll a,b,cost;
    bool operator<(const Edge &e) const{
        return (cost<e.cost);
    }
};
int main(){
    ll n;
    cin >> n;
    vector<l_l> px(n),py(n);
    for(int i=0; i<n; i++){
        ll x,y;
        cin >> x >> y;
        px[i]=l_l(x,i);
        py[i]=l_l(y,i);
    }
    sort(px.begin(),px.end());
    sort(py.begin(),py.end());
    ll m=2*n-2;
    vector<Edge> es(m);
    for(int i=0; i<n-1; i++){
        es[i].a=px[i].second;
        es[i].b=px[i+1].second;
        es[i].cost=px[i+1].first-px[i].first;
    }
    for(int i=0; i<n-1; i++){
        es[i+n-1].a=py[i].second;
        es[i+n-1].b=py[i+1].second;
        es[i+n-1].cost=py[i+1].first-py[i].first;
    }
    sort(es.begin(),es.end());
    UnionFind uf(n);
    ll min_cost=0;
    for(int i=0; i<m; i++){
        if(!uf.same(es[i].a,es[i].b)){
            uf.unite(es[i].a,es[i].b);
            min_cost+=es[i].cost;
        }
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 8832
#include<iostream>

using namespace std;

int main() {
  int x,y;
  cin >> x >> y;
  while (x != 0 || y != 0 ){
  if(x <= y){
    cout << x << " " << y << endl;
  } else {
    cout << y << " " << x << endl;
  }
  cin >> x >> y;
  }
}



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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010
 
void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

// ll dp[]

int main(){
    //ll a, b;
    long double a, b;
    long double h, m;
    long double c, theta;
    
    scanf("%Lf%Lf", &a, &b);
    scanf("%Lf%Lf", &h, &m);
    
    theta = ((60.0*h+m)/720.0  -  m/60.0);
    theta = theta * 2 * M_PI;
    theta = cosl(theta);
    c = a*a + b*b - 2.0*a*b*theta;

    c = sqrt(c);

    printf("%20.20Lf", c);
    
    return 0;
}

Measured memory_bytes: 2492
/*Author - Shubham Gupta (@shubham107)*/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif
void solve() {
	string s;
	cin >> s;
	int t = sz(s) - 1;
	if(s[t] == '2' || s[t] == '4' || s[t] == '5' || s[t] == '7' || s[t] == '9'){
		cout << "hon";
	}else if(s[t] == '0' || s[t] == '1' || s[t] == '6' || s[t] == '8'){
		cout << "pon";
	}else{
		cout << "bon";
	}
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef SHUBHAM107
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
}


Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int main() {
    int m, f, r;
    while(cin >> m >> f >> r, m!= -1||f!= -1||r!= -1) {
        if(m == -1 || f == -1) cout << 'F';
        else if(m + f >= 80) cout << 'A';
        else if (m + f >= 65) cout << 'B';
        else if (m + f >= 50) cout << 'C';
        else if (m + f >= 30) {
            if(r >= 50) cout << 'C';
            else cout << 'D';
        }
        else cout << 'F';
        cout << endl;
    }
}

Measured memory_bytes: 1152
object Main {
  def main(args: Array[String]) {
    if (sys.env.getOrElse("TEST", "") == "1") {
      println(test());
    } else {
      val input = io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input: String): String = {
    val t = input.toCharArray.zipWithIndex.foldLeft((0, 0))((t, e) => {
      val (c, i) = e
      if (i % 2 == 0) {
        if (c == '0') {
          (t._1 + 1, t._2 )
        } else {
          (t._1, t._2 + 1)
        }
      } else {
        if (c == '1'){
          (t._1 + 1, t._2 )
        } else {
          (t._1, t._2 + 1)
        }
      }
    })
    val m = if (t._1 < t._2) t._1 else t._2
    m.toString
  }

  val tests = List(
    """000 """.stripMargin ->"1",
    """10010010""".stripMargin -> "3",
    """0""".stripMargin -> "0");

  def test(): String = {
    return tests.map { case (i, o) => (i.trim(), o.trim()) }
      .zipWithIndex.map {
      case ((input, outputExpect), i) => {
        val output = solve(input).trim();
        s"test${i + 1}:" + (if (output == outputExpect) {
          "Passed"
        } else {
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }
    }
      .mkString("\n");
  }
}


Measured memory_bytes: 42052
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, K = map(int, input().split())

d = defaultdict(int)
res = N
x = N
while 1:
    x = res%K
    y = abs(res-K)
    #print(res, x, y)
    res = min(res, x, y)
    d[res] += 1
    #print(d)
    if d[res] > 10:
        break
print(res)



Measured memory_bytes: 3316
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int K;
  cin >> K;

  int X = 7;
  int ans = 1;
  while (X % K && ans <= 1000002) {
    ans++;
    X = X * 10 + 7;
    X %= K;
  }

  if (ans == 1000003)
    ans = -1;

  cout << ans << endl;
}

Measured memory_bytes: 3632
import sys,math,collections,itertools
input = sys.stdin.readline
#ダイクストラで頂点1と偶数距離を0として塗る
N=int(input())
road=[[] for i in range(N+1)]
for _ in range(N-1):
    u,v,w=list(map(int,input().split()))
    road[u].append((v,w))
    road[v].append((u,w))
dist = [float('inf')for i in range(N+1)]
ans = [0]*(N+1)

q = collections.deque([])
q.append(1)
dist[1]=0
while q:
    now = q.popleft()
    for goto,cost in road[now]:
        if dist[goto]>dist[now]+cost:
            dist[goto]=dist[now]+cost
            q.append(goto)

for a in dist[1:]:
    print(a%2)


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

int main() {
    int N;
    cin >> N;
    vector<int> ans;
    int tmp = 0;
    for(int i=1; i <= ceil(sqrt(2*N))+2; i++) {
        ans.push_back(i);
        tmp += i;
        if (tmp >= N) {
            if(tmp == N) break;
            else {
                ans.erase(remove(ans.begin(), ans.end(), tmp-N), ans.end());;
                break;
            }
        }
    }
    for(int x:ans) {
        cout << x << endl;
    }
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N, M; cin >>N;
	map<string, int>blue;
	map<string, int>red;
	rep(i, N) {
		string a; cin >> a;
		blue[a]++;
	}
	cin >> M;
	rep(i, M) {
		string a; cin >> a;
		red[a]++;
	}
	int ans = 0;
	for (auto p : blue) {
		int res = p.second - red[p.first];
		ans = max(ans, res);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

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


Measured memory_bytes: 256
// /Code by : Harry_Singh/
#include<bits/stdc++.h>
#define int long long int 
#define io ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define ipair pair<int,int>
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define F(i,n) for(int i=1;i<=n;i++)
#define mod 1000000007
using namespace std;
#define inf 100000000000000009
#define tr cout<<"\n" 
#define N 205
// directions
int xx[5]={0,0,1,-1};
int yy[5]={1,-1,0,0};
vector<int > G[N],L[N];
 
 
void we_have_choices()
{

   int x,k,d;
   cin>>x>>k>>d;
   if(x<0)x*=-1;
   int a=x/d;
   if(a<k && -1*a<k){
    x = x -a*d;
    k = k-a;
    }
    else{cout<<x-k*d;tr;return;}

    if(k%2==0)cout<<x;
    else cout<< abs(x-d);
    tr;

   




}



int32_t main()
{
#ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
#endif
    io;
    int t=1;
    while (t--)we_have_choices();
    return 0;
}

Measured memory_bytes: 3620
from collections import deque

N, M = [int(x) for x in input().split()]
k = [None] * M
s = [None] * M
for i in range(M):
    lst = input().split()
    k[i] = int(lst[0])
    s[i] = [int(x) - 1 for x in lst[1:]]  # index調整
p = [int(x) for x in input().split()]

ans = 0
# すべてのスイッチの状態を試す
for sw in range(2 ** N):
    all_on = True
    for i in range(M):  # 各電球がONしているか確認
        light = 0
        for j in s[i]:  # 各スイッチの値の和
            light = (light + (sw >> j) & 1 ) % 2
        if light != p[i]:
            all_on = False
            break
    ans += int(all_on)
print(ans)


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

int main() {
  int i,j,k,n,cnt=0,max=0;
  cin>>n;
  for(i=1;i<n+1;i++){
    j=i;
    bool f=true;
    cnt=0;
    
    while(f){
      if(j%2==0){
        j/=2;
        cnt++;
        if(cnt>max){
          max=cnt;
          k=i;
        }
      }else{
        f=false;
      }
    }
  }  
  if(n==1){
    k=1;
  }
  cout<<k<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	int gcd(int x, int y) {
		if (x < y) {
			int tmp = x;
			x = y;
			y = tmp;
		}
		if (x % y == 0) return y;
		return gcd(y, x%y);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		System.out.println(new Main().gcd(x,y));
	}

}



Measured memory_bytes: 26272