akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <map>
#include <stack>
#include <map>
#include <unordered_map>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

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


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

/*
 * D - Knapsack 1
 */
public class Main
{

public static void main( String[] args ) throws Exception
{
	final Scanner sc = new Scanner( System.in );//new FileInputStream( "6" ) );
	final int N = sc.nextInt();//総アイテム数
	final int W = sc.nextInt();//最大積載量

	final long[] wArray = new long[ N ];
	final long[] vArray = new long[ N ];

	for( int i = 0; i < N; ++i )
	{
		wArray[ i ] = sc.nextLong();
		vArray[ i ] = sc.nextLong();
	}

	final Map< Long, Long > weightValueMap = new HashMap<>( 1000 );
	//final Map< Long, List< Integer > > weightItemListMap = new HashMap<>( 1000 );// wをキー,それを構成するアイテムのiのリストを値とする

	for( int i = 0; i < N; ++i )
	{
		final long w = wArray[ i ];
		final long v = vArray[ i ];

		//キャッシュしているすべてのwに対して組み合わせを計算する

		Map< Long, Long > update = new HashMap<>();
		final Map< Long, List< Integer > > update2 = new HashMap<>();
		for( Map.Entry< Long, Long > entry : weightValueMap.entrySet() )
		{
			final long cachedWeight = entry.getKey();
			final long cachedValue = entry.getValue();
			final long newWeight = cachedWeight + w;
			final long newValue = cachedValue + v;
			if( newWeight <= W )
			{
				final boolean isBetter = isBetter( weightValueMap, newWeight, newValue );
				if( isBetter )
				{
					update.put( newWeight, newValue );
					/*
					List< Integer > itemList = weightItemListMap.get( newWeight );
					if( itemList == null )
					{
						itemList = new ArrayList<>();
						update2.put( newWeight, itemList );
					}
					itemList.addAll( weightItemListMap.get( cachedWeight ) );
					itemList.add( i );
					*/
				}
			}
		}
		
		weightValueMap.putAll( update );
		//weightItemListMap.putAll( update2 );

		//このアイテム単体について処理
		if( w <= W )
		{
			final boolean isBetter = isBetter( weightValueMap, w, v );
			if( isBetter )
			{
				weightValueMap.put( w, v );
				/*
				List< Integer > itemList = weightItemListMap.get( w );
				if( itemList == null )
				{
					itemList = new ArrayList<>();
					weightItemListMap.put( w, itemList );
				}
				itemList.add( i );
				*/
			}
		}
	}

	//答えを求める
	long max = 0;
	for( Map.Entry< Long, Long > entry : weightValueMap.entrySet() )
	{
		final long v = entry.getValue();
		if( v > max )
		{
			max = v;
		}
	}
	p( max );
}

public static boolean isBetter( final Map< Long, Long > weightValueMap, final long w, final long v )
{
	final Long cachedValue = weightValueMap.get( w );
	if( cachedValue == null || cachedValue < v )
	{
		return true;
	}
	else
	{
		return false;
	}
}

public static void p( Object o )
{
	System.out.println( o );
}

}

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

using namespace std;

#define INF (1<<29)

int a[10][10], res;

void dfs(int n, int S, int cost,
        vector<int> &p, vector<int> &pos)
{
    if (S == (1<<n)-1) {
        res = min(res, cost);
        return;        
    }

    if (res <= cost) return;
    
    for (int i = 0; i < n; i++) {
        if (S >> i & 1) continue;
        int npos = 0;
        for (int j = 0; j < (int)pos.size(); j++) {
            npos = max(npos, pos[j] + a[p[j]][i]);
        }
        p.push_back(i);
        pos.push_back(npos);

        dfs(n, S|(1<<i), npos, p, pos);
        
        p.pop_back();
        pos.pop_back();
    }

}

int main()
{
    int n;
    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> a[i][j];
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                a[i][j] = max(a[i][j], a[j][i]);
            }
        }
        
        res = INF;
        vector<int> p, pos;        
        dfs(n, 0, 0, p, pos);
        cout << res << endl;
    }    
    return 0;
}

Measured memory_bytes: 3092
/*
СТРОИМ СТЕНУ РАБОТЯГИ!
█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═█
█═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═╩═╦═█
█▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄█
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
    
     
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
/** Interface */
     
inline int readChar();
template <class T = int> inline T readInt(); 
template <class T> inline void writeInt( T x, char end = 0 );
inline void writeChar( int x ); 
inline void writeWord( const char *s );
     
/** Read */
     
static const int buf_size = 4096;
     
inline int getChar() {
    static char buf[buf_size];
    static int len = 0, pos = 0;
    if (pos == len) {
        pos = 0, len = fread(buf, 1, buf_size, stdin);
    }
    if (pos == len) {
        return -1;
    }
    return buf[pos++];
}
     
inline int readChar() {
    int c = getChar();
    while (c <= 32) {
        c = getChar();
    }
    return c;
}
     
template <class T>
inline T readInt() {
    int s = 1, c = readChar();
    T x = 0;
    if (c == '-')
        s = -1, c = getChar();
    while ('0' <= c && c <= '9')
        x = x * 10 + c - '0', c = getChar();
    return s == 1 ? x : -x;
}
     
/** Write */
     
