akhauriyash/Code-Regression huggingface dataset:
pub fn main() {
  fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse::<T>().ok().unwrap()
  }

  let s = read::<String>();
  match s.as_str() {
    "ABC" => println!("ARC"),
    "ARC" => println!("ABC"),
    _ => println!(""),
  }
}

Measured memory_bytes: 2132
import math
import itertools

N = int(input())
XY = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for v in itertools.permutations(range(N)):
    for i in range(N-1):
        ans += math.sqrt((XY[v[i]][0]-XY[v[i+1]][0])**2 + (XY[v[i]][1]-XY[v[i+1]][1])**2)

print(ans/math.factorial(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	char c; cin >> c;
	if((int)(c-97) < 0) cout << 'A';
	else cout << 'a';
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3584
a,b,c = input().split()
a,b,c = int(a),int(b),int(c)
max = b + c*(a-1)
min = b*(a-1) + c
if a == 0 or (a == 1 and b != c) or b > c:
    print(0)
else:
    print(max-min+1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using edge = pair<P, P>;
const ll inf = numeric_limits<ll>::max()/3;
 
int main(void){
  ll n,m;
  cin >> n >> m;
  ll pinv = (ll)pow(2,m);
  ll a = 1900 * m + 100 * (n-m);
  cout << a * pinv << endl;
  return 0;
}


Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
#ifdef _MSC_VER
	while (true)
#endif
	{
		int n = -1, m, ans = 0, a, b;
		cin >> n >> m;
		if (n <= 0) return 0;
		int edge[16][16] = {};
		for (int i = 0; i < m; ++i) {
			cin >> a >> b;
			--a, --b;
			edge[a][b] = edge[b][a] = 1;
		}
		int seq[] = { 0,1,2,3,4,5,6,7 };
		do {
			int i;
			for (i = 1; i < n; ++i) {
				if (!edge[seq[i - 1]][seq[i]]) {
					break;
				}
			}
			ans += i >= n;
		} while (next_permutation(seq + 1, seq + n));
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
  packs = [int(x) for x in raw_input().split()]
  if packs[0] == packs[1]+packs[2]:
      print("Yes")
      return
  if packs[1] == packs[0]+packs[2]:
      print("Yes")
      return
  if packs[2] == packs[0]+packs[1]:
      print("Yes")
      return
  print("No")
  

main()

Measured memory_bytes: 2568
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        String S = sc.nextLine();
                        for (int i = 0; i < S.length(); i++) {
                                if (Character.isUpperCase(S.charAt(i))) {
                                        System.out.print(Character.toLowerCase(S.charAt(i)));
                                } else {
                                        System.out.print(Character.toUpperCase(S.charAt(i)));
                                }
                        }
                        System.out.println("");
                }
        }
}

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

string A;
ll B, C;

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

	cin >> A;
	B = stoll(A.substr(0, 2));
	C = stoll(A.substr(2, 2));
	if (1 <= B && B <= 12 && 1 <= C && C <= 12) {
		cout << "AMBIGUOUS\n";
	}
	else if (1 <= B && B <= 12) {
		cout << "MMYY\n";
	}
	else if (1 <= C && C <= 12) {
		cout << "YYMM\n";
	}
	else {
		cout << "NA\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double Pi = acos(-1);
const ll mod=1e9+7;

int main(){
    string s,t;
    cin >>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i]) ans++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 3912
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

n = ni()
a = [ni() for _ in range(n)]

a.sort()

b = a.copy()
c = a.copy()

# 小さい順に詰める
bdeq = deque(b)
bret = deque()

bret.append(bdeq.popleft())
push_small = False
while len(bdeq) > 1:
    if push_small:
        bret.append(bdeq.popleft())
        bret.appendleft(bdeq.popleft())
        push_small = False

    else:
        bret.append(bdeq.pop())
        bret.appendleft(bdeq.pop())
        push_small = True

if len(bdeq) > 0:
    if abs(bdeq[0] - bret[0]) > abs(bdeq[0] - bret[-1]):
        bret.appendleft(bdeq[0])
    else:
        bret.append(bdeq[0])

# 大きい順に詰める
cdeq = deque(c)
cret = deque()

cret.append(cdeq.pop())
push_small = True
while len(cdeq) > 1:
    if push_small:
        cret.append(cdeq.popleft())
        cret.appendleft(cdeq.popleft())
        push_small = False

    else:
        cret.append(cdeq.pop())
        cret.appendleft(cdeq.pop())
        push_small = True

if len(cdeq) > 0:
    if abs(cdeq[0] - cret[0]) > abs(cdeq[0] - cret[-1]):
        cret.appendleft(cdeq[0])
    else:
        cret.append(cdeq[0])

# 答えが大きいほうを選択
bans = 0
for i in range(n-1):
    bans += abs(bret[i] - bret[i+1])

cans = 0
for i in range(n-1):
    cans += abs(cret[i] - cret[i+1])

print(max(bans, cans))


Measured memory_bytes: 10616
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Princess, a Cryptanalyst
// 2013/05/22
public class Main{
	Scanner sc=new Scanner(System.in);

	HashSet<String> set;

	void run(){
		for(;;){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			set=new HashSet<String>();
			for(int i=0; i<n; i++){
				set.add(sc.next());
			}
			solve();
		}
	}

	String[] ss;
	int n;

	void solve(){
		for(;;){
			String remove=null;
			for(String s : set){
				for(String t : set){
					if(!t.equals(s)&&t.indexOf(s)>=0){
						remove=s;
					}
				}
			}
			if(remove!=null){
				set.remove(remove);
			}else{
				break;
			}
		}
		ss=set.toArray(new String[0]);
		n=ss.length;
		M=new int[n][n];
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				for(int k=0; k<ss[j].length(); k++){
					if(ss[i].endsWith(ss[j].substring(0, k))){
						M[i][j]=k;
					}
				}
			}
		}
		now=new char[200];
		ans=null;
		rec(0, -1, 0);
		println(new String(ans).substring(0, length(ans)));
	}

	int[][] M;
	char[] now, ans;

	void rec(int length, int last, int used){
		if(used==(1<<n)-1){
			if(ans==null||length(now)<length(ans)
					||(length(now)==length(ans)&&compare(now, ans)<0)){
				ans=now.clone();
			}
		}
		for(int i=0; i<n; i++){
			if((used>>i&1)==0){
				if(last==-1){
					add(now, length, ss[i], 0, ss[i].length());
					rec(ss[i].length(), i, used|(1<<i));
					remove(now, 0, ss[i].length());
				}else{
					add(now, length, ss[i], M[last][i], ss[i].length());
					int delta=ss[i].length()-M[last][i];
					rec(length+delta, i, used|(1<<i));
					remove(now, length, length+delta);
				}
			}
		}
	}

	void add(char[] cs, int from, String s, int from1, int to1){
		for(int i=from1; i<to1; i++){
			cs[from+(i-from1)]=s.charAt(i);
		}
	}

	void remove(char[] cs, int from, int to){
		for(int i=from; i<to; i++){
			cs[i]=0;
		}
	}

	int length(char[] cs){
		for(int i=0; i<cs.length; i++){
			if(cs[i]==0){
				return i;
			}
		}
		return cs.length;
	}

	int compare(char[] c1, char[] c2){
		for(int i=0; i<min(c1.length, c2.length); i++){
			if(c1[i]!=c2[i]){
				return c1[i]-c2[i];
			}
		}
		return Integer.signum(c1.length-c2.length);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 50536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define pb push_back
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define all(s) s.begin(),s.end()
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define _max(v) *max_element(v.begin(), v.end())
#define _min(v) *min_element(v.begin(), v.end())
#define ms(s, n) memset(s, n, sizeof(s))
ll raised(ll x,  ll y){ll res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
ll raisedmod(ll x, ll y, ll p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
ll gcd(ll a, ll b) { if (b == 0)return a; return gcd(b, a % b);} 
ll fact(ll n){ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; } 
ll nCr(ll n, ll r){ return fact(n) / (fact(r) * fact(n - r));} 

const int MAX = 1000001; 
int factor[MAX] = { 0 }; 
void generatePrimeFactors() 
{ 
    factor[1] = 1;  
    for (int i = 2; i < MAX; i++) 
        factor[i] = i; 
  
    for (int i = 4; i < MAX; i += 2) 
        factor[i] = 2;
    for (int i = 3; i * i < MAX; i++) { 
        if (factor[i] == i) { 
            for (int j = i * i; j < MAX; j += i) { 
                if (factor[j] == j) 
                    factor[j] = i; 
            } 
        } 
    } 
} 
   
int calculateNoOFactors(int n) 
{ 
    if (n == 1) 
        return 1; 
  
    int ans = 1; 
    int dup = factor[n]; 
  
    int c = 1; 
    int j = n / factor[n]; 
  while (j != 1) { 
        if (factor[j] == dup) 
            c += 1; 
        else { 
            dup = factor[j]; 
            ans = ans * (c + 1); 
            c = 1; 
        }  
        j = j / factor[j]; 
    }  
    ans = ans * (c + 1); 
  
    return ans; 
} 


int main() 
{
    io;
    ll t; //cin >> t;
    t=1;
    while(t--)
    {
        ll n, ans=0; cin>> n;
        generatePrimeFactors(); 
        rep(i, 1, n) {ans+=calculateNoOFactors(i);}
        cout<< ans << endl;
    }
	return 0;
}


Measured memory_bytes: 7540
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e12;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N, M, L;
  cin >> N >> M >> L;
  // d[u][v] .. The cost between u .. v.
  vector< vector<ll> > d(N, vector<ll>(N, INF));

  rep(i, M) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a; --b;
    // cout << i << endl;
    // cout << a << ", " << b << endl;
    if (c <= L) {
      d[a][b] = c;
      d[b][a] = c;
    } else {
      d[a][b] = INF;
      d[b][a] = INF;
    }
  }

  // Warshal-Floyd
  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  // For Debug
  // rep(i, N) {
  //   rep(j, N) {
  //     cout << "d["<<i<<"]["<<j<<"]: " << d[i][j] << endl;
  //   }
  // }

  // d2[u][v] .. The hopping cost between u .. v.
  // init: d2[u][v] = 1 if d[u][v] <= L.
  vector< vector<ll> > d2(N, vector<ll>(N, INF));
  rep(i, N) {
    rep(j, N) {
      if (d[i][j] <= L) {
        d2[i][j] = 1;
      }
    }
  }
  // Warshal-Floyd
  rep(k, N) {
    rep(i, N) {
      rep(j, N) {
        d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
      }
    }
  }

  ll Q;
  cin >> Q;
  rep(i, Q) {
    ll s, t;
    cin >> s >> t;
    --s; -- t;
    if (d2[s][t] == INF) {
      cout << -1 << endl;
    } else {
      cout << d2[s][t] - 1 << endl;
    }
  }
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<string, ll>;



int main(int argc, char const *argv[]) {
    ll n, r;
    cin >> n >> r;
    if (n < 10) r +=100 *(10 - n);
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

posi = []
nega = []
zeros = 0
A.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

ng = -(10**18 + 1)
ok = 10**18 + 1

ans = (ng..ok).bsearch do |mid|
  
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega.size * posi.size
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        r -= 1 while l < r && a[l] * a[r] > mid
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega.size - 1
    posi.size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega.size - r - 1
    end
  end

  cnt >= K
end

puts ans


Measured memory_bytes: 22472
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> R[i];
    int maxv = -2000000000;
    int minv = R[0];
    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(R[i], minv);
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3876
from itertools import chain,combinations
from itertools import product
def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

def main():
    H, W, K = map(int, input().split())

    rows = []
    for h in range(H):
        rows.append(input())
    
    row_choices = list(powerset(range(H)))
    col_choices = list(powerset(range(W)))

    ans = 0
    for r_set, c_set in product(row_choices, col_choices):
        selected_rows = [r for i, r in enumerate(rows) if i not in r_set]
        n_blacks = 0
        for r in selected_rows:
            n_blacks += len([c for j, c in enumerate(r) if j not in c_set and c == '#'])
        
        if n_blacks == K:
            ans += 1

    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 9240
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let k: usize = read!();
    println!("{}", n - k + 1);
}

Measured memory_bytes: 2084
/*
--> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED,
	DON'T ADJUST THE GOALS,
	ADJUST THE ACTION STEPS.

--> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE.

--> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT.
*/

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <climits>
using namespace std;
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortAll(x) sort(all(x))
#define sz(x) (int)x.size()
#define clr(x) memset(x, 0, sizeof(x))
#define PI 3.1415926535897932384626
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); IO();
typedef long long ll;
typedef pair< int, int >	pii;
typedef pair< ll, ll >		pl;
typedef vector< int >		vi;
typedef vector< ll >		vl;
typedef vector< pii >		vpii;
typedef vector< pl >		vpl;
typedef vector< vi >		vvi;
typedef vector< vl >		vvl;

const int MOD = 1e9 + 7;

ll power(ll a, ll b)
{
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans *= a;
		a = a * a;
		b >>= 1;
	}
	return ans;
}

