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

#define ll long long

const int mxN=1e3, mxW=2e4, M=1e9+7;
int n, w[mxN], s[mxN], v[mxN], p[mxN];
ll dp[mxW+1];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> w[i] >> s[i] >> v[i];
	iota(p, p+n, 0);
	sort(p, p+n, [&](const int &i, const int &j) {
		return s[i]+w[i]<s[j]+w[j];
	});
	for(int i=0; i<n; ++i) {
		int a=p[i];
		for(int j=s[a]; j>=0; --j)
			dp[j+w[a]]=max(dp[j]+v[a], dp[j+w[a]]);
	}
	ll ans=0;
	for(int i=0; i<=mxW; ++i)
		ans=max(dp[i], ans);
	cout << ans;
}


Measured memory_bytes: 384
#include<cstdio>

using namespace std;

const int dx[]={1,-1,-1,1},dy[]={-1,-1,1,1};

int main(){
	for(int n;scanf("%d ",&n),~n;){
		bool mirror[17][17]={};
		for(int k=0;k<n;k++){
			char d;
			int i,j;
			scanf("%c%d%d ",&d,&j,&i);
			if(d=='x')	mirror[2*i][2*j+1]=true;
			else		mirror[2*i+1][2*j]=true;
		}

		int x=1,y=0,dir=3;
		bool loop=false;
		for(int t=0;;t++){
			x+=dx[dir],y+=dy[dir];
			if(mirror[y][x]){
				if(y%2==0){
					switch(dir){
						case 0:	dir=3;	break;
						case 1:	dir=2;	break;
						case 2:	dir=1;	break;
						case 3:	dir=0;	break;
					}
				}
				else{
					switch(dir){
						case 0:	dir=1;	break;
						case 1:	dir=0;	break;
						case 2:	dir=3;	break;
						case 3:	dir=2;	break;
					}
				}
			}
			else{
				if(x==0 || x==16 || y==0 || y==16)	break;
				int bx=x-dx[dir],by=y-dy[dir];
				if(t>1 && x+bx==3 && y+by==1){ loop=true; break; }
			}
		}

		if(loop)	puts("75 25");
		else		printf("%d %d\n",50*x,50*y);
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin >> s;

	char prev=s[0];
	int num=0;
	for(int i=1;i<s.size();i++){
		if(prev!=s[i]) num++;
		prev=s[i];
	}
	cout << num << "\n";
	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string S, X;
  cin >> S >> X;
  int A = S.size();
  int B = X.size();
  int c = 0;
  int ans = 0;
  int I = 0;
  rep(i, A - B + 1) {
    I = i;
    rep(j, B) {
      if(S.at(I) == X.at(j)) {
        c++;
      }
      I++;
    }
    if(c > ans) {
      ans = c;
    }
    c = 0;
  }
  cout << B - ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050;
const long long inf = 1ll<<60;
long long mx[maxn<<2], add[maxn<<2];
void push(int id, int l, int r){
	if(add[id]){
		mx[id] += add[id];
		if(l != r){
			add[id<<1] += add[id];
			add[id<<1|1] += add[id];
		}
		add[id] = 0;
	}
}
void add_to_range(int id, int l, int r, int x, int y, long long v){
	push(id, l, r);
	if(l > y || r < x) return;
	if(x <= l && r <= y){
		add[id] += v;
		push(id, l, r);
		return;
	}
	int mid = (l+r)>>1;
	add_to_range(id<<1, l, mid, x, y, v);
	add_to_range(id<<1|1, mid + 1, r, x, y, v);
	mx[id] = max(mx[id<<1], mx[id<<1|1]);
}
long long get_max(int id, int l, int r, int x, int y){
	push(id, l, r);
	if(l > y || r < x) return -inf;
	if(x <= l && r <= y) return mx[id];
	int mid = (l + r)>>1;
	return max(get_max(id<<1, l, mid, x, y), get_max(id<<1|1, mid + 1, r, x, y));
}
const int maxm = 202;
vector<pair<int, int> > stk[maxm];
int vals[maxn][maxm], a[maxn];
int main(){
	int n, m; cin >> n >> m;
	for(int i = 2; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++) cin >> vals[i][j];
	}
	for(int i = 1; i <= m; i++) stk[i].push_back({1<<30, n + 1});
	long long ans = 0;
	for(int i = n; i >= 1; i--){
		for(int j = 1; j <= m; j++){
			while(stk[j].back().first < vals[i][j]){
				int val, pt; tie(val, pt) = stk[j].back(); stk[j].pop_back();
				add_to_range(1, 1, n, pt, stk[j].back().second - 1, -val);
			}
			add_to_range(1, 1, n, i, stk[j].back().second - 1, vals[i][j]);
			stk[j].push_back({vals[i][j], i});
		}
		ans = max(ans, get_max(1, 1, n, i, n));
		add_to_range(1, 1, n, i, n, -a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4608
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>
#include<math.h>

typedef int32_t i32;
typedef int64_t i64;

#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))

void run (void) {
  char s[5];
  scanf ("%s", s);
  i32 a = 10 * (s[0] - '0') + s[1] - '0';
  i32 b = 10 * (s[2] - '0') + s[3] - '0';
  if (a == 0) {
    if (1 <= b && b <= 12) {
      puts ("YYMM");
    } else {
      puts ("NA");
    }
  } else if (b == 0) {
    if (1 <= a && a <= 12) {
      puts ("MMYY");
    } else {
      puts ("NA");
    }
  } else {
    if (a <= 12 && b <= 12) {
      puts ("AMBIGUOUS");
    } else if (a > 12 && b > 12) {
      puts ("NA");
    } else {
      puts (a <= 12 ? "MMYY" : "YYMM");
    }
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int main(){
	char intra[10004];
	int shift;
	scanf("%d %s", &shift, intra);
	for(int i = 0; intra[i] != '\0'; ++i){
		intra[i] = ((intra[i]-'A') + shift)%26 + 'A';
	}
	printf("%s\n", intra);
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 10
#define MAX_D 10
i64 N, D;
i64 X[MAX_N][MAX_D];

f64 dist(i64 i, i64 j) {
  i64 d = 0;
  REP(k, D) {
    d += pow(X[i][k] - X[j][k], 2);
  }
  return sqrt(d);
}

void solve() {
  i64 cnt = 0;

  f64 d;
  REP(i, N - 1) {
    for (i64 j = i + 1; j < N; j++) {
      d = dist(i, j);
      cnt += d == floor(d);
    }
  }

  cout << cnt << endl;
}

int main() {
  cin >> N >> D;
  i64 x;
  REP(i, N) {
    REP(j, D) {
      cin >> x;
      X[i][j] = x;
    }
  }

  solve();

  return 0;
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    if(s[k-1] == 'A') s[k-1] = 'a';
    else if (s[k-1] == 'B') s[k-1] = 'b';
    else if (s[k-1] == 'C') s[k-1] = 'c';

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	ll H, W;
	cin >> H >> W;
	if(H == 1 || W == 1)
		cout << 1;
	else
		cout << (H * W + 1) / 2;
	return 0;
}


Measured memory_bytes: 3604
import sys
input = lambda: sys.stdin.readline()


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += i & -i


n, m = map(int, input().split())
c = list(map(int, input().split()))
b = BIT(n)
for i in range(n):
    b.add(i + 1, c[i])

res = []
for i in range(m):
    t, x, y = map(int, input().split())
    if t == 1:
        res.append(b.sum(y) - b.sum(x))
    else:
        b.add(x + 1, y)
print("\n".join(map(str, res)))


Measured memory_bytes: 175600
#include <iostream>

int main()
{
    long X[2];
    std::cin >> X[0] >> X[1];
    long money=0;
    for(long i=0; i<2; i++){
        if(X[i]==1){
            money+=300000;
        }else if(X[i]==2){
            money+=200000;
        }else if(X[i]==3){
            money+=100000;
        }
    }
    if(X[0]==1 && X[1]==1){
        money+=400000;
    }
    std::cout << money << std::endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <memory>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(string, s);
    if (s[0] == '7' || s[1] == '7' || s[2] == '7'){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1000000007;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
int distancesum(vi arr, int n) 
{ 
    sort(all(arr));
    int res = 0, sum = 0; 
    for (int i = 0; i < n; i++)
     { 
        res += (arr[i] * i - sum); 
        sum += arr[i]; 
    } 
    return res; 
} 
int inverse(int x)
{
   return power(x,mod-2,mod);
}
signed main()
{
     SPEED;
     int n,m,k;
     cin>>n>>m>>k;
     vi x,y;
     FOR(i,0,n-1)
     {
         FOR(j,0,m-1)
         {
            x.pb(i+1);
            y.pb(j+1);
         }
     }
     int fact[n*m];
     fact[0]=1;
     for(int i=1;i<n*m;i++)
        fact[i]=mul(i,fact[i-1]);
     int res=distancesum(x,n*m)+distancesum(y,n*m);
     res=mul(res,fact[n*m-2]);
     res=mul(res,inverse(fact[k-2]));
     res=mul(res,inverse(fact[n*m-k]));
     cout<<res<<endl;
     time();
     return 0;
 }

Measured memory_bytes: 8292
package main
import (
	"bufio"
	"fmt"
	"strconv"
	"os"
	"strings"
)

const MAX_LENGTH int = 10e5
var Arr []int = make([]int, MAX_LENGTH)

func partition(A []int, p, r int) int {
	i := p-1
	x := A[r]
	for j:=p; j<r; j++ {
		if A[j] <= x {
			i += 1
			A[i], A[j] = A[j], A[i]
		}
	}
	A[i+1], A[r] = A[r], A[i+1]
	return i+1
}

func nextInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	num, _ := strconv.Atoi(scanner.Text())
	return num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	N := nextInt(scanner)
	for i:=0; i<N; i++{
		Arr[i] = nextInt(scanner)
	}
	index := partition(Arr, 0, N-1)
	strArr := make([]string, N)
	for i:=0; i<N; i++ {
		if i==index {
			strArr[i] = "[" + strconv.Itoa(Arr[i]) + "]"
		} else {
			strArr[i] = strconv.Itoa(Arr[i])
		}
	}
	fmt.Println(strings.Join(strArr, " "))
}





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

using namespace std;
typedef long long ll;


int main()
{
    ios_base::sync_with_stdio(0);

    string s;
    cin >> s;

    int n = s.size();

    ll p = 0;

    for (int i = 0; i < n; i++) {
        p+=(s[i]-'0');
    }

    if (p%9) cout << "No";
    else cout << "Yes";

    return 0;
}


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

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

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

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

char bd[100][101];

int main() {
	int a,b, f=0;
	scanf("%d%d", &a, &b);
	REP(i, 100)REP(j, 100)bd[i][j] = '.';
	if (a == 1 && b == 1) {
		bd[0][0] = '#';
	}
	else {
		REP(i, a - 1) {
			int x = (i % 50) * 2;
			int y = (i / 50) * 2;
			REP(j, 3) {
				REP(k, 3) {
					int nx = x + j - 1;
					int ny = y + k - 1;
					if (nx != -1 && ny != -1 && !((j == 1) && (k == 1)))bd[ny][nx] = '#';
				}
			}
		}
		REP(i, b - 1 + (a == 1)) {
			int x = (i % 50) * 2 + 1;
			int y = 100 - ((i / 50) * 2) - 2;
			bd[y][x] = '#';
		}
	}
	printf("100 100\n");
	REP(i, 100) {
		printf("%s\n", bd[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
char s;
scanf("%s",&s);
if('A'==s){
  printf("T");
}
if('T'==s){
   printf("A");
}
if('C'==s){
 printf("G");
}
if('G'==s){
   printf("C");
}
  return 0;
}


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


int main()
{
    string N;
    cin>> N;

    if(N.at(0) == N.at(1)&&N.at(1) == N.at(2)){
        cout << "No"<<endl;
    }
    else {cout <<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {in_n: usize, in_k: usize, mut in_p: [i64; in_n]};
    in_p.sort();
    
    let mut val = 0;

    for i in 0..in_k{
        val += in_p[i];
    }

    println!("{}", val);
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int x = a*b;
  int y = c*d;
  cout << max(x,y) << endl;
}


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

int main() {
  int N, M, D1, D2;
  cin >> N >> M;
  
  int D = 0;
  for(int i=1; i*i<=M; i++) {
    if(M%i==0) {
      D1 = i;
      D2 = M/i;
      
      if(D1<=M/N && D<D1) {D = D1;}
      if(D2<=M/N && D<D2) {D = D2;}
    }
  }
  
  cout << D << endl;
  
  return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

ll gcd(ll x, ll y){
    if(y>x)return gcd(y,x);
    if(x%y==0)return y;
    else return gcd(y,x%y);
}

int main() {
    ll n,t[100];
    cin >> n;
    REP(i,n)cin >> t[i];
    ll ans = t[0];
    REP(i,n){
        ans = ans/gcd(ans,t[i])*t[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int used[114514];
int inv[114514];
signed main(){
	int n,m,q;
	cin>>n>>m>>q;
	vector<int> a;
	for(int i=0;i<q;i++){
		int x; cin>>x; a.pb(x);
	}
	reverse( a.begin(), a.end() );
	vector<int> b;
	b = a;
	for(int i=1;i<=m;i++){
		b.pb(i);
	}
	vector<int> c;
	for(int i=0;i<b.size();i++){
		if( used[b[i]]==0 ){ c.pb(b[i]); used[b[i]] = 1;}
	}
	for(int i=0;i<c.size();i++){ inv[ c[i] ] = i+1; }
	multiset<int> ms;
	for(int i=0;i<n;i++){
		ms.insert(0);
	}
	int goal = m;
	while( goal > 1 && c[goal-1] > c[goal-2] )goal--;
	goal--;
	multiset<int>::iterator it;
	for(int i=0;i<q;i++){
		int cur = inv [ a[i] ];
		it = ms.find(cur-1);
		if( it != ms.end() ){
			ms.erase( it );
			ms.insert( cur );
		}
		//cout<<"cur"<<cur<<" "; for(auto itr = ms.begin(); itr != ms.end(); ++itr)cout<<*itr<<" "; cout<<endl;
	}
	int cnt = 0;
	it = ms.begin();
	while( it != ms.end() ){
		//cout<<*it<<" ";
		if( *it >= goal ) cnt++;
		it++;
	}
	if( cnt == n )cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 10568
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int color[100010];

void dfs(vector<vector<pair<int, int>>> &g, int v, int p, int c) {
    color[v] = c;
    for (auto &e: g[v]) {
        if (e.first == p) continue;
        dfs(g, e.first, v, e.second ? !c : c);
    }
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int>>> g(n+1);
    for (int i = 0; i < n-1; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].emplace_back(v, w%2);
        g[v].emplace_back(u, w%2);
    }

    dfs(g, 1, -1, 0);

    for (int i = 1; i <= n; ++i) {
        cout << color[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 8960
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}
int compw(const void *a, const void *b){return (*(int*)a>*(int*)b)-(*(int*)a<*(int*)b);}

uint32_t nextpint(void){ char c=getchar(); while(c<'0'||'9'<c) c=getchar(); uint_fast32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return x; }

int dif(const int a, const int b){return a>b?a-b:b-a;}

int a[100000];
int main(int argc, char *argv[], char *envp[]){
	int n=nextpint();
	int max=0, maxi;
	for(int i=0; i<n; i++){
		int A=nextpint();
		a[i]=A;
		if(A>max){
			max=A;
			maxi=i;
		}
	}
	int min=INT_MAX, ans;
	for(int i=0; i<n; i++){
		if(i!=maxi){
			int now=dif(a[i]*2, max);
			if(now<min){min=now; ans=a[i];}
		}
	}
	printf("%d %d\n", max, ans);
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>

using namespace std;

const int maxn=500005;
typedef long long ll;

int read()
{
	int f=0; char c=getchar();
	while(c>'9' || c<'0') c=getchar();
	while(c<='9' && c>='0') {f=f*10+c-'0'; c=getchar();}
	return f;
}

ll n,sum;

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if(i%3!=0 && i%5!=0)
			sum+=i;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3588
def b3(n)
  r = []
  while n > 0
    b = 0
    while (1<<(b+1)) <= n
      b += 1
    end
    r << b
    n -= (1<<b)
  end
  r
end

N = gets.to_i
H,*r = b3(N)
es = []
(1..H).each{ |b|
  es << "#{b} #{b+1} 0"
  es << "#{b} #{b+1} #{1 << (b-1)}"
}
s = (1 << H) 
$stderr.puts "#{H} #{r}"
r.each{ |b|
  es << "#{b+1} #{H+1} #{s}"
  s += (1 << b) 
}

puts "#{H+1} #{es.size}"
puts es


Measured memory_bytes: 2044
using System;
using System.Linq;
using System.Collections.Generic;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
    string[] str=Console.ReadLine().Split(' ');
      int[] arr=str.Select(int.Parse).ToArray();
      int ans=0;

      for(int i=0;i<N;i++)
      {
        for(int j=i+1;j<N;j++)
        {
          for(int k=j+1;k<N;k++)
        {
            int[] tmp=new int[3];
            tmp[0]=arr[i];
            tmp[1]=arr[j];
            tmp[2]=arr[k];
            if((tmp[0]!=tmp[1])&&(tmp[1]!=tmp[2])&&(tmp[2]!=tmp[0])){
           if((tmp[0]+tmp[1]>tmp[2])&&(tmp[1]+tmp[2]>tmp[0])&&(tmp[2]+tmp[0]>tmp[1])){
             ans++;
           }
      
          }
               }
        }
      }
      
      Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 34532
#include <iostream>

using namespace std;

int h,w;

char table[110][110];


int dr[4]={1,0,-1,0};
int dc[4]={0,1,0,-1};


void dfs(int r,int c){
	char cur=table[r][c];
	table[r][c]='.';
	for(int i=0;i<4;i++){
		int nr=r+dr[i];
		int nc=c+dc[i];
		if(0<=nr&&nr<h&&0<=nc&&nc<w&&cur==table[nr][nc]){
			dfs(nr,nc);
		}
	}
	return ;
}

int main(void){
	
	while(cin >> h >> w , h|w){

		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin >> table[i][j];

		int ans=0;

		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(table[i][j]!='.'){
					ans++;
					dfs(i,j);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    rep (i, 10) rep(j, 10) rep(k, 10) {
        int state = 0;
        rep (l, s.size()) {
            switch (state) {
                case 0:
                    if (i == s[l] - '0') {
                        state = 1;
                    }
                    break;
                case 1:
                    if (j == s[l] - '0') {
                        state = 2;
                    }
                    break;
                case 2:
                    if (k == s[l] - '0') {
                        state = 3;
                    }
                    break;
                default:
                    break;
            }
        }
        if (state == 3) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
    map<string, int> mp{
        {"SUN", 7},
        {"MON", 6},
        {"TUE", 5},
        {"WED", 4},
        {"THU", 3},
        {"FRI", 2},
        {"SAT", 1},
    };
    string s;
    cin >> s;

    cout << mp[s] << endl;

    return 0;
}

//14:39~

Measured memory_bytes: 256
n, a = map(int,input().split())
x = list(map(int,input().split()))

dp = [[[0] * (n + 1) for i in range(n + 1)] for j in range(50 * 50 + 1)]
dp[0][0][0] = 1

for j in range(1, n + 1):
    for k in range(n + 1):
        for s in range(50 * 50 + 1):
            if s < x[j - 1]:
                dp[s][k][j] += dp[s][k][j - 1]
            else :
                dp[s][k][j] += dp[s][k][j - 1] + dp[s - x[j - 1]][k - 1][j - 1]

ans = 0
for k in range(1, n + 1):
    ans += dp[k * a][k][n]
print(ans)


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

using namespace std;

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

typedef long long ll;
typedef long double ld;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int cnt = 0;
    int tmp = 1;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    rep (i, n) {
        if (a[i] == tmp) {
            tmp++;
            cnt++;
        }
    }
    if (!cnt) cout << -1 << endl;
    else cout << n - cnt << endl;
    
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    int i;
    vector<int> b(n);
    rep(i, n-1) cin >> b[i];
    ll ans(0);
    ans += b[0];
    xrep(i, 1, n-1) {
        ans += min(b[i], b[i-1]);
    }
    ans += b[n-2];
    cout << ans << endl;
}


Measured memory_bytes: 3660
#include <iostream>
#define mod 1000000007
long int dp[1001][1001];
using namespace std;
long int paths(int n,int m)
{   int res;
    if(dp[n][m]>-1)
        res=dp[n][m];
    else if(dp[n][m]==-2)
        res=0;
    else if(n==0||m==0)
        res=0;
    else if(n==1&&m==1)
        res=1;
    else
    {
        res=(paths(n-1,m)%mod+paths(n,m-1)%mod)%mod;
    }
    dp[n][m]=res;
    return res;

}
int main()
{
    int n,m;
    cin>>n>>m;
    char arr[n+1][m+1];
    int i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
            {
                cin>>arr[i][j];
                dp[i][j]=-1;
                if(arr[i][j]=='#')
                    dp[i][j]=-2;
            }
    }
    long int ans=paths(n,m);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <stdio.h>
#include <iterator>

#include <string.h>
using namespace std;

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORD(i,a,b) for(int i=(a);i>(b);i--)
#define scn(a)  scanf("%d",&a)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vecout(vec) for(int i=0;i<vec.size();i++){cout<<vec[i]<<" ";} 
typedef long long ll;


const ll mod =1e9 +7;




int main(){
    ll n,d;
    cin>>n>>d;
    ll x,y;
    int count=0;
    while(n--){
        cin>>x>>y;
        if(d*d>=x*x+y*y) count++;
        
    }
    cout<<count<<'\n';
   
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,a[15],k;
int dfs(int pos,bool start,bool tight,bool num3,bool num5,bool num7){
	if(pos <= 0) return num3 && num5 && num7;
	int maxi = tight ? a[pos] : 7,res = 0;
	for(int i=0;i<=maxi;i++){
		if(start && i == 0) res += dfs(pos - 1,true,tight && i == maxi,num3,num5,num7);
		if(i == 3) res += dfs(pos - 1,false,tight && i == maxi,true,num5,num7);
		if(i == 5) res += dfs(pos - 1,false,tight && i == maxi,num3,true,num7);
		if(i == 7) res += dfs(pos - 1,false,tight && i == maxi,num3,num5,true);
	}
	return res;
}
int main(){
	int n;
	scanf("%d",&n);
	while(n){
		a[++k] = n % 10;
		n /= 10;
	}
	printf("%d\n",dfs(k,true,true,false,false,false));
	return 0;
}


Measured memory_bytes: 256
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
    ll T;cin>>T;
    ll h,m,s;h=T/3600;m=(T-3600*h)/60;s=T%60;
    cout<<h<<":"<<m<<":"<<s<<"\n";
    return 0;
}



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

char str[110];
int i,j,k,l,m,n;
int n,e,s,w,un,up;
int a[7],b[7], qu[25],qf[25],ufl[25];
int t;

void input() {
  for(i=0;i<6;i++){
    scanf("%d",&a[i+1]);
    b[i+1] = a[i+1];
    // printf("a[%d] = %d\n",i+1,a[i+1]);
  }

  scanf("%d",&n);
  //printf("n = %d\n",n);

  for(i=0;i<n;i++) {
    scanf("%d %d",&qu[i],&qf[i]);
    //  printf("qu[%d] = %d qf[%d] = %d\n",i,qu[i],i,qf[i]);
  }
}

void N() {
  t = a[1];
  a[1] = a[2];
  a[2] = a[6];
  a[6] = a[5];
  a[5] = t;
}

void S() {
  t = a[1];
  a[1] = a[5];
  a[5] = a[6];
  a[6] = a[2];
  a[2] = t;
}

void E() {
  t = a[1];
  a[1] = a[4];
  a[4] = a[6];
  a[6] = a[3];
  a[3] = t;
}

void W() {
  t = a[1];
  a[1] = a[3];
  a[3] = a[6];
  a[6] = a[4];
  a[4] = t;
}

void UF() {

  if(qu[k] == a[1]) { // if qu == 1;
    // printf("qu == 1\n");
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[5]) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
  }  else if(qu[k] == a[2]) {  // if qu == 2;
    // printf("qu == 2\n");
    if(qf[k] == a[3])  strcpy( str, "NWS");
    else if(qf[k] == a[1] ) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
  } else if(qu[k] == a[3]){ // if qu == 3;
    //   printf("qu(%d) == %d\n",qu[k],a[3]);
    
    if(qf[k] == a[6])  strcpy( str, "NWS");
    else if(qf[k] == a[5])  strcpy(str ,"NEES");
    else if(qf[k] == a[1]) strcpy(str,"NES");
    W();
  } else if(qu[k] == a[4]) {
    if(qf[k] == a[1]) strcpy( str, "NWS");
    if(qf[k] == a[5])  strcpy(str ,"NEES");
    if(qf[k] == a[6]) strcpy(str,"NES");
    E();
  } else if(qu[k] == a[5]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[6])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    S();
  } else if(qu[k] == a[6]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[2])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
    N();
  }


}

void reset() {
  // printf("before reset str = '%s'\n",str);
  strcpy(str , "");
  for(i=1;i<=6;i++){
    //  printf("before reset a[%d] = %d\n",i,a[i]);
    a[i] = b[i];
    //     printf("a[%d] = %d\n",i,a[i]);
  }
  // printf("str = '%s'\n",str);
}


void output() {
  /*  printf("%d\n",a[1]); */

  printf("%d\n",a[3]);
}

void IF() {

  // scanf("%s",str);

  for(i=0;i<strlen(str);i++) {

    if(str[i] == 'N') N();
    else if(str[i] == 'S') S();
    else if(str[i] == 'W') W();
    else if(str[i] == 'E') E();
  }
}

int main() {

  k = 0;

  input();

  for(j=0;j<n;j++) {
    UF();
    
    IF();

    output();

    reset();
    k = k + 1;

  }

  //  strlen(?) ???????????????(??°)


  return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())


// a,bの最小公倍数
ll LCM(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll GCD(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}


const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){



    string s;
    cin >> s;

    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');

    string ans;
    if (1 <= a && a <= 12 && 1 <= b && b <= 12) {
        ans = "AMBIGUOUS";
    }
    else if (1 <= a && a <= 12) {
        ans = "MMYY";
    }
    else if (1 <= b && b <= 12) {
        ans = "YYMM";
    }
    else {
        ans = "NA";
    }

    cout << ans << endl;
    




}





//              g++ -std=c++1z


Measured memory_bytes: 256
/*
    Code written by Talant I.D.
*/
   
#include <bits/stdc++.h>
   
using namespace std;
   
typedef long long ll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tiii;
   
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define mod (int)1e9+7
#define eps (double)1e-9
#define all(v) v.begin(),v.end()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);
#define curMod 998244353

int main(){
		//do_not_disturb
		int n, i, k;
		cin >> n;
		vector <pii> v;
		for(i = 0; i < n; i++){
			int x;
			cin >> x;
			v.pb(mp(x, i+1));
		}
		sort(all(v));
		for(i = 0; i < n; i++){
			cout << v[i].second << ' ';
		}
		
    return 0;
} // What is to be written here?


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


int main() {
  int n;
  cin >> n;
  int min=1000000;
  vector<int>vec(n);
  vector<int>p(n);
  rep(i,n){
    cin >> p[i];
    if(i==0){
      min = p[i];
      vec[i]=p[i];
    }
    else{
      if(min>p[i])min=p[i];
      vec[i]=min;
    }
  }
  int ans=0;
  rep(i,n){
    if(p[i]<=vec[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[110000];

// DP テーブル
long long dp[110000];

int main() {
    int N, K; cin >> N >> K;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 110000; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 1; j <= K; ++j) {
            chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
        }
    }

    // 答え
    cout << dp[N-1] << endl;
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  long long ans;
  if (K & 1) {
    long long a = N / K;
    ans = a * a * a;
  } else {
    long long a = N / (K / 2);
    long long a1 = a / 2;
    long long a2 = a - a1;
    ans = a1 * a1 * a1 + a2 * a2 * a2;
  }
  cout << ans << endl;

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 10001
using namespace std;
long long n,k,t,u,v,l,d,c,x,a;
bool s[M];

int main(){
  cin>>n>>k>>t>>u>>v>>l;
  for(int i=0;i<n;i++)cin>>d,s[d]=true;
  for(int i=0;i<l;i++){
    if(s[i])
      if(!x||k==c)x=v*t;
      else c++;
    else if(!x&&c>0)c--,x=v*t;
    if(x>0)a++,x--;
  }
  printf("%.10f\n",a*1.0/v+(l-a)*1.0/u);
  return 0;
}

Measured memory_bytes: 1204
memo={}
def calc(A, b):
    score = memo.get(b, None)
    if not score is None:
        return score
    score = sum(abs(a-b) for a in A)
    memo[b] = score
    return score

c = 0
def findmin(A, l, u):
    global c
    c+=1
    d = (u-l)//3
    if d == 0:
        return min(calc(A, i) for i in range(l, u+1))
    left, right = l + d, u - d
    sl = calc(A, left) 
    sr = calc(A, right) 
    if sl > sr:
        return findmin(A, left, u)
    else:
        return findmin(A, l, right)

def solve(A):
    B= [0] * len(A)
    l = A[0]
    u = A[0]
    for i, a in enumerate(A):
        b = a-(i+1)
        l = min(l, b)
        u = max(u, b)
        B[i] = b
    #A = [a-(i+1) for i, a in enumerate(A)]
    return findmin(B, l, u)

N = int(input())
A = [int(x) for x in input().split()]

#abs(A1-(b+1)) + abs(Ai-(b-i)) + abs(AN-(b-N))


# b1 = A[0]    ならば (A[i]-b1) >= 0
# b2 = A[0] -1 ならば (A[i]-b2) > (A[i]-b1) >= 0 なので、スコアは大きくなる

# b = A[-1] ならば (A[i]-b) <= 0
print(solve(A))



Measured memory_bytes: 26016
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long n = long.Parse(Console.ReadLine());

            string[] arry = new string[n];

            for (int i = 0; i < n; i++)
            {
                arry[i] = Console.ReadLine();
            }

            Console.Write(arry.GroupBy(x => x).Count());
        }
    }
}


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

int main(){
    int k;
    string s;

    cin>>k>>s;
    if(s.size()<=k){
        cout<<s<<endl;
    }else{
        string ans = s.substr(0,k);
        cout<<ans<<"..."<<endl;
    }
    return 0;
}

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

//for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

//adjacency list
vector<int> to[100005];

bool f(int x){
    int keta=0;
    while(x){
        keta++;
        x/=10;
    }
    return keta%2==1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int ans=0;
    repe(i,1,n){
        if(f(i)) ans++;
    }
    cout << ans ENDL;
    return 0;
}

Measured memory_bytes: 6000
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>/*toupperとかが入っている*/
#include<vector>/*可変長配列vectorのインクルード*/

const int MOD=1000000007;/* 1,000,000,007 で割った余りを出力する　のとき使う*/
using namespace std;/*標準名前空間を利用する。cinやcoutはこれによって利用可能になる*/

long long int A,B;

int main(void) {
  cin >> A >> B;
  

  if((A+B)%2==0){
    cout << (A+B)/2 << endl;
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll a[1005], b[1005], c[1005], ans;
int main()
{
    ll n;
    cin >> n;
    for(ll i = 1; i <= n; i ++)
    {
        cin >> a[i];
    }
    for(ll i = 1; i <= n; i ++)
    {
        cin >> b[i];
    }
    for(ll i = 1;i <= n - 1; i ++)
    {
        cin >> c[i];
    }
    for(ll i = 1; i <= n; i ++)
    {
        ans += b[a[i]];
        if(a[i]+ 1 ==  a[i+1])
        {
            ans += c[a[i]];
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int unsigned long long int
#define endl "\n"
#define mod 1000000007
#define ps(x,noOfDecimal) fixed<<setprecision(noOfDecimal)<<x

using namespace std;

signed main()
{
    if (fopen("input.txt", "r")) {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
    std::ios::sync_with_stdio(false);
    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        map<int, int> m;
        for (int i = 0; i < n; i++) {
            int a; cin >> a;
            m[a]++;
        }
        vector<int> v;
        for (auto i : m) {
            v.push_back(i.first);
        }
        reverse(v.begin(), v.end());
        int ans = 0;
        int i = 0;
        while (n > 0) {
            if (2 * m[v[i]] <= n) {
                ans += 2 * m[v[i]] * v[i];
                n -= 2 * m[v[i]];
            } else {
                ans += n * v[i];
                n = 0;
            }
            i++;
        }
        cout << ans - v[0];
    }
    return 0;
}

Measured memory_bytes: 17828
#include <cstdlib>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
	int A, B, C, D;
	int length = 0;

	cin >> A >> B >> C >> D;

	length = min(B, D) - max(A, C);

	cout << max(0, length) << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define M 1000000
using namespace std;
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,s;
  cin>>n;
  s=n%10;
  if(s==3)
  cout<<"bon"<<endl;
  else if(s==0||s==1||s==6||s==8)
  cout<<"pon"<<endl;
  else
  cout<<"hon"<<endl;
}

Measured memory_bytes: 3600
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    S = [list(input().strip("\n")) for _ in range(H)]
    round = ((-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1))
    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                count = 0
                for dh, dw in round:
                    if 0<=h+dh<H and 0<=w+dw<W and S[h+dh][w+dw] == "#":
                        count += 1
                S[h][w] = str(count)
    for h in range(H): print("".join(S[h]))

    return 0

if __name__ == "__main__":
    solve()

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

using namespace std;

int main ()
{
    int N;
    cin >>N;
    double res=0; 
    if(N%2==0)
    {
        res = (double)(N/2)/ (double)N;
    }
    else 
    {
        res = ((double)(N/2)+1)/(double)N; 
    }
    cout <<res<<endl; 
    return 0; 
}


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

using namespace std;

#define ll long long

int main(void){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);

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

    string x;
    cin >> x;

    int stop_num;
    for(stop_num = 0;stop_num < n;++stop_num){
        if(x == s[stop_num]){
            break;
        }
    }

    int ans = 0;
    for(int i = stop_num+1;i < n;++i){
        ans += t[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256