akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int d,n;
  cin >> d >> n;
  
  switch (d) {
	case 0:
      if(n == 100){
		cout << 101 << endl;
		return 0;
      }else{
        cout << n  << endl;
        return 0;
      }
      
	case 1:
       if(n == 100){
		cout << 10100 << endl;
		return 0;
      }else{
        cout << n * 100  << endl;
         return 0;
      }
 
	case 2:
       if(n == 100){
		cout << 1010000 << endl;
		return 0;
      }else{
        cout << n * 10000  << endl;
        return 0;
      }
	}
 
}

Measured memory_bytes: 256
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define mp make_pair

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

string str;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    cin>>str;
    int ansa = -1, ansb = -1;
    REP(c,'a','z'){
        int f = 0;
        int sum = 0;
        FOR(i,str.size()){
            if(str[i] == c)sum++;
            else sum--;
            
            if(sum > 0 && i-f+1 >= 2){
                ansa = f+1;
                ansb = i+1;
            }else if(sum < 0){
                f = i+1;
                sum = 0;
            }
        }
    }
    
    cout << ansa << " " << ansb << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

ll X,Y;

int main(){
    cin>>X>>Y;

    ll ans=0;
    ll a=X;
    while(a<=Y){
        ans++;
        a*=2;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

void reverse(char *str, int n) {
	int i;
	for (i = 0; i < n / 2; i++) {
		int t = str[n - i - 1];
		str[n - i - 1] = str[i];
		str[i] = t;
	}
}

int main(void) {
	int i;
	char str[81];
	int len_str;

	while (scanf("%s%n ", str, &len_str), str[0] != '.') {
		char str2[81] = "";
		int len_str2, cnt, l;

		len_str2 = cnt = 0;
		for (i = 0; i < len_str; i++)
			switch (str[i]) {
			case '[': case ']':
				str2[len_str2++] = str[i];
				break;
			case '+':
				cnt++;
				break;
			case '-':
				cnt--;
				break;
			case '?':
				str2[len_str2++] = 'A';
				cnt = 0;
				break;
			default:
				str2[len_str2++] = (str[i] + cnt - 'A' + 104) % 26 + 'A';
				cnt = 0;
				break;
			}

		for (i = 0; i < len_str2; i++)
			if (str2[i] == '[')
				l = i;
			else if (str2[i] == ']') {
				reverse(str2 + l + 1, i - (l + 1));
				str2[l] = str2[i] = 0;
				i = -1;
			}

		for (i = 0; i < len_str2; i++)
			if (str2[i])
				putchar(str2[i]);
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 524
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;

void main() {
    int N;
    scan(N);
    auto s = readln.chomp.map!(ch => ch - 'a').array;

    auto rbt = new RedBlackTree!int[](26);
    foreach (i ; 0 .. 26) {
        rbt[i] = redBlackTree!(int)();
    }
    foreach (i ; 0 .. N) {
        rbt[s[i]].insert(i);
    }

    int Q;
    scan(Q);
    foreach (_ ; 0 .. Q) {
        auto ln = readln.split;
        if (ln.front == "1") {
            int idx = ln[1].to!int - 1;
            int c = ln[2].to!char - 'a';
            rbt[s[idx]].removeKey(idx);
            rbt[c].insert(idx);
            s[idx] = c;
        }
        else {
            int l = ln[1].to!int - 1;
            int r = ln[2].to!int;
            int ans;
            foreach (i ; 0 .. 26) {
                auto up = rbt[i].upperBound(l - 1);
                if (!up.empty && up.front < r) {
                    ans++;
                }
            }
            writeln(ans);
        }
    }
    
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}

Measured memory_bytes: 23056
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#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(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 500050;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


double dist(double x1, double x2, double y1, double y2) {
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}
double dist(P &p1, P &p2) {
	double x1 = p1.first, x2 = p2.first, y1 = p1.second, y2 = p2.second;
	return sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
}


void solve() {
	int M, N; cin >> M >> N;
	if (M == N)print("Yes");
	else print("No");
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




Measured memory_bytes: 256
n,y = [int(x) for x in input().split(' ')]

def solve(n,y):
    for a in range(n+1):
        for b in range(n+1):
            c = n - a - b
            if c >= 0:
                current = 10000*a + 5000*b + 1000*c
                if current == y:
                    print(a,b,c)
                    return
    
    print(-1, -1, -1)

solve(n,y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, K, R, S, P;
string T;

int main() {
  cin >> N >> K >> R >> S >> P >> T;

  unordered_map<char, int> score, idx;
  score['r'] = P;
  score['s'] = R;
  score['p'] = S;
  idx['r'] = 0;
  idx['p'] = 1;
  idx['s'] = 2;

  vector<vector<ll>> dp(N, vector<ll>(3, 0));

  rep(i, N) rep(j, 3) {
    dp[i][j] += ((idx[T[i]] + 1) % 3) == j ? score[T[i]] : 0;
    if (i + K < N) rep(l, 3) if (l != j) {
        dp[i + K][l] = max(dp[i + K][l], dp[i][j]);
      }
  }

  ll ans = 0;
  rep(i, K) ans += *max_element(all(dp[N - 1 - i]));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5760
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] parent;//union-find用
	static int[] rank;//union-find用

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();

		boolean[] stepOK = new boolean[N+1];
		Arrays.fill(stepOK, true);

		for(int i = 0;i<M ; i++) {
			stepOK[sc.nextInt()]=false;
		}


		int[] dp = new int[N+1];
		dp[0]=1;
		if(stepOK[1]) {
			dp[1]=1;
		}
		for(int i = 2;i<=N ; i++) {
			if(!stepOK[i]) {
				continue;
			}
			if(stepOK[i-1]) {
				dp[i]+=dp[i-1];
			}
			if(stepOK[i-2]) {
				dp[i]+=dp[i-2];
			}
			dp[i]%=1000000007;
		}

		System.out.println(dp[N]);
	}

	//素数判定
	public static boolean isPrime(long num) {
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

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

		// 素数である
		return true;
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
	static void ufInit(int n){
		parent = new int[n];
		rank = new int[n];
	}

	//Union-Findの要素の最上位の親（グループ名）を返す
	static int ufFind(int a) {
		if(parent[a]==a) {
			return a;
		}else {
			return ufFind(parent[a]);
		}
	}

	//Union-Find木を連結する
	static void ufUnite(int a, int b) {
		a = parent[a];
		b = parent[b];

		if(a==b) {
			return;
		}
		if(rank[a] > rank[b]){
			parent[b]=a;
		}else {
			parent[a]=b;
			if(rank[a]==rank[b]) {
				rank[b]++;
			}
		}
	}

	static boolean ufSame(int a, int b) {
		return ufFind(a)==ufFind(b);
	}
}


Measured memory_bytes: 57524
#include <bits/stdc++.h>
using namespace std;
static const int INFTY = 2000000000;
static const int NIL = -1;
static const int MAX = 10000;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int,int> > adj[MAX];

void dijkstra(int a[]){
    priority_queue<pair<int,int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i=0;i<n;i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[0] = 0;
    PQ.push(make_pair(0,0));
    color[0] = GRAY;

    while(!PQ.empty()){
        pair<int,int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        //????°???????????????????????????????????????§???????????°??????
        if(d[u] < f.first * (-1)) continue;

        for(int j=0;j<adj[u].size();j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                //priority_queue???DEFAULT??§??§?????????????????????????????????-1??????????????????
                PQ.push(make_pair(d[v] * (-1),v));
                color[v] = GRAY;
            }
        }
    }

    for(int i=0;i<n;i++) a[i] = d[i];
}

int main(){
    int k,u,v,c;

    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        for(int j=0;j<k;j++){
            scanf("%d %d",&v,&c);
            adj[u].push_back(make_pair(v,c));
        }
    }
    int a[MAX];
    dijkstra(a);
    
    for(int i=0;i<n;i++){
            printf("%d %d\n",i,a[i]);
    }

    return 0;
}

Measured memory_bytes: 8048
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}

vvl G(V);
vector<bool> visit(V,false);
vl ans;
bool dfs(ll u){
    visit[u] = true;
    for(auto v : G[u]){
        if(visit[v]) continue;
        visit[v] = true;
        ans.push_back(v);
        bool b = dfs(v);
        if(b) return true;
    }
    return true;
}

int main(){
    ll n,m; cin >> n >> m;
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans.push_back(0);
    dfs(0);
    rep(i,n) visit[i] = false;
    for(auto i : ans) visit[i] = true;
    reverse(all(ans));
    dfs(0);
    cout << ans.size() << endl;
    for(auto i : ans) cout << i+1 << " ";
}


Measured memory_bytes: 11508
#include<bits/stdc++.h>
int a[500],i,l=1;char c[50];
main(){scanf("%s",c);for(;c[i]!='\0';a[c[i++]]=1)l++;for(i='z';i>='a';i--)if(!a[i])c[l++]=i;return std::next_permutation(c,c+l)?puts(c),0:puts("-1"),0;}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var N = cin.Nextlong;
        var ans = int.MaxValue;
        for (long i = 1; i * i <= N; i++)
        {
            if (N % i != 0) continue;
            var B = N / i;
            int cnt = 0;
            while (B > 0)
            {
                B /= 10;
                cnt++;
            }
            ans = Math.Min(cnt, ans);

        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int a,aaa[101];
cin>>a;
for(int i=0;i<a;i++)
cin>>aaa[i];
set<int>s;
for(int i=0;i<a;i++)
s.insert(aaa[i]);
cout<<s.size();
system("pause"); 
return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int counter = 0;
  if(s[0] == '1') counter++;
  if(s[1] == '1') counter++;
  if(s[2] == '1') counter++;
  cout << counter << endl;
}
  

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    cin.tie(NULL);
    int temp=0;
    int l,r,d;
    cin>>l>>r>>d;
    int c=r/d*d;
    while(c>=l)
    {
        temp++;
        c-=d;
    }
    cout<<temp;
    return 0;
}


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

int count_divisors(int N)
{
    int cnt = 0;
    for (int i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            ++cnt;
            if (N / i != i)
                ++cnt;
        }
    }
    return cnt;
}

