akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;

const int mod = 1e9+7;
int A, B;

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


  cin >> A >> B;
  string s;
  cin >> s;
  int N = s.size();
  string ans = "Yes";
  rep(i, N) {
    if (i == A) {
      if (s.at(i) != '-') {
        ans = "No";
        break;
      }
    } else {
      if (s.at(i) < '0' || s.at(i) > '9') {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main
{
	public static void main(String[] args)throws Exception
	{
		Scanner scan=new Scanner(System.in);
		
		while(true)
		{
			double H=scan.nextDouble();		
			double W=scan.nextDouble();

			if(H==0&&W==0)
			{
				break;				
			}
			else
			{
				for(double i=1;i<=H;i++)
				{	
					if(i%2==1)
					{
						for(double a=1;a<=W;a++)
						{
							if(a%2==1)
							{
								System.out.print("#");
							}
							else if(a%2==0)
							{
								System.out.print(".");
							}
						}
						System.out.println("");
					}
					else if(i%2==0)
					{
						for(double b=1;b<=W;b++)
						{
							if(b%2==1)
							{
								System.out.print(".");
							}
							else if(b%2==0)
							{
								System.out.print("#");
							}
						}
						System.out.println("");
					
					}
				}System.out.print("\n");
			
			}
			
		}
		
	}

}

Measured memory_bytes: 35276
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;

int main(void) {
	string S;
	int num;
	num = 0;
	cin >> S;
	for (int i = 0; i < 3;i++) {
		if (S[i] == 'o')num++;
	}
	cout << 700 + num * 100 << endl;
}


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

const long long MAX = 10000000;  // TLEならば小さくする
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {

	ll x, y; cin >> x >> y;
    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll c1 = (2 * y - x) / 3;
    ll c2 = (2 * x - y) / 3;
    if (c1 < 0 || c2 < 0) {
        cout << 0 << endl;
        return 0;
    }
    COMinit(); // 前処理
    cout << COM(c1 + c2, c1) << endl;
	return 0;
}

Measured memory_bytes: 238016
#include<bits/stdc++.h>
#define rep(i, n) for(i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007

int main(){
  ll N, i;
  cin >> N;
  string S;
  cin >> S;
  rep(i, S.size()){
    S[i] += N;
    if(S[i] > 'Z'){
      S[i] -= 26;
    }
  }

  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input())
LR=[]
for i in range(N):
    X,L=map(int,input().split())
    LR.append([X-L,X+L])
LR.sort(key=lambda x:x[1])
nin=LR[0][1]
ans=1
for i in range(1,N):
    if nin<=LR[i][0]:
        nin=LR[i][1]
        ans+=1

print(ans)

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

int main(void){
    
    unsigned int a = 0;
    unsigned int b = 0;
    unsigned int c = 0;
    
    cin >> a >> b >> c;
    
    unsigned int num = 0;
    for(int i = a ; i <= b ; i++){
        if((c % i) == 0){
            num++;
        }
    }
    cout << num<< endl;
    
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)	ret.push_back(n / i);
        }
    }
    return ret;
}
int main()
{
    /*int a, b; cin >> a >> b;
    if (a < 10 && b < 10) cout << a * b << endl;
    else cout << -1 << endl;
    */

    /*int n; cin >> n;
    rep(i, 10) rep(j, 10) {
        if (n == i * j) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    */

    /*ll n; cin >> n;
    vector<ll> d;
    d = divisor(n);
    sort(ALL(d));
    ll ans = 0;
    if (d.size() % 2 == 1) {
        ans += d[d.size() / 2] - 1;
        ans += d[d.size() / 2] - 1;
    }
    else {
        ans += d[d.size() / 2] - 1;
        ans += d[d.size() / 2 - 1] - 1;
    }
    cout << ans << endl;
    */

    int a, b, x; cin >> a >> b >> x;
    double c = 2.0 * x / double(a * a) - double(b);
    double ans;
    if (0 < c) {
        ans = atan(double(a) / (double(b) - double(c))) * 180.0 / M_PI;
    }
    else {
        ans = atan((2 * x) / (double(a) * double(b) * double(b))) * 180.0 / M_PI;
    }
    if (ans < 0) ans += 180;
    ans = 90 - ans;
    cout << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll a,b,c,fa,fb,fc,cnt=0;
  cin>>fa>>fb>>fc;
  if((fa%2+fb%2+fc%2)!=0){cout<<0<<endl;return 0;}
  while(!(a%2+b%2+c%2)&&cnt<400000007){
    a=fb/2+fc/2;
    b=fa/2+fc/2;
    c=fa/2+fb/2;
    fa=a;
    fb=b;
    fc=c;
    cnt++;
  }
  if(cnt==400000007)cout<<-1<<endl;
  else cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

struct edge
{
	int to;
	long long cost;
	edge(int to_, long long cost_) :
		to(to_), cost(cost_) {}
};
const long long INF = 123456789012345;
using P = pair<long long, int>;//first:cost,second:vertice
void dijkstra(vector<edge>graph_[], long long dist[], int n_, int s_)
{
	priority_queue<P, vector<P>, greater<P>>que;
	que.push({ 0,s_ });
	fill(dist, dist + n_, INF);
	dist[s_] = 0ll;
	while (!que.empty())
	{
		auto q = que.top();
		que.pop();
		long long thd = q.first;
		int thv = q.second;
		if (thd > dist[thv])
		{
			continue;
		}
		for (auto ed : graph_[thv])
		{
			if (dist[ed.to] > ed.cost + thd)
			{
				dist[ed.to] = ed.cost + thd;
				que.push({ dist[ed.to],ed.to });
			}
		}
	}
}

vector<edge>graph[100000];
LL dist[100000];

int main(void)
{
	LL K;
	cin >> K;
	for (int i = 0; i < K; ++i) {
		for (int n = 0; n < 10; ++n) {
			if (i == 0 && n == 0)continue;
			graph[i ? i : K].push_back(edge((10 * i + n) % K, n));
		}
	}
	dijkstra(graph,dist,K+1,K);
	cout << dist[0] << endl;
	return 0;
}


Measured memory_bytes: 35828
N = int(input())
h = list(map(int, input().split()))

dp_table = [float("inf")]*N # 0~N-1まで
dp_table[0] = 0

for i in range(N-1): # 0~N-1までだが+1して扱う(1~N)
    dp_table[i+1] = min(dp_table[i]+abs(h[i]-h[i+1]), dp_table[i+1])
    if i-1>=0:
        dp_table[i+1] = min(dp_table[i-1]+abs(h[i-1]-h[i+1]), dp_table[i+1])
        
print(dp_table[N-1])

Measured memory_bytes: 52208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int h,w;
    cin >> h >> w;
    vector<string> masu(110);
    vector<bool>hantei_h(110);
    vector<bool>hantei_w(110);
    rep(i,h) cin >> masu[i];
    rep(i,h){
        rep(j,w){
            if(masu[i][j] == '#'){
                hantei_h[i] = true;
                hantei_w[j] = true;
            }
        }
    }
    rep(i,h){
        if(hantei_h[i]){
        rep(j,w){
            if( hantei_w[j]) cout << masu[i][j];
        }
        cout << endl;
        }
    }
    return 0;
    
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

class UnionFind {
    public:
        UnionFind(){}
        UnionFind(int size) { Init(size); }
        // size: Union-Find で扱いたい要素の数
        void Init(int size) { m_Data.assign(size, -1); }

        // x と y の属する集合を併合
        // 既に一緒な集合内にいるなら false を
        // 新たに併合されたなら true を返す
        bool Unite(int x, int y) {
            x = Find(x), y = Find(y);
            if(x == y) { return (false); }
            if(m_Data[x] > m_Data[y]) { swap(x, y); }
            m_Data[x] += m_Data[y];
            m_Data[y] = x;
            return (true);
        }

        // 要素 k が属する集合の根を返す
        int Find(int k) {
            if(m_Data[k] < 0) { return (k); }
            return (m_Data[k] = Find(m_Data[k]));
        }

        // 要素 k と同じ集合の要素数を返す
        int Size(int k) { return (-m_Data[Find(k)]); }

    private:
        vector<int> m_Data;
};

ll N, M;
vector<ll> A, B;

vector<ll> cnt;     // ノード i が代表点のグループにいるノード数

signed main()
{
    cin >> N >> M;
    A.resize(M);
    B.resize(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    UnionFind uf(N);
    cnt.assign(N, 1);

    vector<ll> ans;

    ll base = N * (N-1) / 2;
    ans.push_back(base);

    ll cur = base;
    for(int i = M-1; i > 0; --i) {
        // 以前のそれぞれのグループのノード数
        ll prev_cnt_a = cnt[uf.Find(A[i])];
        ll prev_cnt_b = cnt[uf.Find(B[i])];
        // 2 つのノードをつなぐ
        uf.Unite(A[i], B[i]);
        // 新しいグループのノード数
        ll cnt_ab = uf.Size(A[i]);

        // 以前と変化があるなら、更新を行う
        if( cnt_ab != prev_cnt_a) {
            cur += prev_cnt_a * (prev_cnt_a - 1) / 2;
            cur += prev_cnt_b * (prev_cnt_b - 1) / 2;
            cur -= cnt_ab * (cnt_ab - 1) / 2;
            cnt[uf.Find(A[i])] = uf.Size(A[i]);
        }
        ans.push_back(cur);
    }

    // 答えの表示
    reverse(ans.begin(), ans.end());
    REP(i, ans.size()) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 5364
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s, op, r;
    int q, a, b;
    cin>>s>>q;
    for (int i=0; i<q; i++)
    {
        cin>>op>>a>>b;
        if (op=="print") cout<<s.substr(a, b-a+1)<<'\n';
        if (op=="reverse")
        {
            r=s.substr(a, b-a+1);
            reverse(r.begin(), r.end());
            for (int j=a; j<=b; j++) s[j]=r[j-a];
        }
        if (op=="replace")
        {
            cin>>r;
            for (int j=a; j<=b; j++) s[j]=r[j-a];
        }
    }
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll inf = 1e18;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, a, b;
	cin>>n>>a>>b;
	vector<ll> v(n + 1);
	for(int i = 1; i <= n; i++){
		cin>>v[i];
	}
	vector<vector<pair<ll, ll> > > dp(n + 1, vector<pair<ll, ll> >(n + 1, {-inf, 0}));
	dp[0][0] = {0, 1};
	for(int i = 1; i <= n; i++){
		dp[i][0] = {0, 1};
		for(int j = 1; j <= i; j++){
			pair<ll, ll> v1 = dp[i - 1][j];
			pair<ll, ll> v2 = dp[i - 1][j - 1];
			if(v1.first == v2.first + v[i])dp[i][j] = {v1.first, v1.second + v2.second};
			else if(v1.first > v2.first + v[i])dp[i][j] = v1;
			else dp[i][j] = {v2.first + v[i], v2.second};
		}
	}
	pair<ll, int> mx = {0, 1};
	for(int j = a; j <= b; j++){
		if(mx.first*j < dp[n][j].first*mx.second)mx = {dp[n][j].first, j};
	}
	ll ans = 0;
	for(int j = a; j <= b; j++){
		if(mx.first*j == dp[n][j].first*mx.second)ans += dp[n][j].second;
	}
	cout<<ld(mx.first)/mx.second<<'\n';
	cout<<ans<<'\n';


	return 0;
}

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

int main(){
    int x;
    cin >> x;
    int sum = 0;
    int a = x/500;
    x %= 500;
    int b = x/5;
    cout << a*1000 + b * 5 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String w = s.next();
		int cnt = 0;
		while(s.hasNext()) {
			String str = s.next();
			if(str.equals("END_OF_TEXT")) break;
			if(str.equalsIgnoreCase(w)) cnt++;
		}
		System.out.println(cnt);
	}
}

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

int main(){
    int H;
    int W;
    cin >> H >> W;
    char S[2002][2002];
    int Left[2002][2002],Right[2002][2002],Up[2002][2002],Down[2002][2002];
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin>>S[i][j];
        }
    }

    for(int i=1;i<=H;i++){
        int count=0;
        for(int j=1;j<=W;j++){
            if(S[i][j]=='#')count=0;
            else count++;
            Left[i][j]=count;
        }
    }
    for(int i=1;i<=H;i++){
        int count=0;
        for(int j=W;j>0;j--){
            if(S[i][j]=='#')count=0;
            else count++;
            Right[i][j]=count;
        }
    }
    for(int j=1;j<=W;j++){
        int count=0;
        for(int i=1;i<=H;i++){
            if(S[i][j]=='#')count=0;
            else count++;
            Up[i][j]=count;
        }
    }
    for(int j=1;j<=W;j++){
        int count=0;
        for(int i=H;i>0;i--){
            if(S[i][j]=='#')count=0;
            else count++;
            Down[i][j]=count;
        }
    }
    int ans=0;
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(S[i][j]=='#')continue;
            ans=max(ans,Left[i][j]+Right[i][j]+Up[i][j]+Down[i][j]-3);
        }
    }
    cout<<ans;
    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


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

    int before_t = 0, before_x = 0, before_y = 0;

    rep(i, n) {
        int t, x, y;
        cin >> t >> x >> y;

        int distance = abs(x - before_x) + abs(y - before_y);
        int time = abs(t - before_t);
        if (distance > time) {
            cout << "No" << endl;
            return 0;
        }
        if ((time - distance) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
        before_t = t;
        before_x = x;
        before_y = y;


    }


    cout << "Yes" << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

def precompute(N, M, data):
    data = data.reshape(-1, 3)
    A, B, C = data[:N].T
    D, E, F = data[N:].T
    X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
    Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
    A = np.searchsorted(X, A)
    B = np.searchsorted(X, B)
    D = np.searchsorted(X, D)
    C = np.searchsorted(Y, C)
    E = np.searchsorted(Y, E)
    F = np.searchsorted(Y, F)
    return A, B, C, D, E, F, X, Y

def solve(A, B, C, D, E, F, X, Y):
    H, W = len(X), len(Y)
    N = H * W
    DX = X[1:] - X[:-1]
    DY = Y[1:] - Y[:-1]

    def set_ng(A, B, C, D, E, F, H, W):
        ng = np.zeros((H * W, 4), np.bool_)

        for i in range(len(A)):
            for x in range(A[i], B[i]):
                v = x * W + C[i]
                ng[v][1] = 1
                ng[v - 1][0] = 1

        for i in range(len(D)):
            for y in range(E[i], F[i]):
                v = D[i] * W + y
                ng[v][3] = 1
                ng[v - W][2] = 1
        return ng

    ng = set_ng(A, B, C, D, E, F, H, W)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = np.empty(N, np.int32)
    p = 0
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal p, ret
        stack[p] = x
        visited[x] = 1
        ret += area(x)
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return stack[p]

    push(v0)
    move = (1, -1, W, -W)
    while p:
        v = pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    signature = '(i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:],i8[:])'
    cc.export('solve', signature)(solve)
    cc.compile()

if sys.argv[-1] == 'ONLINE_JUDGE':
    cc_export()
    exit()

from my_module import solve

N, M = map(int, readline().split())
data = np.int64(read().split())

x = solve(*precompute(N, M, data))
if x == 0:
    print('INF')
else:
    print(x)


Measured memory_bytes: 86172
#from fractions import gcd
#mod = 10 ** 9 + 7
#N = int(input())
#a = list(map(int,input().split()))
#a,b,c = map(int,input().split())
#ans = [0] * N

def intinput():
    return int(input())

def listintinput():
    return list(map(int,input().split()))

def splitintinput():
    return map(int,input().split())
N,K= splitintinput()
l = listintinput()

l.sort(reverse=True)
ans = 0
for i in range(K):
    ans += l.pop(0)

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll  long long int
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define inf 100000000000000000LL
#define fast_io	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
using namespace std;

void addEdge(vector<ll> g[],ll x,ll y)
{
	g[x].pb(y);
	g[y].pb(x);

}
ll dfs(vector<ll> graph[],ll visited[][2],ll val,ll col)
{
	if(visited[val][col]==-1)
	{	
		ll s=0;
		ll p=1;
		for(ll i=0;i<graph[val].size();i++)
		{
	
			s=((col==0)?0:dfs(graph,visited,graph[val][i],col))%mod+dfs(graph,visited,graph[val][i],!col)%mod;
			s=s%mod;
			p=(p%mod*s%mod)%mod;
		}

		if(graph[val].size()==0)
		return 1;
		visited[val][col]=p%mod;
		return visited[val][col];
	}
	else
	return visited[val][col];
}
void directed(vector<ll> g[],vector<ll> graph[],ll *v,ll val)
{
	if(v[val]==-1)
	{
		v[val]=1;
		
		for(ll i=0;i<g[val].size();i++)
		{
			if(v[g[val][i]]==-1)
			{
				graph[val].pb(g[val][i]);
				directed(g,graph,v,g[val][i]);
			}
		}
	}

}
int main()
{
	ll n,x,y;
	cin>>n;
	
	vector<ll> g[n+1];
	vector<ll> graph[n+1];
	
	ll visited[n+1][2];
	ll v[n+1];
	
	memset(v,-1,sizeof(v));
	memset(visited,-1,sizeof(visited));
	
	for(ll i=1;i<n;i++)
	{
		cin>>x>>y;
		addEdge(g,x,y);
	}
	directed(g,graph,v,1);

	ll s1=(dfs(graph,visited,1,0)%mod+dfs(graph,visited,1,1)%mod)%mod;
	cout<<s1<<endl;
}

Measured memory_bytes: 26524
/* 拡張ダイクストラ */
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int n, k;
    cin >> n >> k;
    vector<bool> motu(n, false);
    REP(i, k) {
        int d;
        cin >> d;
        REP(i, d) {
            int a;
            cin >> a;
            a--;
            motu[a] = true;
        }
    }
    int ans = 0;
    REP(i, n) if(!motu[i]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,n) for(int i=(1);i<=(n);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 200005;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}

/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
       int n;
    cin>>n;
    vector<int> c(n-1),s(n-1),f(n-1);
    rep(i,n-1) cin>>c[i]>>s[i]>>f[i];
 
    rep(i,n-1){
        int ans=s[i]+c[i];
        for(int j=i+1;j<n-1;j++){
            if(ans<=s[j]) ans=s[j]+c[j];
            else{
                if((ans-s[j])%f[j]==0){
                    int x=(ans-s[j])/f[j];
                    ans=s[j]+f[j]*x+c[j];
                }
                else{
                    int x=(ans-s[j]+f[j]-1)/f[j];
                    ans=s[j]+f[j]*x+c[j];
                }
            }
        }
 
        cout<<ans<<endl;
    }
 
    cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 3592
import java.util.*;

class Main{
    static int[][] gems;

    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	int n = sc.nextInt();
	while(n!=0){
	    int count = 0;
	    gems = new int[n][2];

	    for(int i=0; i<n; i++){
		gems[i][0] = sc.nextInt();
		gems[i][1] = sc.nextInt();
	    }

	    int m = sc.nextInt();

	    int posX = 10;
	    int posY = 10;
	    for(int i=0; i<m; i++){
		String houi = sc.next();
		int go = sc.nextInt();
		
		for(int k=1; k<=go; k++){ 
		    if(houi.equals("N")){
			posY = posY + 1;
		    }else if(houi.equals("E")){
			posX = posX + 1;
		    }else if(houi.equals("S")){
			posY = posY - 1;
		    }else if(houi.equals("W")){
			posX  = posX - 1;
		    }
		    for(int j=0; j<n; j++){
			if(posX==gems[j][0] && posY==gems[j][1]){
			    count++;
			    gems[j][0]=-1;
			    gems[j][1]=-1;
			}
		    }
		}
	    }
	    
	    String ans = "";
	    if(count==n){ans = "Yes";}
	    else {ans = "No";}

	    System.out.println(ans);

	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int h[] = new int[N];
		for(int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		
		Arrays.sort(h);
		int min = 0;
		int max = 0;
		int sum = 0;
		min = h[0];
		max = h[K - 1];
		int dist = max - min;
		int mindist = dist;
		
		for(int i = 0; i < N - K + 1; i++) {
			dist = h[i + K - 1] - h[i];
			mindist = Math.min(dist, mindist);
		}
		
		System.out.println(mindist);
	}
}


Measured memory_bytes: 50284
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

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

  if (k % 2 == 0)
  {
    cout << -1 << "\n";
    return 0;
  }
  else
  {
    int count = 1;
    long long num = 7;
    while (count <= 1000000)
    {
      if (num % k == 0)
      {
        cout << count << "\n";
        // break;
        return 0;
      }
      count++;
      num = (num * 10 + 7) % k;
    }
  }
  cout << -1 << "\n";

  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    string S;
    cin >> S;
    ll N = S.size(), MOD = 1e9+7;

    vvll dp(100010, vll(4));
    dp[0][0] = 1;

    rep(i, S.size()) {
        rep(j, 4) {
            if (S[i] == '?') dp[i+1][j] += dp[i][j] * 3;
            else dp[i+1][j] += dp[i][j];

            dp[i+1][j] %= MOD;

            if (j < 3 && (S[i] == "ABC"[j] || S[i] == '?')) {
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
        }
    }

    cout << dp[S.size()][3] << endl;
    return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> d;
  for (int i = 0; i < n; i++) {
    int di;
    cin >> di;
    d.push_back(di);
  }
  
  int total = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      total += d[i] * d[j];
    }
  }
  
  cout << total << endl;
  
  return 0;
}


