akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	int N, K;
	cin >> N >> K;
	vector<long long> H(N);
	for (int i = 0; i < N; ++i) {
		cin >> H[i];
	}

	vector<long long> costmap(N);
	costmap[0] = 0;
	costmap[1] = abs(H[1] - H[0]);
	int X = 2;

	for (; X < N; ++X) {
		costmap[X] = 1ll << 60;
		for (int i = X - 1; max(X - K, 0) <= i; --i) {
			costmap[X] = min(abs(H[X] - H[i]) + costmap[i], costmap[X]);
		}
	}

	cout << costmap[N - 1] << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

struct Freq {
public:
    Freq() : key(0), cnt(0)
    {
    }

    int key;
    int cnt;

    bool operator<(const Freq& rhs) {
        return (cnt < rhs.cnt);
    }
};

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

    struct Freq even[100001];
    struct Freq odd[100001];

    int v;
    for (int i = 0; i < n; ++i) {
        std::cin >> v;
        if (i % 2 == 0) {
            even[v].key = v;
            ++(even[v].cnt);
        } else {
            odd[v].key = v;
            ++(odd[v].cnt);
        }
    }

    std::sort(even, even + 100001);
    std::sort(odd,  odd  + 100001);
    std::reverse(even, even + 100001);
    std::reverse(odd,  odd  + 100001);


    int result = 0;
    if (even[0].key != odd[0].key) {
        result = (n / 2 - even[0].cnt) + (n / 2 - odd[0].cnt);
    } else {
        result = std::min(
            n / 2 - even[0].cnt + n / 2 - odd[1].cnt,
            n / 2 - even[1].cnt + n / 2 - odd[0].cnt
        );
    }

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int N, i;
  cin >> N >> i;
  cout << N - i + 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair <int,ii>
#define iil pair<ll,ll>
#define iiil pair<ll,iil>
#define max3(a,b,c) max(a, max(b,c))
#define min3(a,b,c) min(a, min(b,c))
#define s(v) sort(v.begin(),v.end())
#define pf printf
#define sf scanf
#define MIN INT_MIN
#define MAX INT_MAX
#define accepted 0
#define GCD(x,y)  __gcd(x, y)
using namespace std;

int main() {
    //fast
    string a;
        cin>>a;
        if(a[2]==a[3] && a[4]==a[5])cout<< "Yes\n" ;
        else cout<< "No\n";
    return accepted;
}


Measured memory_bytes: 256
from time import time

start = time()
D = int(input())
C = [int(i) for i in input().split()]
scores = [[int(i) for i in input().split()] for j in range(D)]
t = []
for i in scores:
    t.append(i.index(max(i))+1)
DC = [0]*26

def calcScore(t):
    score = []
    S = 0
    last = [0]*26
    for d in range(1,D+1):
        S += scores[d-1][t[d-1]-1]
        last[t[d-1]-1] = d
        for i in range(26):
            S -= C[i] * (d - last[i])
            DC[i] += (d - last[i])
        score.append(S)
    return score[-1]

from random import randint
ts = calcScore(t)
i = 0
while time() - start < 1.8:
    d,q = i, randint(1,26)
    temp = [t[i] if d-1 != i else q for i in range(D)]
    if calcScore(temp) > ts:
        t = temp
        i += 1

print("\n".join(map(str, t)))

Measured memory_bytes: 10040
from operator import itemgetter

n, m = map(int, input().split())
youbou = [tuple(map(int, input().split())) for _ in range(m)]
ab = sorted(youbou, key=itemgetter(1))

ans = 0
removed = 0

for a, b in ab:
    if a >= removed:
        ans += 1
        removed = b  # b島の直前の橋を取り除く

print(ans)

Measured memory_bytes: 62168
use std::io::Read;
 
fn main() {
    let mut buf = String::new();
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    // 値段
    let n: usize = iter.next().unwrap().parse().unwrap();
    // 嫌いな数字の数
    let q: usize = iter.next().unwrap().parse().unwrap();
    
    // 嫌いな数字配列
    let lrt: Vec<char> = (0..q)
        .map(|_| {
                iter.next().unwrap().parse().unwrap()
        }).collect();

    let mut result = 0;
    for i in n..99999 {
        let chars = &i.to_string().chars().collect::<Vec<char>>();
        let mut ok = true;
        for c in chars.iter() {
            if lrt.contains(&c) {
                ok = false;
                break;
            }
        }

        if ok {
            result = i;
            break;
        }
    }
    print!("{}", result);
  
}


Measured memory_bytes: 2184
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll g1(ll n, ll p) {
  if (n == 0) return 0;
  return (n/p) + g1(n/p, p);
}

ll g2(ll n, ll p) {
  // 二重階乗
  if (n&1) return g1(n, p) - g2(n-1, p);
  ll res = g1(n/2, p);
  if (p == 2) res += n/p;
  return res;
}

