akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

Graph tips;
vi vertex;

void dfs(const Graph &G, const int &rad, const int &center, int d, int v, int p) {
  for (auto nv : G[v]) {
    if (nv == p) continue;

    ++vertex[center];

    if (d+1 == rad) {
      tips[center].push_back(nv);
      continue;
    }

    dfs(G, rad, center, d+1, nv, v);
  }
}

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

  if (k == 1) {
    cout << n-2 << endl;
    return 0;
  }

  Graph G(n);
  vector<P> edge(n-1);
  rep(i,n-1) {
    int a, b; cin >> a >> b; --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
    edge[i] = P(a,b);
  }

  if (k%2 == 0) {
    tips.resize(n);  // from vertex
    vertex.assign(n, 1);
    rep(i,n) {
      dfs(G, k/2, i, 0, i, -1);
    }
  }

  else {
    tips.resize(n-1);  // from edge
    vertex.assign(n, 2);
    rep(i,n-1) {
      int a, b;
      tie(a,b) = edge[i];
      dfs(G, k/2, i, 0, a, b);
      dfs(G, k/2, i, 0, b, a);
    }
  }

  int ans = n - *max_element(all(vertex));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
	int n, sum = 0;
	cin >> n;
	vector<int>s(n);
	bool flag = true;//すべてが10の倍数の場合をtrue
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		if (flag&&s[i] % 10 != 0)flag = false;
		sum += s[i];
	}
	sort(s.begin(),s.end());
	if (flag) {
		cout << 0 << endl;
	}
	else if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		for (int i = 0; i < n; i++) {
			if (s[i] % 10 != 0) {
				sum -= s[i];
				break;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    int n;
    String[] a,b;
    String from,to;

    class E{
        String s;
        int cost;
        E(String s, int cost){
            this.s = s;
            this.cost = cost;
        }
    }

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            n = sc.nextInt();
            if(n==0) break;

            a = new String[n];
            b = new String[n];
            for(int i=0; i<n; i++){
                a[i] = sc.next();
                b[i] = sc.next();
            }
            from = sc.next();
            to = sc.next();

            System.out.println(getMin());
        }
    }

    int getMin(){
        LinkedList<E> q = new LinkedList<E>();
        q.add(new E(from,0));
        HashSet<String> set = new HashSet<String>();

        while(q.size()>0){
            E e = q.poll();
            String ss = e.s;
            int cost = e.cost;

            if(ss.equals(to)) return cost;
            if(set.contains(ss)) continue;
            set.add(ss);

            for(int i=0; i<a.length; i++){
                String s = ss;
                s = s.replaceAll(a[i],b[i]);
  
                if(ss.equals(s)) continue;
                if(s.length()>to.length()) continue;
                q.add(new E(s,cost+1));
            }
        }

        return -1;
    }

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

Measured memory_bytes: 13000
#include <stdio.h>


int main(int argc, char *argv[])
{
  int a = 0;
  int b = 0;

  fscanf(stdin, "%d %d", &a, &b);

  if(a < b){
    printf("a < b\n");
  }else if(a > b){
    printf("a > b\n");
  }else{
    printf("a == b\n");
  }

  return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int c = 0;
			while(n>=5){
				c += n/5;
                                n= n/5;
			}
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 17176
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if(n % 2 == 1) {
    double s = n / 2 + 1;
    cout << s / n << endl;
  }
  else {
    cout << 0.5 << endl;
  }
}

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