int	main()
{
    int N;
    cin >> N;
    int cnt = 0;
    for (int i = 1; i <= N; i += 2) {
        if (count_divisors(i) == 8)
            ++cnt;
    }
    cout << cnt << endl;
}


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

int main() {
  int64_t a, b;
  cin >> a >> b;
  
  if (a <= 0 && 0 <= b) {
    cout << "Zero" << endl;
  }
  else if (a > 0) {
    cout << "Positive" << endl;
  }
  else if (b > 0) {
    if (abs(a) % 2 == 0) {
      cout << "Positive" << endl;
    }
    else {
      cout << "Negative" << endl;
    }
  }
  else {
    if ((abs(a) - abs(b)) % 2 != 0) {
      cout << "Positive" << endl;
    }
    else {
      cout << "Negative" << endl;
    }
  }
}


Measured memory_bytes: 256
while True:
    try:
        cnt = 0
        n = int(input())
        for a in range(10):
            for b in range(10):
                for c in range(10):
                    for d in range(10):
                        if a + b + c + d == n:
                            cnt = cnt + 1

        print(str(cnt))
    except:
        break
    

Measured memory_bytes: 7492
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
ll INF=pow(10,18);
struct edge{int from,to;ll cost;};

int main(){
    edge ed[5010];
    int N,M;ll P;cin>>N>>M>>P;
    int a,b;ll c;
    for(int i=0;i<M;i++){
        cin>>a>>b>>c;
        ed[i]={a-1,b-1,P-c};
    }

    ll d[2510];
    d[0]=0;
    for(int i=1;i<N;i++)d[i]=INF;
    for(int k=1;k<=N;k++){
        bool update=false;
        for(int j=0;j<M;j++){
            edge e=ed[j];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                update=true;
            }
        }
        if(!update){
            cout<<max((ll)0,-d[N-1])<<endl;
            return 0;
        }
    }
    //負閉路があるとき
    for(int l=1;l<=N;l++){
        for(int j=0;j<M;j++){
            edge e=ed[j];
            if(d[e.from]!=INF && d[e.to]>d[e.from]+e.cost){
                d[e.to]=-INF;
            }
        }     
    }
    if(d[N-1]!=-INF){
        cout<<max((ll)0,-d[N-1])<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long giant;
inline char nchar() {
	static const int bufl=1<<20;
	static char buf[bufl],*a=NULL,*b=NULL;
	return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
	int x=0,f=1;
	char c=nchar();
	for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=nchar()) x=x*10+c-'0';
	return x*f;
}
template<typename T> inline T& Min(T &x,const T &y) {return x>y?(x=y):x;}
const int maxn=1e5+1;
int n,m,A[maxn],B[maxn],C[maxn],ord[maxn];
namespace uns {
	int f[maxn];
	void init() {
		iota(f+1,f+n+1,1);
	}
	int find(int x) {
		return x==f[x]?x:(f[x]=find(f[x]));
	}
	void merge(int x,int y) {
		x=find(x),y=find(y);
		f[y]=x;
	}
}
namespace tree {
	vector<int> g[maxn];
	giant f[maxn],sum[maxn];
	inline void add(int x,int y) {
		g[x].push_back(y);
	}
	void dfs(int x) {
		giant &sm=sum[x]=B[x];
		giant &fx=f[x]=LLONG_MAX;
		if (g[x].empty()) {
			fx=C[x]+B[x];
			return;
		}
		for (const int &v:g[x]) {
			dfs(v);
			sm+=sum[v];
		}
		for (const int &v:g[x]) Min(fx,sm-sum[v]+max<giant>(C[x],f[v]));
	}
	giant work(int s) {
		dfs(s);
		return f[s];
	}
}
namespace graph {
	vector<int> g[maxn];
	bool vis[maxn];
	inline void add(int x,int y) {
		g[x].push_back(y);
		g[y].push_back(x);
	}
	void work(int x) {
		vis[x]=true;
		for (const int &v:g[x]) if (vis[v]) {
			int k=uns::find(v);
			if (k==x) continue;
			tree::add(x,k);
			uns::merge(x,k);
		}
	}
}
int main() {
	n=read(),m=read();
	for (int i=1;i<=n;++i) {
		A[i]=read(),B[i]=read();
		C[i]=max(A[i]-B[i],0);
		ord[i]=i;
	}
	uns::init();
	for (int i=1;i<=m;++i) graph::add(read(),read());
	sort(ord+1,ord+n+1,[](int x,int y)->bool{return C[x]<C[y];});
	for (int i=1;i<=n;++i) graph::work(ord[i]);
	giant ans=tree::work(ord[n]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 18556
from collections import deque


def main():
    H, W = map(int, input().rstrip().rsplit())

    visited = [[0]*(W+2) for i in range(H+2)]
    maze = [["#"]*(W+2)]

    black_cnt = 0
    for i in range(H):
        # 黒色のマス目の数をカウント
        row = input().rstrip()
        black_cnt += row.count("#")

        # maze作成
        row = "#" + row + "#"
        maze.append(list(row))

    maze.append(["#"]*(W+2))

    # 幅優先探索で始点からの距離を求める
    queue = deque([(1, 1)])

    while queue:
        x, y = queue.popleft()
        # 黒マスの時
        if maze[x][y] == "#":
            continue

        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            # 探索済みかチェック
            if visited[x+dx][y+dy] > 0:
                continue
            # 次のマス目候補に経路長を入れる
            visited[x+dx][y+dy] = visited[x][y] + 1

            # 探索候補に追加
            queue.append((x+dx, y+dy))

    if visited[H][W] == 0:
        print(-1)
        return
    ans = H*W - black_cnt - visited[H][W] - 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#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++)
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int main() {
	ll a, b, c, d;cin >> a >> b >> c >> d;a--;
	ll l = lcm(c, d),au,bu,j,i;
	au = a / c; au += a / d;au -= a / l;
	bu = b / c;bu += b / d;bu -= b / l;
	i = b - bu;j = a - au;
	cout << i - j << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		int n = sc.nextInt();
		fac = new long[10];
		fac[0] = 1;
		for(int i=1;i<fac.length;++i) fac[i] = i*fac[i-1];
		
		long a = 0;
		boolean[] used = new boolean[n+1];
		for(int i=1;i<=n;++i) {
			int x = sc.nextInt();
			long rank = 0;
			for(int j=1;j<=n;++j) {
				if(x == j) {
					used[x] = true;
					break;
				}else if(used[j]) continue;
				else ++rank;
			}
			a+=rank*fac[n-i];
		}
		
		long b = 0;
	    used = new boolean[n+1];
		for(int i=1;i<=n;++i) {
			int x = sc.nextInt();
			long rank = 0;
			for(int j=1;j<=n;++j) {
				if(x == j) {
					used[x] = true;
					break;
				}else if(used[j]) continue;
				else ++rank;
			}
			b+=rank*fac[n-i];
		}
		
		out.print(Math.abs(a-b));
		
		out.close();
	}
	
	
}

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

int main(void){
  int n, ans;
  
  cin >> n;
  ans = 0;
  ans += (n/25);
  n %= 25;
  ans += (n/10);
  n %= 10;
  ans += (n/5);
  n %= 5;
  ans += n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3124
from math import factorial

N, M = map(int, input().split())
div = 10**9 + 7

if abs(M-N) > 1:
    print(0)
elif abs(M-N) == 1:
    print(factorial(M) * factorial(N) % div)

else:
    print(factorial(M) * factorial(N) *2 % div)

Measured memory_bytes: 5180
#include<stdio.h>
int main(void)
{
	int n,x[1000],y[1000],b[1000],p[1000],i,e[10001],r[10001],z[10001],t[10011],e1[10001],r1[10001];
	int z1[10001];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&x[i],&y[i],&b[i],&p[i]);
	}
	for(i=0;i<n;i++){
		if(b[i]>=5 && p[i]>=2){
			e[i]=x[i]*b[i];
			r[i]=y[i]*p[i];
			z[i]=(e[i]+r[i])*0.8;
			printf("%d\n",z[i]);
		}
		else if(b[i]<5 && p[i]<2){
			e[i]=x[i]*b[i];
			r[i]=y[i]*p[i];
			t[i]=e[i]+r[i];
			e1[i]=x[i]*5;
			r1[i]=y[i]*2;
			z1[i]=(e1[i]+r1[i])*0.8;
			if(t[i]>z1[i]){
				printf("%d\n",z1[i]);
			}
			else{
				printf("%d\n",t[i]);
		}
		}
		else if(b[i]>=5 && p[i]<2){
			e[i]=x[i]*b[i];
			r[i]=y[i]*p[i];
			t[i]=e[i]+r[i];
			e1[i]=x[i]*b[i];
			r1[i]=y[i]*2;
			z1[i]=(e1[i]+r1[i])*0.8;
			if(t[i]>z1[i]){
				printf("%d\n",z1[i]);
			}
			else{
				printf("%d\n",t[i]);
		}
	}
	else if(b[i]<5 && p[i]>=2){
			e[i]=x[i]*b[i];
			r[i]=y[i]*p[i];
			t[i]=e[i]+r[i];
			e1[i]=x[i]*5;
			r1[i]=y[i]*p[i];
			z1[i]=(e1[i]+r1[i])*0.8;
			if(t[i]>z1[i]){
				printf("%d\n",z1[i]);
			}
			else{
				printf("%d\n",t[i]);
		}
	}
	}
	return 0;
}

