akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int H, W, N;

int Sx, Sy;
int st[10], ed[10];

vector<string> map, smap;

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

struct State {
	int x, y, d;
	State (int _x, int _y, int _d) : x(_x), y(_y), d(_d) {}
};

int bfs(int sx, int sy, int ex, int ey) {
	queue<State> q;
	q.push(State(sx, sy, 0));
	smap[sy][sx] = '-';
	
	while (!q.empty()) {
		State s = q.front(); q.pop();
		
		if (s.x == ex && s.y == ey) return s.d;
		
		for (int d=0; d<4; d++) {
			int nx = s.x + dx[d], ny = s.y + dy[d];
			
			if (!(0<=nx && nx<W && 0<=ny && ny<H)) continue;
			if (smap[ny][nx]=='-' || smap[ny][nx]=='X') continue;
			
			smap[ny][nx] = '-';
			q.push(State(nx, ny, s.d+1));
		}
	}
	
	return -1;
}

void solve() {
	int ans = 0;
	smap = map;
	ans += bfs(Sx, Sy, st[1], ed[1]);
	
	for (int i=2; i<=N; i++) {
		smap = map;
		ans += bfs(st[i-1], ed[i-1], st[i], ed[i]);
	}
	
	cout << ans << endl;
}

int main() {
	cin >> H >> W >> N;
	for (int i=0; i<H; i++) {
		string s; cin >> s;
		map.push_back(s);
		for (int j=0; j<W; j++) {
			if (s[j]=='S') { Sx = j; Sy = i; }
			if ('1' <= s[j] && s[j] && '9') { st[s[j]-'0'] = j; ed[s[j]-'0'] = i; }
		}
	}
	
	solve();
	
	return 0;
}

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

int main(){
  int s1, s2, s3, input;
  
  cin >> input ;
  
  s3 = input % 10;
  s2 = (input % 100) / 10;
  s1 = input /100;
  
  cout << s1 + s2 + s3 << endl;
}

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

using namespace std;

int main(){
    long long int n, w, V_Max = 0;
    scanf("%lld %lld", &n, &w);

    long long int W[n+1]; long long int V[n+1];
    for(int i = 1; i <= n; i++){
        scanf("%lld %lld", &W[i], &V[i]);
        V_Max += V[i];
    }
    long long int dp[V_Max+1];
    for(long long int i = 0; i <= V_Max; i++) dp[i] = 10000000000000;
    dp[0] = 0;
    for(long long int i = 1; i <= n; i++){
        long long int wt = W[i], v = V[i];
        for(long long int j = V_Max; j >= v; j--){
            dp[j] = min(dp[j], dp[j - v] + wt);
        }
    }
    for(int i = V_Max; i >= 0; i--){
        if(dp[i] <= w){
            cout << i << "\n";
            break;
        }
    }
    return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> howmany(100001);
    ll sum=0;
    for (int i = 0; i < N; i++){
        int A;cin>>A;
        howmany[A]++;
        sum+=A;
    }
    int Q;
    cin>>Q;
    for (int i = 0; i < Q; i++){
        int B,C; cin>>B>>C;
        sum+=(ll)(C-B)*howmany[B];
        cout<<sum<<endl;
        howmany[C]+=howmany[B];
        howmany[B]=0;
    }
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

typedef long long ll;

const int INF = 1e8;

int main() {
  int n, l; cin >> n >> l;
  string s[n]; rep(i, n) cin >> s[i];
  
  sort(s, s + n);
  
  rep(i, n) cout << s[i];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key){
	return key%M;
}
long long h2(long long key){
	return (key%(M-2));
}
long long getNum(char c){
	if(c=='A')return 1;
	if(c=='C')return 2;
	if(c=='G')return 3;
	if(c=='T')return 4;
	return 0;
}
long long getValue(char* s){
	long long i=0,value=0;
	while(s[i]){
		value=value*10+getNum(s[i]);
		i++;
	}
	return value;
}
char s[1046527][13],word[13],order[10];
long long n,key,value;
int main(){
		cin>>n;
		for(long long i=0;i<1000006;i++)s[i][0]=0;
		for(long long i=0;i<n;i++){
			scanf("%s %s",order,word);
			value=getValue(word);
			if(order[0]=='i'){
				long long k=0;
				while(true){
					key=(h1(value)+k*h2(value))%M;
					if(strcmp(s[key],word)==0){
						break;
					}else if(strlen(s[key])==0){
						strcpy(s[key],word);
						break;
					}
					k++;
				}
			}else{
				long long k=0;
				while(true){
					key=(h1(value)+k*h2(value))%M;
					if(strcmp(s[key],word)==0){
						cout<<"yes\n";
						break;
					}else if(strlen(s[key])==0){
						cout<<"no\n";
						break;
					}
					k++;
				}
			}
		}
	
	return 0;
} 


Measured memory_bytes: 16404
#include <stdio.h>
typedef long long ll;

int main() {
	ll n, a, b, x, y, tired = 0;
	scanf("%lld %lld %lld\n%lld", &n, &a, &b, &x);
	for (int i = 0; i < n-1; i++) {
		scanf("%lld", &y);
		if (a * (y - x) > b) { tired += b; }
		else{ tired += a * (y - x); }
		x = y;
	}
	printf("%lld", tired);
}

Measured memory_bytes: 128
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        h: u64,
        w: u64,
    }

    if h == 1 || w == 1 {
        println!("1");
        return;
    }

    let ans = (h as f64 / 2.0).ceil() * (w as f64 / 2.0).ceil() + (h as f64 / 2.0).floor() * (w as f64 / 2.0).floor();
    println!("{}", ans as u64);
}