static int write_pos = 0;
static char write_buf[buf_size];
     
inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}
     
template <class T> 
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;
     
    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}
     
inline void writeWord( const char *s ) {     while (*s)
writeChar(*s++); }
     
struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;   
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228   


int n, m, k;


int main() {    
    cin >> n >> m >> k;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            int st = m * i + n * j - 2 * i * j;
            if (st == k) {
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}


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

map<string, int> train;
string str;
int cnt = 0;

void DivideTrain(){
	for (int i = 1; i < str.size(); i++){
		string t1 = "", t2 = "", Rt1 = "", Rt2 = "";
		for (int j = 0; j < i; j++) t1 += str[j];
		for (int j = i; j < str.size(); j++) t2 += str[j];
		for (int j = t1.size() - 1; j >= 0; j--) Rt1 += t1[j];
		for (int j = t2.size() - 1; j >= 0; j--) Rt2 += t2[j];
		if (train.find(t1 + t2) == train.end()) train[t1 + t2] = 1;
		if (train.find(t1 + Rt2) == train.end()) train[t1 + Rt2] = 1;
		if (train.find(t2 + t1) == train.end()) train[t2 + t1] = 1;
		if (train.find(t2 + Rt1) == train.end()) train[t2 + Rt1] = 1;
		if (train.find(Rt1 + t2) == train.end()) train[Rt1 + t2] = 1;
		if (train.find(Rt1 + Rt2) == train.end()) train[Rt1 + Rt2] = 1;
		if (train.find(Rt2 + t1) == train.end()) train[Rt2 + t1] = 1;
		if (train.find(Rt2 + Rt1) == train.end()) train[Rt2 + Rt1] = 1;
	}
}

int main(){
	int m;
	cin >> m;
	for (int i = 0; i < m; i++){
		cin >> str;
		DivideTrain();
		cout << train.size() << endl;
		train.clear();
		str.clear();
		cnt = 0;
	}
	cin >> m;
	return 0;
}

Measured memory_bytes: 1320
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    ll N, X, M;
    cin >> N >> X >> M;
    int id[M];
    fill(id, id+M, -1);
    int n, s;
    vector<ll> res;
    for(int i = 0; ; i++){
        if(id[X] != -1){
            n = i-id[X], s = id[X];
            break;
        }
        res.pb(X), id[X] = i;
        X *= X, X %= M;
    }
    ll ans = 0;
    if(N < s){
        rep(i, N) ans += res[i];
        cout << ans << endl; return 0;
    }
    N -= s;
    rep(i, s) ans += res[i];
    ll loop = 0;
    rep2(i, s, s+n-1) loop += res[i];
    ans += loop*(N/n);
    N %= n;
    rep(i, N){
        ans += X;
        X *= X, X %= M;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4192
#include <iostream>
#include <cmath>
#include <set>
using namespace std;

int main () {
  int n;
  cin >> n;
  int slime_num = pow(2, n);
  int s[slime_num];
  multiset <int> slime;
  for (int i = 0; i < slime_num; i++) {
    cin >> s[i];
    slime.insert(s[i]);
  }
  auto max_itr = slime.end();
  max_itr--;
  int max = *max_itr;
  multiset <int> born;
  born.insert(max);
  slime.erase(max_itr);
  for (int i = 0; i < n; i++) {
    multiset <int> tmp;
    for (auto j = born.begin(); j != born.end(); j++) {
      int size = *j;
      auto itr = slime.lower_bound(size);
      if (itr == slime.begin()) {
        puts("No");
        return 0;
      }
      itr--;
      int new_size = *itr;
      slime.erase(itr);
      tmp.insert(new_size);
    }
    for (auto j = tmp.begin(); j != tmp.end(); j++) {
      int size = *j;
      born.insert(size);
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 19712
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	s := getNextString(scanner)
	color := make([]int, n*2)
	for i, ch := range s {
		if ch == 'W' {
			color[i] = 1
		}
	}

	for i := 0; i < 2*n; i += 2 {
		color[i] ^= 1
	}

	var l, ans, mod int64
	ans = 1
	mod = int64(1e9 + 7)
	for i := 0; i < 2*n; i++ {
		l += int64(color[i])
		if color[i] == 0 {
			ans *= l
			ans %= mod
			l--
			if l < 0 {
				ans = 0
				break
			}
		}
	}
	if l != 0 {
		ans = 0
	}
	for i := 1; i <= n; i++ {
		ans *= int64(i)
		ans %= mod
	}

	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 2688
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
while True:
    s = str(n)
    poss = False
    for i in s:
        if int(i) in a:
            poss = True
            break
    if not poss:
        print(n)
        exit(0)
    n += 1

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
	int n;
	cin >> n;
	vector < pair<double,double> > v;
	vector < pair<double,double> >::iterator it,it2;
	int i=n;
	while(i--){
		double x,y;
		cin >> x >> y;
		v.push_back(make_pair(x,y));
	}
	double s=0;
	for(it=v.begin();it!=v.end();it++){
		for(it2=v.begin();it2!=v.end();it2++){
			if(it==it2) continue;
			double d=(it->first-it2->first)*(it->first-it2->first);
			d+=(it->second-it2->second)*(it->second-it2->second);
			s+=sqrt(d);
		}
	}
	printf("%.10lf\n", s/n);
	return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using db = double;
#define pb push_back

const int mxn = 100006;

int n;
vi e[mxn];

int dfs(int x, int p) {
	int s = 0;
	for (auto i : e[x]) if (i != p)
		s ^= dfs(i, x) + 1;
	return s;
}

int main() {
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		e[x].pb(y);
		e[y].pb(x);
	}
	
	puts(dfs(1, 0) ? "Alice" : "Bob");
	
	return 0;
}


Measured memory_bytes: 10368
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)

	n := []int{getInt(), getInt(), getInt()}
	K := getInt()

	idx := 0
	if n[idx] < n[1] {
		idx = 1
	}

	if n[idx] < n[2] {
		idx = 2
	}

	for i := 0; i < K; i++ {
		n[idx] *= 2
	}

	out(n[0] + n[1] + n[2])
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
int N, K;
LL A[1010];
LL ans;
vector<LL> as;

void solve(int a){
	if(a < 0) return;
	int cnt = 0;
	ans += 1LL << a;
	for(auto u : as){
		if((ans & u) == ans) cnt++;
	}
	if(cnt < K) ans -= 1LL << a;
	solve(a - 1);
}
int main(){
	cin >> N >> K;
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		A[i] += A[i - 1];
	}
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < i; j++){
			as.push_back(A[i] - A[j]);
		}
	}
	solve(40);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    vector<int> P(N); repp(i,0,N) cin >> P[i];

    map<int, int> counter;
    int maxCount = 1;
    repp(i,0,N) {
        if (counter.count(P[i] - 1)) {
            counter[P[i]] = counter[P[i] - 1] + 1;
            maxCount = max(maxCount, counter[P[i]]);
        } else counter[P[i]] = 1;
    }
    cout << N - maxCount << endl;
}