int main() {
  // 二重階乗、階乗、2と5で何回割れるか小さい方
  ll N;
  cin >> N;
  ll ans = min(g2(N, 2), g2(N, 5));
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int eulerPhi(int n)
{
    if (n == 0) return 0;
    int ans = n;
    for (int i = 2; i*i <= n; i++) {
	if (n % i == 0) {
	    ans -= ans / i;
	    while (n % i == 0) n /= i;
	}
    }
    if (n > 1) ans -= ans / n;
    return ans;
}

int main(){
  int n;cin>>n;cout<<eulerPhi(n)<<endl;
  return 0;
}

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

const int MAXH = 11;
const int W = 5;
int H;
int G[MAXH][W+1];

int main() {
  while(cin >> H && H) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
      }
    }
    int score = 0;
    bool update;
    do {
      update = false;
      for(int i = 0; i < H; ++i) {
        for(int j = 0, k = 0; j <= W; ++j) {
          if(G[i][k] != G[i][j]) {
            if(G[i][k] && j-k >= 3) {
              update = true;
              score += (j-k) * G[i][k];
              while(k < j) G[i][k++] = 0;
            }
            k = j;
          }
        }
      }
      for(int j = 0; j < W; ++j) {
        for(int i = H-1, k = H-1; i >= 0; --i) {
          if(G[i][j]) {
            int tmp = G[i][j];
            G[i][j] = 0;
            G[k--][j] = tmp;
          }
        }
      }
    } while(update);
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
//
//  C - Next Prime.cpp
//  Practice
//
//  Created by Hajime Sakamoto on 2019/12/31.
//  Copyright © 2019 Hajime Sakamoto. All rights reserved.
//


#include <math.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return true;//素数じゃない
    else if (num == 2) return false;//素数
    else if (num % 2 == 0) return true; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return true;
        
        }
    }

    // 素数である
    return false;
}

int main(){
    int X;
    int OP;
    
    cin >> X;
    
    
    while(true){
        if (IsPrime(X) == false){
            OP =X;
            break;
        }
        else {
            X++;
        }
        
    }
    
    cout << OP;
    
    return 0;
}


Measured memory_bytes: 256
n,z,w = map(int,input().split())
a = list(map(int,input().split()))

# 結局最後の2枚をどうするかで決まる
# 「先手がa[n-1]、後手がwのとき」か「先手がa[n-2」、後手がa[n-1]（逆パターンもあり）」の時しかありえない
if abs(a[n-1]-w) > abs(a[n-2]-a[n-1]) :
    print(abs(a[n-1]-w))
else :
    print(abs(a[n-2]-a[n-1]))

