akhauriyash/Code-Regression huggingface dataset:
///Water Hyacinth
///Hakuna Matata
///WAKE THE FUCK UP SAMURAI;WE HAVE A CODE TO RUN <3
///Any Verdict
///(Aes)  Dekhe (Tic) lagche = Aesthetic <3
///**********************************************************///

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define De double

int main()
{
    int n,k;
    cin >> n >> k;
    if (k==1)
        cout << "0" << endl;
    else
        cout << n-k << endl;

    return 0;
}

///Day:37

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
ll INF = (1LL<<31)-1;

int main(){
    ll K; cin >> K;
    ll N = 50;
    vector<ll> a(N);
    ll x = K/N;
    rep(i,N){
        a[i] = 49;
        a[i] += x;
    }
    rep(i,K%N){
        a[i] += N+1;
        rep(j,N) a[j]--;
    }
    cout << N << endl;
    rep(i,N) cout << a[i] << " ";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;cin>>n;
    map<string,int>m;
    for(int i=0;i<n;i++)
    {
        string s;cin>>s;
        m[s]+=1;
    }
    cout<<m.size()<<endl;

}


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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;
struct KEY{
  int price;
  int box;
};

int main() {
  int N,M;
  cin>>N>>M;
  vector<KEY> v(M);
  for(int i = 0; i < M; i++){
    int a,b;
    cin>>a>>b;
    v[i].price = a;
    v[i].box=0;
    for(int j = 0; j < b; j++) {
      int t;
      cin>>t;
      t--;
      v[i].box+=(1<<t);
    }
  }
  vector<vector<int>> dp(M+1,vector<int>((1<<N),-1));
  dp[0][0]=0;
  for(int i = 0; i < M; i++){
    dp[i+1][0]=0;
    for(int j = 0; j < (1<<N);j++){
      if(dp[i][j]==-1) continue;
      if(dp[i+1][j]==-1)dp[i+1][j]=dp[i][j];
      else chmin(dp[i+1][j],dp[i][j]);
      int nj = (j|v[i].box);
      if(dp[i+1][nj]==-1) dp[i+1][nj]=dp[i][j]+v[i].price;
      else chmin(dp[i+1][nj],dp[i][j]+v[i].price);
    }
  }
  cout<<dp[M][(1<<N)-1]<<endl;
}

Measured memory_bytes: 16384
def calculate():
    n,m=tuple(map(int,input().split()))
    
    i=int(float(n)/float(m))
    j=n%m
    k=float(n)/float(m)
    
    return i,j,k


a,b,c=calculate()


print(a,b,"{:.30f}".format(c))

#print("{10} {b} {c:.20g}")

#print(a," ",b," ",c)





Measured memory_bytes: 5620
import scala.io.StdIn.readLine

case class Dice(var d:Array[Int]) {

  private def rollOnce(dir:Char)  =
    dir match {
      case 'S' => Array(4,0,2,3,5,1)
      case 'N' => Array(1,5,2,3,0,4)
      case 'W' => Array(2,1,5,0,4,3)
      case 'E' => Array(3,1,0,5,4,2)
    }

  def roll(dirs:String) = d = dirs.foldLeft(Array(0,1,2,3,4,5)) { (x,y) => rollOnce(y).map(x) }.map(d)

  def getTopFace() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = Dice(faces)
  dice.roll(readLine)

  println(dice.getTopFace())
}

Measured memory_bytes: 44076
#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)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

const int dx[] = { 0,1 };
const int dy[] = { 1,0 };
bool ans[10][10];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	vector<string> a(h);
	rep(i, h) cin >> a[i];
	queue<P> que;
	que.emplace(0, 0);
	ans[0][0] = true;
	while (que.size()) {
		P p = que.front(); que.pop();
		rep(i, 2) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (a[nx][ny] == '.') continue;
			ans[nx][ny] = true;
			que.emplace(nx, ny);
			break;
		}
	}
	bool elf = true;
	rep(i, h)rep(j, w) {
		if (a[i][j] == '#' && !ans[i][j]) elf = false;
	}
	cout << (elf ? "Possible" : "Impossible") << endl;
	return 0;
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> X;
  for(int n=0;n<N;n++){
    int x;
    cin >> x; 
    X.push_back(x);
  }
  float P = 0;
  for(int i=0;i<N;i++){
    P += X[i]*1./N;
  }
  int intP = round(P);
  int ans=0;
  for(int j=0;j<N;j++){
    ans += pow(X[j]-intP,2);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {s: String};
    let s: String = s;

    let s1 = &s[0..1];
    let s2 = &s[1..2];
    let s3 = &s[2..3];

    if s1 == "R" && s2 == "R" && s3 == "R" {
        println!("3")
    } else if s1 == "R" && s2 == "R" {
        println!("2")
    } else if s2 == "R" && s3 == "R" {
        println!("2")
    } else if s1 == "S" && s2 == "S" && s3 == "S" {
        println!("0")
    } else {
        println!("1")
    }
}


Measured memory_bytes: 2196
MOD = 10 ** 9 + 7
s = input()
a = 0
ql = 0
c = s.count('C')
qr = s.count('?')
ans = 0 
for si in s:
    if si == '?':
        qr -= 1
    if si in 'B?':
        ans = (ans + pow(3,ql+qr,MOD)*a*c 
             + (pow(3,ql+qr-1,MOD)*(ql*c+a*qr) if ql + qr - 1 >= 0 else 0)
             + (pow(3,ql+qr-2,MOD)*ql*qr if ql + qr - 2 >= 0 else 0)) % MOD
    if si == '?':
        ql += 1
    elif si == 'A':
        a += 1
    elif si == 'C':
        c -= 1