Measured memory_bytes: 10368
n=int(input())
s=[]
for _ in range(n):
  s.append(input())
import collections 
d=collections.Counter(s)
larger=max(list(d.values()))
ans=[]
for key in d.keys():
  if d[key]==larger:
    ans.append(key)
ans.sort()
for _ in range(len(ans)):
  print(ans[_])
    

Measured memory_bytes: 38848
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	vector<string> s(n);
	for(int i=0;i<n;i++)
		cin>>s[i];
    vector<char> ans;
    vector<int> res={a,b,c};
	auto dfs=[&](auto f,int idx)->void{
		if(idx==n)
		{
			cout<<"Yes"<<endl;
			for(char c:ans)
				cout<<c<<endl;
			exit(0);
		}
		int x=s[idx][0]-'A';
		int y=s[idx][1]-'A';
		for(int i=0;i<2;i++)
		{
			if(res[x]>0)
			{
				ans.push_back('A'+y);
				res[x]--;
				res[y]++;
				f(f,idx+1);
				res[x]++;
				res[y]--;
				ans.pop_back();
			}
			swap(x,y);
		}
	};
	dfs(dfs,0);
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 19496
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

constexpr int d[] = { 1000, 100, 10, 1 };

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> S(M), C(M);
  for (int i: range(0, M)) {
    std::cin >> S[i] >> C[i];
    S[i] += 3 - N;
  }
  int lb, ub;
  if (N == 1) {
    lb = 0;
    ub = 9;
  }
  if (N == 2) {
    lb = 10;
    ub = 99;
  }
  if (N == 3) {
    lb = 100;
    ub = 999;
  }
  auto ok = [&](int x) {
    if (x < lb || x > ub) {
      return false;
    }
    for (int i: range(0, M)) {
      if ((x % d[S[i] - 1]) / d[S[i]] != C[i]) {
        return false;
      }
    }
    return true;
  };
  for (int x: range(0, 1000)) {
    if (ok(x)) {
      std::cout << x << '\n';
      return 0;
    }
  }
  std::cout << "-1\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[MAXN];
ll A[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,n) a[i] *= 2;
    ll sum = 0;
    FOR(i,1,n) sum += a[i];
    sum /= 2;
    for (int i = 1; i < n; i += 2) sum -= a[i];
    A[n] = sum;
    A[1] = a[n] - A[n];
    FOR(i,2,n-1) A[i] = a[i-1] - A[i-1];
    FOR(i,1,n) cout << A[i] << ' ';
    return 0;
}


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

int main() {
  int N, X; cin >> N >> X;
  int sum = 0;
  vector<int> m(N);
  rep(i, N) {
    cin >> m[i];
    sum += m[i];
  }
  sort(m.begin(), m.end());
  int min = m[0];
  cout << (X - sum) / min + N << endl;
}

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

int main() {
	int N, M, X; cin >> N >> M >> X;
	int A[110];
	for(int i=1; i<=M; ++i) cin >> A[i];
	int j;
	for(j=1; j<=M; ++j){
	    if(A[j]>X) break;
	}
	cout << min(j-1, M-j+1) << endl;
	return 0;
}

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