int main()
{
  int a, b, k;
  cin >> a >> b >> k;
  int i;
  for(i = a; i <= b; i++)
  {
    if(i < a+k || i > b-k)
    {
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int a, b, c, d, x, y,z;
	
	cin >> a >> b >> c >> d;

	z = a + b + c + d;
	x = z / 60;
	y = z - x*60;

	cout << x<<endl;
	cout << y << endl;

	return 0;
}


Measured memory_bytes: 3072
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef unsigned long long ll;
const int mn=6e2+5;
int n;
char s[mn][mn];
ll h1[mn][mn],h2[mn][mn],pw[mn];
inline int check(int x,int y){
	int t1=x-n+1,t2=y-n+1;
	for(int i=t1;i<x;i++,t2++)
		if(h1[i][y]-h1[i][t2]*pw[y-t2]!=h2[x][t2]-h2[i][t2]*pw[x-i])
			return 0;
	return 1;
}
int main(){
	int o=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	pw[0]=1;
	int N=n+n;
	for(short i=1;i<N;i++)
		pw[i]=pw[i-1]*31;
	for(short i=1,t1,t2;i<N;i++)
		for(int v=1;v<N;v++){
			t1=i;
			t2=v;
			if(t1>n)
				t1-=n;
			if(t2>n)
				t2-=n;
			s[i][v]=s[t1][t2];
			h1[i][v]=h1[i][v-1]*31+s[i][v]-'a';
			h2[i][v]=h2[i-1][v]*31+s[i][v]-'a';
		}
	for(int i=n;i<N;i++)
		for(int v=n;v<N;v++)
			o+=check(i,v);
	printf("%d\n",o);
	return 0;
}


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

using namespace std;

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

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
	string s;
	cin >> s;
	rep (i, s.size()) {
	  if (s[i] == 'U' || s[i] == 'D') continue;
	  if ((i % 2 && s[i] == 'R') || (i % 2 == 0 && s[i] == 'L')) {
		cout << "No" << endl;
		return 0;
	  }
	}
	cout << "Yes" << endl;
    
    return 0;
}



Measured memory_bytes: 3612
from math import floor,ceil
T1,T2 = map(int,input().split())
A1,A2 = map(int,input().split())
B1,B2 = map(int,input().split())

def f(t):
    if t<=T1:
        return (A1-B1)*t/((B1-A1)*T1+(B2-A2)*T2)
    else:
        return ((A1-B1)*T1+(A2-B2)*(t-T1))/((B1-A1)*T1+(B2-A2)*T2)

ans = 0
if ((B1-A1)*T1+(B2-A2)*T2) == 0:
    ans = 'infinity'
else:
    if f(T1)>0:
        ans += floor(f(T1))
        if f(T1+T2)>0:
            ans += floor(max(f(T1),f(T1+T2)))-ceil(min(f(T1),f(T1+T2)))
        else:
            ans += floor(f(T1))
        if floor(f(T1)) != f(T1):
            ans += 1
    else:
        if f(T1+T2)>0:
            ans += floor(f(T1+T2))+1
print(ans)

Measured memory_bytes: 38384
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
class RH {
	string s;
	int n, m, base;
	int* has;
	int mypow(int x, int y) {
		if (!y)return 1;
		if (y % 2)return this->mypow(x, y - 1) * x % m;
		int memo = this->mypow(x, y / 2);
		return memo * memo % m;
	}
public:
	RH() {}
	RH(string s, int m, int b) { init(s, m, b); }
	~RH() { delete[] has; }
	void init(string s, int m, int b) {
		n = s.size();
		has = new int[n];
		base = b;
		this->s = s;
		this->m = m;
		rep(i, n) {
			has[i] = (int)s[i];
			if (i)has[i] += base * has[i - 1] % m;
			has[i] %= m;
		}
	}
	int query(int a, int b) {
		assert(!(a >= b || a < 0 || n < b));
		return (has[b - 1] - this->mypow(base, b - a) * (!a ? 0 : has[a - 1]) % m + m) % m;
	}
};
int n, m;
string s, q;
set<P> st;
signed main() {
	cin >> n >> m >> s;
	int l = 0, r = 1;
	RH* h1 = new RH(s, 1000000007, 1007);
	RH* h2 = new RH(s, 1000000007, 10007);
	rep(i, m) {
		cin >> q;
		if (q[0] == 'L') {
			if (q == "L++")l++;
			else l--;
		}
		else {
			if (q == "R++")r++;
			else r--;
		}
		st.insert(make_pair(h1->query(l, r), h2->query(l, r)));
	}
	cout << st.size() << endl;
	delete h1;
	delete h2;
}


Measured memory_bytes: 26568
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int H, W;

	cin >> H >> W;

	string grid[H];
	for (int i =  0; i < H; i++) {
		cin >> grid[i];
	}

	vector<bool> row(H, false);
	vector<bool> col(W, false);

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (grid[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}

	for (int i = 0; i < H; i++) {
		if (row[i]) {
			for (int j = 0; j < W; j++) {
				if (col[j]) {
					cout << grid[i][j];
				}
			}
			cout << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 256
use std::cmp::max;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let in_k: i64 = read();
    let in_n: usize = read();
    let mut in_a: Vec<i64> = Vec::new();

    for _ in 0..in_n {
        in_a.push(read());
    }

    in_a.sort();

    let mut dist = in_a[0] - in_a[in_a.len() - 1] + in_k;

    for i in 1..in_n {
        dist = max(in_a[i] - in_a[i - 1], dist);
    }

    println!("{}", in_k - dist);
}


Measured memory_bytes: 6396
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			try
			{
				int d = sc.nextInt();
				
				int res = 0;
				for (int x = 0; x < 600; x += d)
				{
					res += f(x) * d;
				}
				System.out.println(res);
			}
			catch (Exception e)
			{
				break;
			}
		}
	}
	private static int f(int x)
	{
		return x * x;
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define sp ' '
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(long long int yy = 0; yy < YY; ++yy)
#define prn(XX) cout << XX << endl
#define prs(XX) cout << XX << " "

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;

const long long int MOD = 1e9 + 7;
const long long int INF = 2e9 + 13;
const long long int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

int main(int argc, char **argv){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    char c; cin >> c;
    cout << ++c << endl;

    return 0;
}

//cikisir



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

int main() {
	char s[200009];
	cin>>s;
	char t[200009];
	long long ans = 0;int c=0;
	int n=strlen(s);
	for(int i=0;i<n;++i) {
		if(i<n-1 && s[i] == 'B' && s[i+1] == 'C') {
			t[c++] = 'D';
			i++;
		} else {
			t[c++] = s[i];
		}
	}
	//cout<<t;
	long long cnta = 0;
	int m = strlen(t);
	for(int i=0;i<m;++i) {
		if(t[i] == 'A') {
			cnta++;
		} else if(t[i] == 'D') {
			ans += cnta;
		} else {
			cnta = 0;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 764
#include <stdlib.h>
#include <stdio.h>

int main(){
int k,x,n,i,j,a[100];
k=0;
scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d",&a[i]);
}
for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
        if(a[j]<a[j-1]){
            x=a[j];
         a[j]=a[j-1];
       a[j-1]=x;
          k++;
          }
      }
  }
for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
    }
  printf("%d\n%d\n",a[n-1],k);
return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    if(a == b) {
        for(int i=0; i<a; i++) cout << a;
    }
    else{
        int min, max;
        min = std::min(a, b);
        max = std::max(a, b);
        for(int i=0; i<max; i++){
            cout << min;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
 
int main(void){
  long double a,b,c;
  std::cin >> a;
  std::cin >> b;
  std::cin >> c;
  
  std::string ans = "No";
  long double temp = 0;
  temp += std::pow(a,2);
  temp += std::pow(b,2);
  temp += std::pow(c,2);
  temp -= 2 * a * b;
  temp -= 2 * b * c;
  temp -= 2 * a * c;
  
  if(0 < temp && (c - a - b) > 0){
    ans = "Yes";
  }
  std::cout << ans << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<pair<int, int> > > Q(N);
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        while(a--) {
            int x, y;
            cin >> x >> y;
            Q[i].push_back({x-1, y});
        }
    }
    int ans = 0;
    for (int i = 0; i < (1<<N); ++i) {
        int cnt = 0;
        vector<int> f(N, -1);
        for (int j = 0; j < N; ++j) {
            if (((i >> j)&1) == 1) {
                if (f[j] == 0) cnt = INT32_MIN;
                f[j] = 1;
                for (auto & k : Q[j]) {
                    if (f[k.first] != k.second && f[k.first] != -1) cnt = INT32_MIN;
                    f[k.first] = k.second;
                }
                ++cnt;
            } else {
                if (f[j] == 1) cnt = INT32_MIN;
                f[j] = 0;
            }
        }
        ans = max(cnt, ans);
    }
    printf("%d", ans);
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n,m;
map<ll,int> mp;

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

	cin>>n;
	REP(i,n) {
		ll g; cin>>g;
		mp[g]++;
	}
	cin>>m;
	bool flg=true;
	REP(i,m) {
		ll t; cin>>t;
		if(mp[t]>0) mp[t]--;
		else flg=false;
	}
	if(flg) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;

	return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std; 
#define ll  long long
#define pb push_back
const ll  MOD = 998244353 ;
const int N= 1e5 ;


int main()
{

	
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n , m ; 
	cin >> n >> m; 
	if(m >= n)
		cout<<"unsafe";
	else
		cout<<"safe";
 
	return 0 ;
}

Measured memory_bytes: 3652
package main

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

func main() {
	sc := NewScanner()
	N, H := sc.NextInt(), sc.NextInt()
	a := make([]int, N)
	b := make([]int, N)
	mxA := 0

	p := 0
	sumP := 0
	for i := 0; i < N; i++ {
		a[i], b[i] = sc.NextInt(), sc.NextInt()
		if mxA < a[i] {
			mxA = a[i]
		}
	}

	sort.Ints(b)
	for i := N - 1; i >= 0; i-- {
		if mxA < b[i] {
			p++
			sumP += b[i]
			if sumP >= H {
				fmt.Println(N - i)
				return
			}
		}
	}

	l := -1
	h := H

	for h-l > 1 {
		c := (h + l) / 2

		remain := H - sumP - c*mxA
		if remain <= 0 {
			h = c
		} else {
			l = c
		}
	}
	fmt.Println(h + p)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
struct mint {
    ll x;
    mint(ll x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
int main() {

    int n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;    

    mint ans = 1;
    bool flag;
    int idx;
    if(s1[0] == s2[0]){
        ans *= 3;
        flag = true;
        idx = 1;
    }
    else{
        ans *= 6;
        flag = false;
        idx = 2;
    }

    for(int i=idx; i<n; ++i){
        if(s1[i] == s2[i]){
            if(flag){
                ans *= 2;
            }
            flag = true;
        }
        else{
            i++;
            if(flag){
                ans *= 2;
            }
            else{
                ans *= 3;
            }
            flag = false;
        }
    }
    cout << ans.x << endl;

    return 0;
}

Measured memory_bytes: 256
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n, m = LI()
    x = sorted(list(LI()))
    diff = []
    if m == 1:
        print(0)
    else:
        for i in range(1, m):
            diff.append(x[i] - x[i - 1])
        print(sum(diff) - sum(sorted(diff, reverse=True)[:n-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 36528
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    cout << (A + B + C + (max({A, B, C}) * ((1 << K) - 1))) << endl;
}


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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll start, end;
    string S;
    cin >> S;
    for(ll i = 0;i < S.size();i++) {
        if(S[i] == 'A') {
            start = i;
            break;
        }
    }
    for(ll i = S.size() - 1;i >= 0;i--) {
        if(S[i] == 'Z') {
            end = i;
            break;
        }
    }
    cout << end - start + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict
import math
n,m = map(int, input().split())
s = input()
t = input()

ans = int((n*m)/math.gcd(n,m))
d = defaultdict(int)
if n > m:
  for i in range(n):
    if i == 0:
      d[1] = s[i]
    else:
      d[i*int(ans/n)+1] = s[i]
  ng = 0
  for i in range(m):
    if i == 0:
      if d[1] != t[i]:
        ng += 1
    else:
      if d[i*int(ans/m)+1] != 0 and d[i*int(ans/m)+1] != t[i]:
        ng += 1
else:
  for i in range(m):
    if i == 0:
      d[1] = t[i]
    else:
      d[i*int(ans/m)+1] = t[i]
  ng = 0
  for i in range(n):
    if i == 0:
      if d[1] != s[i]:
        ng += 1
    else:
      if d[i*int(ans/n)+1] != 0 and d[i*int(ans/n)+1] != s[i]:
        ng += 1
if ng > 0:
  print (-1)
else:
  print (ans)

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

vector<vector<int> > v(201, vector<int>(201, -1));

int gcd(int i, int j){
  if(v[i][j] != -1) return v[i][j];
  int x = i, y = j;
  if(x < y) swap(x, y);
  while(x % y != 0){
    int t = x;
    x = y;
    y = t % y;
  }
  v[i][j] = y;
  v[j][i] = y;
  return y;
}

void solve(){
  int k; cin >> k;
  long long ans = 0;
  for(int i = 1; i <= k; i++){
    for(int j = 1; j <= k; j++){
      int x = gcd(i, j);
      for(int l = 1; l <= k; l++){
        ans += gcd(x, l);
      }
    }
  }
  cout << ans << endl;
  return;
}
int main(){
  solve();
  return 0;
}


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

int main()
{

        int N, K;
        cin >> N >> K;
        vector<int> have(N, 0);
        for (int i = 0; i < K; ++i){
                int tmp = 0;
                cin >> tmp;
                for (int j = 0; j < tmp; ++j) {
                        int t = 0;
                        cin >> t;
                        have[t-1]++;
                }
        }
        int ans = 0;
        for (int i = 0; i < N; ++i) {
                if (have[i] == 0) ans++;
        }
        cout << ans << endl;

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n;cin>>n;
    ll ans=0;
    REP(i,1,n+1){
        ll a;cin>>a;
        if(i%2&&a%2)ans++;
    }
    out(ans);
}

Measured memory_bytes: 3600
#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);
	}
	cout << vec.at(n - 1);
	for (int i = n - 2; i >= 0; --i) {
		cout << " " << vec.at(i);
	}
	cout << endl;
}



Measured memory_bytes: 3096
#include <stdio.h>

int n;
int happiness[100000][3];//0,1,2:a,b,c
int dp[100000][3];

int max(int a,int b){return a>b?a:b;}

int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    for(int j=0;j<3;j++) scanf("%d",&happiness[i][j]);

    for(int i=0;i<3;i++) dp[0][i]=happiness[0][i];
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+happiness[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+happiness[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+happiness[i][2];
    }
    printf("%d\n",max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])));
}

Measured memory_bytes: 2560
main = interact $ ((flip (++)) "\n") . show . (\[a,b] -> mygcd a b) . take 2 . map read . words
mygcd 0 b = b
mygcd a 0 = a
mygcd a b = let a' = max a b
                b' = min a b
            in  mygcd b' (a' `mod` b')

Measured memory_bytes: 3692
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(std::string S){
  bool flag =true;
  vec(c,S.size())
  ll cnt=0;
  ll now=0;
  rep(i,S.size()){
    if(flag&&S[i]=='R'){
      cnt++;
    }else if(flag&&S[i]=='L'){
      c[i-1]+=(cnt+1)/2;
      c[i]+=(cnt/2)+1;
      cnt=0;
      flag=false;
      now=i;
    }else if(!flag&&S[i]=='L'){
      cnt++;
    }else{
      c[now-1]+=(cnt+1)/2;
      c[now]+=cnt/2;
      cnt=1;
      flag=true;
    }
  }
  c[now-1]+=(cnt+1)/2;
  c[now]+=cnt/2;
  rep(i,S.size()){
    cout<<c[i];
    if(i<=S.size()-2)cout<<" ";
  }cout<<endl;
  return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

typedef struct tag_data {
	int id;
	int ac;
	int rank;
} data;

void sort_r(data** a, int size) {
	int i, sorted, last;

	sorted = size;
	while(sorted) {
		last = 0;
		for(i = 0; i < sorted - 1; i++) {
			if(a[i]->ac < a[i + 1]->ac) {
				data* tmp;
				tmp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = tmp;

				last = i + 1;
			}
		}
		sorted = last;
	}
}

void sort(data* a, int size) {
	int i, sorted, last;

	sorted = size;
	while(sorted) {
		last = 0;
		for(i = 0; i < sorted - 1; i++) {
			if(a[i].id > a[i + 1].id) {
				data tmp;
				tmp = a[i];
				a[i] = a[i + 1];
				a[i + 1] = tmp;

				last = i + 1;
			}
		}
		sorted = last;
	}
}

int main(void) {
	int id, ac, rank;
	int n = 0;
	data input[128];
	data* ip_ptr[128];
	int prev_ac;
	int qes;
	int i, j;

	while(1) {
		scanf("%d,%d", &id, &ac);
		if(!id && !ac)
			break;
		input[n].id = id; input[n].ac = ac;
		n++;
	}

	for(i = 0; i < n; i++) {
		ip_ptr[i] = input + i;
	}

	sort_r(ip_ptr, n);

	prev_ac = ip_ptr[0]->ac;
	ip_ptr[0]->rank = 1;
	for(i = 1, rank = 1; i < n; i++) {
		if(ip_ptr[i]->ac == prev_ac)
			ip_ptr[i]->rank = rank;
		else {
			ip_ptr[i]->rank = ++rank;
			prev_ac = ip_ptr[i]->ac;
		}
	}

	sort(input, n);

	while(scanf("%d", &qes) != EOF) {
		printf("%d\n", input[qes - 1].rank);
	}

	return 0;
}

Measured memory_bytes: 600
n = int(input())
int_list = list(map(int,(input().split())))
count = 0
while count < 100:
    s = 0
    for i in range(len(int_list)):
        
        if int_list[i] % 2 == 0 :
            s += 1
        else:
            break
        int_list[i] = int_list[i]/2
            
    if s == n :
        count += 1
    else: 
        break
print(count)


Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> A(n); rep(i, n) cin >> A[i];
  int cnt = 0;
  rep(i, n) {
    if((i+1)%2==1 && A[i]%2==1) cnt++;
  }
  cout << cnt << "\n";
  return 0;
}


Measured memory_bytes: 3608
N = int(input())
d = {"M":0,"A":0,"R":0,"C":0,"H":0}
for i in range(N):
    s = input()[0]
    if s in d:
        d[s]+=1

ans = 0
for s1 in d:
    for s2 in d:
        for s3 in d:
            if s1 != s2 and s2 != s3 and s3 != s1:
                ans += d[s1]*d[s2]*d[s3]
print(ans//6)

Measured memory_bytes: 3064
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array.Unboxed
import Data.Array.ST

main=do
  (n:m:q:_)<-map read.words<$>getLine::IO[Int]
  lrs<-replicateM m $ unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[[Int]]
  pqs<-replicateM q $ unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[[Int]]
  --
  putStr.unlines $ map (show.g (f n lrs)) pqs
--
f n lrs = runSTUArray $ do
  ar <- newArray ((0,0),(n,n)) 0 :: ST s (STUArray s (Int,Int) Int)
  forM_ lrs $ \(l:r:_) -> do
    forM_ [r..n] $ \rr -> do
      writeArray ar (l,rr) =<< (+1) <$> readArray ar (l,rr)
  pure ar
--
g :: UArray (Int,Int) Int -> [Int] -> Int
g ar (p:q:_) = sum $ map (\l-> ar !(l,q) - ar!(l,p-1)) [p..q]

Measured memory_bytes: 97276
#include<iostream>
#define int long long
using namespace std;
const int N=102;
const int mod=1e9+7;
int ar[N];
int binpow(int x,int y){
	int tich=1;
	while(y){
		if(y&1){
			tich*=x;
			tich%=mod;
		}
		x*=x;
		x%=mod;
		y>>=1;
	}
	return tich;
}
pair<int,int> solve(int l,int r){
//	cout<<l<<' '<<r<<endl;
	int i,dem=0,num1=1,num2=1,min1=mod,lst=l;
	pair<int,int> tmp;
	for(i=l;i<=r;i++){
		min1=min(min1,ar[i]);
	}
	for(i=l;i<=r;i++){
		ar[i]-=min1;
	}
	for(i=l;i<=r;i++){
		if(!ar[i]){
			dem++;
			if(lst!=i){
				tmp=solve(lst,i-1);
				num1*=tmp.first;
				num1%=mod;
				num2*=(tmp.first+tmp.second);
				num2%=mod;
			}
			lst=i+1;
		}
//		dem++;
	}
	if(lst!=r+1&&lst!=l){
		tmp=solve(lst,r);
		num1*=tmp.first;
		num1%=mod;
		num2*=(tmp.first+tmp.second);
		num2%=mod;
	}
	num2=(binpow(2,dem)*num2+(binpow(2,min1)-2)*num1)%mod;
	if(num2<0){
		num2+=mod;
	}
	num1*=binpow(2,min1);
	num1%=mod;
	return {num1,num2};
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	cout<<solve(1,n).second;
}


Measured memory_bytes: 256
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 5 + 10)

import math



def main():
    num = int(input())
    data = list(map(int, input().split()))

    ans_data = [-1 for i in range(num + 1)]
    # count = 0
    for i in range(1, num + 1)[::-1]:
        count = 0
        ind = i * 2
        while ind <= num:
            if ans_data[ind]:
                count ^= 1
            ind += i
        # print('ind', i, data[i - 1], count)
        ans_data[i] = data[i - 1] ^ count

    count = 0
    for i in range(1, num + 1):
        if ans_data[i]:
            count += 1

    print(count)

    for i in range(1, num + 1):
        if ans_data[i]:
            print(i)




if __name__ == '__main__':
    main()

Measured memory_bytes: 76264
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.next();
            var cc = n.ToCharArray();
            var x = int.Parse(n);
            var h = 0;
            for (int i = 0; i < n.Length; i++)
            {
                h += cc[i] - '0';
            }

            Console.WriteLine(x % h == 0?"Yes":"No");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public string[] ArrayString(int N)
        {
            string[] Array = new string[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = next();
            }
            return Array;
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13140
package main

import (
	"fmt"
	"sort"
)



func main() {
	var N int
	fmt.Scan(&N)
	Ls := make([]int64, N, N)
	var L int64
	for i := 0; i < N; i++ {
		fmt.Scan(&L)
		Ls[i] = L
	}

	sort.Slice(Ls, func(i, j int) bool {
        return Ls[i] < Ls[j]
    })
	var x, y,z, res int64
	for i := 0; i < len(Ls); i++ {
		x = Ls[i]
		for j:= i+1; j < len(Ls); j++{
			y = Ls[j]
			if x == y {
				continue
			}
			
			for k :=j+1; k < len(Ls); k++ {
				z = Ls[k]
				if y == z {
					continue
				}
				if z < x + y {
					res++
				} else {
					continue
				}
			}
		}
	}
	
    

	fmt.Println(res)
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if ((a == b && a == c) || (a != b && a != c && b != c)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

typedef long long lint;

lint n;

string conv(int x)
{
	char c[2] = {x + '0', '\0'};
	string s = (string)c;
	
	return (s);
}

void print(lint x, string show)
{
	if (!x){
		reverse(show.begin(), show.end());
		printf("%s\n", show.c_str());
		return;
	}
	
	if (x < 0){
		x = -x;
		print((x + 9) / 10, show + conv((10 - (x % 10)) % 10));
	}
	else {
		print(-(x / 10), show + conv(x % 10));
	}
}

int main()
{
	while (scanf("%lld", &n), n) print(n, "");
	
	return (0);
}

Measured memory_bytes: 1044
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<vector<int>>v(10, vector<int>(10));

int check(string s) {
	int ret = 0;
	for (auto i : s) {
		ret = v[ret][i];
	}
	return ret;
}

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

	int ans = 0;
	for (auto &i : v)for (auto &j : i)cin >> j;
	for (char i = 0; i < 10; i++) {
		for (char j = 0; j < 10; j++) {
			for (char k = 0; k < 10; k++) {
				for (char l = 0; l < 10; l++) {
					string s;
					s.push_back(i);
					s.push_back(j);
					s.push_back(k);
					s.push_back(l);
					char add = 0;
					for (auto e : s) {
						add = v[add][e];
					}
					s.push_back(add);
					bool ok = true;
					for (int a = 0; a < 5; a++) {
						for (char b = 0; b < 10; b++) {
							if (s[a] == b)continue;
							string t = s;
							t[a] = b;
							if (!check(t))ok = false;
						}
					}
					for (int a = 0; a < 4; a++) {
						if (s[a] == s[a + 1])continue;
						swap(s[a], s[a + 1]);
						if (!check(s))ok = false;
						swap(s[a], s[a + 1]);
					}
					if (!ok)ans++;
				}
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
int dp[MAX][3];	
int a[MAX][3];
int n, k;
const int inf = 0x3f3f3f3f;
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)scanf("%d %d %d", &a[i][0], &a[i][1], &a[i][2]);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j){
			dp[i][j] = a[i][j];
		}
	}
	for(int i = n-2; i >= 0; --i) {
		for(int j = 0; j < 3; ++j){
			dp[i][j]+= max(dp[i+1][(j+1)%3], dp[i+1][(j+2)%3]);
		}
	}
	printf("%d\n", max(dp[0][0], max(dp[0][1], dp[0][2])));

	return 0;
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

int main(void)
{
    ll a, b , c, l, r;
    cin >> a >> b >> c;
    l = a * b * 4;
    r = c - a - b;
    if(r < 0) {
        cout << "No" << endl;
        return 0;
    }
    r = r * r;
//    cout << l << " " << r << endl;
    cout << ((l<r)?"Yes":"No") << endl;
}


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

#define M_PI       3.14159265358979323846

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(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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 SQ(a) ((a)*(a))
#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 SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

int dp[100000];
int s[100000];

int main() {
	int x;
	cin >> x;
	REP(i, 100000) {
		int k = i;
		while (k) {
			s[i] += k % 10;
			k /= 10;
		}
	}
	priority_queue<PII, vector<PII>, greater<PII>> q;
	memset(dp, 0x7f, sizeof(dp));
	int ans = 0x7f7f7f7f;
	FOR(i, 1,10) {
		int n = x * i;
		dp[n / 10] = n % 10;
		ans = min(ans, s[n / 10] + n % 10);
		q.push(MP( n % 10, n / 10));
	}
	while (!q.empty()) {
		auto tmp = q.top();
		q.pop();
		if (dp[tmp.second] < tmp.first)continue;
		REP(i, 10) {
			int n = x * i + tmp.second;
			int k = n % 10 + tmp.first;
			if (dp[n / 10] > k) {
				dp[n / 10] = k;
				ans = min(ans, s[n / 10] + k);
				q.push(MP(k, n / 10));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

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


Measured memory_bytes: 3916
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define F first
#define S second
using namespace std;

int gcd(int a,int b) {
  if(a<b) swap(a,b);
  if(b==0) return a;
  return gcd(b,a%b);
}

signed main() {
  int n;
  cin>>n;
  vector<bool>vec(n);//W
  vector<bool>vek(n);//E
  vector<pair<int,int>>veq(n);/*
  first->W
  second->E
  */
  int mi=inf;
  rep(i,n) {
    vec.at(i)=false;
    vek.at(i)=false;
    veq.at(i).F=0;
    veq.at(i).S=0;
  }
  rep(i,n) {
    char a;
    cin>>a;
    if(a=='W') {
      if((i)) {
        vec.at(i)=true;
      }
    }
    else {
      if(i<n-1) {
        vek.at(i)=true;
      }
    }
  }
  rep(i,n) {
    if(i<n-1) {
      if(vek.at(i)) {
        veq.at(i+1).F+=1;
      }
    }
    if(0<i) {
      veq.at(i).F+=veq.at(i-1).F;
    }
  }
  for(int i=n-1;i>=0;i--) {
    if(0<i) {
      if(vec.at(i)) {
        veq.at(i-1).S+=1;
      }
    }
    if(i<n-1) {
      veq.at(i).S+=veq.at(i+1).S;
    }
  }
  rep(i,n) {
    int a=abs(veq.at(i).F-i);
    int b=abs((n-i-1)-veq.at(i).S);
    mi=min(mi,a+b);
  }
  cout<<mi<<endl;
}

Measured memory_bytes: 4992
N, K = map(int, input().split())

c = 0
for i in range(K, N + 2):
    min = i * (i + 1) / 2
    max = i * (N + 2 - i + N + 1) / 2
    c += max - min + 1
    c %= (1e9 + 7)
print(int(c))

Measured memory_bytes: 9132
x = input()
a, b, c = x.split(' ')
a, b, c = int(a), int(b), int(c)
if a > b:
    a, b = b, a
if b > c:
    b, c = c, b
if a > b:
    a, b = b, a
print('%d %d %d'%(a, b, c))


Measured memory_bytes: 5596
a,b,c,d = map(int,raw_input().split())
t = [0 for _ in xrange(101)]
t[a] += 1
t[b] -= 1
t[c] += 1
t[d] -= 1
for i in xrange(len(t)):
  if(i > 0): t[i] += t[i-1]
count = 0
for i in xrange(len(t)):
  if(t[i] == 2): count += 1
print count

Measured memory_bytes: 2568