Measured memory_bytes: 2576
n,d=map(int,input().split())
x=[list(int(i) for i in input().split()) for _ in range(n)]
dis=0
ans=0
for i in x:
  for j in x:
    for k in range(d):
      dis+=(i[k]-j[k])*(i[k]-j[k])
    if dis**0.5%1==0:
      ans+=1
    dis=0
ans-=n
print(ans//2)

Measured memory_bytes: 3064
#d.py
n = int(input())
ab = [list(map(int,input().split())) for x in range(n)]
yes = True
time = 0
ab.sort(key=lambda x:x[1])
for x in ab:
    time += x[0]
    if time > x[1]:
        yes = False
        break
if yes:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 53600
#include<stdio.h>

int main(){
  int n,m,l;
  int mA[1000][1000];
  int mB[1000][1000];
  long temp;

  scanf("%d %d %d", &n, &m, &l);

  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      scanf("%d",&mA[i][j]);
    }
  }
  for(int i=0; i<m; i++){
    for(int j=0; j<l; j++){
      scanf("%d",&mB[i][j]);
    }
  }
  //解答の配置場所を確認
  for(int i=0; i<n; i++){
    for(int j=0; j<l; j++){
      //該当要素の作成
      temp=0;
      for(int k=0; k<m; k++){
	temp += mA[i][k]*mB[k][j];
      }
      printf("%ld",temp);
      if(j<l-1) printf(" ");
    }
    printf("\n");
  }
  
}



Measured memory_bytes: 3388
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main(){
    int p,q,r; cin>>p>>q>>r;
    OUT(min({p+q, p+r, q+r}));
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int empNum = sc.nextInt();
		int[] rel = new int[empNum - 1];

		for (int i=0;i<rel.length;i++) {
			rel[i] = 0;
		}

		for(int i=0;i<rel.length;i++) {
			rel[sc.nextInt()-1]++;
		}

		for (int i = 0; i < rel.length; i++) {
			System.out.println(rel[i]);
		}
		System.out.println("0");


		sc.close();
	}
}

Measured memory_bytes: 60332
import numpy as np
N, M, X = map(int,input().split())
l = []
li = np.array([])
for i in range(N):
  l.append(list(map(int,input().split())))

li = np.array(l)

skill_sum = []
for j in range(2**N):
  sum = np.zeros([M+1])
  for k in range(N):
    if ((j >> k) & 1):
        sum += li[k] 
  skill_sum.append(list(sum))      
pricelist = []
for l in range(2**N):
  cnt = 0
  for m in range(M):
    if skill_sum[l][m+1] >= X:
      cnt += 1
  if cnt ==  M:
    pricelist.append(int(skill_sum[l][0]))

if pricelist == []:
  print('-1')
else:
  print(min(pricelist))