Measured memory_bytes: 616
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

typedef vector<int> VI;
typedef vector<VI> VVI;

VVI add_mat(VVI A, VVI B, int MOD) {
    for (int i = 0; i < A.size(); i++) {
        for (int j = 0; j < A[i].size(); j++) {
            A[i][j] += B[i][j];
            A[i][j] %= MOD;
        }
    }
    return A;
}

VVI mul_mat(VVI &A, VVI &B, int MOD) {
    VVI C(A.size(), VI(B[0].size(), 0));

    for (int i = 0; i < A.size(); i++) {
        for (int j = 0; j < B[0].size(); j++) {
            for (int k = 0; k < B.size(); k++) {
                C[i][j] += A[i][k] * B[k][j];
                C[i][j] %= MOD;
            }
        }
    }

    return C;
}

VVI pow_mat(VVI A, int p, int MOD) {
    VVI ans(A.size(), VI(A[0].size(), 0));
    for (int i = 0; i < ans.size(); i++) ans[i][i] = 1;
    while (p > 0) {
        if ((p & 1) == 1) ans = mul_mat(ans, A, MOD);
        A = mul_mat(A, A, MOD);
        p >>= 1;
    }
    return ans;
}

int main() {

    while (true) {

        int N, M, A, B, C, T;
        cin >> N >> M >> A >> B >> C >> T;

        if (!(N | M | A | B | C | T)) break;

        VI s(N);
        for (int i = 0; i < N; i++) cin >> s[i];

        VVI matA(N, VI(N));
        for (int i = 1; i < N; i++) matA[i][i - 1] = A;
        for (int i = 0; i < N; i++) matA[i][i] = B;
        for (int i = 1; i < N; i++) matA[i - 1][i] = C;

        VVI matB(N, VI(1));
        for (int i = 0; i < N; i++) matB[i][0] = s[i];

        matA = pow_mat(matA, T, M);
        auto ans = mul_mat(matA, matB, M);

        for (int i = 0; i < ans.size(); i++) {
            if(i != ans.size()-1) cout << ans[i][0] << " ";
            else cout << ans[i][0] << endl;
        }

    }

}














