print(ans)

Measured memory_bytes: 72764
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

int w, h, cnt = 0;

void srch(int x, int y, vector<vector<int>> &inp, vector < vector <bool>> &hit)
{
	if (x < 0 || w <= x || y < 0 || h <= y || inp[y][x] == 0) { return; }
	if (hit[y][x]) return;
	hit[y][x] = true;
	cnt += 1;
	srch(x + 1, y, inp, hit);
	srch(x - 1, y, inp, hit);
	srch(x, y + 1, inp, hit);
	srch(x, y - 1, inp, hit);
	srch(x + 1, y + 1, inp, hit);
	srch(x + 1, y - 1, inp, hit);
	srch(x - 1, y + 1, inp, hit);
	srch(x - 1, y - 1, inp, hit);
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> w >> h && w != 0 && h != 0)
	{
		vector<vector<int>> inp(h, vector<int>(w, 0));
		vector<vector<bool>> hit(h, vector<bool>(w, false));
		int ans = 0;
		rep(y, h) rep(x, w){ cin >> inp[y][x]; }
		rep(y, h) rep(x, w)
		{
			srch(x, y, inp, hit);
			if (cnt > 0) { ans += 1; }
			cnt = 0;
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));

    vl sum(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + A[i];

    ll ans = 1;
    repe(i,1,N){
        if (sum[i] * 2 < A[i]) ans = 0;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
template<typename Itr>
auto partition2(const Itr first, const Itr last){
  auto i=first;
  for(auto j=first; j!=last; ++j){
    if(*j<=*last){
      iter_swap(i, j);
      ++i;
    }
  }
  iter_swap(i, last);
  return i;
}
int32_t main(){
  size_t n; cin>>n;
  vector<uint32_t> a(n); for(auto&& e:a) cin>>e;
  const auto last=--end(a);
  auto mid=partition2(begin(a), last);
  for(auto i=begin(a); i!=mid; ++i) cout<<*i<<' ';
  cout<<'['<<*mid<<"] ";
  for(auto i=next(mid); i!=last; ++i) cout<<*i<<' ';
  cout<<*last<<'\n';
}


Measured memory_bytes: 3120
# -*- coding: utf-8 -*-
"""
Created on Sat May 30 17:31:55 2020

@author: NEC-PCuser
"""

N, P = map(int, input().split())
A = list(map(int, input().split()))

gusu = 0
kisu = 0

for i in A:
    if i % 2 == 0:
        gusu += 1
    else:
        kisu += 1

if (kisu == 0):
    if (P == 0):
        print(2 ** N)
    else:
        print(0)
else:
    print(2 ** (N - 1))
    

Measured memory_bytes: 3064
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>W(N);
	int sum = 0;
	rep(i, N)
	{
		cin >> W[i];
		sum += W[i];
	}
	int S1, S2;
	int sa = 1e9;
	for (int i = 0; i < N; i++)
	{
		S1 = S2 = 0;
		for (int j = 0; j <= i; j++)
		{
			S1 += W[j];
		}
		S2 = sum - S1;
		sa = min(abs(S1 - S2), sa);
	}
	cout << sa;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    int B[M], ans = 0;
    REP(i, M) cin >> B[i];
    REP(i, N) {
        int sum = C;
        REP(j, M) {
            int A;
            cin >> A;
            sum += A * B[j];
        }
        if (sum > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
// AOJ 2795 Fuda
// 2018.4.18 bal4u

#include <stdio.h>

int main()
{
	int N, M, i, j, k, v, ans;

	scanf("%d%d", &N, &M);
	ans = 0;
	for (i = 0; i < N; i++) {
		printf("lst %d\n", i), fflush(stdout);
		scanf("%d", &k);
		ans += k*(k-1);
		for (j = 0; j < k; j++) scanf("%d", &v);
	}
	printf("ans %d\n", ans), fflush(stdout);
	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
string ans = "No";
for(int i=1;i<=9;i++) {
  if(n%i==0&&n/i<=9) ans = "Yes"; 
} 
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int main() {
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	sum += min(a,k);
	k -= a;
	k -= b;
	if(k>0) {
		sum -= min(c,k);
	}
	cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3548
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let mut a: Vec<(i32, usize)> = (0..n).map(|i| (read(), i)).collect();

    a.sort();
    let ans = a
        .iter()
        .enumerate()
        .filter(|&(i, &(_, j))| j % 2 == 0 && i % 2 == 1)
        .count();

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

	int n, s;
	cin >> n >> s;
	int a[n];
	rep(i, n) cin >> a[i];
	ll dp[n + 1][s + 1];
	rep(i, n + 1) rep(j, s + 1) dp[i][j] = 0;
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, s + 1) {
			dp[i + 1][j] = dp[i][j] * 2;
			if (j >= a[i]) dp[i + 1][j] += dp[i][j - a[i]];
			dp[i + 1][j] %= MOD;
		}
	}
	cout << dp[n][s] << endl;
	return 0;
}

Measured memory_bytes: 74024
#include <iostream>
using namespace std;
#define ll long long
int main() {
    string s;
    cin>>s;
    ll k;
    cin>>k;
    k--;
    int p=-1;
    for(int i=0;i<s.size();i++){
        if(s[i]!='1'){
            p=i;
            break;
        }
    }
    if(p==-1){
        cout<<1;
        return 0;
    }
    if(k<p)
    cout<<1;
    else cout<<s[p];
}


Measured memory_bytes: 256
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define vp vector<pi>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define f(i,x,z) for(int i=x;i<z;i++)
#define debug(x) cout<<"DEBUG------> "<<x<<endl
#define endl "\n"
#define mii             map<int,int>
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
#define srt(v) sort(v.begin(), v.end())
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

// Driver Program 
int main() 
{ 
    int max1=0,c=0,diff,d=0,var;
    string str;
    cin>>str;
    if(str[0]=='R')
    {
        if(str[1]=='R' && str[2]=='R')
        {
            c=3;
        }
        else if(str[1]=='R' && str[2]!='R')
        {
            c=2;
        }
        else if(str[1]!='R' && str[2]=='R')
        {
            c=1;
        }
        else{
            c=1;
        }
    }
    else if(str[0]=='S')
    {
        if(str[1]=='R' && str[2]=='R')
        {
            c=2;
        }
        else if(str[1]=='R' && str[2]!='R')
        {
            c=1;
        }
        else if(str[1]!='R' && str[2]=='R')
        {
            c=1;
        }
        else{
            c=0;
        }
    }
    cout<<c;
}

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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define len(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

#define ll long long
#define ld long double

int n, m;
char a[107][107];
int dp[107][107];

int get(char x, char y) {
    return x == '.' && y == '#';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) cin >> a[i][j];
    }
    dp[0][0] = a[0][0] == '#';
    for (int i = 1; i < n; i++) dp[i][0] = dp[i - 1][0] + get(a[i - 1][0], a[i][0]);
    for (int j = 1; j < m; j++) dp[0][j] = dp[0][j - 1] + get(a[0][j - 1], a[0][j]);
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) dp[i][j] = min(dp[i - 1][j] + get(a[i - 1][j], a[i][j]), dp[i][j - 1] + get(a[i][j - 1], a[i][j]));
    }
    cout << dp[n - 1][m - 1];
    return 0;
}