Measured memory_bytes: 29180
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        s: chars,
    }
    let mut s = s;
    while s.len() < 15 {
        s.push('o');
    }
    let c = s.iter().filter(|&&x| x == 'o').count();
    puts!("{}\n", if c >= 8 { "YES" } else { "NO" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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

int main()
{
	long long int n,a,b;
  	cin>>n>>a>>b;
	vector<long long int> towns;
  	long long int town;
  	long long int ans=0;
  	for(long long int i=0 ; i<n ; ++i)
    {
    	cin>>town;
      	towns.push_back(town);
      	if(i)
        {
        	ans+=(min(a*(town-towns[i-1]),b));
        }
    }
	cout<<ans<<endl;
	return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b; cin>>a>>b;
  if(b==1) cout<<0<<endl;
  else if(b<=a) cout<<1<<endl;
  else{
    ll cnt=(b-a+a-2)/(a-1);
    cout<<cnt+1<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h> // gcc -lm

int isprime(int);


int main() {
  int i, N, x, count=0;

  scanf( "%d" , &N );
  for( i=0; i<N; i++ ) {
    scanf( "%d" , &x );
    if ( isprime(x) == 1 ) count++;
  }
  printf( "%d\n" , count );

  return 0;
}


int isprime(int x) {
  // return 1 : true  ,  return 0 : false
  int i=3;

  if ( x == 2 ) return 1;
  if ( (x < 2) || (x%2 == 0) ) return 0;
  while ( i <= sqrt(x) ) {
    if ( x%i == 0 ) return 0;
    i = i+2;
  }

  return 1;
}



Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int main(){
	int n_input;
	string s_input[201];
	int number_out[201];
	cin >> n_input;
	for (int i = 0; i < n_input; ++i) cin >> s_input[i];
	for (int i = 0; i < n_input; ++i)number_out[i] = stoi(s_input[i]);
	int division_cnt = 999;
	for (int i = 0; i < n_input; ++i){
		for (int j = 0; j < division_cnt; ++j){
			if (number_out[i] % 2 == 1){
				division_cnt = j;
				break;
			}
			else number_out[i] /= 2;
		}
	}
	cout << division_cnt << endl;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		String[] s = new String[n];
		for (int i = 0; i < n; i++) {
			s[i] = br.readLine();
		}
		br.close();

		int ans = 0;
		int a = 0;
		int b = 0;
		int ab = 0;
		for (int i = 0; i < n; i++) {
			ans += s[i].split("AB", -1).length - 1;
			if (s[i].charAt(s[i].length() - 1) == 'A') {
				if (s[i].charAt(0) == 'B') {
					ab++;
				} else {
					a++;
				}
			} else {
				if (s[i].charAt(0) == 'B') {
					b++;
				}
			}
		}

		int cnt = 0;
		if (ab > 0) {
			if (a > 0) {
				a--;
				cnt++;
			}
			cnt += ab - 1;
			if (b > 0) {
				b--;
				cnt++;
			}
		}
		cnt += Math.min(a, b);
		System.out.println(ans + cnt);
	}
}


Measured memory_bytes: 33876
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,a[200005],sta[200005],top,l[200005],r[200005];
long long ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",a+i);
		r[i]=n+1;
	}
	for(int i=1;i<=n;++i){
		while(top && a[sta[top]]>=a[i]){
			r[sta[top]]=i;
			--top;
		}
		l[i]=sta[top];
		sta[++top]=i;
	}
	for(int i=1;i<=n;++i)
		ans+=(long long)(i-l[i])*(r[i]-i)*a[i];
	printf("%lld\n",ans);
	return 0;
}

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

#define watch(x) cout << (#x) << " is " << (x) << endl
#define fr(i,n) for(int i=0; i<n; i++)
#define rep(i, st, en) for(int i=st; i<=en; i++)
#define repn(i, st, en) for(int i=st; i>=en; i--)
#define sq(a) (a*a)
typedef unsigned long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll mod = 1e9+7;


void solve(){
    ll x;
    cin>>x;
    ll st = 100;
    ll ad;
    int yrs = 0;
    while(st < x){
        ad = st/(100ll);
        st += ad;
        yrs++;
    }
    cout<<yrs;
}

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

    ll t = 1;
    //  cin>>t;
    while(t--){
        solve();
    }

    return 0;
}