Measured memory_bytes: 3196
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A,B,C,D = map(int,input().split())

a = int(B//C) - int((A-1)//C)
b = int(B//D) - int((A-1)//D)
c = int(B//lcm(C,D)) - int((A-1)//lcm(C, D))

count = B - (A - 1) - (a + b - c)
print(count)

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

void solve() {
	string s;
	cin>>s;
	int n = s.size();
	for (int i = 0, j = n-1; i < n/2; ++i, --j) {
		if (s[i] != s[j]) {
			cout<<"No\n";
			return;
		}
	}
	for (int i = 0, j = (n-1)/2 - 1; i < (n-1)/2; ++i, --j) {
		if (s[i] != s[j]) {
			cout<<"No\n";
			return;
		}
	}
	for (int i = (n+3)/2 - 1, j = n-1; i < n; ++i, --j) {
		if (s[i] != s[j]) {
			cout<<"No\n";
			return;
		}
	}
	cout<<"Yes\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
	solve();
  	return 0;
}

Measured memory_bytes: 256
// Ho-kago Tea Time

#include <bits/stdc++.h>

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int) (u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status()
{
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline T read()
{
	register T sum(0), fg(1);
	register char ch(getchar());
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') fg = -1;
	for(;  isdigit(ch); ch = getchar()) sum = sum * 10 - '0' + ch;
	return sum * fg;
}

typedef long long LL;
typedef pair<int, int> pii;

const int MOD = (int) 1e9 + 7;

const int MAXN = (int) 2e3;

namespace MATH
{
	inline int fpm(int x, int y)
	{
		int res = 1;
		for(; y; y >>= 1, x = (LL) x * x % MOD) if(y & 1) res = (LL) res * x % MOD;
		return res;
	}

	const int n = MAXN * MAXN;

	int fac[n + 5], ifac[n + 5];

	inline int C(int N, int M) { return N < M ? 0 : (LL) fac[N] * ifac[N - M] % MOD * ifac[M] % MOD; }

	inline void init()
	{
		fac[0] = 1;
		for(int i = 1; i <= n; ++i) fac[i] = (LL) fac[i - 1] * i % MOD;
		ifac[n] = fpm(fac[n], MOD - 2);
		for(int i = n - 1; i >= 0; --i) ifac[i] = (LL) ifac[i + 1] * (i + 1) % MOD;
	}
}
using MATH::fac;
using MATH::ifac;
using MATH::C;

inline int div_to(int N, int M) { return C(N + M - 1, M - 1); }

int n, m;

inline void input()
{
	n = read<int>(), m = read<int>();
}

inline void solve()
{
	if(m == 1) { puts("1"); return; }

	static int f[MAXN + 5][MAXN + 5];

	f[0][0] = 1;
	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= i; ++j)
		{
			f[i][j] = 0;
			if(j > 0) (f[i][j] += f[i][j - 1]) %= MOD;
			(f[i][j] += (LL) f[i - 1][j] * div_to(m - 2, (m - 1) * (i - 1) + j + 1) % MOD) %= MOD;
		}

	int ans = (LL) f[n][n] * fac[n] % MOD;
	printf("%d\n", (ans + MOD) % MOD);
}

int main()
{
#ifdef K_ON // K-ON!
	freopen("F.in", "r", stdin);
	freopen("F.out", "w", stdout);
#endif

	MATH::init();
	input();
	solve();

	return 0;
}



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

int main(void){
	int i,j,n,max=0,sum;
	int A[5000];
	char str[100];

	fgets(str,sizeof(str),stdin);
	sscanf(str,"%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			fgets(str,sizeof(str),stdin);
			sscanf(str,"%d",&A[i]);
		}
		for(i=0;i<n;i++){
			sum=0;
			for(j=i;j<n;j++){
				sum+=A[j];
				if((i==0 && j==0) || max<sum)
					max=sum;
			}
		}
		printf("%d\n",max);
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n);	
	}
	return 0;			
}

Measured memory_bytes: 632
#include <stdio.h>

int main() {
  long n,t;
  long sum = 0;

  scanf("%ld", &n);
  t = n;

  while(1){
    sum += t % 10;
    t /= 10;
    // printf("%ld%ld\n", n, sum);
    if(t <= 0) break;
  }

  if(n % sum == 0){
    printf("Yes");
  } else {
    printf("No");

  }

  return 0;

}

Measured memory_bytes: 128
// ---------- BEG ../defs.hpp BEG ----------
#ifndef atcoder_defs_hpp
#define atcoder_defs_hpp
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
using i8t = std::int64_t;
using u8t = std::uint64_t;
using vi8t = std::vector<i8t>;
using vvi8t = std::vector<std::vector<i8t>>;
using vu8t = std::vector<u8t>;
#include <limits>
static const i8t i8t_max=numeric_limits<i8t>::max();
static const i8t i8t_min=numeric_limits<i8t>::min();
#include <unordered_map>
#include <unordered_set>
template<typename Key,typename Value> using map_t=std::unordered_map<Key, Value>;
template<typename Key> using set_t=std::unordered_set<Key>;
#define F3(i,i0,iN,step) for(i8t i=i0,i##_N=iN;i<i##_N;i+=step)
#define F2(i,i0,iN) F3(i,i0,iN,1)
#define F(i,N) F3(i,0,N,1)
#define FR(i,N) for(i8t i=N;i--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
template<typename T> T umax(T& ans,T const& value) {if(value>ans)ans=value;return ans;}
template<typename T> T umin(T& ans,T const& value) {if(value<ans)ans=value;return ans;}
template<typename T> struct identity { using type = T; };
#endif
// ---------- END ../defs.hpp END ----------

int main() {
  RL(S);
  i8t N = S.size();
  i8t M=(N-1)/2;
  bool same=true;
  F(i,M){
    if(S[i]!=S[M-1-i])same=false;
    if(S[i]!=S[N-1-i])same=false;
    if(S[i]!=S[M+1+i])same=false;
  }
  P(same?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  map<string, bool> mp;
  char before;
  for (ll i = 0; i < N; ++i) {
    string W;
    cin >> W;
    if (mp[W]) {
      cout << "No" << endl;
      return 0;
    }
    mp[W] = true;
    if (i == 0) {
      before = W[W.size() - 1];
      continue;
    }
    if (before != W[0]) {
      cout << "No" << endl;
      return 0;
    }
    before = W[W.size() - 1];
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
char c[55][55]; int H, W, cnt;
 
int main() {
	cin >> H >> W;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (c[i][j] == '#' && c[i][j - 1] != '#' && c[i - 1][j] != '#' && c[i][j + 1] != '#' && c[i + 1][j] != '#') cnt++;
		}
	}
	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * author: said_v15
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
 
typedef long long  ll;

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define pb push_back 
#define sc second 
#define f first 
#define kek cout<<"\n"; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 


const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
const int MAXN = 1000100;
const int INF = 1e8;
const ll LL_INF=1e18;
const double pi=3.1415926535;
using namespace std;
int divide(int a, int b)
{
          return (a+b-1)/b;
}

int main()
{
    #if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
    #endif
 fast;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 
 int questions=1;
 // cin>>questions;
 while(questions--)
 {
           int n;
           cin>>n;
           
          vector<ll> cnt(n+10,0);
          for(ll i=1;i<=n;i++) 
          {
                    for(ll j=1;j<=n;j++) 
                    {
                              if(i*j>n) break;
                              cnt[i*j]++;
                    }
          }
        //  for(auto x: cnt) cout<<x<<" ";
          ll ans=0;
          for(int i=1;i<=n;i++) 
          {
                    ll need=n-i;
                    ans+=cnt[need];
          }
          cout<<ans;
 }
    
 
 // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions)
 

  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
}

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

int main() {
 
  int a,b,c;
  //string s;
  
  cin >> a ;
  cin >> b >> c ;
  
  int count = b;
  int judge = 0;
 
  for(int i = b; i<=c ; i++){
  	if(count%a==0){
    	judge = 1;
    }
    count++;
  }
  
  if(judge == 0){
  	cout << "NG" << endl;
  }else{
  	cout << "OK" << endl;
  }
  return 0;
  
}


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

int main(void){
    int a,b,tmp;
	int cnt=1;
    cin >> a;
	cin >> b;
	if(b == 1){
		cout << "0" << endl;
	}
	else{
		tmp = a;
		while(tmp < b){
			tmp = tmp + a - 1;
			cnt++;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
main(){
    int i,N,X,T,count;
    cin >> N >> X >> T;
    if(N<=X){
        count=1;
    }
    else{
        count=N/X;
        if(0==!(N%X)){
            ++count;
        }
    }
    cout << count*T << endl;
}

Measured memory_bytes: 3592
fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let a = read_vec::<usize>()
        .into_iter()
        .map(|x| x - 1)
        .collect::<Vec<_>>();
    let sum = (1..n).map(|x| (m + a[x] - a[x - 1]) % m).sum::<usize>() as i64;
    let mut count = vec![0i64; 2 * m];
    let mut rate = vec![0i64; 2 * m];
    for i in 1..n {
        let cost;
        if a[i] >= a[i - 1] {
            cost = a[i] - a[i - 1];
            count[a[i]] += 1;
            count[a[i - 1] + 1] -= 1;
            rate[a[i]] += cost as i64 - 1;
        } else {
            cost = m + a[i] - a[i - 1];
            count[m + a[i]] += 1;
            count[a[i - 1] + 1] -= 1;
            rate[m + a[i]] += cost as i64 - 1;
        }
    }
    let mut current_count = 0;
    let mut gain = vec![0; 2 * m];
    let mut current_gain = 0;
    for i in (0..2 * m).rev() {
        current_gain -= current_count;
        current_gain += rate[i];
        gain[i] = current_gain;
        current_count += count[i];
    }

    let max_gain = (0..m).map(|x| gain[x] + gain[m + x]).max().unwrap();
    println!("{}", sum - max_gain);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 12540
#include <stdio.h>
#define N 100000
#define max 101
void matrixachainMultiplication(void);

  int i, m[max][max], p[max], l, n, k, j;

int main(){

        scanf("%d", &n);
        for(i=1; i<=n; i++) {
                scanf("%d%d", &p[i-1], &p[i]);
        }
matrixachainMultiplication();

        printf("%d\n", m[1][n]);
        return 0;
}

void matrixachainMultiplication(void){

          for(i = 1; i<=n; i++) {
                  m[i][i] = 0;
          }

          for(l = 2; l<=n; l++) {
                  for(i = 1; i<=n-l+1; i++) {
                          j = i + l - 1;
                          m[i][j]= N;
                          for(k = i; k<=j-1; k++) {
                                  if(m[i][j] > m[i][k] + m[k+1][j]+(p[i-1]*p[k]*p[j])) {
                                          m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
                                  }
                          }
                          //  printf("%d\n", m[][]);
                  }
          }

}

Measured memory_bytes: 636
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

ll int expo(ll int base,ll int exponent,ll int mod){
    ll int ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int n,a,b;
		cin>>n>>a>>b;
		ll int ans=expo(2,n,hell);
		ll int tmpa=1;
		for(ll int i=n-a+1;i<=n;i++) tmpa=(tmpa*i)%hell;
		for(ll int i=1;i<=a;i++) tmpa=(tmpa*expo(i,hell-2,hell))%hell;
		ll int tmpb=1;
		for(ll int i=n-b+1;i<=n;i++) tmpb=(tmpb*i)%hell;
		for(ll int i=1;i<=b;i++) tmpb=(tmpb*expo(i,hell-2,hell))%hell;
		ans=(ans+hell-tmpa)%hell;
		ans=(ans+hell-tmpb)%hell;
		ans=(ans+hell-1)%hell;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
INF=100000000
n,k=map(int,input().split())
h=np.array(list(map(int,input().split())))
cost=np.array([INF for _ in range(n)])
cost[0]=0
# print(h,cost)
for i in range(1,n):
    s=max(0,i-k)
    cost[i]=min(cost[s:i]+abs(h[i]-h[s:i]))
print(cost[n-1])


Measured memory_bytes: 22824
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

  int f = 0;
  while(n>0){
    f += n % 10;
    n /= 10;
  }

  if(N % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
// Aizu Vol-2 0261: Mayan Crucial Prediction
// 2017.8.7

#include <stdio.h>
#include <ctype.h>

char *gets(char *);
char buf[100], *p;

int getInt(void)
{
	int n = 0;
	while (isspace(*p) || *p == '.') p++;
	if (!*p) return -1;
	while (isdigit(*p)) n = 10 * n + (*p++ - '0');
	return n;
}

#define MAGIC 2456283		// 2012.12.21

long long greg2jd(int year, int month, int day)
{
	long long a, y, m;
	long long j;

	a = (14 - month) / 12;
	y = year + 4800 - a;
	m = month + 12 * a - 3;
	j = day + (153 * m + 2) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 32045;
	return j;
}

int jd2greg(int *year, int *month, int *day, int jd)
{
	int a, b, c;
	int d, e, m;
	int yy;
	int m1;

	a = jd + 32044;
	b = (4 * a + 3) / 146097;
	c = a - (146097 * b) / 4;
	d = (4 * c + 3) / 1461;
	e = c - (1461 * d) / 4;
	m = (5 * e + 2) / 153;
	m1 = m / 10;
	*day = e - (153 * m + 2) / 5 + 1;
	*month = m + 3 - 12 * m1;
	yy = 100 * b + d - 4800 + m1;
	if (yy <= 0) { *year = -yy + 1; return -1; }
	*year = yy; return 1;
}

int main()
{
	int b, ka, t, w, ki;
	int y, m, d;
	int a, k;
	long long x;

	while (1) {
		gets(p = buf);
		if (*p == '#') break;
		y = getInt(), m = getInt(), d = getInt(), a = getInt();
		if (a >= 0) {  // maya -> Gregorian
			b = y, ka = m, t = d, w = a, ki = getInt();
			k = (((20 * b + ka) * 20 + t) * 18 + w) * 20 + ki;
			k += MAGIC;
			jd2greg(&y, &m, &d, k);
			printf("%d.%d.%d\n", y, m, d);
		}
		else {
			x = (greg2jd(y, m, d) - MAGIC) % 1872000;
			k = (int)x;
			b = k / 144000, k %= 144000;
			ka = k / 7200, k %= 7200;
			t = k / 360, k %= 360;
			w = k / 20, ki = k % 20;
			printf("%d.%d.%d.%d.%d\n", b, ka, t, w, ki);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi l(n); rep(i, n) cin >> l[i];
  sort(all(l));

  int ans = 0;
  for (int a = 0; a < n-1; a++) {
    for (int b = a+1; b < n; b++) {
      int k = lower_bound(all(l),l[a]+l[b]) - l.begin();
      ans += k-b-1;
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 256