int main() {
    double n;
    cin >> n;
    double p;
    if ((int)n % 2)
        p = ((int)n / 2 + 1) / n;
    else
        p = (n / 2) / n;
    cout << setprecision(10) << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9+7;
// Int MOD = 998244353;

int main() {
    ios::sync_with_stdio(false);
    Int s;
    cin >> s;
    map<Int, Int> mp;
    mp[s]++;
    for (Int i = 2; i <= 1000000; i++) {
        if (s % 2 == 1) {
            s = 3 * s + 1;
        }
        else {
            s /= 2;
        }
        if (mp[s] > 0) {
            dump(i);
            return 0;
        }
        mp[s]++;
    }
    return 0;  
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

deque<pair<ll, ll>> q;
void pp(ll a, ll mid){
  if(a==1) q.push_front(make_pair(1, 1));
  else if(q.front().first<a) q.push_front(make_pair(a, 1));
  else if(q.front().first>a){
    while(q.front().first>a) q.pop_front();
    if(q.front().first==a) pp(a, mid);
    else pp(a, mid), pp(a, mid);
  }else {
    q.front().second++;
    while(q.front().first!=1&&q.front().second==mid+1){
      q.pop_front();
      if(q.front().first==a) pp(a-1, mid);
      else pp(a, mid), pp(a-1, mid);
    }
  }
}
int main(int argc, char const *argv[]) {
  ll N;
  std::cin >> N;
  std::vector<ll> A(N);
  ll now = 0;
  bool flag = true;
  for(int i=0;i<N;i++) {
    std::cin >> A[i];
    if(now<A[i]) now = A[i];
    else flag = false;
  }
  if(flag){
    std::cout << 1 << '\n';
    return 0;
  }
  ll l = 1, r = 1000000000;
  while(r-l>1){
    ll mid = (l+r)/2, one=0;
    if(A[0]!=1) pp(1, mid);
    for(int i=0;i<N;i++) pp(A[i], mid);
    //std::cout << "now" << mid << '\n';
    while(!q.empty()){
      //std::cout << q.front().first << " " << q.front().second << '\n';
      if(q.front().first==1) one+=q.front().second;
      q.pop_front();
    }
    if(one>mid||mid==1) l = mid;
    else r = mid;
  }
  std::cout << r << '\n';
  return 0;
}


Measured memory_bytes: 5028
#include <iostream>
#include <set>

using namespace std;

int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    set<int> S;
    S.insert(a);
    S.insert(b);
    S.insert(c);
    cout<<S.size()<<endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>arr(n);
	rep(i, n)cin >> arr[i];
	int l = 0, r = 1e9;
	while (r - l> 1) {
		int m = (l + r) / 2;
		ll cnt = 0;
		rep(i, n)cnt += (arr[i] - 1) / m;
		if (cnt <= k)r = m;else l = m;
	}
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 3876
n,p=map(int,input().split())
A=[i%2 for i in map(int,input().split())]
A0=A.count(0)
A1=A.count(1)
if p==1 and A1==0:
    print(0)
elif p==0 and A1==0:
    print(2**A0)
else:
    print((2**A0)*(2**A1)//2)


Measured memory_bytes: 3060
# 入力
N, M = [int(i) for i in input().split()]

# カウント用の配列
count = [0] * M

for i in range(N):  # 入力しながら
    _, *A = [int(i)-1 for i in input().split()]
    for j in A:     # 数える
        count[j] += 1

res = 0
for i in count:
    if i == N: res += 1

print(res)

Measured memory_bytes: 3060
#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
const int N=1e5+10;
int n,k,res,dp[N];
int qmi(int a,int b){
	int res=1;
	while(b){if(b&1LL) res=res*a%mod; a=a*a%mod; b>>=1LL;}
	return res;
}

signed main(){
	cin>>n>>k;
	for(int i=k;i>=1;i--){
		dp[i]=qmi(k/i,n);
		for(int j=i*2;j<=k;j+=i)	dp[i]=((dp[i]-dp[j])%mod+mod)%mod;
		res=(res+i*dp[i]%mod)%mod;
	}
	cout<<res;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    string S;
    cin >> S;
    
    int N = S.size()/2;
    int ans=0;
    REP(i,N){
        if(S[i] != S[S.size()-1 - i]){
            ans++;
        }
        // cout << S[i] << "!" << S[S.size()-1 - i] << "\n";
    }

    cout << ans << "\n";

return 0;
}

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

int main() {
  string str;
  bool chk = true;
  
  cin >> str;
  
  for(int i = 0; i < str.size()-1; i++){
    for(int j = i+1; j < str.size(); j++){
      if(str.at(i) == str.at(j)){
        chk = false;
        break;
      }
      
      if(chk == false) break;
    }
  }
  
  if(chk == true) cout << "yes";
  else cout << "no";
}


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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(int i=0; i<(n); i++)
#define REPj(n) for(int j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

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

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

/* 
	add utility Algorithm
*/


int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int K;
    cin >> K;
    string S;
    cin >> S;

    if (K < S.size()) cout << S.substr(0, K) << "..." << endl;
    else cout << S << endl;

    return 0;
}


Measured memory_bytes: 3656
#include <iostream>

using namespace std;

int main()
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    if (C>=B||A>=D)
    {
        cout<<"0";
    }
    else
    {
        cout<<min(B,D)-max(A,C);
    }

    return 0;
}


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

kyori = 0
if A[0] == 0:
    kyori = k-A[-1]
else:
    kyori = k-(A[-1]-A[0])

for i in range(n-1):
    kyori = max(kyori, A[i+1]-A[i])
print(k-kyori)


Measured memory_bytes: 26436
import java.util.*;

public class Main {
	
	/*
	 * default function
	 * */	
	int ni() {
		return cin.nextInt();
	}
	
	long nl() {
		return cin.nextLong();
	}
	
	String line() {
		return cin.nextLine();
	}
	
	void println(String str) {	
		System.out.println(str);
	}
	
	void print(String str) {
		System.out.print(str);
	}
	
	/*
	 * default variable
	 */
	
	static final int MOD = 1000000007;
	
	Scanner cin = new Scanner(System.in);	
	String  output;
	
	public static void main(String[] args) {			
		new Main().run();						
	}
	/* default above */
		
	public void run() {
			
		input();
		/* 
		 * start
		 */	
		
		int res = solve();
		
		/*
		 * finish
		 */
		
		output = res +"";
		println(output);
			
	}
	/* 
	 * define variable
	 */
	
	int H, W;
	
	void input() {
		H = ni();
		W = ni();
		
		if (W > H) {
			W = H + W;
			H = W - H;
			W = W - H;
		}
	}
	
	int solve() {
		
		if (H % 3 == 0 || W % 3 == 0) {
			return 0;
		}
		
		return Math.min(cal(H, W), cal(W, H));		
	}
	
	int cal(long h, long w) {
		
		long res = w;		
		
		for (long i = h/3; i <= h/2; i ++) {
			long a[] = new long[3];
			
			a[0] = (i) * w;
			a[1] = (h - i) * (w / 2);
			a[2] = (h - i) * (w - w/2);
			Arrays.sort(a);
			res = Math.min(res, a[2] - a[0]);		
		}
		return (int)res;
	}
	
	
}


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

using namespace std;

#define int long long

struct Dijkstra {
	struct E {
		int t; // to
		int c; // cost
		E(int t_, int c_) : t(t_), c(c_) {}
//		E(void) : t(0), c(0) {}
		inline bool operator<(const E a) const {
			return c < a.c;
		}
		inline bool operator>(const E a) const {
			return a < (*this);
		}
	};
	int n; // num of vertex
	vector<vector<E>> es; // edges list
	Dijkstra(int sz) : n(sz), es(sz) {}
    void add_edge(int s, int t, int cost) {
        es[s].push_back(E(t, cost));
    }
	// s : start, inf : infinity
    auto calc(int s, int inf) {
        vector<int> res(es.size(), inf);
		// res[i] : cost of position i
        priority_queue<E, vector<E>, greater<E>> q;
        q.emplace(s, 0);
        while (!q.empty()) {
            auto a = q.top();
            q.pop();
			// a.t : now position
			// a.c : now position's cost
            if (a.c >= res[a.t]) continue;
            res[a.t] = a.c;
            for (auto& p : es[a.t]) {
                if (a.c + p.c < res[p.t]) q.emplace(p.t, a.c + p.c);
            }
        }
        return res;
    }
};

signed main()
{
	int n, m, S, T;
	cin >> n >> m >> S >> T;
	S--, T--;
	Dijkstra EN(n), SN(n);
	for (int i = 0; i < m; i++) {
		int v, u, x, y;
		cin >> v >> u >> x >> y;
		v--, u--;
		EN.add_edge(u, v, x);
		EN.add_edge(v, u, x);
		SN.add_edge(u, v, y);
		SN.add_edge(v, u, y);
	}
	auto en = EN.calc(S, LLONG_MAX);
	auto sn = SN.calc(T, LLONG_MAX);
	vector<int> res(n);
	for (int i = 0; i < n; i++) res[i] = en[i] + sn[i];
	for (int i = n - 2; i >= 0; i--) res[i] = min(res[i], res[i + 1]);
	for (int i = 0; i < n; i++) cout << (int)1e15 - res[i] << endl;
}
/*
	verified on 2018/5/13
	https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d
*/

Measured memory_bytes: 19000
#include<iostream>
#include<math.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define lrep(i,n) for(long int i=0;i<(n);i++)
using namespace std;
int main(){
	long int n;
	cin >> n;
	long N=n;
	long count=0,counta;
	for(int a=2;a<=sqrt(N);a++){
		counta=0;
		while(!(n%a)){
			n=n/a;
			counta++;
		}
		for(int k=1;k<=counta;k++){
			counta-=k;
			count++;
		}
	}
	if(n!=1) count++;
	cout << count;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e18+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define dbgmint(n,arr) rep(i,n){cerr<<arr[i].x<<" ";}cerr<<endl;
#define out(a) cout<<a<<endl
#define out2(a,b) cout<<a<<" "<<b<<endl
#define vout(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second

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

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,v.size())i>>v[j];return i;}

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

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

    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=0;
    Vec v(n);
    cin>>v;

    REP(i,1,n){
        ll diff = v[i]-v[i-1];
        ans += min(diff*a,b);
    }
    cout<<ans<<endl;
    return  0;
}


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