Measured memory_bytes: 384
// Precomputation: O(nlgn)
// Query: O(1)
//
// Data structure: Sparse Table

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

#define fi first
#define se second

typedef pair<int,int> ii;
typedef vector<int> vi;

const int MAXN = 100005;
const int LOGN = 20;

int idx_in_path[MAXN];
ii path[MAXN<<1];
vi adjList[MAXN];

int path_size = 0;

// compute and store the dfs order in path
// initial call with dfs(root)
void dfs(int u, int depth = 0) {
    idx_in_path[u] = path_size;

    path[path_size++] = ii(depth,u);
    for (int v : adjList[u]) {
        dfs(v, depth + 1);

        path[path_size++] = ii(depth, u);
    }
}

// must call dfs before build
// compute entries for sparse table
ii st[LOGN][MAXN<<1];
void build(int n) {
    int h = ceil(log2(n + 1));

    for (int i = 0; i < n; i++) st[0][i] = path[i];
    for (int i = 1; i < h; i++)
        for (int j = 0; j + (1<<i) <= n; j++)
            st[i][j] = min(st[i-1][j], st[i-1][j+(1<<(i-1))]);
}

// return the lowest common ancestor between node u and v
int lca(int u, int v) {
    int l = idx_in_path[u], r = idx_in_path[v]; 
    if (l > r) swap(l, r); r++; // range [l, r)
    
    int p = 31 - __builtin_clz(r-l);
    return min(st[p][l],st[p][r-(1<<p)]).se;
}

int main() {

    int num_nodes;
    scanf("%d", &num_nodes);
    for (int u = 0; u < num_nodes; u++) {
        int num_neighbors;
        scanf("%d", &num_neighbors);
        for (int i = 0; i < num_neighbors; i++) {
            int v;
            scanf("%d", &v);
            
            adjList[u].push_back(v); // directed edge
        }
    }

    dfs(0);
    build(path_size);

    int num_queries;
    scanf("%d",&num_queries);
    for (int i = 0; i < num_queries; i++) {
        int u, v;
        scanf("%d%d",&u,&v);

        printf("%d\n", lca(u, v));
    }

    return 0;
}

Measured memory_bytes: 41500
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int first = 0;
		int count = 1;

		for (int i = 1; i < 4; i++) {

			if (s.substring(0, 1).equals(s.substring(i, i + 1))) {
				count++;

				if (count > 2) {
					System.out.print("No");
					System.exit(0);
				} else {
					first = i;
				}
			}
		}
		if (count == 2) {
			if (first == 1) {
				if (s.substring(2, 3).equals(s.substring(3, 4))) {
					if (!(s.substring(0, 1).equals(s.substring(2, 3)))) {
						System.out.print("Yes");
						System.exit(0);
					}
				} else {
					System.out.print("No");
					System.exit(0);
				}
			}
			if (first == 2) {
				if (s.substring(3, 4).equals(s.substring(1, 2))) {
					if (!(s.substring(0, 1).equals(s.substring(1, 2)))) {
						System.out.print("Yes");
						System.exit(0);
					}
				} else {
					System.out.print("No");
					System.exit(0);
				}

			}
			if (first == 3) {
				if (s.substring(2, 3).equals(s.substring(1, 2))) {
					if (!(s.substring(0, 1).equals(s.substring(2, 3)))) {
						System.out.print("Yes");
						System.exit(0);
					}
				} else {
					System.out.print("No");
					System.exit(0);
				}
			}
		} else {
			System.out.print("No");
			System.exit(0);
		}

	}

}

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

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


