akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
)

func main() {
	var S,T string
	fmt.Scan(&S, &T)
	
	var s,t string
	var counter int
	for i := 0; i < len(S); i++ {
		s = S[i:i+1]
		t = T[i:i+1]
		if s != t {
			counter++
		}
	}
	fmt.Println(counter)
}



Measured memory_bytes: 3392
#include <iostream>
#include <cstdlib>
#include <stack>
#include <string>
#include <stdio.h>

using namespace std;

stack<int> x;

int calc(string a);

int main(){

  string a;

  while(cin >> a){
    if(a == "+" || a == "-" || a == "*"){
      x.push(calc(a));
    }
    else{
      int y = atoi(a.c_str());
      x.push(y);
    }
    if(getchar() == '\n'){
      break;
    }
  }
  cout << x.top() << '\n';
  return 0;
}
int calc(string a){

  int m = x.top();
  x.pop();
  int n = x.top();
  x.pop();

  if(a == "+"){
    return (m + n);
  }
  else if(a == "-"){
    return (n - m);
  }
  else if(a == "*"){
    return (m * n);
  }
  else{
    cout << "error\n";
    exit(1);
  }
}



Measured memory_bytes: 3160
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    string s; cin >> s;
    long long sum = 0;
    for (int i = 0; i < s.size(); i++) {
        sum += s[i] - '0';
    }
    if (sum % 9 == 0) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#define fi(p) for(int i=0;i<(p);i++)
using namespace std;
int N;
int L;
int P;
const int MAX_N = 100000;
const int MAX_W = 100000;


int A[MAX_N+1];
int B[MAX_N+1];

void solve() {
	int a;
	int b;
	int c;

	cin >> a >> b >> c;

	int res = c - (a - b);

	if (res < 0) {
		cout << 0 << endl;
	}
	else {
		cout << res << endl;
	}

	
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
  int n; std::cin >> n;
  int prev = 0;
  long long res = 0;
  for (int i = 0; i < n; ++i) {
    int t; std::cin >> t;
    if (t < prev) res += prev - t;
    else prev = t;
  }
  std::cout << res;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> H(n), Good(n, 1);

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


  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    if (H[a] >= H[b]) Good[b] = 0;
    if (H[b] >= H[a]) Good[a] = 0;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (Good[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int li[] = new int[N];
    int count = 0;
    
    for(int i=0;i<N;i++){
      li[i] = sc.nextInt();
      if(li[i]!=i+1){
        count++;
      }
    }
    
    if(count==0 || count==2){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
} 

Measured memory_bytes: 21844
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N; cin >> N;    
    vll A(N);
    cin >> A[0];
    ll t = A[0];
    rep(i, 1, N){
        cin >> A[i];
        t = t^A[i];
    }
    rep(i, 0, N){
        prt(t^A[i]); prt(" ");
    }
}



Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);cout.precision(20);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) (upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X))
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')
#define pow2(x) ((long long)((long long)1<<x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const long long dy9[] = {0,1,1,1,0,-1,-1,-1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

bool check(const vl& L,const ll& N){
	FOR(i,0,N-1)if(L[i+1] < L[i])return 0;
	return 1;
}

vl Sort(vl L,ll N){
	random_device rnd;
	while(!check(L,N)){
		ll a = rnd()%N;
		ll b = rnd()%N;
		swap(L[a],L[b]);
	}
	return L;
}

signed main(){
	ll N;
	cin >> N;
	vl L(N);
	FOR(i,0,N)cin >> L[i];
	vl ans = Sort(L,N);
	ll SUM = 0;
	FOR(i,0,N)SUM += ans[i];
	Yes(SUM-ans[N-1] > ans[N-1]);
}


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

#define ll long long
#define endl "\n"
#define int ll

const int mx = 1e7 + 5;
const int MOD = 1e9 + 7;

int power(int a, int b) {
	int res = 1;

	while (b) {
		if (b % 2) {
			res = (res * a) % MOD;
		}

		a = (a * a) % MOD;
		b /= 2;
	}

	return res;
}

int inv(int a) {
	return power(a, MOD - 2);
}

int nCr(int a, int b) {
	if (a < b) return 0;
	int ans = 1;
	for (int i = a, j = 1; i >= a - b + 1; i--, j++) {
		ans = (ans * i) % MOD;
		ans = (ans * inv(j)) % MOD;
	}
	return ans;
}

signed main ()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

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

	cout << (power(2, n) - 1 - nCr(n, a) - nCr(n, b) + 2 * MOD) % MOD << endl;

	return 0;

}