int main() {
    int N, ans = 1;
    string S;
    cin >> N >> S;
    for (int i = 1; i < N; ++i) {
        if (S[i] != S[i - 1]) ++ans;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=505;
int n,m,f[MAXN][MAXN];
int ans,Ans[MAXN*MAXN][5];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			scanf("%d",&f[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++)
			if(f[i][j]%2==1){
				f[i][j]--;
				f[i][j+1]++;
				ans++;
				Ans[ans][1]=i;
				Ans[ans][2]=j;
				Ans[ans][3]=i;
				Ans[ans][4]=j+1;
			}
		if(f[i][m]%2==1&&i!=n){
			f[i][m]--;
			f[i+1][m]++;
			ans++;
			Ans[ans][1]=i;
			Ans[ans][2]=m;
			Ans[ans][3]=i+1;
			Ans[ans][4]=m;
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++)
		printf("%d %d %d %d\n",Ans[i][1],Ans[i][2],Ans[i][3],Ans[i][4]);
}

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

using namespace std;
typedef long long ll;

// int main()
// {
//     vector<vector<vector<ll>>> Lun(12, vector<vector<ll>>(10, vector<ll>(0)));

//     int K;
//     cin >> K;

//     vector<ll> nums(0);

//     for (int i = 0; i < 10; i++)
//     {

//         Lun[0][i].push_back(i);

//         if (i != 0)
//         {
//             nums.push_back(i);
//         }
//     }

//     for (int i = 1; i < 12; i++)
//     {

//         for (int j = 0; j < 10; j++)
//         {

//             if (j > 0)
//             {

//                 for (int k = 0; k < Lun[i - 1][j - 1].size(); k++)
//                 {

//                     ll A = j * pow(10, i) + Lun[i - 1][j - 1][k];

//                     Lun[i][j].push_back(A);

//                     nums.push_back(A);
//                 }
//             }

//             for (int k = 0; k < Lun[i - 1][j].size(); k++)
//             {

//                 ll A = j * pow(10, i) + Lun[i - 1][j][k];

//                 Lun[i][j].push_back(A);

//                 if (j != 0)
//                 {

//                     nums.push_back(A);
//                 }
//             }

//             if (j < 9)
//             {

//                 for (int k = 0; k < Lun[i - 1][j + 1].size(); k++)
//                 {

//                     ll A = j * pow(10, i) + Lun[i - 1][j + 1][k];

//                     Lun[i][j].push_back(A);

//                     if (j != 0)
//                     {
//                         nums.push_back(A);
//                     }
//                 }
//             }
//         }
//     }

//     sort(nums.begin(),nums.end());

//     cout << nums[K-1] << endl;

//     return 0;
// }

int main()
{

    int K;
    cin >> K;

    queue<ll> A;


    int count = 0;


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

        A.push(i);
        count++;
        if(count==K){


            cout << A.back() << endl;


            return 0;
        }
    }

    
    while (count < K)
    {
        ll a = A.front();

        A.pop();

        if (a % 10 != 0)
        {

            A.push(a * 10 + a % 10 - 1);
            count++;
            if (count == K)
            {

                break;
            }
        }
        A.push(a * 10 + a % 10);

        count++;
        if (count == K)
        {

            break;
        }

        if (a % 10 != 9)
        {

            A.push(a * 10 + a % 10 + 1);

            count++;
            if (count == K)
            {

                break;
            }
        }
    }


    cout << A.back() << endl;

    return 0;
}

Measured memory_bytes: 4136
/*
Á·Ï°Ìâ£ºMr.Rito Post Office_AOJ 2200 
	ÏÈµ¥¶À¿¼ÂÇÖ»×ßË®Â·»òºµÂ·µÄÇé¿ö£¬ÓÃwarshall_floydÇó³öÈÎÒâÁ½µã¼äµÄ×î¶ÌÂ·¡£
	È»ºó¶¨Òå dp[i][k] := ÒÑ¾­È¥ÁËµÚi¸öÕò×Óºó£¬´¬Í£ÔÚµÚk¸öÕò×ÓÀïµÄ×´Ì¬ÏÂµÄ×î¶ÌÂ·¡£
	È»ºóijkÈýÖØÑ­»·¸üÐÂdp£¬ÆäÖÐµÝÍÆ¹«Ê½Ë¼Â·£º
	ÔÚÍÆµ¼ikµÄÊ±ºò£¬¶¨ÒåÒ»¸öÖÐ¼ä×´Ì¬j±íÊ¾ÏÈ´Ói-1×ßºµÂ·µ½j£¬
	È»ºó´Ój×ßË®Â·È¥k£¬×îºó´Ók×ßºµÂ·È¥i£¬ÓÚÊÇ¾Í°Ñ´¬ÈÓÔÚÁËk¡£
	Èç¹ûj==kµÄÊ±ºò¾Í²»ÐèÒªÈÆÈ¦×ÓÁË¡£
*/

#include <iostream>
#include <algorithm>
using namespace std;
 
#define INF 1e8
#define MAX_V 256
#define MAX_R 1024
int dl[MAX_V][MAX_V];	//	d[u][v]±íÊ¾±ße=(u,v)µÄÈ¨Öµ£¬²»´æÔÚµÄÊ±ºòµÈÓÚÎÞÇî´ó»òÕßd[i][i] = 0
int ds[MAX_V][MAX_V];
int z[MAX_R];
int dp[MAX_R][MAX_V];	// dp[i][j] := ÒÑ¾­È¥ÁËµÚi¸öÕò×Óºó£¬´¬Í£ÔÚµÚj¸öÕò×ÓÀï
int N;					//	¶¥µãÊý
 
///////////////////////////SubMain//////////////////////////////////
int main(int argc, char *argv[])
{
 
	int M;
	while (cin >> N >> M , N || M)
	{
// 		memset(dl, 0x3f, sizeof(dl));
// 		memset(ds, 0x3f, sizeof(ds));
		for (int i = 0; i < N; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				if (i == j)
				{
					dl[i][j] = ds[i][j] = 0;
				}
				else
				{
					dl[i][j] = ds[i][j] = INF;
				}
			}
		}
 
		for (int i = 0; i < M; ++i)
		{
			int x, y, t;
			char s;
			cin >> x >> y >> t >> s;
			--x; --y;
			if (s == 'L')
			{
				dl[x][y] = min(dl[x][y], t);
				dl[y][x] = dl[x][y];
			}
			else
			{
				ds[x][y] = min(ds[x][y], t);
				ds[y][x] = ds[x][y];
			}
		}
		
		int R;
		cin >> R;
		for (int i = 0; i < R; ++i)
		{
			cin >> z[i];
			--z[i];
		}
 
		// warshall_floyd
		for (int k = 0; k < N; ++k)
		{
			for (int i = 0; i < N; ++i)
			{
				for (int j = 0; j < N; ++j)
				{
					dl[i][j] = min(dl[i][j], dl[i][k] + dl[k][j]);
					ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
				}
			}
		}
		// end of warshall_floyd
 
		// dp
		// ÄáÂê3¸ö0x3f3f3f3f¼ÓÆðÀ´Òç³öÁË
		//memset(dp, 0x3f, sizeof(dp));
		for (int i = 0; i < R; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				dp[i][j] = INF;
			}
		}
		for (int i = 0; i < N; ++i)
		{
			// È¥ÁËÊ×¸öÕò×Óºó£¬´¬·ÅÔÚµÚi¸öÕò×ÓÀï
						// ×ø´¬È¥	 // ×ø11Â·³µ»ØÀ´
			dp[0][i] = ds[z[0]][i] + dl[i][z[0]];
		}
		for (int i = 1; i < R; ++i)
		{
			for (int j = 0; j < N; ++j)
			{
				for (int k = 0; k < N; ++k)
				{
					if (j != k)
					{
						//                          i-1Õ¾     + ´Ói-1Õ¾×ßºµÂ·È¥j+ ´Ój×ßË®Â·È¥k+´Ók×ßºµÂ·È¥i
						dp[i][k] = min(dp[i][k], dp[i - 1][j] + dl[z[i - 1]][j] + ds[j][k] + dl[k][z[i]]);
					}
					else
					{
						// j == k                   i-1Õ¾     + ´Ói-1Õ¾×ßºµÂ·È¥i
						dp[i][j] = min(dp[i][j], dp[i - 1][j] + dl[z[i - 1]][z[i]]);
					}
				}
			}
		}
 
		cout << *min_element(dp[R - 1], dp[R - 1] + N) << endl;
	}
 
	return 0;
}
///////////////////////////End Sub//////////////////////////////////