const int INF = 1 << 30;
vector<int> dp;

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

    dp.assign(n+10, n);

    dp.at(0) = 0;

    int a, b;
    for(int i=1; i<=n; i++){
        a=1;
        chmin(dp.at(i), dp.at(i-1) + 1);
        while(i>=a){
            chmin(dp.at(i), dp.at(i-a)+1);
            a = a*6;
        }

        b=1;
        while(i>=b){
            chmin(dp.at(i), dp.at(i-b)+1);
            b = b*9;
        }

    }

    cout << dp.at(n) << endl;

    return 0;
}


Measured memory_bytes: 640
import java.io.*; 
import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
class Main{
public static void main(String[] args){
try{
   BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String b = reader.readLine();
   String c = reader.readLine();
  String parts[] = c.split(" ");
 	int n = Integer.parseInt(b);
  Arrays.sort(parts);
   int flag = 0;
  for(int i =0;i<n-1;i++){
  	if(parts[i].compareTo(parts[i+1]) == 0){
      flag =1;
      System.out.println("NO");
      i = n;
    }
  }
  
 
  
  if(flag == 0){
    System.out.println("YES");
  }
}catch(Exception e){}
}
}

Measured memory_bytes: 49492
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = n-1; i >= 0; --i)
#define REP(i, s, n) for (int i = s; i< (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
ll inf = ll(1e18);
using ll1d = vector<ll>;
using ll2d = vector<ll1d>;
using ll3d = vector<ll2d>;

void solve(istream &ccin = cin, ostream &ccout = cout) {
  ll n;
  ccin >> n;
  string s;
  ccin >> s;
  ll cntl = 0, cntr = 0;
  ll ansl = 0;
  rep(i, n) {
    if (s[i] == '(')
      ++cntl;
    else
      ++cntr;

    if (cntl < cntr) {
      --cntr;
      ++ansl;
    }
  }

  ll ansr = 0;
  cntl = 0;
  cntr = 0;
  rrep(i, n) {
    if (s[i] == '(')
      ++cntl;
    else
      ++cntr;
    if (cntl > cntr) {
      --cntl;
      ++ansr;
    }
  }

  string ans = "";
  rep(i, ansl)ans += "(";
  ans += s;
  rep(i, ansr)ans += ")";

  ccout << ans << endl;

}