Measured memory_bytes: 3620
n,W=map(int,input().split())
values=[]
weights=[]

for _ in range(n):

    a,b=map(int,input().split())
    weights.append(a)
    values.append(b)

ans=[[0]*(W+1) for _ in range(n)]

for i in range(0,n):
    for j in range(1,W+1):
        p=0
        if j>=weights[i] :
            p=ans[i-1][j-weights[i]]+values[i]
        ans[i][j]=max(ans[i-1][j],p)

print(ans[-1][W])



Measured memory_bytes: 148920
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M;
    cin>>N>>M;
    int a[M],b[M];
    vector<vector<bool>> data(N,vector<bool>(N,false));
    for(int i=0;i<M;i++){
        cin>>a[i]>>b[i];
        data.at(a[i]-1).at(b[i]-1)=true;
    }
    vector<int> x(N-1);
    for(int i=0;i<N-1;i++){
        x.at(i)=i+1;
    }
    int ans=0;
    do{
        bool j=true;
        if(!data.at(0).at(x.at(0))) j=false;
        for(int i=0;i<N-2;i++){
            int m=min(x.at(i),x.at(i+1));
            int M=max(x.at(i),x.at(i+1));
            if(!data.at(m).at(M)){
                j=false;
            }
        }
        if(j) ans++;
    }while(next_permutation(x.begin(),x.end()));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
const int mod=(int)1e9+7;
int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n; bool f=0;
  cin>>n;
  while(n>0){
int d=n%10; n/=10;
    if(d==9){
f=1; break;
    }}
  if(f) cout<<"Yes";
  else cout<<"No";
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp(a,b) make_pair(a,b)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*y/gcd(x,y);
}