Measured memory_bytes: 4500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    int ans = 0;
    rep(i, S.size()) {
        if(S[i]=='+') ans++;
        else ans--;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
#define ls (x<<1)
#define rs (ls|1)
const int maxN=202000;
const ll INF=1e18;
class SegmentTree{
    public:
    ll Mn[maxN<<2],Lazy[maxN<<2];
    void Plus(int x,ll key){
        Mn[x]+=key;Lazy[x]+=key;return;
    }
    void PushDown(int x){
        if (Lazy[x]){
            Plus(ls,Lazy[x]);Plus(rs,Lazy[x]);Lazy[x]=0;
        }
        return;
    }
    void Update(int x){
        Mn[x]=min(Mn[ls],Mn[rs]);return;
    }
    void Build(int x,int l,int r){
        if (l==r){
            Mn[x]=INF;
            return;
        }
        int mid=(l+r)>>1;
        Build(ls,l,mid);Build(rs,mid+1,r);Update(x);return;
    }
    void Init(int n){
        Build(1,1,n);return;
    }
    void RangePlus(int x,int l,int r,int ql,int qr,ll key){
        if (l==ql&&r==qr){
            Plus(x,key);return;
        }
        int mid=(l+r)>>1;PushDown(x);
        if (qr<=mid) RangePlus(ls,l,mid,ql,qr,key);
        else if (ql>=mid+1) RangePlus(rs,mid+1,r,ql,qr,key);
        else RangePlus(ls,l,mid,ql,mid,key),RangePlus(rs,mid+1,r,mid+1,qr,key);
        Update(x);return;
    }
    void Cmpmin(int x,int l,int r,int p,ll key){
        if (l==r){
            Mn[x]=min(Mn[x],key);return;
        }
        int mid=(l+r)>>1;PushDown(x);
        if (p<=mid) Cmpmin(ls,l,mid,p,key);else Cmpmin(rs,mid+1,r,p,key);
        Update(x);return;
    }
    ll Query(int x,int l,int r,int ql,int qr){
        if (l==ql&&r==qr) return Mn[x];
        int mid=(l+r)>>1;PushDown(x);
        if (qr<=mid) return Query(ls,l,mid,ql,qr);
        else if (ql>=mid+1) Query(rs,mid+1,r,ql,qr);
        else return min(Query(ls,l,mid,ql,mid),Query(rs,mid+1,r,mid+1,qr));
    }
    ll Get(int x,int l,int r,int opt){
        if (l==r) return Mn[x]+l*opt;
        PushDown(x);int mid=(l+r)>>1;
        return min(Get(ls,l,mid,opt),Get(rs,mid+1,r,opt));
    }
};

int n,Q,A,B;
SegmentTree T1,T2;
int P[maxN];

int main(){
    scanf("%d%d%d%d",&n,&Q,&A,&B);
    P[0]=A;
    T1.Init(n);T1.Cmpmin(1,1,n,B,B);
    T2.Init(n);T2.Cmpmin(1,1,n,B,-B);
    for (int i=1;i<=Q;i++){
        int p;scanf("%d",&p);P[i]=p;
        ll mn=INF;
        mn=min(T1.Query(1,1,n,p,n)-p,T2.Query(1,1,n,1,p)+p);
        T1.RangePlus(1,1,n,1,n,abs(p-P[i-1]));T2.RangePlus(1,1,n,1,n,abs(p-P[i-1]));
        T1.Cmpmin(1,1,n,P[i-1],mn+P[i-1]);T2.Cmpmin(1,1,n,P[i-1],mn-P[i-1]);
    }
    ll Ans=min(T1.Get(1,1,n,-1),T2.Get(1,1,n,1));
    printf("%lld\n",Ans);return 0;
}

Measured memory_bytes: 24704
from math import floor
large_p = 10**9 + 7
from operator import mul
from functools import reduce
def main():
    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        if arr == []:
            arr.append([n, 1])
        return arr

    n = int(input())
    n_sq = floor(n ** 0.5)
    divs = [1] * (n + 1)
    for i1 in range(n , 1, -1):
        div = factorization(i1)
        for dive, divnum in div:
            divs[dive] += divnum
    r = reduce(mul, divs)
    r %= large_p

    print(r)
if __name__ == '__main__':
    main()

Measured memory_bytes: 75280
def resolve():
    n, m = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(m)]

    prev = lst[0]
    for new in lst[1:]:
        prev = [max(prev[0], new[0]), min(prev[1], new[1])]

    print(len(range(prev[0], prev[1]+1)))