int main() {
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
read s

if [ ${s:0:1} != 'A' ] ; then
    echo "WA" && exit
fi

flag=0

for (( i = 2; i < ${#s}-1; i++ )) do
    if [ ${s:$i:1} == 'C' ] ; then
        flag=1
    fi
done

if [ $flag != 1 ] ; then
    echo "WA" && exit
fi

count=0

for (( i = 0; i < ${#s}; i++ )) do
    if [[ $(echo ${s:$i:1} | awk '/[A-Z]/') ]] ; then
        count=$((count+=1))
    fi
done

if [ $count != 2 ] ; then
    echo "WA"
else
    echo "AC"
fi

Measured memory_bytes: 4168
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <stack>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define dd(x) cout << #x << "=" << x << ", "
#define de(x) cout << #x << "=" << x << endl
#define ds() puts("---stop here---")
#define mset(a,i) memset(a,i,sizeof(a))
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6
#define INF 0x3f3f3f3f
void open(){freopen("data.txt","r",stdin);}
void out(){freopen("out.txt","w",stdout);}
const int maxn = 101010;
const int MOD = 1e9 + 7;

int cost[10][10];
int h,w;
int maps[205][205];


int main()
{
    scanf("%d%d",&h,&w);
    rep(i,0,10) rep(j,0,10) scanf("%d",&cost[i][j]);
    rep(k,0,10) rep(i,0,10) rep(j,0,10) cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);

    int x;
    ll ans = 0;
    rep(i,0,h) rep(j,0,w){
        scanf("%d",&x);
        if(x==1||x==-1) continue;
        ans+=cost[x][1];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
p = 0
for i in range(N):
  if A[i] % 2 == 0:
    A[i] //= 2
  else:
    p = 1
    break
L = A[0]
k = 0
while A[0] % 2 == 0:
  k += 1
  A[0] //= 2
for i in range(1, N):
  a, b = L, A[i]
  while b != 0:
    a, b = b, a % b
  b = A[i] // a
  L *= b
  cnt = 0
  while A[i] % 2 == 0:
    cnt += 1
    A[i] //= 2
  if cnt != k:
    p = 1
    break
if p == 1:
  S = 0
else:
  S = M // L - M // (2 * L)
print(S)

Measured memory_bytes: 15060
#include <iostream>
#include <cmath>

using namespace std;

int main(){
  int A,B;
  cin >> A >> B;
  if((A+B) % 2 == 1){
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }else{
    int K = (A+B)/2;
    cout << K << endl;
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
const int N = 2e4 + 10;
const int s = N - 1;
const int t = N - 2;
int n, pre[N], pree[N], flow[N];
ll dis[N];
bool vis[N];
struct edge {
  int to, val, cost, rev;
};
const ll inf = 2e18;
vector<edge> g[N];
//
inline void addedge(int x, int y, int z, int w) {
  g[x].emplace_back((edge){y, z, w, (int)g[y].size()});
  g[y].emplace_back((edge){x, 0, -w, (int)g[x].size() - 1}); 
}
bool spfa() {
  memset(vis, 0, sizeof(vis)); pre[t] = -1;
  rep(i, N) dis[i] = -inf, flow[i] = INF; dis[s] = 0;
  queue<int> qu; qu.emplace(s);
  while (qu.size()) {  
    int u = qu.front(); qu.pop(); vis[u] = false;
    rep(i, g[u].size()) {
      edge &e = g[u][i];
      if (e.val && dis[e.to] < 1ll * e.cost + dis[u]) {
        dis[e.to] = 1ll * e.cost + dis[u];
        pre[e.to] = u;
        pree[e.to] = i;
        flow[e.to] = min(flow[u], e.val);
        if (!vis[e.to]) {
          vis[e.to] = true;
          qu.emplace(e.to);
        }
      }
    }
  }
  return pre[t] >= 0;
}
ll ek() {
  ll res = 0;
  while (spfa()) {
    int now = t;
    res += 1ll * flow[t] * dis[t];
    while (now != s) {
      int u = pre[now], x = pree[now];
      g[u][x].val -= flow[t];
      g[now][g[u][x].rev].val += flow[t];
      now = u;
    }
  }
  return res;
}
int main() {
  n = getint();
  rep(i, n) {
    int x = getint(), y = getint(), c = getint();
    addedge(s, i, c, 0);
    addedge(i, 2 * n, INF, x + y);
    addedge(i, 2 * n + 1, INF, x - y);
    addedge(i, 2 * n + 2, INF, y - x);
    addedge(i, 2 * n + 3, INF, -x - y);
  }
  for (int i = n; i < 2 * n; i++) {
    int x = getint(), y = getint(), c = getint();
    addedge(i, t, c, 0);
    addedge(2 * n, i, INF, -x - y);
    addedge(2 * n + 1, i, INF, y - x);
    addedge(2 * n + 2, i, INF, x - y);
    addedge(2 * n + 3, i, INF, x + y);
  }
  cout << ek() << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> l(N);
    rep(i, N) cin >> l[i];
    
    int ans = 100100100;
    rep(bit, 1 << (2 * N)) {
        vector<int> S(N);
        int co = bit;
        rep(i, N) {
            S[i] = co % 4;
            co /= 4;
        }
        int a = 0;
        int b = 0;
        int c = 0;
        int a_cnt = 0;
        int b_cnt = 0;
        int c_cnt = 0;
        rep(i, N) {
            if (S[i] == 1) {
                a += l[i];
                ++a_cnt;
            }
            if (S[i] == 2) {
                b += l[i];
                ++b_cnt;
            }
            if (S[i] == 3) {
                c += l[i];
                ++c_cnt;
            }
        }
        if (a == 0 || b == 0 || c == 0) continue;
        ans = min(ans, abs(A - a) + abs(B - b) + abs(C - c) + 10 * (a_cnt + b_cnt + c_cnt - 3));
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int N, A, B;
  cin >> N;
  A = 0;
  B = 0;
  vector<int> X(N);
  for (int i=0; i<N; i++){
  	cin >> X[i];
  }
  sort (X.begin(),X.end());
  reverse (X.begin(),X.end());
  for (int i=0; i<N; i+=2){
    A += X[i];
  }
  for (int i=1; i<N; i+=2){
    B += X[i];
  }
  cout << A-B << endl;
}


Measured memory_bytes: 3512
def f(e):
 a=list([*map(int,input().split())]for _ in range(int(e)))
 s,t=a[0]
 b={tuple(map(int,input().split()))for _ in range(int(input()))}
 for x,y in b:
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:break
  else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)


Measured memory_bytes: 5904
# AGC035A - XOR Circle_2.py
import sys

STDIN = 1
number = 1
elements = [[0]]

sample = """
3
1 2 3
"""

example = """
3
1 1 4
5 1 4
8 1 0
"""

if bool(sample.strip().splitlines()) or bool(STDIN):
    if bool(STDIN):
        number = int(sys.stdin.readline().strip())


        def pick():
            return sys.stdin.readline().strip()

    else:
        stack = sample.strip().splitlines()[::-1]
        number = int(stack.pop().strip())


        def pick():
            return stack.pop().strip()

    elements = list(map(int, pick().split()))

elif bool(number):
    i = 0
    for amp in (sample, example):
        i, j = i + 1, 0
        for p in (amp, amp.strip()):
            j += 1
            print("{}-{} = {}".format(i, j, repr(p)))
            print(p.split())
            print(p.splitlines())

##############################################################################

numbers = tuple(elements)
kinds = set(numbers)


def yes():
    print("Yes")
    sys.exit()


if kinds == {0}:
    yes()

elif len(kinds) == 2:
    if 0 in kinds:
        if numbers.count(0) * 3 == number:
            yes()

elif len(kinds) == 3:
    a, b, c = tuple(kinds)
    if a ^ b == c:
        if (numbers.count(a) == numbers.count(b)) and (numbers.count(b) == numbers.count(c)):
            yes()

print("No")


Measured memory_bytes: 14212
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int d = scan.nextInt();
			double D = (double)d;
			
			long[]X = new long[N];
			long[]Y = new long[N];
			for(int i = 0;i<N;i++) {
				X[i] = scan.nextLong();
				Y[i] = scan.nextLong();
			}
			
			int count = 0;
			
			for(int i = 0;i<N;i++) {
				double dist = Math.sqrt(X[i]*X[i]+Y[i]*Y[i]);
				if(D>=dist)count++;
			}
			
			System.out.println(count);
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 62908
N = gets.to_i
a = []
a = gets.chomp.split(" ").map(&:to_i)
alice = 0
bob = 0
max = 0

(1..N).each do |i|
  # 最大値判定
  a.sort! {|a, b| b <=> a }

  if i % 2 != 0 then
    alice += a[i-1]
  else
    bob += a[i-1]
  end
end

puts alice - bob

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
 
#define pll pair<ll, ll>
#define pi pair<int,int>
 
map<pll,int> black;
 
int dx[3] = {0,-1,-2}, dy[3] = {0,-1,-2};
 
map<pi,int> found;
 
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll h, w;
	cin >> h >> w;
	int n;
	cin >> n;
	ll R[n], C[n];
	for(int i = 0; i < n; i++)
	{
		cin >> R[i] >> C[i];
		black[pll(R[i],C[i])] = 1;
	}
	ll ans[10];
	memset(&ans,0,sizeof(ans));
	ll tt = 0;
	int total = 0;
	for(int i = 0; i < n; i++)
	{
		for(int px = 0; px < 3; px++)
		{
			if(R[i]+dx[px] > h-2 || R[i]+dx[px] <= 0) continue;
			int cnt = 0;
			int st = 0;
			for(int py = 0; py < 3; py++)
			{
				if(C[i]+dy[py] > w-2 || C[i] + dy[py] <= 0) continue;
				pi rect;
				rect.first = R[i]+dx[px], rect.second = C[i]+dy[py];
				if(found.count(rect))
				{
					continue;
				}
				if(st == 0)
				{
					cnt = 0;
					for(int r = 0; r < 3; r++)
					{
						for(int c = 0; c < 3; c++)
						{
							int blck_cnt = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py])+c));
							if(blck_cnt)
							{
								cnt ++;
							}
						}
					}
				}
				else
				{
					for(int r = 0; r < 3; r++)
					{
						int blck_cnt = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py-1]+2)));
						int blck_cnt2 = black.count(pll((R[i]+dx[px])+r,(C[i]+dy[py])));
						cnt -= blck_cnt;
						cnt += blck_cnt2;
					}
				}
				found[rect]=cnt;
				ans[cnt]++;
				tt++;
				st++;
			}
		}
	}
	ans[0] = ((h-2)*(w-2))-tt;
	for(int j = 0; j <= 9; j++)
	{
		cout << ans[j] << endl;
	}
	return 0;
}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

struct UnionFind{
  vector<int> d;
  UnionFind(int n) : d(n, -1){}
  int find(int x){
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x == y) return false;
    if(d.at(x) > d.at(y)) swap(x, y);
    d.at(x) += d.at(y);
    d.at(y)= x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d.at(find(x)); }
};