Measured memory_bytes: 256
var
        s:string;
        i,x,y:longint;
begin
        readln(s);
        for i:=1 to length(s) do
                if s[i]='C' then
                begin
                        if x=0 then x:=i;
                end
                else if s[i]='F' then y:=i;
        if (x>0)and(y>0)and(x<y)then writeln('Yes')
        else writeln('No'); 
end.


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, b * d, a * d, b * c}) << '\n';
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,x,a,b;
	cin>>k>>x;
	if(k>0)
	{
		 a=x-(k-1);
		b=x+(k-1);
	}
	else
	{
		a=x;
		b=x;
	}
	for(int i=a;i<=b;i++)
	{
		if(i!=b)
		cout<<i<<" ";
		else
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
int main(){
  
  int x,y,z,q,i,m,flg;
  unsigned long long int box1[101][101]={0};
  unsigned long long int box2[101][101]={0};
  unsigned long long int box3[101][101]={0};
  scanf("%d%d%d",&x,&y,&z);
  flg=0;
for(i=0;i<x;i++){
	for(q=0;q<y;q++){
		scanf("%d",&box1[i][q]);
		if(box1[i][q]>10000){flg=1;}
	}
}  
for(i=0;i<y;i++){
	for(q=0;q<z;q++){
		scanf("%d",&box2[i][q]);
		for(m=0;m<x;m++){
			box3[m][q] += box2[i][q]*box1[m][i];
			if(box2[i][q]>10000){flg=1;}
		}
		
	}
}
if(flg != 0){printf("Too Large\n");return 0;}
for(i=0;i<x;i++){
	for(q=0;q<z;q++){
		if(q==0){printf("%llu",box3[i][q]);}
		else{printf(" %llu",box3[i][q]);}
	}printf("\n");
}

  return 0;
}

Measured memory_bytes: 856
// Problem : C - Distinct or Not
// Contest : AtCoder - AtCoder Beginner Contest 154
// URL : https://atcoder.jp/contests/abc154/tasks/abc154_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int n,a;
    cin>>n;
    set<int> s;
    for(int i=0;i<n;i++) cin>>a, s.insert(a);
    if(sz(s) == n) cout<<"YES\n";
    else cout<<"NO\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 13004
// AOJ DPL_1_H Huge Knapsack Problem
// 2018.5.11 bal4u
 
#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

long long inLL()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

#define MAX  ((1<<20)+5)

typedef struct { long long v, w; } TBL;
TBL a[42]; int c;
TBL a1[MAX]; int c1, c2;

long long binarysearch_upper(long long x)
{
	int m, l = 0, r = c2;

    while (l < r) {
        m = (l+r) >> 1;
		if (a1[m].w == x) return a1[m].v;
		if (a1[m].w < x) l = m + 1; else r = m;
    }
	return a1[l-1].v;
}

int cmp(TBL *a, TBL *b)
{
	if (a->w == b->w) {
		if (a->v > b->v) return -1;
		return (a->v < b->v);
	}
	if (a->w < b->w) return -1;
	return (a->w > b->w);
}

int main()
{
	int N, i, j, m1, m2, lim;
	long long W, x, y, t, ans;

	N = in(), W = inLL();

	c = 0; for (i = 0; i < N; i++) {
		a[c].v = inLL(), a[c].w = inLL();
		if (a[c].w <= W) c++;
	}

	m1 = c / 2, lim = 1 << m1;
	c1 = 0; for (i = 0; i < lim; i++) {
		x = 0, y = 0;
		for (j = 0; ; j++) {
			if (j == m1) {
				a1[c1].v = x, a1[c1++].w = y;
				break;
			}
			if ((i >> j) & 1) {
				if ((y += a[j].w) > W) break;
				x += a[j].v;
			}
		}
	}

	qsort(a1, c1, sizeof(TBL), cmp);

	c2 = 1;
	for (i = 1; i < c1; i++) {
		if (a1[c2-1].v < a1[i].v) a1[c2++] = a1[i];
	}

	ans = 0;
	m2 = c - m1, lim = 1 << m2;
	for (i = 0; i < lim; i++) {
		x = 0, y = 0;
		for (j = 0; ; j++) {
			if (j == m2) {
				t = x + binarysearch_upper(W-y);
				if (t > ans) ans = t;
				break;
			}
			if ((i >> j) & 1) {
				if ((y += a[m1+j].w) > W) break;
				x += a[m1+j].v;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 34396
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll gcd(ll,ll);
ll lcm(ll,ll);

int main()
{
	int N;
	cin >> N;
	vector<ll> t(N, 0);
	rep(i, N)cin >> t[i];
	ll l = 1;
	rep(i, N) l = lcm(l, t[i]);
	co(l);
	return 0;
}

ll gcd(ll a,ll b)
{
	if (a < b)return gcd(b, a);
	while (b != 0)
	{
		ll r = a % b;
		a = b;
		b = r;
	}
	return a;
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);
	ll l = a * (b / g);
	return l;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = m; i >= n; --i)
#define ALL(v) (v).begin(),(v).end()
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; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[8]={1,0,-1,0,-1,-1,1,1};
int dy[8]={0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    const int amx=1000000;
    vector<bool> p(amx+1,true);
    vector<int> a(n),c(amx+1);
    map<int,int> mp;
    REP(i,n){
        cin >> a[i];
        c[a[i]]++;
    }
    for(int i=1;i<=amx;i++){
        if(c[i]){
            if(c[i]>1){
                p[i]=false;
            }
            for(int j=2;j*i<=amx;j++){
                p[i*j]=false;
            }
        }
    }
    int ans=0;
    REP(i,n){
        if(p[a[i]]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7928
S=input()

new=""
ans=""

def func(s,new,i=0):
    
    if i==3:
        global ans
        ans=""
        new+=s[i]
        if eval(new)==7:
            ans=new+"=7"
            return True
        else:
            return False
   
    if func(s,new+s[i]+"+",i+1):
        return True
    
    if func(s,new+s[i]+"-",i+1):
        return True

if func(S,new):
    print(ans)


Measured memory_bytes: 38256
#include<stdio.h>

int main(void)
{
    int a, b, c, d, i;

    scanf("%d %d %d", &a, &b, &c);

    d = 0;

    for(int i = a; i <= b; i++){
        if(0 == c % i){
           d  += 1;
        }
        else if(0 != c % i){
        }

    }

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

    return 0;
}


Measured memory_bytes: 2144
from sys import stdin
INF = 1<<21
WHITE = 0
GRAY = 1
BLACK = 2
n = int(stdin.readline())
M = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(0, n):
    for j, e in enumerate(list(map(int, stdin.readline().split()))):
        if e != -1: M[i][j] = e
d = [INF] * n
d[0] = 0
t = [-1] * n
color = [0] * n
def prim():
    while True:
        minv = INF
        u = -1
        for i in range(0, n):
            if minv > d[i] and color[i] != BLACK:
                u = i
                minv = d[i]
        if u == -1: break
        color[u] = BLACK
        for v in range(0, n):
            if color[v] != BLACK and d[v] > M[u][v]:
                d[v] = M[u][v]
                t[v] = u
                color[v] = GRAY
    return sum(d)
print(prim())

Measured memory_bytes: 7916
n, m = map(int, input().split())
stud = []
poit = []
for i in range(n):
    a, b = map(int, input().split())
    stud.append([a, b])
for i in range(m):
    c, d = map(int, input().split())
    poit.append([c, d])
    
for a, b in stud:
    dist = float('inf')
    for i, info in enumerate(poit):
        c = info[0]
        d = info[1]
        mdist = abs(a-c) + abs(b-d)
        if dist > mdist:
            dist = mdist
            ans = i+1
    print(ans)
    # print(i, info)


Measured memory_bytes: 9176
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
ll val[105],v[105],dp[100025];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,V;ll ans = 0;scanf("%d%d",&n,&V);
    for(int i = 1;i<=n;++i) scanf("%lld%lld",&v[i],&val[i]);
    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    for(int i = 1;i<=n;++i)
    {
        for(int j = 100000;j>=val[i];j--)
            dp[j] = min(dp[j],dp[j-val[i]]+v[i]);
    }
    for(int i = 1;i<=1e5;++i) if(dp[i]<=V) ans = max(ans,1ll*i);
    printf("%lld\n",ans);
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

#define MAXN (100010)
#define mod (1000000007)
#define ll long long

int n;
ll A, B, s[MAXN];
int dpx[MAXN], prex[MAXN];
int dpy[MAXN], prey[MAXN];
std::map<ll, int> map;

int main(){
	scanf("%d%lld%lld", &n, &A, &B);
	for(int i = 1; i <= n; ++ i){
		scanf("%lld", s + i);
		map[- s[i]] = i;
	}
	dpx[0] = prex[0] = 1;
	dpy[0] = prey[0] = 1;
	int now1 = 0, now2 = 0;
	for(int i = 2; i <= n; ++ i){
		auto u = map.lower_bound(B - s[i]);
		int sit = u == map.end() ? 0 : u -> second;
		if(sit == i - 1) -- sit;
		dpy[i - 1] = prex[sit];
		
		u = map.lower_bound(A - s[i]);
		sit = u == map.end() ? 0 : u -> second;
		if(sit == i - 1) -- sit;
		dpx[i - 1] = prey[sit];
		
		if(s[i] - s[i - 1] < B){
			for(int j = now1; j < i - 1; ++ j){
				dpy[j] = prey[j] = 0;
			}
			now1 = i - 1;
		}
		
		if(s[i] - s[i - 1] < A){
			for(int j = now2; j < i - 1; ++ j){
				dpx[j] = prex[j] = 0;
			}
			now2 = i - 1;
		}
		
		prey[i - 1] = (prey[i - 2] + dpy[i - 1]) % mod;
		prex[i - 1] = (prex[i - 2] + dpx[i - 1]) % mod;
	}
	printf("%d\n", (prex[n - 1] + prey[n - 1]) % mod);
	return 0;
}



Measured memory_bytes: 8832
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, mm, aa, cc, sum, ans = 0;
	cin >> nn >> mm >> cc;
	vector<int64> bb(mm);
	for(int64 ii = 0;ii < mm;ii++)
	{
		cin >> bb[ii];
	}
	for(int64 jj = 0;jj < nn;jj++)
	{
		sum = 0;
		for(int64 ii = 0;ii < mm;ii++)
		{
			cin >> aa;
			sum += aa * bb[ii];
		}
		if(sum > -1 * cc)
		{
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3616
import math

a, b, h, m = list(map(int, input().split()))
deg_a = (60 * h + m) * (360 / (60 * 12))
deg_b = m * (360 / 60)
deg = abs(deg_a - deg_b)
rad = math.radians(deg)

c2 = a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)
print(c2 ** 0.5)

Measured memory_bytes: 9512
N = int(input())
N_List = list(map(int,input().split()))
NR_List = [i // 400 for i in N_List]
Number_NRD = len(set([i for i in NR_List if i < 8]))
Number_NRU = len([i for i in NR_List if i >= 8])
max_p= Number_NRD + Number_NRU
min_p= (Number_NRD,1)[Number_NRD == 0]
print(str(min_p) + " " + str(max_p))

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll a[]={1,3,1,2,1,2,1,1,2,1,2,1};
  ll x, y;
  cin >> x >> y;
  x--;y--;
  if(a[x]==a[y])cout << "Yes";
  else cout << "No";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

struct Coord {
    Int x;
    Int y;
};

template <typename LoopFunc>
void PermutationLoop(Int n, LoopFunc& loopFunc);

double CalcDist(Coord first, Coord second) {
    return sqrt((first.x - second.x) * (first.x - second.x) + (first.y - second.y) * (first.y - second.y));
}
double CalcDistSum(vector<Coord>& coords, vector<Int>& coordId) {
    Int size = (Int)coordId.size();
    double ret = 0;
    for (Int i = 0; i < size - 1; ++i) {
        ret += CalcDist(coords[coordId[i]], coords[coordId[i + 1]]);
    }
    return ret;
}
Int Factorial(Int n) {
    if (n == 1) {
        return 1;
    } else {
        return n * Factorial(n - 1);
    }
}

// ここの処理が問題によって変わる
void Func(vector<Coord>& coords, vector<Int>& v) {
    Int n = (Int)v.size();
    double sum = 0;
    do {
        sum += CalcDistSum(coords, v);
    } while (std::next_permutation(v.begin(), v.end()));
    cout << fixed << setprecision(10) << sum / (double)Factorial(n) << endl;
    return;
}

int main(void) {
    // 入出力処理
    Int n;
    cin >> n;
    vector<Coord> coords(n);
    for (Int i = 0; i < n; ++i) {
        cin >> coords[i].x >> coords[i].y;
    }

    // permutationループの処理(キャプチャリストは問題によって変わる)
    auto loopFunc = [&coords](vector<Int>& v) -> void {
        Func(coords, v);
        return;
    };

    PermutationLoop(n, loopFunc);
    return 0;
}

template <typename LoopFunc>
void PermutationLoop(Int n, LoopFunc& loopFunc) {
    vector<Int> v(n);
    for (Int i = 0; i < n; ++i) {
        v[i] = i;
    }
    loopFunc(v);
    return;
}


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

int a;

int main() {
	map<string, int> m;
	cin>>a;
	for(int k = 1; k<= a; k++){
		string s;
		cin >> s;
		m[s] ++;
	}
	cout << "AC x " << m["AC"]<< '\n';
	cout << "WA x " << m["WA"] << '\n';
	cout << "TLE x " << m["TLE"] << '\n';
	cout << "RE x " << m["RE"]<< '\n';
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<utility>
using namespace std;

int top;
int ans[(1<<20)];

int swap_bit(int x, int pos1, int pos2)
{
    int x1=0,x2=0,bit1,bit2;
    bit1 = (1<<pos1), bit2 = (1<<pos2);
    if(x&bit1)x1=1,x-=bit1;
    if(x&bit2)x2=1,x-=bit2;
    if(x1)x+=bit2;
    if(x2)x+=bit1;
    return x;
}

pair<int, int> f(int A, int B, int lev)
{
    int S, E, i, pos, maxbit, nA, nB, bit, bitA, bitB;
    if(lev==1){
        S = top;
        ans[top++]=A,ans[top++]=B;
        E = top;
        return make_pair(S, E);
    }
    for(i=0;i<lev;i++){
        bit=(1<<i);
        bitA=A&bit, bitB=B&bit;
        if(bitA!=bitB)break;
    }
    pos = i;
    nA = swap_bit(A, pos, lev-1), nB = swap_bit(B, pos, lev-1);
    maxbit = (1<<(lev-1));
    if((nA|maxbit)==(nB|maxbit)){
        S = f(nA, (nA^1), lev-1).first;
        E = f((nB^1), nB, lev-1).second;
        for(i=S;i<E;i++)ans[i]=swap_bit(ans[i], pos, lev-1);
    }
    else{
        S = f(nA,(nA^1),lev-1).first;
        E = f(((nA^1)^maxbit),nB,lev-1).second;
        for(i=S;i<E;i++)ans[i]=swap_bit(ans[i], pos, lev-1);
    }
    return make_pair(S, E);
}

int main()
{
    int N, A, B, T, i, j, bit, cnt=0;
    scanf("%d %d %d", &N, &A, &B);
    T=A^B;
    for(i=0,bit=1;i<N;i++,bit<<=1)if(T&bit)cnt++;
    if(cnt%2==0){
        printf("NO");
        return 0;
    }
    f(A,B,N);
    printf("YES\n");
    for(i=0;i<(1<<N);i++){
        printf("%d ", ans[i]);
        /*for(j=0;j<N;j++){
            if(ans[i]&(1<<j))printf("1");
            else printf("0");
        }
        printf("\n");*/
    }
    return 0;
}
/*
1a -> 1b -> 0b -> 0c(a,b, b,c는 해밀턴 홀수차이)

1a -> 0a : 1a -> 1a' -> a'0 -> a0
000
010
111

1. (10100, 01110) -> (00110, 11100)

2. (

10100 -> 10101 -> 00101 -> 01110
*/


Measured memory_bytes: 1408