resolve()

Measured memory_bytes: 28116
// D - Lunlun Number
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int K; cin>>K; //候補の個数
	int k = 0;
	queue<ll> q;
	rp(i, 1, 10) q.push(i); //最上位桁かつ候補の初期値
	while(q.size()){
		ll n = q.front(); q.pop(); //候補を取り出す
		k++;
		if(k >= K){ //候補が K 番目なら解
			cout<< n <<endl;
			return 0;
		}
		//m = n%10 + {-1,0,+1}: 登録した候補の第一位に差分を加算して次の第一位へ
		rp(m, n%10-1, n%10+2) if(0<=m && m<=9) q.push(n*10+m); //第一位が [0,9] の範囲内なら末尾に追加
	}
}

Measured memory_bytes: 1792
n,k,s = map(int,input().split())
if s < 10 ** 9:
    z = ((str(s) + ' ') * k) + ((str(s+1) + ' ') * (n-k))
else:
    z = ((str(s) + ' ') * k) + (('1' + ' ') * (n-k))
print(z)

Measured memory_bytes: 10980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

// combination(n,r)
int combination(int n, int r){
	if(r == 0 || r == n)	return 1;
	else if(r == 1)	return n;
	return (combination(n - 1, r - 1) + combination(n - 1, r));
}