int main(){
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i, m){
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    uf.unite(x, y);
  }
  int ans = 0;
  rep(i, n){
    if(uf.d.at(i) < 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
#include <deque>
#include <string>
#include <queue>
#include <omp.h>
#include <fstream>   // ifstream, ofstream
typedef int64_t ll;
using namespace std;
const ll INF=1e10;
const double EPS=1e-8;
#include <cstdint>
#include <iostream>
#include <utility>
#include <map>

int64_t gcd(int64_t a,int64_t b){//calc gcd
	if(a==0){
		return b;
	}else if(b==0){
		return a;
	}else if(a>b){
		return gcd(a%b,b);
	}else{
		return gcd(b%a,a);
	}
}

std::pair<int64_t,int64_t> extgcd(int64_t a,int64_t b){//a*(pair->first) + b*(pair->second) = gcd(a,b)
	if(a==0){
		return std::make_pair(0,1);
	}else if(b==0){
		return std::make_pair(1,0);
	}else{
		if(a>b){
			std::pair<int64_t,int64_t> d=extgcd(a%b,b);
			return std::make_pair(d.first,d.second-(a/b)*d.first);
		}else{
			std::pair<int64_t,int64_t> d=extgcd(a,b%a);
			return std::make_pair(d.first-(b/a)*d.second,d.second);
		}
	}

}
template<class T>
T normalize_mod(T a,T m){
	return (m+a%m)%m;
}
int64_t mod_inv(int64_t a,int64_t m){//a^-1(mod m),m is a prime number
	int64_t raw=extgcd(a,m).first;
	return normalize_mod(raw,m);;
}
std::map<int64_t,int64_t> factorization(int64_t n){
	std::map<int64_t,int64_t> retval;
	for(int64_t i=2;i*i<=n;i++){
		int64_t counter=0;
		while(n%i==0){
			n=n/i;
			counter++;
		}
		if(counter!=0){
			retval.emplace(i,counter);
		}
	}
	return retval;
}
std::pair<int64_t,int64_t> mod_fact(int64_t n,int64_t m){//n!=first*m^second
	if(n==0){
		return std::make_pair(1,0);
	}else{

		std::pair<int64_t,int64_t> d=mod_fact(n/m,m);
		int64_t second=d.second+n/m;
		int64_t first;
		if((n/m)%2==0){
			first=1;
		}else{
			first=m-1;
		}
		for(int64_t i1=1;i1<=(n%m);i1++){
			first=normalize_mod(first*i1,m);
		}
		return std::make_pair(first,second);
	}
}

int main(){
	ll n,k;
	cin>>n>>k;
	ll **combination = new ll*[n+1];
	for(ll i1=0;i1<n+1;i1++){
		combination[i1]=new ll[n+1];
	}
	for(ll i1=0;i1<=n;i1++){
		combination[i1][0]=1;
		for(ll i2=1;i2<=i1;i2++){
			ll multiply = normalize_mod<ll>((i1-i2+1)*mod_inv(i2,1000000007),1000000007);
			combination[i1][i2]=(multiply*combination[i1][i2-1])%1000000007;
		}
	}
	for(ll i1=1;i1<=k;i1++){
		cout<<(combination[n-k+1][i1]*combination[k-1][i1-1])%1000000007<<endl;
	}

}


Measured memory_bytes: 22912
package main

import "fmt"

type dice struct {
	a [7]int
}

func (d *dice) init(a [6]int) {
	for i := range a {
		d.a[i+1] = a[i]
	}
}

func (d *dice) top() int {
	return d.a[1]
}

func (d *dice) front() int {
	return d.a[2]
}

func (d *dice) right() int {
	return d.a[3]
}

func (d *dice) north() {
	d.a[1], d.a[2], d.a[5], d.a[6] = d.a[2], d.a[6], d.a[1], d.a[5]
}

func (d *dice) south() {
	d.a[1], d.a[2], d.a[6], d.a[5] = d.a[5], d.a[1], d.a[2], d.a[6]
}

func (d *dice) west() {
	d.a[1], d.a[4], d.a[6], d.a[3] = d.a[3], d.a[1], d.a[4], d.a[6]
}

func (d *dice) east() {
	d.a[1], d.a[4], d.a[6], d.a[3] = d.a[4], d.a[6], d.a[3], d.a[1]
}

func (d *dice) spin() {
	d.a[4], d.a[2], d.a[3], d.a[5] = d.a[2], d.a[3], d.a[5], d.a[4]
}

func (d *dice) rotate(t, f int) int {
	for i := 0; i < 2; i++ {
		for j := 0; j < 4; j++ {
			for k := 0; k < 4; k++ {
				if d.top() == t && d.front() == f {
					return d.right()
				}
				d.spin()
			}
			d.north()
		}
		d.east()
	}
	return -1
}

func main() {
	var a [6]int
	for i := range a {
		fmt.Scan(&a[i])
	}
	var d dice
	var q, t, f int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&t, &f)
		d.init(a)
		fmt.Println(d.rotate(t, f))
	}
}