Measured memory_bytes: 3636
#include<cstdio> 
#include<iostream>
using namespace std;
int main()
{
	int x;
	cin>>x;
	if(x>=400&&x<600)
	cout<<8;
	else if(x>=600&&x<800)
	cout<<7;
	else if(x>=800&&x<1000)
	cout<<6;
	else if(x>=1000&&x<1200)
	cout<<5;
	else if(x>=1200&&x<1400)
	cout<<4;
	else if(x>=1400&&x<1600)
	cout<<3;
	else if(x>=1600&&x<1800)
	cout<<2;
	else if(x>=1800&&x<2000)
	cout<<1; 
	return 0;
}

Measured memory_bytes: 3636
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;



int main(){
    Shazam;
    int n; cin>>n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++) cin>>a[i];
    int res = 0;
    vector<int> ans(n+1);
    for(int i = n; i>0; i--){
        int curr = 0;
        for(int j = 2*i; j <=n; j+=i){
            curr+=ans[j];
        }
        if ((curr & 1) != (a[i] & 1)){
            ans[i] = 1;
            res++;
        }
    }
    cout<<res<<endl;
    for(int i = 1; i <= n; i++){
        if(ans[i])
            cout<<i<<" ";
    }
    cout<<endl;/*  */
  
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

int main() {
source:
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    sort(a, a + n);
    if (k > a[n - 1]) {
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll gcd_all = a[0];
    rep(i, n) { gcd_all = gcd(gcd_all, a[i]); }
    if (k % gcd_all == 0) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}



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

using namespace std;

#define int long long
#define sz(x) (int)x.size()
#define yes cout << "Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ft first
#define sd second
typedef pair<int, int> pii;
typedef long double ld;
typedef vector<int> vi;
typedef vector<bool> vb;
mt19937_64 rnd(time(0));

void start() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(10);
    // cerr << fixed << setprecision(10);
#ifdef MY
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}

signed main() {
    start();
    int n, W, ans = -1;
    cin >> n >> W;
    vi w(n), c(n);
    for (int i = 0; i < n; ++i) cin >> w[i] >> c[i];
    vector<vi> d(n + 1, vi(W + 1));
    d[0][0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= W; ++j) {
            d[i][j] = d[i - 1][j];
            if (j >= w[i - 1])
                d[i][j] = max(d[i][j], d[i - 1][j - w[i - 1]] + c[i - 1]);
            ans = max(ans, d[i][j]);
        }
    }
    cout << ans;


}


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

int main() {
  int a[3],  b[3], sum=0;
  for(int i = 0; i < 3; i++) {
    cin >> a[i] >> b[i];
    sum += (a[i] + b[i]);
  }
  if(sum == 15) cout << "YES";
  else cout << "NO";      
}  

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