Measured memory_bytes: 3188
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll quick_pow(ll a,ll b){
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
int n,K,bin[2005],f[2005][2005];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int main(){
	scanf("%d%d",&n,&K);
	bin[0]=1;
	for(int i=1;i<=n;i++) bin[i]=add(bin[i-1],bin[i-1]);
	for(int i=2;i<=n;i++) f[1][i]=1;
	for(int i=1;i<K-1;i++){
		int sum=f[i][n-i+1];
		for(int p=n-i;p>1;p--){
			sum=add(sum,f[i][p]);
			f[i+1][p]=add(f[i+1][p],sum);
		}
	}
	int ans=0;
	for(int i=2;i<=n-K+2;i++) ans=add(ans,f[K-1][i]);
	if(K==1) ans=1;
	if(n==K) printf("%d",ans);
	else{
		printf("%lld",1LL*ans*bin[n-K-1]%mod);
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

typedef pair<int, int> p_ii;

int main() {
  int N, M; cin >> N >> M;
  vector<int> adj[N], radj[N];
  int num_to[N] = {};
  rep(i,N-1+M) {
    int A, B; cin >> A >> B; A--; B--;
    adj[A].push_back(B);
    radj[B].push_back(A);
    num_to[B]++;
  }

  vector<p_ii> topo;
  queue<int> q; rep(i,N) if (num_to[i]==0) q.push(i);
  int count = 0;
  while (!q.empty()) {
    int now = q.front(); q.pop();
    topo.push_back(make_pair(now,count));
    count++;
    for (auto x: adj[now]) {
      num_to[x]--;
      if (num_to[x]==0) q.push(x);
    }
  }
  sort(topo.begin(), topo.end(), [](const p_ii &x, const p_ii &y){return x.first<y.first;});

  rep(i,N) {
    int result = -1;
    for (auto x: radj[i]) {
      if (result==-1||topo[result].second<topo[x].second) {
        result = x;
      }
    }
    cout << result+1 << endl;
  }
  // rep(i,N) cout << topo[i].first << "->" << topo[i].second << endl;
  return 0;
}

Measured memory_bytes: 13048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

pair<int, int> e[50];
int N, M;
void dfs(int n1, int g[][50], bool* n)
{
	n[n1] = true;
	REP(i, N)
	{
		if (g[n1][i] == 1 && n[i] == false)dfs(i, g, n);
	}
	return;
}

int main()
{
	cin >> N >> M;
	REP(i, M)
	{
		cin >> e[i].first >> e[i].second;
		e[i].first--; e[i].second--;
	}

	int ans = 0;
	REP(i, M)
	{
		//! e[i]を取り除いて連結かどうか見る
		int g[50][50] = {};
		REP(j, M)
		{
			if (j == i)continue;
			g[e[j].first][e[j].second] = 1;
			g[e[j].second][e[j].first] = 1;
		}

		bool n[50] = { };
		dfs(0, g, n);
		REP(l, N)
		{
			if (n[l])continue;
			ans++;
			break;
		}

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String str = reader.readLine();

    if (str.contains("7")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 32632
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=1e3+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  string s,t;
  cin>>s>>t;
  int m=t.size(),n=s.size();
  int ans=inf;
  for(int i=m-1;i<n;i++)
  {
    int j=i-m+1;
    int cnt=0;
    for(int k=j;k<=i;k++)
    {
      if(s[k]!=t[k-j])
      {
        cnt++;
      }
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3660
import numpy as np

N = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

V = np.array(v)
C = np.array(c)

X = V - C
T = 0

for i in range(N):
	if X[i] > 0:
		T += X[i]
	else:
		pass

print(T)



Measured memory_bytes: 21288
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで毎回include
//以下プログラム

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<long> data(n);
	for (int i = 0; i < n; i++) {
		cin >> data.at(i);
	}
	sort(data.begin(), data.end());
	int result = 0;
	for (int i = 0; i < n; i++) {
		long nowCheck = data.at(i);
		int check = 1;
		while( i + 1 < n && data.at(i + 1) == nowCheck) {
			check++;
			i++;
		}
		if (check != nowCheck) {
			if (check < nowCheck) {
				result += check;
			}
			else {
				result += check - nowCheck;
			}
		}
		check = 1;
	}
	cout << result << endl;
}



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

int main()
{
	int n;
	cin >> n;
	double x,sum = 0;
	for(int i = 0;i < n;i++){
		cin >> x;
		sum += 1.0/x;
	}
	cout << 1.0/sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

const int mod = 1e9 + 7;

const int maxm = (1 << 15) + 10;

int dp[16][maxm][2], pw3[18], n, m, tmp, ans, g[18], pw2[18], bits[maxm], log[maxm], f[14348907 + 10];

void add(int &x, int y) {
	x = x + y < mod ? x + y : x + y - mod;
}

int F(int s1, int s2) {
	int s = 0;
	for (int i = 0; i < n; ++i) {
		if((s1 >> i) & 1) {
			s += pw3[i];
		}
		if((s2 >> i) & 1) {
			s += (pw3[i] << 1);
		}
	}
	return s;
}

int main() {
	scanf("%d%d", &n, &m);
	while(m--) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[--u] |= (1 << --v);
	}
	pw2[0] = pw3[0] = 1;
	for (int i = 1; i <= n; ++i) {
		pw3[i] = pw3[i - 1] * 3;
		pw2[i] = pw2[i - 1] << 1;
	}
	for (int i = 1; i < maxm; ++i) {
		bits[i] = bits[i >> 1] + (i & 1);
	}
	for (int i = 2; i < maxm; ++i) {
		log[i] = log[i >> 1] + 1;
	}
	for (int s = 0; s < pw3[n]; ++s) {
		int s1 = 0, s2 = 0, t = s, cur = 1;
		while(t) {
			if(t % 3 == 1) {
				s1 |= cur;
			}
			else if(t % 3 == 2) {
				s2 |= cur;
			}
			t /= 3;
			cur <<= 1;
		}
		f[s] = 1;
		int ts1 = s1;
		while(s1) {
			int i = log[s1 & (-s1)];
			s1 ^= (s1 & (-s1));
			int t = bits[g[i] & s2];
			t = pw2[t] - 1;
			f[s] = 1ll * f[s] * t % mod;
		}
		s1 = ts1;
		while(s2) {
			int i = log[s2 & (-s2)];
			s2 ^= (s2 & (-s2));
			int t = bits[g[i] & s1];
			f[s] = 1ll * f[s] * pw2[t] % mod;
		}
	}
	m = 1 << n;
	for (int s = 0; s < m; ++s) {
		int t = 0;
		for (int i = 0; i < n; ++i) {
			t += pw3[i] * (((s >> i) & 1) + 1);
		}
		dp[0][s][(s & 3) == 3] = f[t];
	}
	for (int i = 0; i < n; ++i) {
//		printf("%d\n", ans);
		for (int s = 0; s < m; ++s) {
			for (int ss = 0; ss < 2; ++ss) {
				if(tmp = dp[i][s][ss]) {
//					printf("dp[%d][%d][%d] = %d\n", i, s, ss, tmp);
					int rev_s = m - 1 ^ s;
					for (int t = rev_s; t; t = (t - 1 & rev_s)) {
						add(dp[i + 1][s | t][((t & 3) == 3) | ss], 1ll * tmp * f[F(rev_s ^ t, t)] % mod);
					}
				}
			}
		}
	}
	--m;
	for (int i = 0; i <= n; ++i) {
		add(ans, dp[i][m][0]);
	}
	printf("%d\n", ans);
	return 0;
}

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

public class Main{

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		Pair[] P = new Pair[N];
		for(int i = 0;i < N;i++) {
			long X = scn.nextInt(), L = scn.nextInt();
			Pair p = new Pair(X-L, X+L);
			P[i] = p;
		}
		Arrays.sort(P);
		int ans = 0;
		long nowL = Integer.MIN_VALUE;
		for(int i = 0;i < N;i++) {
			if(nowL <= P[i].first) {
				ans++;
				nowL = P[i].second;
			}
		}
		System.out.println(ans);
	}

}

class Pair implements Comparable<Pair> {
	long first, second;

	public Pair(long f, long s) {
		this.first = f;
		this.second = s;
	}

	@Override
	public int compareTo(Pair o) {// Comparatorを自由記述せよ(これはfirstが小さい順, secondが小さい順)
		if (this.second < o.second) {
			return -1;
		}
		if (this.second > o.second) {
			return 1;
		}
		if (this.first < o.first) {
			return -1;
		}
		if (this.first > o.first) {
			return 1;
		}
		return 0;
	}
}


Measured memory_bytes: 90828
k,a,b = map(int, input().split())
if b - a <= 2:
  print(k + 1)
else:
  yen = 0
  if k >= a + 1:
    yen += 1
    k -= a + 1
    c,d = divmod(k,2)
    yen += c
    print(a + (b-a) * yen + d)
  else:
    print(k + 1)

Measured memory_bytes: 3060
N = int(input())

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

for i in range(N):
    A[i] = A[i]-i-1
    
A.sort()

b1 = A[N//2-1]
b2 = A[N//2]

ans1 = 0
ans2 = 0

for i in range(N):
    ans1 = ans1 + abs(A[i]-b1)
    ans2 = ans2 + abs(A[i]-b2)
    
print(min(ans1, ans2))

Measured memory_bytes: 26020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#include <cmath>

using namespace std;



int main(void){
    int n;
    cin >> n;
    vector<pair<int, int>> t(n);
    for(int i = 0; i < n; i++){
        cin >> t[i].first >> t[i].second;
    }
    sort(t.begin(), t.end());
   // cout << t[0].first << ' '<< t[0].second;
    int count = t[0].first;
    for(int i = 0; i < n-1; i++){
        count += t[i+1].first - t[i].first;
        //cout << count << endl;
    }
    count += t[n-1].second ;
    cout << count;
    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



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

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


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

  vector<ll>v(4);
  rep(i,4)cin>>v[i];
  sort(all(v));
  if(v[0]==1&&v[1]==4&&v[2]==7&&v[3]==9)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n, x;
int main() {
    cin >> n;
    vector<ll> s(n);
    REP(i, n){
        cin >> s[i];
        x ^= s[i];
    }
    REP(i,n){
        if(i != 0)cout <<" ";
        cout << (x xor s[i]);
    }
    cout<<endl;
}


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

#define ll long long int
#define mod 1000000007
#define sbits(x) __builtin_popcountll(x)
#define zbits(x) __builtin_ctzll(x)
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;

int main()
{
	int t;
	cin>>t;
	if(t==1) cout<<0;
	else if(t==0) cout<<1;
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <string>
#include <algorithm>



using namespace std;


int main (void)
{
    long n, m, a[1000], b[1000], k[1000],X;
    cin >> n >> m;

    for (long i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (long j = 0; j < m; j++)
    {
        cin >> b[j];
    }

    for (int i = 0; i < n; i++)
    {
        k[i] = 0;
    }

    //aaaaaaaaaaaaaaaaaaaa
    for (long j = 0; j < m; j++)
    {
        for (long i = 0; i < n; i++)
        {
            if (a[i] <= b[j])
            {
                k[i] += 1;
                break;
            }
        }
    }
    

    X = 0;
    for (long i = 0; i < n; i++)
    {
        if (k[i] > X)
        {
            X = 0;
            X = k[i];
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (X == k[i])
        {
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3120
#include <iostream>
using namespace std;
long long mod=1e9+7;
int main(void){
    long long n,m,ans1=0,ans2=0,a;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a;
        ans1+=(2*i-n+1)*a;
    }
    for(int i=0;i<m;i++){
        cin>>a;
        ans2+=(2*i-m+1)*a;
    }
    cout<<((ans1%mod)*(ans2%mod))%mod<<endl;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split()))
p = list(map(int, input().split()))

rsum = [(p[0] + 1) / 2]
for i in range(1, n):
  rsum.append((p[i] + 1) / 2 + rsum[i-1])
  
result = 0
if (n == k):
  result = rsum[-1]

else:
  for i in range(n-k):
    if result < rsum[i+k] - rsum[i]:
      result = rsum[i+k] - rsum[i]

print(result)

Measured memory_bytes: 24548
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n, q; cin >> n >> q;
	string s; cin >> s;
	vector<int> sum(n+1);
	

	for (int i = 2; i < n+1; i++) {
		if (s[i - 2] == 'A' && s[i - 1] == 'C') {
			sum[i] = sum[i - 1] + 1;
		}
		else {
			sum[i] = sum[i - 1];
		}
	}
	
	int ans = 0;
	for (int i = 0; i < q; i++) {
		int a, b; cin >> a >> b;
		a--; b;

		ans = sum[b] - sum[a];

		if (a > 0) {
			if (s[a - 1] == 'A' && s[a] == 'C') {
				ans--;
			}
		}
		
		cout << ans << endl;
	}
	
	return 0;
}



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

using namespace std;

class Dsu {
public:
  int n;
  vector<int> par;
  vector<bool> used;

  Dsu(int _n) : n(_n) {
    par.resize(n);
    used.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      used[i] = false;
    }
  }

  int find(int i) {
    if (par[i] == i) return i;
    return par[i] = find(par[i]);
  }

  bool unite(int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) {
      if (used[i]) return false;
      return (used[i] = true);
    } else {
      if (used[i] && used[j]) return false;
      par[j] = i;
      used[i] = used[i] || used[j];
      return true;
    }
  }
};

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

  int n, h, w;
  cin >> n >> h >> w;
  vector< tuple<int,int,int> > edge;
  for (int i = 0; i < n; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    edge.emplace_back(w, u, v + h);
  }
  sort(edge.rbegin(), edge.rend());

  long long ans = 0;
  Dsu dsu(h + w);
  for (auto e : edge) {
    int u, v, w;
    tie(w, u, v) = e;
    if (dsu.unite(u, v)) {
      ans += w;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 2676
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
int a,b,x;
cin>>x>>a>>b;
x-=a;
while(x>=0)
x-=b;
x+=b;
cout<<x;
return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


int main() {
  string s, ss = "";
  cin >> s;
  rep(i, 0, s.length()) {
    if(s[i] != 'x') ss += s[i];
  }
  rep(i, 0, ss.length() / 2) {
    if(ss[i] != ss[ss.length() - i - 1]) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  int l = 0, r = s.length() - 1;
  while(l <= r) {
    if(s[l] != s[r]) {
      if(s[l] == 'x') l++;
      else r--;
      ans++;
    }else l++, r--;
  }

  cout << ans << endl;
}


Measured memory_bytes: 592
-- https://github.com/minoki/my-atcoder-solutions
import Data.Int (Int64)

check :: (Int64, Int64, Int64, Int64, Int64, Int64) -> Maybe Int64
check (x1,y1,x2,y2,x3,y3)
  | 0 <= x1 && x1 <= 10^9
  , 0 <= y1 && y1 <= 10^9
  , 0 <= x2 && x2 <= 10^9
  , 0 <= y2 && y2 <= 10^9
  , 0 <= x3 && x3 <= 10^9
  , 0 <= y3 && y3 <= 10^9 = let x2' = x2 - x1
                                y2' = y2 - y1
                                x3' = x3 - x1
                                y3' = y3 - y1
                            in Just (x2' * y3' - y2' * x3')
  | otherwise = Nothing

solve :: Int64 -> (Int64, Int64, Int64, Int64, Int64, Int64)
solve s | s == 10^18 = (0,0,10^9,0,0,10^9)
        | otherwise = let (a,b) = s `quotRem` (10^9)
                      in (0,0,10^9,1,10^9-b,a+1)

main = do
  s <- readLn
  let (x1,y1,x2,y2,x3,y3) = solve s
  putStrLn $ unwords $ map show [x1,y1,x2,y2,x3,y3]

{-# RULES
"^9/Int" forall x. x ^ (9 :: Int) = let u = x; v = u * u * u in v * v * v
"^9/Integer" forall x. x ^ (9 :: Integer) = let u = x; v = u * u * u in v * v * v
 #-}


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める
bool is_dot(vector<char> a, int w){
    rep(i,w){
        if(a[i] != '.' && a[i] != 'a') return false;
    }
    return true;
}

bool is_wdot(vector<vector<char>> a, int h, int w){
    rep(j,h){
        if(a[j][w] != '.' && a[j][w] != 'a') return false;
    }
    return true;
}

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    rep(i,h){
        if(is_dot(a[i],w)){
            rep(j,w){
                a[i][j] = 'a';
            }
        }
    }
    rep(i,w){
        rep(j,h){
            if(is_wdot(a,h,i)){
                rep(k,h){
                    a[k][i] = 'a';
                }
            }
        }
    }
    bool flag;
    rep(i,h){
        flag = false;
        rep(j,w){
            if(a[i][j] != 'a'){
                cout <<  a[i][j];
                flag = true;
            } 
        }
        if(flag) cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
n=int(input())

dictA={}

for i in range(n):
	cand=input()
	if cand in dictA:
		dictA[cand]=dictA[cand]+1
	else:
		dictA[cand]=1

maxnum=0
candlist=list(dictA.keys())
candlist.sort()
maxlist=[]

for i in candlist:
	if dictA[i]>maxnum:
		maxlist.clear()
		maxlist=[i]
		maxnum=dictA[i]
	elif dictA[i] == maxnum:
		maxlist.append(i)



for i in maxlist:
	print(i)



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

using LL = long long;
using Point = pair<int, int>;
using Interval = pair<int, int>;
using Event = pair<int, bool>;
const bool IN = false;
const bool OUT = true;

int N, K;
string S;

LL loop(auto& p) {
  set<Point> s(begin(p), end(p));
  LL res = 0;
  for(auto i: s) {
    auto x = i.first, y = i.second;
    res += s.count(Point(x+1, y)) && s.count(Point(x, y+1)) && s.count(Point(x+1, y+1));
  }
  return res;
}

LL solve(auto& p, int a, int b) {
  // vectorize
  map<Point, set<Interval>> vec;
  for(auto i: p) {
    auto k = i.first / a;
    auto x = i.first % a;
    auto y = i.second - b * k;
    if(x < 0) {
      --k;
      x += a;
      y += b;
    }
    vec[{x, y}].emplace(k, k + K - 1);
  }
//   for(auto i: vec){
//     cout<<i.first.first<<","<<i.first.second<<": ";
//     for(auto j: i.second)cout<<" ["<<j.first<<","<<j.second<<"] ";
//     cout<<endl;
//   }

  // merge
  map<Point, set<Event>> event;
  for(auto& i: vec) {
    auto cur = begin(i.second);
    auto l = cur->first, h = cur->second;
    for(auto pre = cur++; pre != end(i.second); pre = cur++) {
      if(cur == end(i.second)) {
        event[i.first].emplace(l, IN);
        event[i.first].emplace(h, OUT);
        break;
      }
      if(cur->first - 1 <= pre->second) h = cur->second;
      else {
        event[i.first].emplace(l, IN);
        event[i.first].emplace(h, OUT);
        l = cur->first;
        h = cur->second;
      }
    }
  }
//   for(auto i: event) {
//     cout<<i.first.first<<","<<i.first.second<<": ";
//     for(auto j: i.second)cout<<" "<<j.first<<"_"<<j.second<<" ";
//     cout<<endl;
//   }

  // unite
  LL res = 0;
  for(auto i: event) {
    auto cur = i.first;
//     cout<<res<<endl;
//     cout<<"TRY: "<<cur.first<<","<<cur.second<<endl;
    multiset<Event> q;
    for(auto e: event[cur]) q.emplace(e);
    for(auto nex: {Point(cur.first + 1, cur.second), Point(cur.first + 1, cur.second + 1), Point(cur.first, cur.second + 1)}) {
//       cout<<"  with: "<<nex.first<<","<<nex.second<<endl;
      auto dif = 0;
      if(nex.first >= a) {dif = 1; nex = Point(nex.first - a, nex.second - b);}
//       if(!event.count(nex)) cout<<"NG"<<endl;
      if(!event.count(nex)) break;
      for(auto e: event[nex]) q.emplace(e.first - dif, e.second);
    }
    // count
    auto cnt = 0;
    auto l = 0;
    for(auto e: q) {
      if(e.second == IN) {
        ++cnt;
        l = e.first;
      } else {
        if(cnt == 4) res += e.first - l + 1;
        --cnt;
      }
    }
  }
  return res;
}

LL solve() {
  // simulate
  auto x = 0, y = 0;
  vector<Point> p;
  p.emplace_back(x, y);
  for(auto i: S) {
    x += (i=='E') - (i=='W');
    y += (i=='N') - (i=='S');
    p.emplace_back(x, y);
//     cout<<x<<" "<<y<<endl;
  }

  if(x == 0 && y == 0) return loop(p);

  if(x < 0) {x *= -1; for(auto& i: p) i.first *= -1;}
  if(y < 0) {y *= -1; for(auto& i: p) i.second *= -1;}
  if(x == 0) {swap(x, y); for(auto& i: p) swap(i.first, i.second);}
  return solve(p, x, y);
}

int main() {
  cin >> N >> K >> S;
  cout << solve() << endl;
}

Measured memory_bytes: 36524
#include <iostream>
using namespace std;
#define MAX_N 100010
const int INF = 1e9;
int n;
int h[MAX_N];
int dp[MAX_N];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> h[i];
    fill(dp, dp + MAX_N, INF);
    dp[0] = 0; dp[1] = abs(h[0] - h[1]);
    for (int i = 2; i <= n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i]), dp[i-2] + abs(h[i-2] - h[i]));
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1024
cx, cy, r = map(int, input().split())
q = int(input())
for _ in range(q):
    x1, y1, x2, y2 = map(int, input().split())
    dx, dy = x2 - x1, y2 - y1
    px, py = cx - x1, cy - y1
    s2 = dx ** 2 + dy ** 2
    dot = dx * px + dy * py
    crs = dx * py - dy * px
    t1 = (dot + (s2 * r ** 2 - crs ** 2) ** 0.5) / s2
    t2 = (dot - (s2 * r ** 2 - crs ** 2) ** 0.5) / s2
    if (dx < 0 or (dx == 0 and dy < 0)) ^ (t1 > t2):
        t1, t2 = t2, t1
    print(x1 + dx * t1, y1 + dy * t1, x1 + dx * t2, y1 + dy * t2)

Measured memory_bytes: 7760
# ABC073d
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n, m, _ = map(int, input().split())
d = [[float("inf") for i in range(n)] for i in range(n)]
for i in range(n):
    d[i][i] = 0  # 自身のところに行くコストは０
r = list(map(int, input().split()))


def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


for _ in range(m):
    a, b, c = map(int, input().split())
    d[a-1][b-1] = c
    d[b-1][a-1] = c
warshall_floyd(d)

ans = 10**9
for i in itertools.permutations(r, len(r)):
    t = 0
    for j in range(1, len(i)):
        t += d[i[j]-1][i[j-1]-1]
    #print(i, t)
    ans = min(ans, t)
print(ans)


Measured memory_bytes: 56028
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
#define mod 1000000007
#define fs(x,y) for(int i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(int i=x;i<=y;i++)
using namespace std;

ll n,m,ar[N],sum;

char s[N];

int main()
{
	fast;
	cin>>s+1;
	fo(i,2,4)
		if(s[i]==s[i-1])
			return cout<<"Bad",0;
	cout<<"Good";


}



/*     cd onedrive\desktop\kod
cls


*/

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,i,j,fc,c=0;
  scanf("%d",&n);
  for(i=1;i<=n;i+=2){
    for(j=1;j<=i;j++){
      if(i%j==0){
        fc++;
      }
    }
    if(fc==8){
      c++;
    }
    fc=0;
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

ll GCD (ll x, ll y) {
  if (y == 0) return x;
  return GCD(y, x%y);
}

int main() {
    ll n,X;
    cin >> n >> X;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    x.push_back(X);
    ll ans = x[1]-x[0];
    rep(i,x.size()-1) {
        ans = GCD(ans, abs((x[i+1]-x[i])));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    double p[n+1];
    for(int i=1;i<=n;i++)cin>>p[i];
    double dp[n+1][n+1];
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            if(j==0)dp[i][j]=(1-p[i])*dp[i-1][j];
            else dp[i][j]=p[i]*dp[i-1][j-1]+((i-1>=j)?(1-p[i])*dp[i-1][j]:0);
        }
    }
    
    double ans=0.0;
        for(int j=0;j<=n;j++){
            if(j>n-j){
                ans+=dp[n][j];
            }
        }
  
    cout<<setprecision(15)<<fixed<<ans<<endl;
 return 0;   
}

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

#define VALUES_PER_UNIT	0xFF
#define VOID_VAL	(-1)


typedef struct unit {
	struct unit *before, *after;
	int values[VALUES_PER_UNIT];
} unit;

int main(void) {
	char s[20];
	int index = 0, i, j, n, val;
	FILE *fp = fopen("ALDS1_3_C_in9.txt", "rb");
	unit *funit, *lunit, *u;
	funit = malloc(sizeof(unit));
	funit->before = funit->after = NULL;
	lunit = funit;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", s);
		if (strcmp(s, "insert") == 0) {
			scanf("%d", &val);
			lunit->values[index++] = val;
			if (index >= VALUES_PER_UNIT) {
				u = malloc(sizeof(unit));
				lunit->after = u;
				u->before = lunit;
				u->after = NULL;
				lunit = u;
				index = 0;
			}
		} else if (strcmp(s, "delete") == 0) {
			scanf("%d", &val);
			j = index;
			u = lunit;
			while (u != NULL) {
				while (--j >= 0) {
					if (u->values[j] == val) {
						u->values[j] = VOID_VAL;
						break;
					}
				}
				if (j >= 0) break;
				u = u->before;
				j = VALUES_PER_UNIT;
			}
		} else if(strcmp(s, "deleteFirst") == 0) {

			do {
				index--;
				if (index < 0) {
					if (lunit->before == NULL) break;
					u = lunit;
					lunit = lunit->before;
					lunit->after = NULL;
					free(u);
					index = VALUES_PER_UNIT - 1;
				}
			} while (lunit->values[index] == VOID_VAL);
		} else if(strcmp(s, "deleteLast") == 0) {
			j = 0;
			while (funit->values[j] == VOID_VAL) {
				if (++j >= VALUES_PER_UNIT) {
					if (funit->after == NULL) break;
					u = funit;
					funit = funit->after;
					funit->before = NULL;
					free(u);
					j = 0;
				}
			}
			if (j < VALUES_PER_UNIT) {
				funit->values[j] = VOID_VAL;
			}
		} else printf("invalid operation: %s\n", s);
	}
	i = 0;
	for (u = lunit; u != NULL; u = u->before) {
		while (--index >= 0) {
			if (u->values[index] != VOID_VAL) {
				if (i) {
					printf(" ");
				} else i++;
				printf("%d", u->values[index]);
			}
		}
		index = VALUES_PER_UNIT;
	}
	printf("\n");
}

Measured memory_bytes: 5584
#include <bits/stdc++.h>
#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 = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int n, m, q;
vector<int> a, b, c, d;

int ans = 0;
map<vector<int>, bool> used;

void dfs(vector<int>& p) {
  if (used[p]) return;
  used[p] = true;
  int sum = 0;
  rep(i, q) {
    if (p[b[i]] - p[a[i]] == c[i]) sum += d[i];
  }
  chmax(ans, sum);
  vector<int> res = p;
  repr(i, n - 1) {
    if (res[i] == m) continue;
    res[i]++;
    dfs(res);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  cin >> n >> m >> q;
  a.resize(q);
  b.resize(q);
  c.resize(q);
  d.resize(q);
  rep(i, q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  vector<int> p(n, 1);
  dfs(p);
  cout << ans << '\n';

  




  
  return 0;
}

Measured memory_bytes: 15176
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, n) for (int i = 0; i < n; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  char s[5];
  scanf("%s", s);

  int before = (int)(s[0] - '0') * 10 + (int)(s[1] - '0');
  int after = (int)(s[2] - '0') * 10 + (int)(s[3] - '0');

  if (1 <= before && before <= 12 && 1 <= after && after <= 12)
    printf("AMBIGUOUS\n");
  else if (1 <= before && before <= 12)
    printf("MMYY\n");
  else if (1 <= after && after <= 12)
    printf("YYMM\n");
  else 
    printf("NA\n");
  return 0;
}


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

int main() {
  int N;
  cin >> N ;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i) ;}
  
  sort(vec.begin(), vec.end());   
  int count =1;
  
  for(int i=0; i<N-1; i++){
    if(vec.at(i) != vec.at(i+1)){
      count++;}}
  cout << count <<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int x,a,b,sa,sb;
	scanf("%d %d %d",&x,&a,&b);
	sa=(x<a)?a-x:x-a;
	sb=(x<b)?b-x:x-b;
	if(sa<sb){
		printf("A\n");
	}
	else{
		printf("B\n");
	}
	return 0;
}

Measured memory_bytes: 128
<?php

	$str1 = fgets(STDIN);
	$str = fgets(STDIN);
	$array = str_split(trim($str));

	$cnt = 0;
	$previous = '';
	
	foreach ($array as $char) {
		if ($char === $previous) {
			continue;
		} else {
			$cnt++;
		}
		$previous = $char;
	}
	
	echo $cnt;
?>

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

int main(){

int N, M;
cin >> N >> M;
vector<int>A(M, 0);

for(int i = 0; i < N; i++){ 
       int K;
       cin >> K;
       for(int i = 0; i < K; i++){ 
             int a;
             cin >> a;
             A.at(a - 1)++;
       }
}

int ans = 0;

for(int i = 0; i < M; i++){ 
       
      if(A.at(i) == N){
            ans++;
      }

}
cout << ans << endl;
}
          

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
const int mx=11;
const int mxe=21;
const int mxb=(1<<mxe);
vector<int>g[mx];
vector<int>w[mx];
vector<int>e[mx];
int f[mx][mxb];
int nxt[mx][mxb];
int main(){
   int n,m,u,v,wuv;
   while(scanf("%d %d",&n,&m),n!=0 && m!=0){
      for(int i=0;i<n;i++){
         g[i].clear();
         w[i].clear();
         e[i].clear();
      }
      for(int i=0;i<m;i++){
         scanf("%d %d %d",&u,&v,&wuv);
         u--,v--;
         g[u].push_back(v);
         g[v].push_back(u);
         w[u].push_back(wuv);
         w[v].push_back(wuv);      
         e[u].push_back(i);
         e[v].push_back(i);
      }
      for(int b=(1<<m)-1;b>=0;b--){
         for(u=0;u<n;u++){
            int &fu=f[u][b];
            int &nu=nxt[u][b];
            fu=0,nu=-1;
            for(int i=0;i<int(g[u].size());i++){
               v=g[u][i];     
               int euv=e[u][i];
               if(b&(1<<euv))continue;
               int bet=w[u][i]+f[v][b^(1<<euv)];
               if(bet>fu)fu=bet,nu=i;
               else if(bet==fu && v<g[u][nu])nu=i;
            }
         }
      }
      int x=0;
      for(u=0;u<n;u++)
         if(f[u][0]>f[x][0])
            x=u;
      u=x;
      printf("%d\n",f[u][0]);
      int b=0,cnt=0;
      while(true){
         if(cnt!=0)printf(" ");
         printf("%d",u+1);
         int euv=nxt[u][b];
         if(euv==-1)break;
         v=g[u][euv];
         b^=(1<<e[u][euv]);
         u=v;
         cnt++;
      }
      printf("\n");
   }
   return 0;
}

Measured memory_bytes: 40164
K,T = map(int, input().split())
a = list(map(int, input().split()))
lis = [0] * K
d = -1
T2 = T
for i in range(K):
    if T2 == 1:
        for j in range(T):
            if a[j] > 0:
                val = j
        lis[i] = val
    else:
        val = [0,0]
        for j in range(T):
            if j == d:
                continue
            if a[j] > val[0]:
                val = [a[j],j]
        a[val[1]] -= 1
        if a[val[1]] == 0:
            T2 -= 1

        lis[i] = val[1]
        d = val[1]

#print(lis)
ans = 0
for i in range(1,K):
    if lis[i] == lis[i-1]:
        ans += 1
print(ans)


Measured memory_bytes: 40940
import itertools
n,m,q = map(int,input().split())
x = [list(map(int,input().split())) for _ in range(q)]
d = 0
ans = 0

ele = [i for i in range(1,m+1)]

for i in itertools.combinations_with_replacement(ele,n):
    a = list(i)
    d = 0
    for j in range(q):
        if a[x[j][1]-1] - a[x[j][0]-1] == x[j][2]:
            d += x[j][3]
    ans = max(ans,d)
print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define print(x,y) (cout << (x) << (y))
#define inf INT_MAX
#define sz(x) (ll)x.size()
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair< int , pii> piii;
typedef pair<int,bool> pib;
typedef vector<pii> vii;
typedef vector<pib> vib;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<string,string> pss;
typedef vector<pss> vss;
const int MOD = 1e9 + 7; //998244353;


int main() {
    int n , k;
    cin >> n >> k;
    set<int> s;
    while(k--){
        int t;
        cin >> t;
        while(t--){
            int x;
            cin >> x;
            s.insert(x);
        }
    }
    cout << n-  s.size();
}




Measured memory_bytes: 3644
n, m = map(int, input().split())
lis = [list(map(int, input().split())) for i in range(n)]

def arr_multiply( lis2):
    def inner(lis1):
        return sum([l1*l2 for l1, l2 in zip(lis1, lis2)])
    return inner

max_score = 0
if m == 0:
    print(0)
else:
    for a in (-1, 1):
        for b in (-1, 1):
            for c in (-1, 1):
                func = arr_multiply([a, b, c])
                score = sum(sorted(list(map(func, lis)))[-m:])
                if score > max_score:
                    max_score = score
    print(max_score)

Measured memory_bytes: 3316
s_prime = input()
t = input()
s_length = len(s_prime)
t_length = len(t)
t_start = -1 # tが入る最初のindex
for i in range(s_length-t_length+1):
    for j in range(t_length):
        flag = True
        # print(i, j, s_prime[i+j], t[j])
        if s_prime[i+j] == '?' or s_prime[i+j] == t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        t_start = i

if t_start == -1:
    print('UNRESTORABLE')
    exit()
s = []
i = 0
while i < s_length:
    if i == t_start:
        s.append(t)
        i += t_length
    elif s_prime[i] == '?':
        s.append('a')
        i += 1
    else:
        s.append(s_prime[i])
        i += 1
for i in range(len(s)):
    print(s[i], end='')
print()


Measured memory_bytes: 9164