int main(){
  string s; cin>>s;
  if(s[0]==s[2]) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
//x ??? 3 ???
//
//???????????´??° x ?????????????????§???x ?????????????¨????????????????????????????????????°?????????????????????????????????
//
//Input
//??\?????¨?????????????????´??° x ????????????????????????
//
//Output
//x ?????????????¨???????????????????????????????????????????????????????????????????????????????????????????????????????
//
//Sample Input 1
//2
//Sample Output 1
//8
//Sample Input 2
//3
//Sample Output 2
//27
//Note

#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <math.h>

int main()
{
	int x, x3;

	// ??\???
	scanf("%d", &x);

	// 3????¨????
	x3 = (int)pow((double)x, (double)3);

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

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N; cin >> N;

	int cnt = 0;
	FOR(i,1,N+1){
		if(i %2 == 1) cnt++;
	}

	double ans = (double)cnt / N;
	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int,int> pii;
const int mod = (int) 1000000007;
const int inf = (int) 2e18;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
  	int h, w, m, x, y;
    map<int, int> mx;
    map<int, int> my;
  	set<pii> s;
  	cin >> h >> w >> m;
  	while(m--){
  	    cin >> x >> y;
  	    mx[x]++;
  	    my[y]++;
  	    s.insert({x, y});
  	}
  	int xf, xs = 0;
  	vector<int> vx, vy;
  	for(auto it : mx){
  	    if(it.second > xs){
  	        xs = it.second;
  	        xf = it.first;
  	    }
  	}
  	for(auto it : mx){
  	    if(it.second == xs){
  	        vx.push_back(it.first);
  	    }
  	}
  	int yf, ys = 0;
  	for(auto it : my){
  	    if(it.second > ys){
  	        ys = it.second;
  	        yf = it.first;
  	    }
  	}
  	for(auto it : my){
  	    if(it.second == ys){
  	        vy.push_back(it.first);
  	    }
  	}
  	int res = xs + ys - 1;
  	bool ok = true;
  	for(int i=0; i<vx.size(); i++){
  	    if(!ok) break;
  	    for(int j=0; j<vy.size(); j++){
  	        if(s.find({vx[i], vy[j]}) == s.end()){
  	            res += 1;
  	            ok = false;
  	            break;
  	        }
  	    }
  	}
  	cout << res << "\n";
}

Measured memory_bytes: 67804
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();

    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    let hs: Vec<isize> = line.trim().split_whitespace().flat_map(str::parse).collect();

    let mut height = Ok(None);
    for h in hs.into_iter().rev() {
        height = match height {
            Ok(None)                    => { Ok(Some(h)) },
            Ok(Some(x)) if x == h       => { Ok(Some(x)) },
            Ok(Some(x)) if x + 1 == h   => { Ok(Some(x)) },
            Ok(Some(x)) if x < h        => { Err(Some(0)) },
            Ok(Some(_))                 => { Ok(Some(h)) },
            Err(x)                      => { Err(x) },
        }
    }

    if height.is_ok() {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int X;
	cin >> X;

	if (X % 2 && 3 <= X && X <= 7)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()

ll q, h, s, d, n, ans;
int main(){
    cin >> q >> h >> s >> d >> n;
    h=min(h, q*2);
    s=min(s, h*2);
    d=min(d, s*2);
    ans=d*(n/2)+(n%2)*s;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
// 解き直し.
// https://img.atcoder.jp/data/agc/004/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[2020], b[2020][2020];

int main(){
    
    // 1. 入力情報.
    int N;
    LL x;
    scanf("%d %lld", &N, &x);
    rep(i, N) scanf("%lld", &a[i]);
    rep(i, N) rep(j, N) b[i][j] = 2020202020202020;
    
    // 2. 事前計算.
    rep(i, N) rep(k, N) b[i][k] = min(b[i][(k - 1 + N) % N], a[(i - k + N) % N]);
    
    // 3. 魔法を唱える回数を固定し全探索.
    LL ans = 2020202020202020;
    rep(k, N){
        LL t = k * x;
        rep(i, N) t += b[i][k];
        ans = min(ans, t);
    }
    
    // 4. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 35336
def make_divisors(n):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    return div
n, m = map(int, input().split())
d = make_divisors(m)
d.sort()
for i in reversed(d):
    if i * n <= m:
        print(i)
        exit()

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

int main(void) {
  char str[101];
  char ke[] = {'k', 'e', 'y', 'e', 'n', 'c', 'e'};

  cin >> str;

  int cnt_a = 0;
  int cnt_b = 0;

  int l = strlen(str);

  char *p = ke;

  for (int i = 0; i < l; i++) {
    if (*p != str[i]) break;
    cnt_a++;
    p++;
  }
  if (cnt_a == 7) {
    cout << "YES" << endl;
    return 0;
  }

  p = ke + 6;
  for (int i = l - 1; i >= 0; i--) {
    if (*p != str[i]) break;
    cnt_b++;
    p--;
  }

  if (cnt_a + cnt_b >= 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int adjacency_matrices[n][n];
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            adjacency_matrices[i][j] = 0;
    int vertex;
    int degree;
    for(int i = 0; i < n; i++)
    {
        cin >> vertex;
        cin >> degree;
        int to_v;
        for(int j = 0; j < degree; j++)
        {
            cin >> to_v;
            adjacency_matrices[vertex - 1][to_v - 1] = 1;
        }
    }

    for(int i = 0; i < n; i++)
    {
        for (int j = 0; j < n - 1; j++)
        {
            cout << adjacency_matrices[i][j] << " ";
        }
        cout << adjacency_matrices[i][n - 1] << endl;
    }
}


Measured memory_bytes: 3116
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from collections import deque
 
N,Q = map(int,readline().split())
ki = []
for i in range(N-1):
    ki.append(list(map(int,readline().split())))
co = []
for i in range(Q):
    co.append(list(map(int,readline().split())))
 
ki.sort()
 
kid = deque(ki)
ver = []
check = []
for i in range(N):
    ver.append(0)
    check.append(False)
 
for c in co:
    ver[c[0]-1] += c[1]
 
check[0] = True
 
kid2 = deque()
 
while len(kid) != 0:
    k = kid.popleft()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.append(k)
 
while len(kid2) != 0:
    k = kid2.pop()
    if check[k[0]-1] == True:
        ver[k[1]-1] += ver[k[0]-1]
        check[k[1]-1] = True
    elif check[k[1]-1] == True:
        ver[k[0]-1] += ver[k[1]-1]
        check[k[0]-1] = True
    else:
        kid2.appendleft(k)
 
 
print(' '.join(map(str,ver)))

Measured memory_bytes: 129952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int main(void) {
  string s;
  cin >> s;
  int res = 0;
  rep(i, 3) {
    if (s[i] == 'R') res++;
  }
  if (s[1] != 'R' && res >= 2) res = 1;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1e9+7;
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
const int N = 3e5+9;
int c[] = {0,2,5,5,4,5,6,3,7,6};
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n, m; cin >> n >> m;
    vector<int> a(m);
    for(int i = 0; i < m; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    // dp[i] = dp[i-c[j]]+1
    vector<int> digs(n+1, -mod);
    digs[0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j < m; j++) {
            if(i-c[a[j]] >= 0) {
                digs[i] = max(digs[i], digs[i-c[a[j]]]+1);
            }
        }
    }
    while(n > 0) {
        // cout << n << ": " << digs[n]-1 << endl;
        for(int j = m-1; j >= 0; j--) {
            if(n-c[a[j]] >= 0 && digs[n-c[a[j]]] == digs[n]-1) {
                // cout << "  " << a[j] << " " << digs[n-c[a[j]]] << endl;
                cout << a[j];
                n -= c[a[j]];
                break;
            } 
        }
    }
    cout << "\n";








    return 0;
    
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
char S[5050];

ll ln[5050];
ll i, j, k, ans;

ll calc(ll b){
    ll i = 1;
    ll j = 0;
    ll ret = 0;
    while(i+b<N){
        //printf("%lld%lld\n", b,i);
        if(i+ln[i-j]<j+ln[j]){
            ln[i] = ln[i - j];
            if(ret<min(i,ln[i])){
                ret = min(i, ln[i]);
            }
        }else{
            ll k = j + ln[i] - i > 0 ? j + ln[i] - i : 0;
            while(i+k+b<N&&S[k+b]==S[i+k+b])
                k++;
            ln[i] = k;
            if(ret<min(i,ln[i])){
                ret = min(i, ln[i]);
            }
            j = i;
        }
        i++;
    }
    return ret;
}
int main(){
    scanf("%lld%s", &N, S);
    fornum(i,0,N){
        ll a = calc(i);
        //printf("%lld:%lld\n", i, a);
        if(ans<a)
            ans = a;
        
    }
    printf("%lld", ans);
    return 0;
}


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n;
string s;

int isPos(int u) {
  int l = 0, h = u;
  bool d = u == 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      l--, h--;
    else if (s[i] == '1')
      l++, h++;
    else
      l--, h++;
    if (!d)
      l = max(l, 0), h = min(h, u);
    else {
      if (l < 0)
        l += 2;
      if (h > u)
        h -= 2;
    }
    if (l == h)
      d = true;
    if (l > h)
      return false;
  }
  return true;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> s;
  n = sz(s);
  int l = -1, r = n;
  while (l + 1 < r) {
    int m = (l + r) / 2;
    if (isPos(m))
      r = m;
    else
      l = m;
  }
  cout << r << "\n";
}


Measured memory_bytes: 4256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
 


int main(){
    int n;cin >> n;
    vector<LL> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    LL ans = 0;
    vector<vector<LL>> dp(n+1);
    for (int i = 1; i < n; i++) {
        dp[i].pb(0);
        set<int> st;
        bool f = false;
        for (int j = 1; j < (n-1)/i; j++) {
            if(f||n-1-i*j==i*j||st.find(n-1-i*j)!=st.end()||st.find(i*j)!=st.end()){
                break;
            }
            else{
                st.insert(i*j);
                st.insert(n-1-i*j);
                dp[i].pb(dp[i][j-1]+s[n-1-i*j]+s[i*j]);
            }
            ans = max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 17004
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    int s = 0;
    int div = 10;
    while(div/10 <= n){
        s += (n%div)/(div/10);
        div *= 10;
    }
    
    if(n%s == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int,int> State;

void solve(){
    ll a,b,n;cin>>a>>b>>n;
    ll val=min(b-1,n);
    cout<<(ll)((a*val)/b)-a*(ll)(val/b);
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 3552
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>

#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }

using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 1e5+2;
const ll mod = 1e9+7;
vector<bool> used(SIZE,false);


void solve(){
	int n,m;
	cin >> n >> m;
	if(n > 12){
		cout << m << endl;
	}else if(n >= 6 && n <= 12){
		cout << m/2 << endl;
	}else{
		cout << 0 << endl;
	}
}

int main(){ 
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

typedef long long ll;
const int N = 20, Q = 60;

ll res = 0;

struct Node {
	int a, b, c, d;
}p[Q];
int n, m, q;

int A[N];

void dfs(int u, int num) {
	if(u == n + 1) {
		ll sum = 0;
		for(int i = 1; i <= q; i++) 
			if(A[p[i].b] - A[p[i].a] == p[i].c) sum += p[i].d;
			
		res = max(res, sum);
		return ;
	}
	
	A[u] = num;
	for(int i = num; i <= m; i++) dfs(u + 1, i);
}

void solve() {
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; i++) 
		scanf("%d%d%d%d", &p[i].a, &p[i].b, &p[i].c, &p[i].d);
	
	for(int i = 1; i <= m; i++) dfs(1, i);
	
	printf("%lld\n", res);
}

int main()
{
	int T = 1;
	//scanf("%d", &T);
	
	while(T--) {
		solve();
	}
}

Measured memory_bytes: 3780
import Data.List

tr _ [] = []
tr tab (x:xs) = (tab!!x):(tr tab xs)

ans' x =
  let u = sort $ nub x
      r = case u of
            [1,2,3]   -> replicate 5 3
            [1]       -> replicate 5 3
            [2]       -> replicate 5 3
            [3]       -> replicate 5 3
            [1,2]     -> tr [0,1,2,0] x
            [1,3]     -> tr [0,2,0,1] x
            [2,3]     -> tr [0,0,1,2] x
            otherwise -> replicate 5 0
  in
    r

ans [0] = []
ans x =
  let f = ans' $ take 5 x
      b = ans  $ drop 5 x
  in
    f ++ b

main = do
  c <- getContents
  let i = map read $ lines c :: [Int]
      o = ans i
  mapM_ print o

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

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
ll COM (long a,long b){
	if(a<b)return 0;
	long ans=1;
	for(long i=1;i<=b;i++)ans=ans*(a-i+1)/i;
	return ans;
}

ll v[100010];

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    rep(i, n) cin >> v[i];
    sort(v, v+n);
    reverse(v, v+n);
    long double ave = 0;
    rep(i, a) ave += v[i];
    ave /= a;

    int cnt = 0, pos = 0;
    rep(i, n) {
        if (v[i] == v[a-1]) {
            cnt++;
            if (i < a) pos++;
        }
    }
    ll ans = 0;
    if (pos == a) for(int i = a; i <= b; i++) ans += COM(cnt, i);
    else ans += COM(cnt, pos);

    cout << fixed << setprecision(10) << ave << endl;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// abc045_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    vector<string> S(3);
    REP(i, 3) cin >> S[i];

    vector<int> t(3);
    int turn = 0;
    while (true){
        if (t[turn] == S[turn].size()){
            print((char)('A' + turn));
            break;
        }

        int tmp = turn;
        turn = S[tmp][t[tmp]] - 'a';
        t[tmp]++;
    }

    return 0;
}


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

int main() {
    char c;

    cin >> c;

    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
        cout << "vowel" << endl;
    else
        cout << "consonant" << endl;

    return 0;
}

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

long long N, K;

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

	N = N%K;
	long long ans = N;

	for(long long i = 0; i < 10; i++) {
		N = abs(N - K);
		ans = min(ans, N);
		//cout << "N = " << N << endl;
	}

	cout << ans << endl;

}

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

int main(){
    int n; cin >> n;
    pair<int, int> p[n];
    for(int i = 0; i < n; i++){
        int x,l; cin >> x >> l;
        p[i] = make_pair(x+l,x-l);
    }
    sort(p,p+n);
    int rest = 0, now = INT_MIN;
    for(int i = 0; i < n; i++){
        if(p[i].second >= now){
            now = p[i].first; rest++;
        }
    }
    cout << rest << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int x = sc.nextInt();
    if(x < a || a + b < x){
      System.out.println("NO");
    }else{
      System.out.println("YES");
    }
  }
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n, 0));
    for (int i=0; i<n; i++) {
        int u, k, v;
        cin >> u >> k;
        for (int j=0; j<k; j++) {
            cin >> v;
            a[u-1][v-1] = 1;
        }
    }
    
    for (int i=0; i<n; i++) {
        for (int j=0; j<n-1; j++) {
            cout << a[i][j] << " ";
        }
        cout << a[i][n-1] << endl;
    }
}

Measured memory_bytes: 3180
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <numeric>
#include <array>
#include <set>
#include <map>
#include <queue>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

int main() {

    string S; cin >> S;
    string A = "KIHBR";

    string St = S;
    REMOVE(St, 'A');
    if (St != A) {
        cout << "NO" << endl;
        return 0;
    }

    REP(i,S.size()) {
        if (S[i] == 'A') {
            if (i - 1 >= 0) {
                if (S[i - 1] == 'A') {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            if (i + 1 < S.size()) {
                if (S[i + 1] == 'A') {
                    cout << "NO" << endl;
                    return 0;
                }
            }
            if (i - 1 >= 0 && i + 1 < S.size()) {
                if (!((S[i - 1] == 'H' && S[i + 1] == 'B') ||
                      (S[i - 1] == 'B' && S[i + 1] == 'R'))) {
                    cout << "NO" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
// #include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
 
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}
	 
 //using namespace __gnu_pbds;
 //#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
// mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); for randomized solutions

typedef int ftype;
typedef complex<ftype> point;
#define x real
#define y imag

vector<point> hull, vecs;
ftype dot(point a, point b) {
    return (conj(a) * b).x();
}

ftype cross(point a, point b) {
    return (conj(a) * b).y();
}


void add_line(ftype k, ftype b) {
    point nw = {k, b};
     point iota = {0,1};
    while(!vecs.empty() && dot(vecs.back(), nw - hull.back()) < 0) {
        hull.pop_back();
        vecs.pop_back();
    }
    if(!hull.empty()) {
        vecs.push_back(iota * (nw - hull.back()));
    }
    hull.push_back(nw);
}
int get(ftype x) {
    point query = {x, 1};
    auto it = lower_bound(vecs.begin(), vecs.end(), query, [](point a, point b) {
        return cross(a, b) > 0;
    });
    return dot(query, hull[it - vecs.begin()]);
}
vector<int> v[11];
int n;
void recurse(int i)
{
	if(i==n)
	{
		char ch[n+1];
		int c=0;
		for(int j=0;j<n;j++)
		{
			char ch1='a'+j;
			if(v[j].size()==0)
				break;
			int p=0;
			for(int k=0;k<v[j].size();++k)
			{
				p++;
				c++;
				ch[v[j][k]]=ch1;
			}
			if(p==0)
				break;
		}
		if(c!=n)
			return ;
		string s1="";
		int ph[11];
		memset(ph,-1,sizeof(ph));
		for(int j=0;j<n;j++)
		{
			if(ph[ch[j]-'a']==-1)
				ph[ch[j]-'a']=j;
			s1+=ch[j];
		}
		for(int i=1;i<11;i++)
		{
			if(ph[i]==-1)
				break;
			if(ph[i-1]>ph[i])
			{
				return ;
			}
		}

		cout<<s1<<endl;
		return ;
	}
	else
	{
		for(int j=0;j<=i;j++)
		{
			v[j].push_back(i);
			recurse(i+1);
			v[j].pop_back();

		}
	}

}
int32_t main()
{
    IOS
  
    

	 	cin>>n;
	 	recurse(0);
	
}       

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

using pii = pair<int,int>;

int main(int argc, const char** argv) {
    
    int max_sum = 0;
    int max_dif = 0;
    int min_sum = 0;
    int min_dif = 0;


    int N;
    cin>>N;
    int x[N];
    int y[N];

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

    max_sum = x[0]+y[0];
    min_sum = x[0]+y[0];
    max_dif = x[0]-y[0];
    min_dif = x[0]-y[0];
    
    vector<int> max_sum_i(1,0);
    vector<int> max_dif_i(1,0);
    vector<int> min_sum_i(1,0);
    vector<int> min_dif_i(1,0);

    for(int i=1;i<N;i++){
        if(x[i]+y[i]==max_sum){
            max_sum_i.push_back(i);
        }
        if(x[i]+y[i]>max_sum){
            max_sum = x[i]+y[i];
            max_sum_i  = vector<int>(1,i);
        }


        if(x[i]+y[i]==min_sum){
            min_sum_i.push_back(i);
        }
        if(x[i]+y[i]<min_sum){
            min_sum = x[i]+y[i];
            min_sum_i = vector<int>(1,i);
        }


        if(x[i]-y[i]==max_dif){
            max_dif_i.push_back(i);
        }
        if(x[i]-y[i]>max_dif){
            max_dif = x[i]-y[i];
            max_dif_i = vector<int>(1,i);
        }


        if(x[i]-y[i]==min_dif){
            min_dif_i.push_back(i);
        }

        if(x[i]-y[i]<min_dif){
            min_dif = x[i]-y[i];
            min_dif_i = vector<int>(1,i);
        }
    }

    int max_pp = 0;
    int max_pn = 0;
    for(int i=0;i<max_sum_i.size();i++){
        for(int j=0;j<min_sum_i.size();j++){
            if(x[max_sum_i[i]]>=x[min_sum_i[j]] && y[max_sum_i[i]]>=y[min_sum_i[j]])
                max_pp = max_sum - min_sum;
                goto End;
        }
    }   
    End:  
    for(int i=0;i<max_dif_i.size();i++){
        for(int j=0;j<min_dif_i.size();j++){
            if(x[max_dif_i[i]]>=x[min_dif_i[j]] && y[max_dif_i[i]]<=y[min_dif_i[j]])
                max_pn = max_dif - min_dif;
                goto End2;
        }
    }  
    End2:
    cout<<max(max_pp, max_pn);

    return 0;
}


Measured memory_bytes: 8156
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+2;
int n;
map<LL,int> mp;
LL dis[maxn];
int id[maxn],fa[maxn],siz[maxn];
bool cmp(int x,int y){
	return dis[x]>dis[y];
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld",&dis[i]);
		siz[i]=1;
		id[i]=mp[dis[i]]=i;
	}
	sort(id+1,id+n+1,cmp);
	for (int i=1;i<n;i++){
		fa[id[i]]=mp[dis[id[i]]-n+2*siz[id[i]]];
		if (!fa[id[i]]){
			puts("-1");
			return 0;
		}
		siz[fa[id[i]]]+=siz[id[i]];
	}
	for (int i=1;i<n;i++) dis[id[n]]-=siz[id[i]];
	if (dis[id[n]]){
		puts("-1");
		return 0;
	}
	for (int i=1;i<n;i++) printf("%d %d\n",fa[id[i]],id[i]);
	return 0;
}

Measured memory_bytes: 9728
#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef pair <string,int> P;

int main(){
    long long sum;
    int n,m,tmp2;
    char sta[8];
    string tmp;
    bool judge;
    while(1){
        vector <P> data;
        cin >> n >> m;
        if(n == 0) break;
        for(int i=0;i<n;i++){
            cin >> tmp >> tmp2;
            data.push_back(P(tmp,tmp2));
        }
        sum = 0;
        for(int i=0;i<m;i++){
            cin >> sta;
            for(int k=0;k<n;k++){
                judge = true;
                for(int j=7;data[k].first[j]!='*'&& j>=0;j--){
                    if(sta[j] != data[k].first[j]) {
                        judge = false;
                        break;
                    }
                }
                if(judge) sum += data[k].second;
            }
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean f = false;
		while (n > 0) {
			if (n % 10 == 9)
				f = true;
			n /= 10;
		}
		System.out.println(f ? "Yes" : "No");
	}
}


Measured memory_bytes: 25172
#include<stdio.h>
int main()
{
          int H,W,i,j,k;

          for(k=0;;k++)
          {
                    scanf("%d %d",&H,&W);
           if(H==0&&W==0)
                    {
                              break;
                    }
          for(i=0;i<H;i++)
          {
                    for(j=0;j<W;j++)
                    {
                              printf("#");
                    }
                    printf("\n");
          }
          printf("\n");
          }
          return 0;
}



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

string S;

int main(){
	cin >> S;
	if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3]){
		cout << "Bad" << endl;
	} else {
		cout << "Good" << endl;
	}
}

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

signed main() {
    string s, t;
    cin>>s>>t;
    int a, b;
    cin>>a>>b;
    string c;
    cin>>c;
    if(c == s){
        a--;
    } else b--;
    cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define init(a,i) for(int k=0;k<(i);k++)(a)[k]=0
#define in(a,i) for(int k=0;k<(i);k++)cin>>(a)[k]
#define all(a)  (a).begin(),(a).end()
#define mod 1000000007
#define inf 2147483647
#define range(x,a,b) (a)<=x&&x<=(b)
int main(){
	int n,k;
	cin>>n>>k;
	int sunuke[n];
	rep(i,n)sunuke[i]=1;
	int d,a;
	rep(i,k){
		cin>>d;
		rep(j,d){
			cin>>a;
			sunuke[a-1]=0;
		}
	}
	int count=0;
	rep(i,n)count+=sunuke[i];
	cout<<count;
	return 0;
}

Measured memory_bytes: 3636
//#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <math.h>
 
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
// using namespace __gnu_pbds;
// template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
 
#define ll long long int
#define ull unsigned long long int
 
#define lp(i,n) 	    for(int i=0;i<(int)(n);i++)
#define lpi(i, j, n)    for(int i=(j);i<(int)(n);i++)
#define lpd(i, j, n)    for(int i=(j);i>=(int)(n);i--)
 
#define all(v)  	 ((v).begin()), ((v).end())
#define sz(v)    	 ((int)((v).size()))
#define clr(v, d)    memset(v, d, sizeof(v))
#define PB           push_back
#define MP           make_pair
#define N 100006
 
#define PI 3.14159265359
 
ll gcd(ll a, ll b);
vector<string> split(string target,unsigned char c );
 
 
ll n,k,t,m,x,y,l,r,a[N];
 
bool isPrime(ll h); 
 
ll ans;

 
ll mod=1e9 +7;


 
int main() {
// freopen("d.in","r",stdin); 
// 	freopen("d_out.txt","w",stdout); 
cout.precision(7);
ios_base::sync_with_stdio(false);
cin.tie(NULL);  cout.tie(NULL);

cin>>n;
lp(i,n)cin>>a[i];
lp(i,n){
	if(a[i]%2==0 && a[i]%3 && a[i]%5 ){
		ans=1;break;
	}
}
if(ans)cout<<"DENIED\n";
else cout<<"APPROVED\n";


	
 
 
}

ll gcd(ll a, ll b){
	return b==0?a:gcd(b,a%b);
}
 
 
vector<string> split(string target,unsigned char c ){
	string d="";
	vector<string>arr;
	for(auto n:target)
	{
		if(n!=c)
		d+=n;
		else if(d!="")
		arr.push_back(d),d="";
	}
	if (d!="")
	arr.push_back(d),d="";
	return arr;
}
// bool isPrime(ll h){
//      for(ll i=0;primes[i]*primes[i]<= h;i++)
//      if (h%primes[i]==0)
//      	return 0;
//      return h!=1;
//  }
 bool isPrime(ll g){
   if((g%2==0 && g>2) || g==1)return 0;
   for(ll i=3;i*i<=g;i+=2)if(g%i==0)return 0;
   return 1;   
 
 }

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

using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    if (a > 1 && b > 1) {
        cout << (a-1)*(b-1) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  if (a == 0)
  {
    cout << a << endl;
    return 0;
  }
  
  else if (n <= a + b)
  {
    if (n < a)
    {
      cout << n << endl;
      return 0;
    }
    else
    {
      cout << a << endl;
      return 0;
    }
  }
  
  else
  {
    ll div = n / (a + b);
    ll mod = n % (a + b);
    if (mod <= a)
    {
    	cout << div * a + mod << endl;
   	 	return 0;
    }
    else
    {
      cout << div * a + a << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(a, n) for(LL e=0; e<n; e++) cout<<a[e]<<" "; cout<<endl;
#define read(a, n) for(LL e=0; e<n; e++) cin>>a[e];
using namespace std;

int main()
{
	fastio;
	int a, b;
	cin>>a>>b;
	if(a>9 || b>9 || a<=0 || b<=0)
		cout<<-1<<endl;
	else
		cout<<a*b<<endl;
	return 0;
}

Measured memory_bytes: 256
ss=input()
s=[0]*4
for i in range(len(ss)):
  s[i]=int(ss[i])
dif=7-s[0]
ans=str(s[0])
found=False
for b in [s[1],-s[1]]:
  for c in [s[2],-s[2]]:
    for d in [s[3],-s[3]]:
      if b+c+d==dif:
        if b==s[1]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[1])
        if c==s[2]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[2])
        if d==s[3]:
          ans+="+"
        else:
          ans+="-"
        ans+=str(s[3])
        found=True
        break
    if found:
      break
  if found:
    break
print(ans+"=7")         
          


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
#define meax 100507
 vll a(meax,LONG_MAX);
  vll b(meax,LONG_MAX);
  ll sum1=0;
  ll k=0;
ll maximize(ll i,ll n,ll prev){

    if(b[i]!=LONG_MAX){
        return b[i];
    }
    if(i>=n){
        return LONG_MAX;
    }

    if(i==n-1){
            b[i]=0;
        return b[i];
    }
    ll d2=LONG_MAX;
    for(ll j=1;j<=k;j++){
        ll d1=maximize(i+j,n,a[i]);
        if(i+j<n)
        d2=min(d2,abs(a[i+j]-a[i])+d1);
    }
    b[i]=d2;
    return b[i];


}
int main(){
    ll n;
    cin>>n>>k;


    rep(i,0,n,1){
        cin>>a[i];
    }
    ll d=maximize(0,n,a[0]);
    cout<<d<<endl;
}


Measured memory_bytes: 11132
def main():
    n, k = [int(e) for e in input().split()]
    X = [int(e) for e in input().split()]

    ans = float('inf')
    for i in range(n - k + 1):
        d = None
        add = None
        if abs(X[i]) > abs(X[i + k - 1]):
            d = abs(X[i])
            add = abs(X[i + k - 1])*2
        else:
            d = abs(X[i + k - 1])
            add = abs(X[i])*2

        if X[i] * X[i + k - 1] < 0:
            d += add

        ans = min(ans, d)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 62576