struct Node {
  int key;
  struct Node *right, *left, *parent;
};
typedef struct Node Node;

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  // yの子xを決める
  if(y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL) {
    x->parent = y->parent;
  }

  if(y->parent == NIL) {
    root = x;
  } else {
    if(y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z) {
    z->key = y->key;
  }
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key   = k;
  z->left  = NIL;
  z->right = NIL;
  
  while(x != NIL) {
    y = x;
    if(z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  
  z->parent = y;
  if(y == NIL) {
    root = z;
  } else {
    if( z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(void) {
  int n, i, x;
  char com[16];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    scanf("%s",com);
    if(!strcmp(com,"find")) {
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    } else if(!strcmp(com,"insert")) {
      scanf("%d",&x);
      insert(x);
    } else if(!strcmp(com,"print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(!strcmp(com,"delete")) {
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

  return 0;
}


Measured memory_bytes: 20480
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> pre(n, 0), suff(n, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x') {
      if (i > 0) pre[i] = pre[i - 1];
      continue;
    }
    if (i - (c + 1) >= 0) {
      pre[i] = 1 + pre[i - (c + 1)];
    }
    else {
      pre[i] = 1;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'x') {
      if (i + 1 < n) suff[i] = suff[i + 1];
      continue;
    }
    if (i + c + 1 < n) {
      suff[i] = 1 + suff[i + c + 1];
    } else {
      suff[i] = 1;
    }
  }
  vector<int> ans;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      if (suff[i + 1] < k) {
        ans.pb(i + 1);
      }
      continue;
    }
    if (i == n - 1) {
      if (pre[i - 1] < k) {
        ans.pb(i + 1);
      }
      continue;
    }
    if (pre[i - 1] + suff[i + 1] < k) {
      ans.pb(i + 1);
    }
  }
  for (auto i: ans) {
    cout << i << endl;
  }
  return 0;
}


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

int main() {
	
	int N;
	char S[100];
	char T[100];

	scanf("%d", &N);
	scanf("%s %s", S, T);

	for (int i = 0; i < N; i++) {
		putchar(S[i]);
		putchar(T[i]);
	}

	putchar('\n');
	
	return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;
bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}
int main(void){
   int N,M;
   cin>>N>>M;
   vector<int> a(M),b(M);
   for(int i=0;i<M;i++){
      cin>>a[i]>>b[i];
   }
   vector<pair<int,int>> land(M);
   for(int i=0;i<M;i++){
      land[i]=make_pair(a[i],b[i]);
   }
   sort(land.begin(),land.end(),sort_sec);
   int now=-1;
   int ans=0;
   for(int i=0;i<M;i++){
      if(land[i].first<=now) continue;
      now=land[i].second-1;
      ans++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1792
package main

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

func configure(scanner *bufio.Scanner) {
	// scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for s := getNextString(scanner); s != "END OF INPUT"; s = getNextString(scanner) {
		ss := strings.Split(s, " ")
		for i := 0; i < len(ss); i++ {
			fmt.Fprint(writer, len(ss[i]))
		}
		fmt.Fprintln(writer, "")
	}
}



Measured memory_bytes: 1184
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int inf = 1000000000; //10^9
const ll MOD = 1e9 + 7;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main()
{
    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" <<endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


int main(){
    int p, q, r;
    cin >> p >> q >> r;

    cout << min(p+r, min(p+q, q+r)) << endl;


    return 0;
}


Measured memory_bytes: 256
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End


/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template


signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cinii(N,K);
    int count = 0;
    while(N>0){
        N -= N%K;
        N /= K;
        count++;
    }
    cout << count << nn;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  def countDivisor(n: Int): Int = (1 to n).count( d => (n % d) == 0 )

  val n = StdIn.readLine.toInt
  val ans = (1 to n by 2).count(i => countDivisor(i) == 8)
  println(ans)
}

Measured memory_bytes: 25532
#include<stdio.h>
#pragma GCC optimize ("O2")
int main(void)
{
  int K,div,N;long long a=0;K=scanf("%d",&N);
  while(K<=N){div=N/K;a+=1ll*K++*div*(div+1)/2;}
  return printf("%lld\n",a),0;
}

Measured memory_bytes: 1736
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <typeinfo>
using namespace std;
using ll = long long;

int main() {
	int N, A, B;
	cin >> N;

	if (N == 1)
	{
		cout << "Hello World" << endl;
	}
	else
	{
		cin >> A >> B;
		cout << A + B << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <utility>

#define MAX 100000
#define SENTINEL 1000000001

struct Card {
  char suit;
  int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void Merge(struct Card A[], int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for (i = 0; i < n1; ++i) { L[i] = A[left + i]; }
  for (i = 0; i < n2; ++i) { R[i] = A[mid + i]; }
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for (k = left; k < right; ++k) {
    if (L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void MergeSort(struct Card A[], int left, int right) {
  int mid;
  if (left + 1 < right) {
    mid = (left + right) / 2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

int Partition(struct Card A[], int p, int r) {
  int i, j;
  struct Card x;
  x = A[r];
  i = p - 1;
  for (j = p; j < r; ++j) {
    if (A[j].value <= x.value) {
      ++i;
      std::swap(A[i], A[j]);
    }
  }
  std::swap(A[i + 1], A[r]);
  return i + 1;
}

void QuickSort(struct Card A[], int p, int r) {
  int q;
  if (p < r) {
    q = Partition(A, p, r);
    QuickSort(A, p, q - 1);
    QuickSort(A, q + 1, r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for (i = 0; i < n; ++i) {
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  MergeSort(A, 0, n);
  QuickSort(B, 0, n - 1);

  for (i = 0; i < n; ++i) {
    if (A[i].suit != B[i].suit) { stable = 0; }
  }

  if (stable == 1) {
    std::printf("Stable\n");
  } else {
    std::printf("Not stable\n");
  }
  for (i = 0; i < n; ++i) { std::printf("%c %d\n", B[i].suit, B[i].value); }

  return 0;
}

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

vector<int>to[200005];
vector<int>ans;
void dfs(int v,int p=-1){
  for(int u:to[v]){
    if (u==p)continue;
    ans[u]+=ans[v];
    dfs(u,v);
  }
}

int main(){
  int n,q;
  cin>>n>>q;  
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    --a;--b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  rep(i,q){
    int p,x;
    cin>>p>>x;
    --p;
    ans[p]+=x;
  }
  dfs(0);
  rep(i,n){
    cout<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 23424
#include<iostream>

using namespace std;

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

int dp[2][2][9];

bool valid(int left, int right) {
  if (left == right) return false;
  left %= 3;
  right %= 3;
  return left <= right;
}

int main() {
  string str;
  while (true) {
    cin >> str;
    if (str == "#") break;
    rep (i, 2) rep (j, 9) {
      if (i == 0) {
	if (valid(str[0] - '1', j)) dp[0][i][j] = 0;
	else dp[0][i][j] = 1e9;
      } else {
	if (valid(j, str[0] - '1')) dp[0][i][j] = 0;
	else dp[0][i][j] = 1e9;
      }
    }
    rep (i, str.size() - 1) {
      rep (j, 2) rep (k, 9) dp[1][j][k] = 1e9;
      rep (j, 2) rep (k, 9) {
	if (j == 0) {
	  if (valid(str[i + 1] - '1', k)) dp[1][j][k] = dp[0][j][k] + 1;
	  else dp[1][j][k] = 1e9;
	  if (valid(str[i + 1] - '1', str[i] - '1')) {
	    rep (l, 9) dp[1][j][k] = min(dp[1][j][k], dp[0][j ^ 1][l]);
	  }
	} else {
	  if (valid(k, str[i + 1] - '1')) dp[1][j][k] = dp[0][j][k] + 1;
	  else dp[1][j][k] = 1e9;
	  if (valid(str[i] - '1', str[i + 1] - '1')) {
	    rep (l, 9) dp[1][j][k] = min(dp[1][j][k], dp[0][j ^ 1][l]);
	  }
	}
      }
      rep (j, 2) rep (k, 9) dp[0][j][k] = dp[1][j][k];
    }
    int res = 1e9;
    rep (i, 2) rep (j, 9) res = min(dp[0][i][j], res);
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    ll F[100];
    memset(F, 0, sizeof F);
    F[0] = 2;
    F[1] = 1;
    for (int i = 2; i <= n; i++) {
        F[i] = F[i - 1] + F[i - 2];
    }
    cout << F[n] << endl;
    return 0;
}

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

int main(){
	int x;
	cin>>x;
	
	for(int z=0;z<x;z++){
		int a,b,w,h;
	cin>>a>>b>>w>>h;
		int n;
		cin>>n;
		
		int ans=0;
		for(int i=0;i<n;i++){
			int c,d;
			cin>>c>>d;
			if(a<=c&&c<=a+w&&b<=d&&d<=b+h)ans++;
			}
			cout<<ans<<endl;
		}
		return 0;
	}

Measured memory_bytes: 2980
W, H, x, y = map(int, input().split())

import fractions

if x * 2 == W or y * 2 == H:
	if x * 2 == W and y * 2 == H:
		c = 1
	else:
		c = 0
else:
	x1 = fractions.Fraction(H * x - y * W, H - 2 * y)
	y1 = fractions.Fraction(W * y - x * H, W - 2 * x)
	
	if 0 <= x1 <= W and 0 <= y1 <= H:
		if (x1 == 0 or x1 == W) and (y1 == 0 or y1 == H):
			c = 0
		else:
			c = 1
	else:
		c = 0
	
	
	

print(W * H / 2, c)


Measured memory_bytes: 5304
/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: ABC SWAP
  *  Date:   05.04.2020
  *  Time:   03:03:40
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define d(...) 1729
#endif


typedef unsigned int ui;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(),s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define test int T = 1;if(testcases)cin >> T;for(int tc = 1 ; tc <= T ; tc++)
#define make_unique(vec) sort(all(vec));vec.erase(unique(all(vec)),vec.end())
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

ll seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}

template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a)
{in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a)
{for(auto &x : a)in>>x;return in;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}

int main(int argc, char **argv)
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","a",stderr);
    #endif
    
    fast;
    int x, y, z;
    test
    {
        cin >> x >> y >> z;
        cout << z << " " << x << " " << y << endl;

        fundri;
    }

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n");
    if(elapsed_time<10000)
        o("Elapsed Time: "<<elapsed_time<<" ms\n");
    else
        o("Elapsed Time: "<<elapsed_time/1000<<" s\n");

    return 0;
}


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

int main() {
  ll n,t;
  cin >> n >> t;
  vector<ll> p(n);
  for(ll i=0;i<n;i++) {
    cin >> p[i];
  }
  ll mx=0;
  vector<ll> buy(n);
  for(ll i=0;i<n;i++) {
    mx=max(mx,p[n-1-i]);
    buy[n-1-i]=mx-p[n-1-i];
  }
  ll pmx=0;
  for(ll i=0;i<n;i++) {
    pmx=max(pmx,buy[i]);
  }
  ll ans=0;
  for(ll i=0;i<n;i++) {
    if(buy[i]==pmx) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    int r;
    cin >> r;
    cout << (float)(r*r)/(1*1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){


	int H,W,i,o,p,a,g;
 
   for(p=0;p<300;p++)//全てのループ
   {
       cin>>H>>W;
       if(H==0 && W==0)
       {
           break;
       }
       
	   for(i=0;i<W;i++)
	   {
		   cout<<"#";
	   }
	   cout<<endl;
	   for(o=0;o<H-2;o++)
	   {
		   cout<<"#";
		   for(a=0;a<W-2;a++)
		   {
			   cout<<".";
		   }
		   cout<<"#";
		   cout<<endl;


	   }
	   for(g=0;g<W;g++)
	   {
		   cout<<"#";
	   }
	   cout<<endl;

	   
	   cout<<endl;
   }
 
     
		   


		 
      
     
   


	return 0;
}


Measured memory_bytes: 3084
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <climits>
#include <cassert>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> vi;
typedef vector<string> VS;
typedef pair<int, int> pii;
typedef long long ll;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int dx[] = {-1,1,0,0};
const int dy[] = {0,0,1,-1};

#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

vi sub(int p, int q)
{
	vi res(p);
	int t = p / q + 1;

	rep(i, p) {
		if (i % q == q-1) {
			res[i] = -(t*(q-1))-1;
		} else {
			res[i] = t;
		}
	}
	return res;
}

vector<vi> solve(int a, int b, int c, int d)
{
	vector<vi> res;
	vi t = sub(c, d);
	rep(i, a) res.pb(t);
	return res;
}

void out(vector<vi> res)
{
	puts("Yes");
	rep(i, res.size()) {
		rep(j, res[i].size()) {
			printf("%d%c", res[i][j], j + 1 == (int)res[i].size() ? '\n' : ' ');
		}
	}
}

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;

	if (W % w != 0) {
		auto t = solve(H, h, W, w);
		out(t);
	} else if (H % h != 0) {
		auto t = solve(W, w, H, h);
		vector<vi> res;
		rep(i, H) {
			vi vec;
			rep(j, W) {
				vec.pb(t[j][i]);
			}
			res.pb(vec);
		}
		out(res);
	} else {
		puts("No");
	}

	return 0;
}

Measured memory_bytes: 4352
Data = [0, 0, 0, 0]

for i in range(3):
  D = list(map(int, input().split()))
  Data[D[0] - 1] += 1
  Data[D[1] - 1] += 1

if 0 in Data or 3 in Data:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<long long> A(X), B(Y), C(Z);
    for (int i = 0; i < X; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < Y; i++)
    {
        cin >> B[i];
    }
    for (int i = 0; i < Z; i++)
    {
        cin >> C[i];
    }
    vector<long long> AB;
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            AB.push_back(A[i] + B[j]);
        }
    }
    sort(AB.begin(), AB.end());
    reverse(AB.begin(), AB.end());
    vector<long long> ABC;
    for (int i = 0; i < min(K, (int)AB.size()); i++)
    {
        for (int j = 0; j < Z; j++)
        {
            ABC.push_back(AB[i] + C[j]);
        }
    }
    sort(ABC.begin(), ABC.end());
    reverse(ABC.begin(), ABC.end());
    for (int i = 0; i < K; i++)
    {
        cout << ABC[i] << endl;
    }
    return 0;
}

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

long long int N[100] = {};

long long int func(int _i)
{
	if (N[_i] == 0)
	{
		N[_i] = func(_i-1)+func(_i-2);
		return N[_i];
	}
	else
	{
		return N[_i];
	}
   
}

int main()
{
	N[0] = 2;
	N[1] = 1;
	int N;
	cin >> N;
	cout << func(N) << endl;

	return 0;
}

Measured memory_bytes: 256
N=input()
s1=input()+"000"
s2=input()+"000"
ans=3
status=1
place=0
while True:
    if s1[place]=="0":
        break
    if status==1:
        if s1[place]==s2[place]:
            status=3
            place+=1
        else:
            ans=ans*2
            status=2
            place+=2
    elif status==2:
        if s1[place]==s2[place]:
            status=3
            place+=1
        else:
            ans=ans*3
            place+=2
    elif status==3:
        ans=ans*2
        if s1[place]==s2[place]:
            place+=1
        else:
            status=2
            place+=2
print(ans%1000000007)

Measured memory_bytes: 38384
n,k=map(int,input().split())
r,s,p=map(int,input().split())
d={'r':p,'s':r,'p':s}
t=input()
ans=0
for i in range(k):
  x=t[i]
  ans+=d[x]
  for j in range(i+k,n,k):
    if t[j]!=x:
      x=t[j]
      ans+=d[x]
    else:
      x='z'
print(ans)

Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let a: i32 = get();
    let b: i32 = get();
    if a + b == 15 {
        println!("+");
    } else if a * b == 15 {
        println!("*");
    } else {
        println!("x");
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
n, m = map(int, input().split())
s = [False] * n
g = [False] * n
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        s[b] = True
    if b == n:
        g[a] = True

ans = "IMPOSSIBLE"
for i in range(n):
    if s[i] and g[i]:
        ans = "POSSIBLE"
        break
print(ans)


Measured memory_bytes: 6260
#include <bits/stdc++.h>
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    string s;
    cin >> s;
    int n = s.length();
    
    vector<int> dp(n + 2, 0);
    vector<pair<int, char>> dp_pos(n + 1);
    
    map<char, int> next;
    for (char c = 'a'; c <= 'z'; ++c) next[c] = n;
    
    dp[n + 1] = 0;
    dp[n] = 1;
    repeat_reverse_from_to (i, n - 1, 0) {
        next[s[i]] = i;
        int m = n;
        for (char c = 'z'; c >= 'a'; --c) {
            if (dp[ next[c] + 1 ] <= m) {
                m = dp[ next[c] + 1 ] + 1;
                dp_pos[i].first = next[c] + 1;
                dp_pos[i].second = c;
            }
        }
        dp[i] = m + 1;
    }
    
    //repeat_from_to(i, 0, n) {cout << "dp_pos[" << i << "]=(" << dp_pos[i].first << "," << dp_pos[i].second << ")" << endl;}
    
    int pos = 0;
    while (pos < n) {
        cout << dp_pos[pos].second;
        pos = dp_pos[pos].first;
    }
    cout << endl;
}

Measured memory_bytes: 3076
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

typedef long long ll;

const double EPS = 1e-9;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()

int main(){
  int n,t;
  vi s;
  scanf("%d",&n);
  rep(i,n){
    scanf("%d",&t);
    s.push_back(t);
  }

  int p=0;
  rep(i,n)
    p+=s[i];

  sort(ALL(s));
  
  int an=0;
  if(p%10==0){
    rep(i,n){
      if(s[i]%10!=0){
        an = p-s[i];
        break;
      }
    }
  }else{
    an=p;
  }
  printf("%d\n",an);

  return 0;
}


Measured memory_bytes: 256