akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;

void func(long long K) {
    queue<string> q;
    vector<string> ans;
    rep(i, 0, 10) { ans.push_back(to_string(i)); }
    rep(i, 1, 10) { q.push(to_string(i)); }
    ll cnt = 0;
    string s;
    ll tail;
    char c;
    while (cnt <= 100000) {
        s = q.front();
        q.pop();
        tail = s[s.size() - 1] - '0';
        if (tail == 0) {
            q.push(s + '0');
            q.push(s + '1');
            ans.push_back(s + to_string(tail));
            ans.push_back(s + to_string(tail + 1));
        } else if (tail == 9) {
            q.push(s + '8');
            q.push(s + '9');
            ans.push_back(s + to_string(tail - 1));
            ans.push_back(s + to_string(tail));
        } else {
            q.push(s + to_string(tail - 1));
            q.push(s + to_string(tail));
            q.push(s + to_string(tail + 1));
            ans.push_back(s + to_string(tail - 1));
            ans.push_back(s + to_string(tail));
            ans.push_back(s + to_string(tail + 1));
            cnt++;
        }
        cnt += 2;
    }
    cout << ans[K] << endl;
}

int main() {
    // cout << fixed << setprecision(5);

    long long K;
    scanf("%lld", &K);
    func(K);
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(arr.begin(),arr.end());
	for(int i=1; i<arr.size(); i++){
		if(arr[i-1]==arr[i]){
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
}

Measured memory_bytes: 4056
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner kb = new Scanner(System.in);
		int n = kb.nextInt(), k = kb.nextInt();
		int[] h = new int[n];
		for(int i=0; i < n; i++) {
			h[i] = kb.nextInt();
		}
		int[] dp = new int[n];
	//	Arrays.fill(dp, -1);
		boolean[] visited = new boolean[n];

		dp[0] = 0;
		visited[0] = true;
		for(int i = 1; i < n; i++) {
			for(int j = 1; j <= k && j <= i; j++) {
				int ksteps = dp[i-j] + Math.abs(h[i-j]-h[i]);
				if(!visited[i]) {
					dp[i] = ksteps;
					visited[i] = true;
				}
				else
					dp[i] = Math.min(dp[i], ksteps);
			}
		}
		System.out.println(dp[n-1]);
	}
}