ll powm(ll a, ll b)
{
	a %= MOD;
	ll ans = 1;

	while (b > 0)
	{
		if (b & 1)
			ans = (ans * a) % MOD;
		a = (a * a) % MOD;
		b >>= 1;
	}
	return ans;
}

void IO()
{
	#ifndef ONLINE_JUDGE
		freopen("Input.txt", "r", stdin);
		freopen("Output.txt", "w", stdout);
	#endif
}

//================================

int main()
{
	// FAST;

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

	double A[n], sum = 0;
	for (double &x : A)
	{
		cin >> x;
		sum += x;
	}

	double x = (1.0 / (4.0 * double(m))) * sum;
	double cnt = 0;
	for (int i = 0; i < n; i++)
		if (A[i] >= x)
			cnt++;

	if (cnt >= m)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */
int EDSum(ll);//各桁の和
vector<int> SOE(int,int);//素数 (Min,Max)
int MinCM(int,int);//最小公倍数(num1,num2)
int MaxCD(int,int);//最大公約数(num1,num2)
vector<int> igets(int);//cin * N
ll nPr(ll,ll); //(n,r)
ll nE(ll); //(n)
ll nCr(ll,ll); //(n,r)

void solve(){
  string a;
  cin >> a;
  a[3]='8';
  cout << a << endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}

vector < int > SOE(int min, int max) {
  if (min < 2) min = 2;
  vector < int > int_array;
  for (int i = min; i <= max; i++) int_array.push_back(i);
  vector < int > sosu;
  double stop = sqrt(max);
  while (true) {
    sosu.push_back(int_array.front());
    int_array.erase(int_array.begin());
    if (stop < (double)(sosu.back())) break;
    for (int i = 0; i < (int) int_array.size(); i++) {
      if (int_array[i] % sosu.back() == 0)
        int_array.erase(int_array.begin() + i);
    }
  }
  sosu.insert(sosu.end(), int_array.begin(), int_array.end());
  return sosu;
}

int MinCM(int a, int b) {
  int c = a * b;
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return c / b;
}

int MaxCD(int a, int b) {
  if (a < b)
    swap(a, b);
  int r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
vector < int > igets(int N) {
  vector < int > A;
  int temp;
  for (int i = 0; i < N; ++i) {
    cin >> temp;
    A.push_back(temp);
  }
  return A;
}

ll nPr(ll n, ll r) {
  ll ans = 1;
  r = n - r;
  while (n != r) {
    ans *= n;
    --n;
  }
  return ans;
}

ll nE(ll n) {
  return nPr(n, n);
}

ll nCr(ll n, ll r) {
  if (r == 0) return -1;
  else {
    if (0 != n - r && n - r < r) r = n - r;
    return nPr(n, r) / nE(r);
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<array>
#include<algorithm>
#include<deque>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<list>
#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x,y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x,LLI y) {
//	return x / gcd(x,y) * y;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI A, B, C, K;
	string S;
	vector<LLI>vec;
	cin >> N >> S >> K;
	char a = S[K - 1];
	for (int i = 0; i < N; i++) {
		if (S[i] != a) {
			S[i] = '*';
		}
	}
	cout << S << endl;
}

Measured memory_bytes: 256
n = int(input())
dp = [[0]*3 for _ in range(n)]
dp[0][0],dp[0][1],dp[0][2] = map(int, input().split())
for i in range(1,n):
    a = list(map(int,input().split()))
    for j in range(3):
        dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + a[j] 
print(max(dp[n-1][:])) 

Measured memory_bytes: 22772
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).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(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll h,w;cin>>h>>w;
    vector<string> s(h);
    rep(i,h)cin>>s[i];

    rep(i,h)rep(j,w){
        if(s[i][j]=='.')continue;
        bool ng=true;
        rep(k,4){
            ll ti=i+D4[k],tj=j+D4[k+1];
            if(ti<0||ti>=h||tj<0||tj>=w)continue;
            if(s[ti][tj]=='#')ng=false;
        }
        if(ng){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

struct Monoid {
  int64_t val;
  Monoid() {}
  Monoid(int64_t v) : val(v) {}
  static Monoid ident() { return Monoid(numeric_limits<int>::max()); }
  static Monoid multiply(Monoid l, Monoid r) {
    return Monoid(min(l.val, r.val));
  }
  bool operator==(const Monoid &rhs) const { return val == rhs.val; }
};

struct Lonoid {
  int64_t x;
  Lonoid() {}
  Lonoid(int64_t x) : x(x) {}
  static Lonoid ident() { return Lonoid(0); }
  static Lonoid multiply(Lonoid f, Lonoid g) { // f \circ g
    return Lonoid(f.x + g.x);
  }
  static Monoid apply(Lonoid f, Monoid m) { // f(m)
    if (m == Monoid::ident()) return m;
    return Monoid(f.x + m.val);
  }
};

template <typename M, typename L>
struct SegmentTree {
  int n;
  M em;
  L el;
  vector<M> dat;
  vector<L> laz;
  SegmentTree(int N, vector<M> a) {
    assert(N == (int)a.size());
    n = 1;
    em = M::ident();
    el = L::ident();
    while (n < N) {
      n *= 2;
    }
    dat.resize(n * 2 - 1, em);
    rep(i, N) dat[i + n - 1] = a[i];
    for (int i = n - 2; i >= 0; i--) {
      dat[i] = M::multiply(dat[i * 2 + 1], dat[i * 2 + 2]);
    }
    laz.resize(n * 2 - 1, el);
  }
  void _update(int i, L f) {
    dat[i] = L::apply(f, dat[i]);
    laz[i] = L::multiply(f, laz[i]);
  }
  void update(int ql, int qr, L f) { update(ql, qr, f, 0, 0, n); }
  void update(int ql, int qr, L f, int i, int il, int ir) {
    if (qr <= il or ir <= ql) return;
    if (ql <= il and ir <= qr) {
      _update(i, f);
    } else {
      auto m = (il + ir) / 2, lch = i * 2 + 1, rch = i * 2 + 2;
      _update(lch, laz[i]);
      _update(rch, laz[i]);
      laz[i] = el;
      update(ql, qr, f, lch, il, m);
      update(ql, qr, f, rch, m, ir);
      dat[i] = M::multiply(dat[lch], dat[rch]);
    }
  }

  M query(int ql, int qr) { return query(ql, qr, 0, 0, n); }
  M query(int ql, int qr, int i, int il, int ir) {
    if (ql <= il and ir <= qr) {
      return dat[i]; // apply(laz[i], dat[i]) ではない
    } else if (qr <= il or ir <= ql) {
      return em;
    } else {
      auto m = (il + ir) / 2;
      return L::apply(laz[i], M::multiply(query(ql, qr, i * 2 + 1, il, m),
                                          query(ql, qr, i * 2 + 2, m, ir)));
    }
  }
};

int main() {

  int n, q;
  cin >> n >> q;
  SegmentTree<Monoid, Lonoid> seg(n, vector<Monoid>(n, Monoid(0)));
  while (q--) {
    int t;
    cin >> t;
    if (t == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      seg.update(s, t + 1, Lonoid(x));
    } else {
      int s, t;
      cin >> s >> t;
      cout << seg.query(s, t + 1).val << endl;
    }
  }

  return 0;
}



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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);
    string s;
    map<string,int> cnt;
    int m = 0;
    Rep(i,N){
        cin >> s;
        cnt[s]++;
        m = max(m, cnt[s]);
    }

    for( pair<string,int> t : cnt ){
        if( t.second == m ){
            cout << t.first << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 25216
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        os << "\n";
    }
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

int N;
vector<string> ans;
void dfs(string& res, int remain, int turn){
    if(remain==0){
        ans.emplace_back(res);
        return;
    }
    int i=0;
    while(res[i]!='.') i++;
    
    res[i] = turn+'a';
    remain--;
    
    REP(mask,1<<remain){
        int i=0;
        string tmp = res;
        REP(j,remain){
            while(i<N and tmp[i]!='.') i++;
            if(mask>>j&1) tmp[i] = turn+'a';
            i++;
        }
        dfs(tmp, remain-__builtin_popcount(mask), turn+1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    string s(N,'.');
    dfs(s, N, 0);
    sort(ALL(ans));
    cout << ans;
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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 x,y;
    cin >> x >> y;
    int a=max(0,4-x),b=max(0,4-y);
    int ans=100000*(a+b);
    if (x==1&&y==1) ans+=400000;
    cout << ans << endl;
}

Measured memory_bytes: 256
def resolve():
    h, w = map(int, input().split())
    maze = [input() for _ in range(h)]
    from collections import deque
    def slv(maze, startx, starty):
        if maze[startx][starty] == "#":
            return 0
        else:
            visited = [[-1] * w for _ in range(h)]
            visited[startx][starty] = 0
            nxt = deque([[startx, starty]])
            while len(nxt) != 0:
                a = nxt.popleft()
                x = a[0]
                y = a[1]
                for i, j in [(x+1, y), (x, y+1), (x-1, y), (x, y-1)]:
                    if 0 <= i < h and 0 <= j < w:
                        if maze[i][j] == "." and visited[i][j] == -1:
                            visited[i][j] = visited[x][y] + 1
                            nxt.append([i,j])
            rtn = 0
            for i in range(h):
                rtn = max(rtn, max(visited[i]))
            return rtn

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(slv(maze, i, j), ans)
    print(ans)
resolve()

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


ll n,k,r,l,m,ko;
vector <ll> a;
ll b2(ll x){
    ll ans;
    ans=0;
    rep(i,n-1){
        
        ko=0;
        if(a[i]>=0){
            r=n-1;
            l=i+1;
            if(a[r]*a[i]<x){
                ko=r-i;
            }
            else if(a[i+1]*a[i]>=x){
                ko=0;
            }
            else{
                while(r!=l+1){
                    m=(r+l)/2;
                    if(a[m]*a[i]<x){
                        l=m;
                    }
                    else{
                        r=m;
                    }
                }
                ko=l-i;
            }
            ans+=ko;
            
        }
        else{
            r=n-1;
            l=i+1;
            if(a[r]*a[i]>=x){
                ko=0;
            }
            else if(a[i+1]*a[i]<x){
                ko=r-i;
            }
            else{
                while(r!=l+1){
                    m=(r+l)/2;
                    if(a[m]*a[i]<x){
                        r=m;
                    }
                    else{
                        l=m;
                    }
                }
                ko=n-r;
            }
            
            ans+=ko;
            
        }

    }
    //cout << "ans" << endl;
    return ans;
}

int main(){
    
    cin >> n >> k;
    a.resize(n);
    
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    ll l2=-ll(1e18)-1, r2=ll(1e18)+1;
    ll m2;
    while(r2-l2!=1){
        m2=(l2+r2)/2;
       
        if(b2(m2)<k){
            l2=m2;
        }
        else{
            r2=m2;
      }
    }

    cout << l2 << endl;

    

    return 0;
}

Measured memory_bytes: 1792
def comb(n,k); k.times.inject(1) {|s,i| s * (n - i) / (i + 1) }; end

H, W, K = gets.split.map(&:to_i)
MAP = H.times.map{ gets.chomp }

def black(h,w)
  bc = 0
  H.times do |y|
    W.times do |x|
      bc += 1 if !(h[y] > 0 || w[x] > 0) && MAP[y][x] == '#'
    end
  end
  bc
end

count = 0
(1 << H).times do |h|
  (1 << W).times do |w|
    count += 1 if black(h,w) == K
  end
end
puts count




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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	t = 1;
	while(t--) {
	 int arr[3];
	 cin >> arr[0] >> arr[1] >> arr[2];
	 sort(arr, arr + 3);
	 cout << arr[0] + arr[1] << endl;
	}
	return 0;
}



Measured memory_bytes: 256
class Array
  def diff; (size-1).times.map { |i| self[i + 1] - self[i] }.to_a end
end
INF = 0xffffffffffffffff
# mod = 998244353
# mod = 10 ** 9 + 9
mod = 10 ** 9 + 7
PI = Math::PI
dx = [ 1,  0, -1,  0,  1,  1, -1, -1]
dy = [ 0,  1,  0, -1,  1, -1,  1, -1]
eight = [0, 1, 1, 0, -1, -1, 1, -1, 0]
def max(a,b);       a > b ? a : b                              end
def min(a,b);       a < b ?  a : b                             end
def swap(a,b);      a, b = b, a                                end
def gi;             gets.to_s.to_i                             end
def gf;             gets.to_s.to_f                             end
def gs;             gets.to_s.chomp                            end
def gmi(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_i} : n.times.map{ gets.to_s.to_i } end
def gmf(n=nil); n.nil? ? gets.to_s.split.map{|t|t.to_f} : n.times.map{ gets.to_s.to_f } end
def gms(n=nil); n.nil? ? gets.to_s.split : n.times.map{ gets.to_s.chomp } end
def ga2i(h);        h.times.map{ gets.to_s.split.map{|t|t.to_i} }      end
def gm(h);        Array.new(h){ gets.to_s.split.map{|t|t.to_i} }      end
def yn(f); puts f ? "Yes" : "No" end
#def YN(f); puts f ? "YES" : "NO" end
def yes(f=nil); f.nil? ? (puts "Yes"; exit) : (puts f ? "Yes" : "No") end
def no(f=nil); f.nil? ? (puts "No"; exit) : (puts f ? "Yes" : "No") end
def yay(f=nil); f.nil? ? (puts "Yay!"; exit) : (puts f ? "Yay!" : ":(") end

def an(n,d=0) Array.new(n,d)end
def an2(n,m,d=0) Array.new(n){an(m,d)}end
def an3(n,m,l,d=0) Array.new(n){an2(m,l,d)}end
def zeros(n); an2(n,n) end
def eye(n); an2(n,n).each_with_index{|e,i|e[i]=1} end # 単位行列 identity matrix
# n = gets.to_s.to_i
# a = gets.to_s.split.map{|t|t.to_i}
# s = gets.to_s.chomp
# m = Array.new(n){ gets.split.map{|t|t.to_i} }

n = gets.to_s.to_i
# s = gets.to_s.chomp
# a = gets.to_s.split.map{|i|i.to_i}

ans = 0
1.upto(n) do |i|
  1.upto(n) do |j|
    1.upto(n) do |k|
      ans += i.gcd(j).gcd(k)
    end
  end
end

puts ans






Measured memory_bytes: 14316
def root(x):
    while P[x-1]!=x:
        x = P[x-1]
    return x

def mark(x):
    P[x-1] = x

while True:
    n,q = map(int,input().split())
    res = 0
    if n==0:
        break
    P = [1]
    for _ in range(n-1):
        P.append(int(input()))
    
    for _ in range(q):
        com,num=map(str,input().split())
        if com == "Q":
            res += root(int(num))
        else:
            mark(int(num))
    print(res)



Measured memory_bytes: 9604
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int a, b, n;
    while(cin >> a >> b >> n){
        a %= b;
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            a *= 10;
            ans += a/b;
            a %= b;
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3092
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int n,i;
    int a[1000];

    cin >> n;
    for(i=0;i<n;i++){
        if(i==0){
            scanf("%d",&a[i]);
        }else{
            scanf(" %d",&a[i]);
        }
    }
    for(i=n-1;i>=0;i--){
        if(i==n-1){
            cout << a[i];
        }else{
            cout << " " << a[i];
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3132
rc = input()
H, W = rc.split()
N = input()
colors = input()
cs = colors.split()

dim1_len = [1 for i in range(int(H)*int(W))]

count = 0
output = [[1 for i in range(int(W))] for j in range(int(H))]

for i in range(int(N)):
    n = int(cs[i])
    for j in range(n):
        dim1_len[count] = i+1
        count += 1

for i in range(int(H)):
    for j in range(int(W)):
        if i % 2 == 0:
            output[i][j] = dim1_len[i*int(W)+j]
        else:
            output[i][int(W)-j-1] = dim1_len[i*int(W)+j]
        
for i in range(len(output)):
    for j in range(len(output[0])):
        print(output[i][j],end=" ")
    print("\n")


Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <cmath>
#define ll long long
using namespace std;

int A, B, M;
vector<int> a, b, x, y, c;

int main()
{
  cin >> A >> B >> M;
  a.resize(A);
  b.resize(B);
  x.resize(M);
  y.resize(M);
  c.resize(M);

  for (int i = 0; i < A; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < B; i++)
  {
    cin >> b[i];
  }
  for (int i = 0; i < M; i++)
  {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
  }

  int a_min = *min_element(a.begin(), a.end());
  int b_min = *min_element(b.begin(), b.end());
  int min1 = a_min + b_min;

  int min2 = 200000;
  for (int i = 0; i < M; i++)
  {
    int price = a[x[i]] + b[y[i]] - c[i];
    if (price < min2)
    {
      min2 = price;
    }
  }

  cout << min(min1, min2) << endl;
}


Measured memory_bytes: 2176
#include <stdio.h>
#include <iostream>
#include <map>
#include <string>

int main(){
    int n;
    std::string str;
    char com[9];
    std::map<std::string, int> m;

    scanf("%d",&n);
    
    for(int i = 0;i < n;++i){
        
        std::cin >> com >> str;
        if(com[0] == 'i'){
            m.insert(std::make_pair(str, i));
        }
        else if(com[0] == 'f'){
            std::map<std::string, int>::iterator it = m.find(str);
            if (it != m.end()) {
                printf("yes\n");
            }
            else{
                printf("no\n");
            }
        }
    }
    return 0;
}




Measured memory_bytes: 37024
#include<iostream>

using namespace std;

int main()
{
    int n,m;
    int l,r;
    while(cin >> n >>m){
        int i=m;
        int max_l=-1,min_r=1e7;
        while(i--){
            cin >> l >> r;
            max_l=max(max_l,l);
            min_r=min(min_r,r);
        }
        if(max_l<=min_r){
            cout << min_r-max_l+1 << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#define ll long long


using namespace std;
struct edge
{
	int to;
	int cost;
	edge(int x,int y):to(x),cost(y){}
};
const ll inf=1e16+7;
int n;
typedef pair<int,ll> P;
vector<edge> G[100024];
ll d[100024];
void dijstra(int s){
	priority_queue<P,vector<P>,greater<P> >que;
	for(int i=0;i<=n;i++)  d[i]=inf;
    d[s]=0;
  //  memset(done,0,sizeof(done));
    que.push(P(0,s));
    while(!que.empty())
    {
    	P p=que.top();
    	que.pop();
    	int v=p.second;
    	if(d[v]<p.first) continue;
    	for(int i=0;i<G[v].size();i++){
    		edge e=G[v][i];
    		if(d[e.to]>d[v]+e.cost){
    			d[e.to]=d[v]+e.cost;
    		  que.push(P(d[e.to],e.to));
			}
		}
	}
}
int main()
{
	 scanf("%d",&n);
     for(int i=1;i<=n;i++)
     {
     	G[i].clear();
	 }
    int a,b,st;
	for(int i=1;i<n;i++){
		scanf("%d%d%d",&a,&b,&st);
		G[a].push_back(edge(b,st));
		G[b].push_back(edge(a,st));
	}
	int q,k;
	scanf("%d%d",&q,&k);
	dijstra(k);
	//for(int i=1;i<=n;i++) cout<<i<<"d"<<d[i]<<endl;
    while(q--)
    {
        scanf("%d%d",&a,&b);
     //   cout<<d[a]<<" "<<d[b]<<endl;
        printf("%lld\n",d[a]+d[b]);
    }
	return 0;
}


Measured memory_bytes: 9460
N, M = map(int, input().split())

linkedSwitch = []

for _ in range(1, M + 1):
    s = list(map(lambda x: int(x) - 1, input().split()))[1:]
    linkedSwitch.append(s)
p = list(map(int, input().split()))


ans = 0

for i in range(2 ** N):
    switchStatus = bin(i)[2:].zfill(N)

    for bulbIndex in range(M):
        onCount = 0

        for switchIndex in linkedSwitch[bulbIndex]:
            onCount += int(switchStatus[switchIndex])

        if onCount % 2 != p[bulbIndex]:
            break
    else:
        ans += 1

print(ans)


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

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int>D( N );
	for( size_t i = 0; i < N; i++ ) {
		cin >> D[i];
	}
	double maxans = 1, minans = 0;
	for( size_t idx = 0; idx < 28; idx++ ) {
		double midans = ( maxans + minans ) / 2;
		set<int>prev;
		prev.insert( 1 );
		for( size_t i = 0; i < N; i++ ) {
			double minvalue = D[i] * ( 1. - midans );
			double maxvalue = D[i] * ( 1. + midans );
			set<int>next;
			for( auto one : prev ) {
				for( int j = minvalue / one + 1; j <= maxvalue / one; j++ ) {
					next.insert( j*one );
				}
			}
			prev = next;
		}
		if( prev.size() ) {
			maxans = midans;
		} else {
			minans = midans;
		}

	}
	cout << fixed << setprecision( 20 ) << minans << endl;
}

Measured memory_bytes: 10808
// https://atcoder.jp/contests/abc042/tasks/abc042_b
// B - 文字列大好きいろはちゃんイージー
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// 標準入力から改行かスペースまで読み取り、数字として返す
int get_num() {
    // 10文字+区切り文字までしか受け付けられない
    char s[11];
    int i, n;
    // scanf()の直後は改行が入力に残っているので、
    // 最初の改行は読み飛ばす
    do {
        s[0] = getchar();
    } while (s[0] == '\0' || s[0] == '\n');
    for (i = 1; i < sizeof(s); i++) {
        s[i] = getchar();
        if (s[i] == ' ' || s[i] == '\n') {
            s[i] = '\0';
            break;
        }
    }
    sscanf(s, "%d", &n);
    return n;
}

// 文字列の比較
int comp_s(char a[], char b[], int n) {
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) {
            return a[i] - b[i];
        }
    }
    return 0;
}

// 文字列ソート
void sort_s(char* a[], int num) {
    int i, j;
    char* t;

    for (i = 0; i < num-1; i++) {
        for (j = 0; j < num-i-1; j++) {
            if (comp_s(a[j], a[j+1], 100) > 0) {
                t = a[j];
                a[j] = a[j+1];
                a[j+1] = t;
            }
        }
    }
}
int main(void) {
    int l, n, i;
    char s[100][101];
    char* sp[100];
    n = get_num();
    l = get_num();
    for (i = 0; i < n; i++) {
        scanf("%s", s[i]);
        sp[i] = s[i];
    }

    sort_s(sp, n);
    
    for (i = 0; i < n; i++) {
        printf("%s", sp[i]);
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const int MOD = 1e9 + 7;
using namespace std;
typedef long long ll;

map<ll, int> mp;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) cin >> d[i];
	sort(d.begin(), d.end());
	cout << d[n / 2] - d[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define lowbit(x) (x&-x)
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
const int N=16;
const int M=300;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,m,tot,dp[N][1<<N],ans;
int c[N],w[N][1<<N],can[1<<N];
int q[1<<N],cnt;
int main()
{
	//file();
	int x,y,z;
	read(n),read(m);
	For(i,1,m)
	{
		read(x),read(y),read(z);
		c[x]|=(1<<(y-1));
		w[x][1<<(y-1)]=z;
		c[y]|=(1<<(x-1));
		w[y][1<<(x-1)]=z;
		ans+=z;
	}
	For(i,1,n)
	{
		cnt=0;
		for(int x=c[i];x;x=(x-1)&c[i])
			q[++cnt]=x;
		rFor(j,cnt,1)
		{
			int x=q[j];
			w[i][x]=w[i][x^lowbit(x)]+w[i][lowbit(x)];
		}
	}
	mem(dp,-inf);
	dp[1][1]=0;
	tot=(1<<n)-1;
	For(x,1,tot)
	{
		For(u,1,n)
			if(x&(1<<(u-1)))
				can[x]+=w[u][x&c[u]];
		can[x]>>=1;
	}
	LL MAX=0;
	For(x,1,tot)
		For(u,1,n)
		if(dp[u][x]>=0){
			int bx=tot^x;
			for(int sm=bx;sm;sm=(sm-1)&bx)
				chkmax(dp[u][x|sm],dp[u][x]+can[sm|(1<<(u-1))]);
			For(v,1,n)
				if(c[u]&(1<<(v-1))&&!(x&(1<<(v-1))))
					chkmax(dp[v][x|(1<<(v-1))],dp[u][x]+w[v][1<<(u-1)]);
		}
	printf("%d\n",ans-dp[n][tot]);
	return 0;
}


Measured memory_bytes: 7808