// gcd(a,b)
int gcd(int a,int b){
	int ret;
	ret = (b == 0) ? a : gcd(b, a % b);
	return ret;
}

// lcm(a.b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

// append(array,*size,addNum)
void append(int *array,int *size,int num){
	realloc(array, sizeof(int) * (*size + 1));
	array[(*size)] = num;
	++(*size);
}

// pop(array,*size) & nongetpop(array,*size)
int pop(int *array,int *size){
	int temp = array[(*size - 1)];
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
	return temp;
}

void nongetpop(int *array,int *size){
	realloc(array,sizeof(int) * (*size - 1));
	--(*size);
}

int main(int argc, char const *argv[])
{
	char str[12],yaki[] = "YAKI";
	scanf("%s",str);
	if(strncmp(str,yaki,4) == 0)	puts("Yes");
	else puts("No");
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{

	int a,b,c;
	int i;
	int sum = 0;
	scanf("%d %d %d", &a, &b, &c);

	if(a == b) {
	}
	else{
		sum++;
	}
	if(a == c){
	}
	else{
		sum++;
	}
	if(b == c){
	}
	else{
		sum++;
	}

	if(sum == 0){
		sum++;
	}

	printf("%d\n", sum);

	return 0;
}



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

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

    vector<int> vec(N+1);
    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }
    vec.at(N) = vec.at(0)+K;

    int m=0;
    for(int i=0; i<N; i++){
        m = max( m , max(vec.at(i)-vec.at(i+1) ,vec.at(i+1)-vec.at(i) ) );
    }
    cout << K-m << endl;
}

Measured memory_bytes: 1152