Measured memory_bytes: 1120
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;

const int N = 1e5+10;
int a[N];
int main(){
    ll a,b;
    cin >> a >> b;
    priority_queue<ll,vector<ll>,greater<ll>> q;
    q.push(a);
    a%= b;
    q.push(a);
    a = b - a;
    q.push(a);
    cout << q.top() << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	cin>>n;
	vector<string>in(n);
	map<string,int>tmp;
	vi ne(n);
	rep(i,n)cin>>in[i]>>ne[i];
	rep(i,n)tmp[in[i]]=i;
	int m;
	cin>>m;
	vi in1,in2;
	rep(i,m){
		string a,b;
		cin>>a>>b;
		int c=tmp[a],d=tmp[b];
		in1.pb(c);
		in2.pb(d);
	}
	rep(i,m){
		rep(j,m){
			if(ne[in1[j]]>ne[in2[j]])ne[in1[j]]=ne[in2[j]];
			else if(ne[in1[j]]<ne[in2[j]])ne[in2[j]]=ne[in1[j]];
		}
	}
	int sum=0;
	rep(i,n)sum+=ne[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 1880
#include<stdio.h>


int main()
{
	long a,b,sum,count=0;

	while(scanf("%ld %ld",&a,&b)==2)
	{
		sum=a+b;

		while(sum>0)
		{
			sum=sum/10;
			count++;
		}

		printf("%d\n",count);
		count=0;
	}
		
	
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;

int t[10][10];
int d[10][10];

void gen() {exit(0);}
int main() {
    #ifdef DEBUG
    freopen("input", "r", stdin);
//    freopen("output", "w", stdout);
//    gen();
    #endif
    int h, w;
    scanf("%d %d", &h, &w);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            scanf(" %d", &t[i][j]);
        }
    }
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            if (i == j) d[i][j] = 0;
            else d[i][j] = t[i][j];
        }
    }
    for (int k = 0; k < 10; k++) {
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    
    int ans = 0;
    forn(i, 0, h) {
        forn(j, 0, w) {
            int x;
            scanf(" %d", &x);
            if (x != -1) {
                ans += d[x][1];
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    string s; cin >> s;
    REP(i, 0, s.size()) {
        if (i % 2 == 1 && s[i] == 'R') {
            cout << "No" << endl;
            return 0;
        }
        if (i % 2 == 0 && s[i] == 'L') {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
N=int(input())
a_list = list(map(int,input().split()))
index = defaultdict(int)
total = 0
for a in a_list:
  total += a
  index[a] += 1

Q = int(input())
for _ in range(Q):
  B,C= list(map(int,input().split()))
  move = index[B]
  index[B] = 0
  index[C] += move
  total += (C-B)*move
  print(total)

Measured memory_bytes: 94496
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string s;
long long n;
int main()
{
    cin>>s;
    cin>>n;
    for(long long i=0;i<n;i++)
        if(s[i]!='1'){ printf("%c",s[i]); return 0;}
    printf("1");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define pb push_back
#define f(i,a) for(ll i=1;i<a;i++)


int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n;
    cin>>n;
    
    ll a[10001]={0};
    
    f(x,100)
    {
        f(y,100)
        {
            f(z,100)
            {
                ll k=((x+y)*(x+y))+((y+z)*(y+z))+((z+x)*(z+x));
                if(k<=20000 && k%2==0)
                {
                    k/=2;
                a[k]++;
                }
              
            }
        }
    }
    
    for(ll i=1;i<=n;i++)
    {
        cout<<a[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3716
H, W, K = gets.chomp.split().map(&:to_i)
cells = []
gyou = Hash.new(0)
retu = Hash.new(0)
total = 0

H.times do |h|
  c = gets.chomp.split('')
  cells << c
  gyou[h.to_s] += c.count {|s| s == '#'}
  total += gyou[h.to_s]
end
W.times do |w|
  H.times do |h|
    if cells[h][w] == '#'
      retu[w.to_s] += 1
    end
  end
end

cnt = 0
[0, 1].repeated_permutation(H).to_a.each do |gyou_bit|
  [0, 1].repeated_permutation(W).to_a.each do |retu_bit|
    d_total = total.dup
    gyou_bit_ind = gyou_bit.each_index.select{|i| gyou_bit[i] == 1}
    retu_bit_ind = retu_bit.each_index.select{|i| retu_bit[i] == 1}
    gyou_bit_ind.each do |i|
      d_total -= gyou[i.to_s]
      next if retu_bit_ind.empty?
      retu_bit_ind.each do |j|
        d_total += 1 if cells[i][j] == "#"
      end
    end
    retu_bit_ind.each do |j|
      d_total -= retu[j.to_s]
    end
    cnt += 1 if d_total == K
  end
end

puts cnt


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

using namespace std;
using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;
  if (N == K) {
    cout << 0 << endl;
  } else if (K < N) {
    ll a = N / K;
    ll m = min(N - a * K, (a + 1) * K - N);
    cout << m << endl;
  } else {
    set<ll> s;
    ll a = K - N;
    s.insert(a);
    ll m = a;
    while (1) {
      a = abs(a - K);
      m = min(m, a);
      if (s.find(a) != s.end()) {
        break;
      }
    }
    cout << m << endl;
  }
  return 0;
}

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

long long int addnum(long long int l, long long int s){
  return l*(l+1LL)/2LL + s*(s-1LL)/2LL;
}

int main(){
  string s;
  cin >> s;
  if(s[0] == '>') s = '<' + s;
  if(s[s.size()-1] == '<') s = s + '>';
  long long int l = 0LL;
  long long int r = 0LL;
  long long int ans = 0LL;
  bool rflag = false;
  for (int i = 0; i < s.size(); i++){
    if(s[i] == '<'){
      if(rflag){
        rflag = false;
        ans += addnum(max(l,r), min(l,r));
        l = 0LL;
        r = 0LL;
      }
      l++;
    }
    else{
      r++;
      rflag = true;
    }
  }
  ans += addnum(max(l,r), min(l,r));
  cout << ans << endl;
}

Measured memory_bytes: 1796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<arr[k-1];
	return 0;
	
}

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

int main(){
  int H,W,x = 0;
  cin >> H >> W;
  string C[H];
  for(int i = 0;i < H;i++){
    cin >> C[i];
  }
  for(int i = 0;i < 2 * H;i++){
    cout << C[i / 2] << endl;
  }
  return 0;
}


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

vector<int> count_array(MAX_N, 0);

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

    vector<long long> A(N, 0);
    long long s = 0;
    for (int i = 0; i < N; i++){
        cin >> A[i];
        count_array[A[i]] += 1;
        s += A[i];
    }

    cin >> Q;
    vector<long long> B(Q, 0);
    vector<long long> C(Q, 0);
    for (int i = 0; i < Q; i++){
        cin >> B[i] >> C[i];
        long long tmp = count_array[B[i]];
        count_array[C[i]] += tmp;
        count_array[B[i]] = 0;
        s += (C[i] - B[i]) * tmp;
        cout << s << endl;
    }
}

Measured memory_bytes: 5876
// Hack it and have it ;) //
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include      <bits/stdc++.h>
#include      <ext/pb_ds/assoc_container.hpp>
#include      <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC   optimize ("Ofast")
#pragma GCC   optimize ("unroll-loops")
#pragma GCC   target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS   ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC  cout.precision (10); cout << fixed
#define x     first
#define y     second
#define bg(x) " [ " << #x << " : " << (x) << " ] "
#define un(x) sort(x.begin(), x.end()), \
              x.erase(unique(x.begin(), x.end()), x.end())
using   ll  = long long;
using   ull = unsigned long long;
using   ff  = long double;
using   pii = pair<int,int>;
using   pil = pair<int,ll>;
typedef tree
< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;

struct chash {
   int operator()(pii x) const { return x.x*31 + x.y; }
};
gp_hash_table <pii, int, chash> mp;

seed_seq seq{
   (uint64_t) chrono::duration_cast<chrono::nanoseconds>
      (chrono::high_resolution_clock::now().time_since_epoch()).count(),
      (uint64_t) __builtin_ia32_rdtsc(),
      (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq); //uniform_int_distribution<int> (l, h)(rng); //[low, high]

#define debug(args...) { \
   /* WARNING : do NOT compile this debug func calls with following flags: // \
    * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); \
   istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) {
   it->empty(); cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
   cerr << fixed << setprecision(15)
      << " [ " <<  *it << " : " << a  << " ] "<< ' ';
   err(++it, args...);
}
/*****************************************************************************/

signed main() {
   IOS; PREC;

   ll a, b, c, d;
   cin >> a >> b >> c >> d;
   ll lc = (c * d) / __gcd(c, d);
   cout << (b - a + 1)  - (b/c - (a - 1)/c + b/d - (a - 1)/d - ((b/lc) - (a - 1)/lc)) << '\n';

   return EXIT_SUCCESS;
}


Measured memory_bytes: 256