Measured memory_bytes: 51204
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	int N, P;
	string S;
	cin >> N >> P >> S;

	if (10 % P == 0) {

		lint ans = 0;
		for (int i = N - 1; i >= 0; i--) {
			if ((S[i] - '0') % P == 0) ans += i + 1;
		}

		cout << ans << "\n";

		return 0;
	}

	unordered_map<int, int> mp;
	int rem = 0, pw = 1;
	for (int i = N - 1; i >= 0; i--, (pw *= 10) %= P) {
		(rem += (S[i] - '0') * pw) %= P;
		mp[rem]++;
	}

	lint ans = mp[0];
	for (const auto& [key, val] : mp) {
		ans += 1LL * val * (val - 1) / 2;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main()
{
    int n;cin>>n;
    ll ans=1;
    vector<ll>a(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n;++i){
        if(a[i]==0){
            ans=0;
            break;
        }
        if((ll)1e18/a[i] < ans){
            ans=-1;
            break;
        }
        ans*=a[i];
    }
    cout<<ans;
}

Measured memory_bytes: 4056
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 10e9+7LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
//時間が厳しいとき使う
#define INI(...) int __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, x, y); --x; --y;
    ll v[n];
    ll count[n];
    rep(i, n)
    {
        count[i] = 0;
    }
    rep(i, n)
    {
        rep(j, n)
        {
            v[j] = abs(i - j);
        }
        rep(j, n)
        {
            chmin(v[j], abs(i - x) + abs(j - y) + 1);
        }
        rep(j, n)
        {
            chmin(v[j], abs(i - y) + abs(j - x) + 1);
        }
        rep(j, n)
        {
            if (i < j)
            {
                ++count[v[j]];
            }
        }
    }
    reps(i, 1, n)
    {
        cout << count[i] << endl;
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	boolean flg = true;
		int A = sc.nextInt();
      	int B = sc.nextInt();
      	int C = sc.nextInt();
      	if(B/A > C){
        	System.out.println(C);
        }else{
        	System.out.println(B/A);
        }
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  REP(i, a+1) REP(j, b+1) REP(k, c+1){
    if(x == 500*i+100*j+50*k) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://beta.atcoder.jp/contests/arc090/tasks/arc090_b>
問題文============================================================
 x  軸上に N 人の人が立っています。 人 iの位置を xi とします。
 任意のi に対して、 xi は0 以上10^9 以下の整数です。同じ位置に複数の人が立っていることもありえます。
 
 これらの人の位置に関する情報が M 個与えられます。 このうち i 個めの情報は (Li,Ri,Di) という形をしています。
 この情報は、人 Ri は人 Li よりも距離 Di だけ右にいること、 すなわち、
 xRi−xLi=Di が成り立つことを表します。
 
 これら M 個の情報のうちのいくつかに誤りがある可能性があることがわかりました。
 与えられる M 個すべての情報と矛盾しないような値の組 (x1,x2,...,xN) が存在するかどうか判定してください。
 
 制約
 1≤N≤100,000
 0≤M≤200,000

 1≤Li,Ri≤N ( 1≤i≤M)
 0≤Di≤10,000 ( 1≤i≤M)
 Li≠Ri ( 1≤i≤M)
 i≠j のとき、 (Li,Ri)≠(Lj,Rj) かつ (Li,Ri)≠(Rj,Lj) Di は整数である
=================================================================

解説=============================================================

 ある頂点uから頂点vに互いに到達可能なグループに分ける。
 各グループの基準位置(適当なグループ内の任意の頂点の位置)は独立して考えることができるので
 各グループごとに最初の基準位置を決めうちして、dfsで頂点間を辿っていき、矛盾がないか見ていけば良い。
 各頂点での操作は高々１回の行われるだけなので間に合う
 
================================================================
*/

struct edge{
    ll u;
    ll v;
    ll cost;
    
    ll l;
    ll r;
    edge(){}
    edge(ll u,ll v,ll cost,ll l,ll r):u(u),v(v),cost(cost),l(l),r(r){}
};

ll N,M;
vector<ll> L,R,D;
vector<vector<edge>> G;
vector<ll> loc;
vector<ll> check;

bool dfs(ll n,bool from){
    if(check[n] == 1) return true;
    check[n] = 1;
    if(from){
        loc[n] = 0;
    }
    for(auto e:G[n]){
       if(loc[e.l] == INF){
            loc[e.l] = loc[e.r] - e.cost;
            if(!dfs(e.l,false)) return false;
            
            continue;
        }
        
        if(loc[e.r] == INF){
            loc[e.r] = loc[e.l] + e.cost;
            if(!dfs(e.r,false)) return false;
            
            continue;
        }
        
        if(loc[e.r] - loc[e.l] != e.cost) return false;
    }
    return true;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    L.resize(M);R.resize(M);D.resize(M);
    loc.resize(N,INF); check.resize(N);
    for(int i = 0; i < M;i++){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }
    
    G.resize(N);
    for(int i = 0; i < M;i++){
        G[L[i]].push_back(edge(L[i],R[i],D[i],L[i],R[i]));
        G[R[i]].push_back(edge(R[i],L[i],D[i],L[i],R[i]));
    }
    
    for(int i = 0; i < N;i++){
        if(!dfs(i,true)){
            cout << "No" << endl;
            return 0;
        }
    }
    
 //   cout << loc[6] << " " << loc[7] << " " << loc[8] << endl;
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 33536
#include <iostream>

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;

    int day_of_expired = b - a;
    if (day_of_expired <= 0)
        cout << "delicious\n";
    else if (day_of_expired <= x)
        cout << "safe\n";
    else
        cout << "dangerous\n";
}


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

int main(){
    int N;
    cin >> N;
    string s;
    set<string> S;
    for (int i = 0; i < N; i ++){
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
}

Measured memory_bytes: 19100
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

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

    size_t N; string s;
    cin >> N >> s;

    intmax_t res = 0;
    for (char c1 = '0'; c1 <= '9'; ++c1) {
        for (char c2 = '0'; c2 <= '9'; ++c2) {
            for (char c3 = '0'; c3 <= '9'; ++c3) {

                bool found1, found2, found3;
                found1 = found2 = found3 = false;
                for (auto si: s) {
                    if (found2) {
                        if (si == c3) {
                            found3 = true;
                        }
                    }
                    if (found1) {
                        if (si == c2) {
                            found2 = true;
                        }
                    }
                    if (!found1) {
                        if (si == c1) {
                            found1 = true;
                        }
                    }
                }

                if (found3) {
                    res++;
                }
            }
        }
    }

    cout << res << "\n";

    return 0;
}


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

#define MAX 500000
#define INFTY 2000000000

int R[MAX / 2 + 2];
int L[MAX / 2 + 2];
int cnt = 0;

void merge(int a[], int left, int mid, int right,int n)
{
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++)
	{
		L[i] = a[left + i];
	}
	for (int i = 0; i < n2; i++)
	{
		R[i] = a[mid + i];
	}
	L[n1] = R[n2] = INFTY;
	int i = 0, j = 0;
	for (int k = left; k < right; k++)
	{
		cnt++;
		if (L[i] <= R[j]) {
			a[k] = L[i];
			i++;
		}	
		else
		{
			a[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int a[], int left, int right,int n)
{
	if (right - left > 1)
	{
		int mid = (right + left) / 2;
		mergeSort(a, left, mid,n);
		mergeSort(a, mid, right,n);
		merge(a, left, mid, right,n);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	int *a;
	a = (int*)malloc(sizeof(int) * MAX);
	if (a != NULL)
	{
		for (int i = 0; i < n; i++)
		{
			scanf("%d", &a[i]);
		}

		mergeSort(a, 0, n,n);
                for (int i = 0; i < n; i++)
		{
			if (i >0)
				printf(" ");
			printf("%d", a[i]);
		}
		printf("\n%d\n", cnt);
	}
	return 0;
}


Measured memory_bytes: 6664
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	string S;
	cin >> S;
	if(S[0] != 'A'){
		cout << "WA" << endl;
		return 0;
	}
	int C = 0;
	for(int i=2; i<S.length()-1; ++i){
		if(S[i] == 'C') ++C;
	}
	if(C != 1){
		cout << "WA" << endl;
		return 0;
	}
	for(int i=1; i<S.length(); ++i){
		if(i==1 || i==S.length()-1) if(isupper(S[i])){
			cout << "WA" << endl;
			return 0;
		}else if(isupper(S[i])) if(S[i] != 'C'){
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
}


Measured memory_bytes: 3560
import numpy as np
N = int(input())
h = np.array(list(map(int, input().split())))

# ダルマ落としみたいにやる
cnt = 0
while True:
    if all(h==0):
        break

    i = 0
    while i < N:
        if h[i] == 0:
            i += 1
        else:
            cnt += 1
            while i < N and h[i] > 0:
                # 落とし
                h[i] -= 1
                i += 1
print(cnt)

Measured memory_bytes: 12504
def slove():
    import sys
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ls = [0] * (n+2)
    for i in range(m):
        l, r = list(map(int, input().rstrip('\n').split()))
        ls[l] += 1
        ls[r+1] -= 1
    t = 0
    cnt = 0
    for i in range(len(ls)):
        t += ls[i]
        if t == m:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 41836
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int S = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());

        if(W >= S){
            System.out.println("unsafe");
        }else{
            System.out.println("safe");
        }

        sc.close();
    }

}

Measured memory_bytes: 35692
def main():
    N = int(input())
    A = []
    for _ in range(N): A.append(int(input()))

    d = dict()
    for a in A:
        d[a] = d.get(a, 0) + 1
    count = 0
    for a in d:
        if d[a] % 2 == 1:
            count += 1
    return count


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

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

int main() {
  
  int N, K, x, sum = 0;
  cin >> N >> K;

  for (int i = 0; i < N; i++){
    cin >> x;
    if (x > K - x){
      sum += K - x;
    }
    else {
      sum += x;
    }
  }
  cout << sum * 2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)

using ll = int64_t;
using ld = long double;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

constexpr ll inf = 2e18;
constexpr int M = 1e9 + 7;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	ld p[n]; rep(i, 0, n) cin >> p[i];
	ld dp[n + 1][n + 1];
	rep(i, 0, n + 1) rep(x, 0, n + 1) dp[i][x] = 0;
	dp[0][0] = 1;
	rep(i, 0, n) {
		dp[i + 1][0] = (1 - p[i]) * dp[i][0];
		rep(x, 0, n)
			dp[i + 1][x + 1] = p[i] * dp[i][x] + (1 - p[i]) * dp[i][x + 1];
	}
	ld ans = 0;
	rep(x, n / 2, n) ans += dp[n][x + 1];
	cout << fixed << setprecision(10) << ans;
}

Measured memory_bytes: 140928
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
#define vec vector

/*  <<bit全探索>>
 
    for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
        bitset<ビット数> s(tmp);
    }
*/
 
/*　<<stringで読み込んだ数列を一桁ずつint型へ変換>>
 
    string str;
    int N[桁数];
 
    cin >> str;
 
    for (int i = 0; i < 桁数; ++i) {
 
        N[i] = (int)(str[i] - '0');  //str[i]　はchar型なのでchar→intへ変換
 
        //cout << N[i] << endl;  //確認のため表示
    }
*/
 
typedef long long ll;

///////////////////////////////////////////////////////////////////////////


int main() { 

    ll X, M = 100, YEAR = 0;
    cin >> X;

    while(M < X){
        M = M + (M / 100);
        YEAR++;
        }
    cout << YEAR << endl;
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;


int main() {
	string s;
	cin >> s;
	for (int i = 0; i < 4; ++i)
		cout << s[i];
	cout << " ";
	for (int i = 4; i < 12; ++i)
		cout << s[i];
	cout << "\n";
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int n,k;
    cin >> n >> k;
    vector<int>vc(n);
    for(int i = 0;i < n;i++)
    {
        cin >> vc[i];
    }
    sort(vc.begin(),vc.end());
    if ( n <= k)
        {
        cout << 0;
        exit(0);
    }
    vc.erase(vc.end() - k, vc.end());
    long long sum = 0;
    for(int i = 0;i < vc.size();i++)
    {
        sum += vc[i];
    }
    cout << sum;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }

int main()
{
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  cout << fixed << setprecision(20 )<< ((W*H)/2.0); 
  cout << " " << (x+x == W && y+y == H) << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 114514191919;
ll N, M; 


int main(){

    //頂点数と辺の数
    cin >> N;

    vector<vector<ll > > G(N, vector<ll >(N, 0));
    vector<vector<ll > > t_G(N, vector<ll >(N, 0));
    //初期化
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < N; j++){
            ll t = 0; cin >> t;
            G[i][j] = t;
            ans += t;
        }       
    }

    //ワーシャルフロイド
    for(ll reley = 0; reley < N; reley++){
        for(ll from = 0; from < N; from++){
            for(ll to = 0; to < N; to++){
                if(reley == from || reley == to || from == to){
                    continue;
                }
                if( G[from][reley] == INF || G[reley][to] == INF || G[from][to] == INF){
                    continue;
                }
                //直接fromからtoへ行くより他を経由していく経路のほうが長いと辻褄が合わないので終了
                if(G[from][to] > G[from][reley] + G[reley][to]){
                    cout << -1 << endl;
                    return 0;
                }
                //直接fromからtoへ行くより他を経由していく経路の距離が同じなら直接行く距離を消す
                if(G[from][to] == G[from][reley] + G[reley][to])
                {   
                    //cout << G[from][to] << endl;
                    ans -= G[from][to];
                    G[from][to] = INF;
                }
            }
        }
    }

    cout << ans / 2 << endl;

}

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

int main(){
  int n, k; cin >> n >> k;
  int count = 0;
  int count1 = 0;
  for(int i = 1; i < n + 1; ++i){
    if(k%2 == 1 && i%k == 0) count++;
    else if(k%2 == 0 && i%k == 0) count++;
    else if(k%2 == 0 && i%k == (k/2)) count1++;
  }
  if(k%2 == 1){
    cout << (ll)count*(ll)count*(ll)count << '\n'; 
  }
  else{
    ll ans = (ll)count*(ll)count*(ll)count;
    ans += (ll)count1*(ll)count1*(ll)count1;
    cout << ans << '\n';
  }
}

Measured memory_bytes: 3628
//
//  main.cpp
//  atcoder
//
//  Created by cfhaiteeh on 11/03/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define LL long long
using namespace std;
LL n,m;
LL ans;
int main() {
    while(scanf("%lld%lld",&n,&m)!=EOF){
        if(n>m)swap(n,m);
        if(n==1&&m==1)printf("1\n");
        else {
            if(n==1)printf("%lld\n",m-2);
            else {
                LL ans=(n-2)*(m-2);
                printf("%lld\n",ans);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left

def index(A, x):
	i = bisect_left(A, x)
	if i != len(A) and A[i] == x:
		return i
	else:
		return -1


n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))

cnt = 0
for t in T:
	if index(S, t)>=0:
		cnt += 1

print(cnt)


Measured memory_bytes: 16744
N, X = map(int, input().split())
*L, = map(int, input().split())

D = [0]
for i in range(1, N+1):
    D.append(D[i-1] + L[i-1])

num = 0
i = 0
d = D[i]
while d <= X and num < N+1:
    num += 1
    i += 1
    if i != N+1:
        d = D[i]

print(num)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse4")
#pragma GCC optimize("unroll-loops")
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
using namespace std;
int main()
{
    // std::ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
	int n,k,d;
	bool bad[10]={};
	cin>>n>>k;
	while(k--){
		cin>>d;
		bad[d]=1;
	}
	while(1){
		int m=n;
		while(m){
			if(bad[m%10])
				break;
			m/=10;
		}
		if(m==0){
			cout<<n;
			return 0;
		}
		n++;
	}
    return 0;
}

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

int main(){
    string str;
    char c;
    getline(cin, str);
    for (int i=0; i<str.size(); i++){
        if (isalpha(str[i])){
            if (islower(str[i])) c = toupper(str[i]);
            else c = tolower(str[i]);
        } else{
            c = str[i];
        }
        cout << c;
    }
    cout << endl;
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    map<int,ll> lucas;

    lucas[1]=1;
    lucas[2]=3;

    for(int i=3;i<=n;i++){
        lucas[i]=lucas[i-1]+lucas[i-2];
    }
    cout<<lucas[n]<<"\n";
    return 0;    
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int[][] pea = new int[m][2];
		for(int i = 0; i < m; i++) {
			pea[i][0] = sc.nextInt();
			pea[i][1] = sc.nextInt();
		}
		int[] tem = new int[n];
		for(int i = 0; i < n; i++) {
			tem[i] = 0;
		}
		
		
		for(int i = 0; i < m; i++) {
			if(h[pea[i][0]-1] > h[pea[i][1]-1]) {
				tem[pea[i][1]-1] = -1;
			}else if(h[pea[i][0]-1] < h[pea[i][1]-1]) {
				tem[pea[i][0]-1] = -1;
			}else if(h[pea[i][0]-1] == h[pea[i][1]-1]) {
				tem[pea[i][1]-1] = -1;
				tem[pea[i][0]-1] = -1;
			}
		}
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			if(tem[i] == 0) {
				cnt++;
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 53916
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

ll sum[200010];
vector<ll>g[200010];
bool visit[200010];

int main(void){
    ll n,q;
    cin>>n>>q;
    for(ll i=0;i<n-1;i++){
        ll a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for(ll i=0;i<q;i++){
        ll p,x;
        cin>>p>>x;
        sum[p]+=x;
    }
    queue<ll>que;
    que.push(1);
    while (!que.empty())
    {
        int now = que.front();
        que.pop();
        visit[now]=true;
        ll d = sum[now];
        for(int i=0;i<g[now].size();i++){
            int next = g[now][i];
            if(visit[next])continue;
            sum[next]+=d;
            que.push(next);
        }
    }
    for(ll i=0;i<n;i++){
        if(i==n-1)cout<<sum[i+1]<<endl;
        else cout<<sum[i+1]<<" ";
    }
    return 0;
}

Measured memory_bytes: 18032
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

int dp[2010][2010];
int p[2][2010];
int sum[2][4010][2010];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int a; char c;
	for(int i=0;i<2*n;i++){
		cin >> c >> a;
		if(c=='W'){
			p[0][a-1]=i;
			sum[0][i][a-1]=1;
		}
		else{
			p[1][a-1]=i;
			sum[1][i][a-1]=1;
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			dp[i][j]=1e9;
		}
	}
	for(int k=0;k<2;k++){
		for(int i=0;i<2*n;i++){
			for(int j=n-1;j>=1;j--){
				sum[k][i][j-1]+=sum[k][i][j];
			}
		}
		for(int i=0;i<2*n-1;i++){
			for(int j=0;j<n;j++){
				sum[k][i+1][j]+=sum[k][i][j];
			}
		}
	}
	dp[0][0]=0;
	for(int i=0;i<n+1;i++){
		for(int j=0;j<n+1;j++){
			if(i<n){
				int pp=p[0][i];
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]+sum[0][pp][i+1]+sum[1][pp][j]);
			}
			if(j<n){
				int pp=p[1][j];
				dp[i][j+1]=min(dp[i][j+1],dp[i][j]+sum[0][pp][i]+sum[1][pp][j+1]);
			}
		}
	}
	cout << dp[n][n] << endl;
}


Measured memory_bytes: 78976
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
#include<set>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


int N;
string S;
vector<vector<int>> li;
vector<int> siz;
bool judge(int len){
	map<string,int> s;
	string now=S.substr(0,len);
	REP(i,0,N-len+1){
		if(s.find(now)!=s.end()){
			int t=s.find(now)->second;
			if(t+len<=i){
				return true;
			}
		}else{
			s[now]=i;
		}
		now=S.substr(i+1,len);
	}
	return false;
}


int main()
{
	
	cin>>N>>S;
	li.resize(26);
	REP(i,0,N){
		li[S[i]-'a'].push_back(i);
	}
	siz.resize(26);
	REP(i,0,26){
		siz[i]=li[i].size();
	}
	int left=0;
	int right=N;
	while(right-left>1){
		int mid=(right+left)/2;
		//cout<<right<<" "<<left<<endl;
		if(mid==0){
			cout<<0<<endl;
			return 0;
		}
		if(mid==1){
			REP(i,0,26){
				if(li[i].size()>=2){
					cout<<1<<endl;
					return 0;
				}else{
					cout<<0<<endl;
					return 0;
				}
			}
		}
		if(judge(mid)){
			left=mid;
		}else{
			right=mid;
		}

	}
	//cout<<judge(2)<<endl;
	cout<<left<<endl;
	return 0;
}

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

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

    int rectangleA = a * b;
    int rectangleB = c * d;
    if (rectangleA == rectangleB)
    {
        cout << rectangleA << endl;
    }
    else
    {
        int bigger = (rectangleA > rectangleB) ? rectangleA : rectangleB;
        cout << bigger << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
# 奇数の数が奇数個ならあまる（偶数はいくつあっても最終的に1つの偶数にできるので関係ない）

n = int(input())
arr = list(map(int, input().split()))

odd_count = len(list(filter(lambda x : x%2==1, arr)))
if odd_count%2==1:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 14108
#include <stdio.h>
#include <math.h>

int main(void)
{
	int a[100010];
	int b[100010];
	int n, k, i;
	scanf("%d", &n);
	
	for(i=1;i<n+1;i++){
		scanf("%d", &a[i]);
		b[a[i]]=i;
	}

	for(i=1;i<n+1;i++){
		printf("%d ", b[i]);
	}
	return 0;
}

Measured memory_bytes: 1536
H, W = map(int, input().split())
board = []
for _ in range(H):
    board.append(input())

def count(x, y):
    result = 0
    for my in range(-1, 2):
        for mx in range(-1, 2):
            tx = x + mx
            ty = y + my
            if 0 <= tx < W and 0 <= ty < H:
                if board[ty][tx] == "#":
                    result += 1

    return result

output = []

for y, b in enumerate(board):
    line = ""
    for x, c in enumerate(b):
        if c == ".":
            num = count(x, y)
            line += str(num)
        else:
            line += c
    output.append(line)

for o in output:
    print(o)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;

typedef struct GE {
    int to;
    ll w;
    GE() {};
}GE;

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

char s[5];
int main() {
    ll A, B, C, D;
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

    if (A > B) swap(A, B);
    A--;

    if (C > D) swap(C, D);
    ll ans = 0;

    ll G = gcd(C, D);
    G = C * D / G;

    ll dcnt = B / D;
    ll ccnt = B / C;
    ll gcnt = B / G;
    // printf("%lld %lld %lld\n", dcnt, ccnt, gcnt);
    ans += (dcnt + ccnt - gcnt);

    dcnt = A / D;
    ccnt = A / C;
    gcnt = A / G;
    // printf("%lld %lld %lld\n", dcnt, ccnt, gcnt);
    ans -= (dcnt + ccnt - gcnt);

    printf("%lld", B - A - ans);
    return 0;
}

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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<int,int>;
//Write From this Line

const int dx[4] = {-1,0,0,1};
const int dy[4] = {0,1,-1,0};
vector<string> field(410);
vector<vector<bool>> used(410,vector<bool>(410,false));
int main()
{
	int h, w;
	cin >> h >> w;
	rep(i,h) cin >> field[i];
	ll ans = 0;

	queue<P> que;
	for(int i = 0; i < h; i++){ 
		for(int j = 0; j < w; j++){
			if(used[i][j])continue;
			que.push({i,j});
			used[i][j] = true;
			ll black = 0, white = 0;
			if(field[i][j] == '#') black++;
			else  white++;
			while(!que.empty()){
				int sx = que.front().second, sy = que.front().first;
				que.pop();
				rep(k,4){
					int nx = sx + dx[k]; // こいつが j + dx[k]になってた
					int ny = sy + dy[k];
					if(ny < 0 || nx < 0 || nx >= w || ny >= h) continue;
					if(used[ny][nx]) continue;
					if(field[ny][nx] == field[sy][sx]) continue;
					que.push({ny,nx});
					used[ny][nx] = true;
					if(field[ny][nx] == '#') black++;
					else white++;
				}
			}
			ans += black * white;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  long long h,ans,b,i;
  i = 0;
  ans = 0;
  cin >> h;
  for( ; ; ){
    h = h / 2;
    b = pow(2,i);
    ans += b;
    i += 1;
    if(h == 0){
      break;
    }
  }
  cout << ans;
}


Measured memory_bytes: 512
//============================================================================
// Name        : HairetuTest.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int i,n;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)cin>>a[i];
		for(i=n-1;i>=0;i--)	{
			cout<<a[i];
			if(i!=0)cout<<" ";
		}
			cout<<endl;
}



Measured memory_bytes: 3080
n=int(input())
l=[]
for i in range(n):
    l.append(list(input().split()))
ans=0
x=380000
for i in range(n):
    if(l[i][1]=='BTC'):
        ans+=float(l[i][0])*x
    else:
        ans+=float(l[i][0])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	double ans = 0;
	rep(i,0,n){
		int x;
		cin >> x;
		ans += 1.0/double(x);
	}
	ans = 1.0/ans;
	cout << fixed << setprecision(15);
	cout << ans << '\n';
}


Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new A_Biscuit(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())

    def nextLong(): Long = java.lang.Long.parseLong(next())

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class A_Biscuit(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val A = (ni(), ni(), ni())
    out.println(A._3 / A._1 * A._2)
  }
}


Measured memory_bytes: 25416
# -*- coding: utf-8 -*-

def readInts():
  return [int(s) for s in input().split(" ")]

def paint(ans, h, w, cur):
  hi = h
  while hi >= 0 and ans[hi][w] == 0:
    ans[hi][w] = cur
    hi -= 1
  return

def solve():
  H, W, K = readInts()
  S = [input() for _ in range(H)]
  ans = [[0 for _ in range(W)] for _ in range(H)]
  k = 1

  for h in range(H):
    cur = 0
    for w in range(W):
      if S[h][w] == "#":
        cur = k
        k += 1
        wi = w - 1
        while wi >= 0 and ans[h][wi] == 0:
          paint(ans, h, wi, cur)
          wi -= 1

      if cur > 0:
        paint(ans, h, w, cur)

    if cur == 0 and h > 0:
      for w in range(W):
        if ans[h-1][w] > 0:
          ans[h][w] = ans[h-1][w]
  return ans

def main():
  ans = solve()
  for row in ans:
    print(" ".join(map(str, row)))

if __name__ == "__main__":
  main()


Measured memory_bytes: 7280
#include<iostream>
#include<stack>
using namespace std;
 
int main(){
    int i,cnum = 0;
    stack<int> car;
    while(cin >> i){
        if(i != 0){
            car.push(i);
            cnum++;
        }else if(cnum == 0){
            
        }else{
            cout << car.top() << endl;;
            car.pop();
            cnum--;
        }
    }
    return 0;
}

Measured memory_bytes: 1200
# -- coding: utf-8 --

N = int(input())
a = [[0, 0, 0]]
for i in range(N):
    a.append(list(map(int, input().split(' '))))

for i in range(1, N+1):
    def_t = a[i][0] - a[i-1][0]
    def_d = abs(a[i][1] - a[i-1][1]) + abs(a[i][2] - a[i-1][2])
    if abs(def_t - def_d) % 2 != 0 or def_t < def_d:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

int main() {
	int n, x;
	cin >> n >> x;
	vector<int> s(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> s[i];
	}
	sort(s.begin(), s.end(), greater<int>());
	vector<vector<ll> > dp(n+1, vector<ll>(x+1, 0));
	dp[0][x] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < x+1; ++j)
		{
			dp[i+1][j] += (n-1-i) * dp[i][j];
			dp[i+1][j] %= MOD;
			dp[i+1][j%s[i]] += dp[i][j];
			dp[i+1][j%s[i]] %= MOD;
		}
	}
	ll ans = 0;
	for (int j = 0; j < x+1; ++j)
	{
		ans += dp[n][j] * j;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 158592
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    string S,T;
    cin>>N>>S>>T;
    for(int i=0;i<N;i++){
        cout<<S[i]<<T[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int N,K; cin>>N>>K;
    int v[2*N];
    rep(i,N)cin>>v[i];
    rep(i,N)v[i+N]=v[i];
    int ans=0;
    rep(i,min(N,K)+1){
        vector<vector<int>> G(200);
        rep(j,i+1){
            rep(k,i){
                G[j].push_back(v[N-j+k]);
            }
            sort(G[j].begin(),G[j].end());
            rep(k,min(K-i,i)+1){
                int cnt=0;
                rep(l,i-k){
                    cnt+=G[j][k+l];
                }
                ans=max(ans,cnt);
            }
            rep(k,i){
                G[j].pop_back();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000

int main() {
	long long n, ans = 0;
	cin >> n;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	a.push_back(INF);
	vector<bool> table(a[n-1]+1, true);
	for (int i = 0; i < n; i++) {
		if (table[a[i]]) {
			for (int j = 1; a[i] * j < a[n-1]+1; j++) {
				table[a[i] * j] = false;
			}
			if(a[i] != a[i + 1]) ans++;
			while (a[i] == a[i + 1]) i++;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T>
inline void remax(T& x, T y) { x = max(x, y); }

template<typename T>
inline void remin(T& x, T y) { x = min(x, y); }

int main() 
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, d;
    cin >> n >> d;
    d = d * d;
    int ans = 0; 
    rep(i, 0, n) {
        ll x, y;
        cin >> x >> y;
        ll D = x * x + y * y;
        if(D <= d) ans++;
    }
    cout << ans << '\n';
    return 0;
}





Measured memory_bytes: 3652
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

struct edge
{
	int to;
	int cost;
};

const int MAX = 202020;

vector<edge> edges[3 * MAX];

map<P,int> seed;

int n;
int m;

int getID(int i,int c)
{
	if(seed.count({i,c})) return seed[P(i,c)];
	return seed[P(i,c)] = seed.size();
}

int p[MAX];
int q[MAX];
int c[MAX];


int main()
{
	cin >> n >> m;
	for(int i = 0;i < m;i++)
	{
		cin >> p[i] >> q[i] >> c[i];
		int s = getID(p[i] , c[i]);
		int t = getID(q[i] , c[i]);
		edges[s].push_back({t,0});
		edges[t].push_back({s,0});
	}
	int last = seed.size();
	for(int i = 0;i < m;i++)
	{
		// p side
		{
			int kai = last + p[i];
			edges[getID(p[i],c[i])].push_back({last + p[i] , 0});
			edges[last + p[i]].push_back({getID(p[i],c[i]),1});
		}
		// q side
		{
			int kai = last + q[i];
			edges[getID(q[i],c[i])].push_back({last + q[i] , 0});
			edges[last + q[i]].push_back({getID(q[i],c[i]),1});
		}
	}

	vector<int> dist(n + last + 5,1e9);

	{
		deque<P> que;
		que.push_front({0,1 + last});
		dist[1 + last] = 0;

		while(!que.empty())
		{
			int v = que.front().second;
			int d = que.front().first;
			que.pop_front();

			if(dist[v] < d) continue;

			for(auto& e : edges[v])
			{
				if(dist[e.to] > d + e.cost)
				{
					dist[e.to] = d + e.cost;
					if(e.cost)
						que.push_back({dist[e.to] , e.to});
					else
						que.push_back({dist[e.to],e.to});
				}
			}
		}
	}

	if(dist[n + last] == 1e9)
		dist[n + last] = -1;
	cout << dist[n + last] << endl;

}

			


Measured memory_bytes: 65152
n,k = map(int,input().split())
#l = [i for i in range(n+1)]
ans = 0

for i in range(k,n+2):
#  MIN = sum(l[:i])
  MIN = i*(i-1)/2
  MAX = (n+1-i+n)*i/2
  ans +=(MAX-MIN+1)
  
print(int(ans%(10**9+7)))

Measured memory_bytes: 67420
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main()
{
    fast();


    LL t,n,i,j,k,x,y,c,m;
    cin >> n;
    LL a[n];
    LL suffmin[n];
    gall(a, n);
    suffmin[n - 1] = a[n - 1]; 
    for(LL i = n - 2; i >= 0; --i){
        suffmin[i] = min(a[i], suffmin[i + 1]);
    }
    bool ok = true;
    REP(i, n - 1){
        if(a[i] - suffmin[i + 1] > 1){
            ok = false;
        }
    }
    if(ok){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

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

int main(){
    int n;
    cin>>n;
    int h[n], cost[n];

    for(int i=0; i<n; ++i)
        cin>>h[i];

    if(n == 2){
        cout<<abs(h[0] - h[1])<<endl;
    }
    else{
        cost[0] = 0;
        cost[1] = abs(h[0] - h[1]);
        for(int i=2; i<n; ++i){
            cost[i] = min(cost[i-1]+abs(h[i] - h[i-1]), cost[i-2]+abs(h[i] - h[i-2]));
        }
        cout<<cost[n-1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024