akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = list(map(int, input().split()))

acc_A = [0]
d = dict()
for i in range(N):
    acc_A.append((acc_A[i] + A[i]) % M)
    if acc_A[i + 1] in d:
        d[acc_A[i + 1]] += 1
    else:
        d[acc_A[i + 1]] = 1

result = 0
for i in range(N):
    if acc_A[i] in d:
        result += d[acc_A[i]]
    d[acc_A[i + 1]] -= 1
print(result)

Measured memory_bytes: 63640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{
	return b>0?gcd(b,a%b):a;
}
int main()
{
	ll sum = 0;
	int m;
	cin>>m;
	for(int i=1;i<=m;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=1;k<=m;k++)
			{
				sum+=gcd(gcd(i,j),k);
			}
		}	
	}
	cout<<sum<<endl;
}

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



int main(){
  int n,x;
  cin >>n >>x;
  int a[n];
  rep(i,n)cin >> a[i];
  int ans=abs(x-a[0]);
  for(int i=1;i<n;i++){
    int g=abs(x-a[i]);
    ans=__gcd(g,ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

A,B,H,M = LI()

t = math.radians(5.5*(60*H+M))

x = A**2+B**2-2*A*B*math.cos(t)

print(math.sqrt(x))

Measured memory_bytes: 66092
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let s = get!(String).split_whitespace().collect::<Vec<_>>()[1].chars().next().unwrap();
    println!("{}", ['A', s, 'C'].into_iter().cloned().collect::<String>());
}

Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		String a = sc.next();

		String b = sc.next();
		String c= a+b;
    double d =	Integer.parseInt(c);
		double e = Math.floor(Math.sqrt(d));
		if (d-(e*e)==0){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n, k;
  cin >> n >> k;
  vll p(n);

  REP(i, n) {
    cin >> p[i];
  }

  SORT(p);

  ll ans=0;
  REP(i, k) {
    ans += p[i];
  }

  COUT(ans);

}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
const int N=310;
int n,k,p,dp[N][N][N];
int main(){
	scanf("%d%d%d",&n,&k,&p);
	dp[0][1][0]=1;
	for(int i=0; i<=n; ++i)
		for(int j=1; j<=k; ++j)
			for(int l=i; l>=0; --l){
				if(l)(dp[i][j][l-1]+=dp[i][j][l])%=p;
				else (dp[i][j+1][i]+=dp[i][j][l])%=p;
				(dp[i+1][j][l]+=1ll*dp[i][j][l]*(l+1)%p)%=p;
			}
	printf("%d",dp[n][k+1][n]);
	return 0;
}

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


int main() {

    ll n; cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n) cin >> a[i];

    if(n%2 == 1){
        rep(i,n){
            b[n/2 + ((i%2 == 1)?1:-1)*((i+1))/2] = a[i];
        }
    }else{
        rep(i,n){
            b[n/2 + ((i%2 == 1)?-1:1)*((i+1))/2] = a[i];
        }
    }

    rep(i,n) cout << b[i] << " ";
    return 0;
}











Measured memory_bytes: 6432
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


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

  int a = (n-m)*100 + m*1900;
  REP(i, m)a*=2;
  cout<<a<<endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

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

#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define STF(i, a, b) for(size_t i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define SRF(i, a, b) for(size_t i = a;i >= b;i--)

#define ALL(v) v.begin(),v.end()
#define PRECISION(x) cout<<fixed<<setprecision(x)
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define MOD 1000000007

#define TO(v, type) static_cast<type>(v)

void solve(int x);
int main()
{
#ifdef OJ
	READ;
	WRITE;
#endif

	FASTIO;
	int x{};
	cin >> x;
	solve(x);
	return 0;
}
void solve(int x)
{
	if (x == 0)
		cout << 1 << '\n';
	else if (x == 1)
		cout << 0 << '\n';
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
stringstream __ss__;
#define debug __ss__
#endif

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;i--)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);i--)
#define rep0(i,n) for(i=0;i<(n);++i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int k[300000];

int main() {
	IL{
		memset(k,0,sizeof(k));
		int n=in();
		if(n==0)break;
		string f,t;
		int from,to;
		rep(i,n){
			cin>>f>>t;
			from=(f[0]-'0')*100000+(f[1]-'0')*10000+(f[3]-'0')*1000+(f[4]-'0')*100+(f[6]-'0')*10+f[7]-'0';
			to=(t[0]-'0')*100000+(t[1]-'0')*10000+(t[3]-'0')*1000+(t[4]-'0')*100+(t[6]-'0')*10+t[7]-'0';
			++k[from];
			--k[to];
		}
		int res=0,p=0;
		rep(i,300000){
			p+=k[i];
			chmax(res,p);
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n;
  cin >> n;
  
  vector<long long> a(n),count(n+1);
  for(int i=0; i<n; i++){
    cin >> a[i];
    count[a[i]]++;
  }
  
  long long ans=0;
  for(int i=1; i<n+1; i++){
    ans+=count[i]*(count[i]-1)/2;
  }
  
  for(int i=0; i<n; i++){
    cout << ans-count[a[i]]+1 << endl;
  }
  
}


Measured memory_bytes: 5760
import collections
S = input()

if len(S) == 1:
    print(-1,-1)
    exit()

tmp_s1 = '1'
tmp_s2 = '2'
tmp_s3 = '3'

for i,s in enumerate(S):
    if i == 0:
        tmp_s1 = s
    elif i == 1:
        tmp_s2 = s
    elif i == 3:
        tmp_s3 = s

    else:
        tmp_s1 = tmp_s2
        tmp_s2 = tmp_s3
        tmp_s3 = s

    if tmp_s1 == tmp_s2:
        print(i-1 + 1,i + 1)
        exit()
    elif tmp_s2 == tmp_s3:
        print(i, i+1)
        exit()
    elif tmp_s1 == tmp_s3:
        print(i-2 + 1,i + 1)
        exit()
print(-1,-1)


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

int n;
int a,b,c;
vector<int> l;
int ans=1000000000;

void dfs(int i,int A,int B,int C,int cal){
  if(i==n){
    if(A>0 && B>0 && C>0){
      ans=min(ans,abs(A-a)+abs(B-b)+abs(C-c)+cal);
    }
    return;
  }
  if(A>0 && B>0 && C>0) ans=min(ans,abs(A-a)+abs(B-b)+abs(C-c)+cal);
  dfs(i+1,A,B,C,cal);
  dfs(i+1,A+l[i],B,C,(A>0 ? cal+10 : cal));
  dfs(i+1,A,B+l[i],C,(B>0 ? cal+10 : cal));
  dfs(i+1,A,B,C+l[i],(C>0 ? cal+10 : cal));

}

int main(){
  cin >> n >> a >> b >> c;
  l=vector<int>(n);
  for(int i=0;i<n;++i){
    cin >> l[i];
  }
  dfs(0,0,0,0,0);

  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
template<typename T>T maxx(T a,T b){if(a>=b) return a;else return b;}
template<typename T>T minn(T a,T b){if(a<=b) return a;else return b;}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y>>=1;x=(x*x)%p;}return res;}
ll powerfew(ll x,ll y){ll res=1;while(y>0){if(y&1)res*=x;y>>=1;x*=x;}return res;}
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define loop(i,n) for(int i=1;i<=n;++i)
#define mem(x,y) memset(x,y,sizeof(x))
#define PI  3.141592653589
#define INF 0x3f3f3f3f//(1061109567)
const ll MAX=2e5+10;
ll a[1000000],b[1000000],c[1000000];
int main()
{
	ll n;
	cin >>n;
	for(ll i=1;i<=n;i++)
	{
		cin >>a[i];
	}
	for(ll i=1;i<=n;i++)
	{
		if((i+a[i])<=n)
		{
			b[i+a[i]]++;
		}
	}
	for(ll i=1;i<=n;i++)
	{
		if((i-a[i])>0)
		{
			c[i-a[i]]++;
		}
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		ans+=c[i]*b[i];
	}
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 8300
k=int(input())

mod=[0]*k
c=7
cnt=1

while True:
    if c%k==0:
        print(cnt)
        break
    
    mod[c%k]=1

    c*=10
    c+=7
    c%=k
    cnt+=1

    if mod[c]==1:
        print(-1)
        break


Measured memory_bytes: 71340
MOD = 10 ** 9 + 7
fac = [1] * (10 ** 5 + 1)
for i in range(len(fac) - 1):
    fac[i + 1] = fac[i] * (i + 1)
    fac[i + 1] %= MOD


def comb(n, k):
    if n < k:
        return 0
    else:
        return fac[n] * pow(fac[n - k], MOD - 2, MOD) * pow(fac[k], MOD - 2, MOD) % MOD


n, k = map(int, input().split())
a = list(map(int, input().split()))
if k == 1:
    print(0)
    exit(0)
a.sort()
c = [0] * n
c[0] = comb(0, k - 2)
for i in range(n - 1):
    c[i + 1] = c[i] + comb(i + 1, k - 2)
ans = 0
t = 0
for i in range((n - 1) // 2):
    t += c[n - 2 - i]
    if i >= 1:
        t -= c[i - 1]
    ans += t * (a[i + 1] - a[i] + a[n - i - 1] - a[n - i - 2])
    ans %= MOD
if n % 2 == 0:
    i = (n - 1) // 2
    t += c[n - 2 - i]
    if i >= 1:
        t -= c[i - 1]
    ans += t * (a[n // 2] - a[n // 2 - 1])
print(ans % MOD)


Measured memory_bytes: 66600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pii pair<int, int>
#define pll pair<long long, long long>
#define rep(i,l,r) for(long long i = l;i<r;i++)

#define fastout  ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using namespace __gnu_pbds;

typedef tree<pll,null_type,less<pll>,rb_tree_tag,tree_order_statistics_node_update> order_set;

const int INF = (int)1e9 + 7;
const long long LLINF = (long long)1e18 + 7;

mt19937 mt('O' + '4' + 'K' + 'O');

void kekek()
{
    
    mt();
    #ifdef EB_UG
        freopen("in.txt", "r", stdin), freopen("out.txt", "w", stdout);
    #endif
    #ifndef EB_UG
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #endif
}

int main() {
    kekek();
    int k;
    cin >> k;
    string s;
    cin >> s;
    string ans = "";
    for (auto it: s) {
        int delta = it - 'A' + k;
        delta %= 26;
        ans += (char)(delta + 'A');
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include <string>
#include<math.h>
using namespace std;
int main() {
	string str;
	bool frag=true;
	int size;
	cin >> str;
	size = str.length();
	for (int i = 0; i <(size-1)/2 ; i++) {
		if (str[i] == str[size - 1 - i]) {
		}
		else {
			frag = false;
		}
	
	
	}
	if ((size-1)/2 % 2 == 0) {
		for (int i = 0; i < (size - 1) / 4; i++) {
			if (str[i] == str[((size - 1)/2)-1-i]) {
			}
			else {
				frag = false;
			}
		
		
		}
	
	}
	else {
		for (int i = 0; i < (size - 1) / 4; i++) {
			if (str[i] == str[((size - 1) / 2) - 1 - i]) {
			}
			else {
				frag = false;
			}


		}
	}
	if (frag) {
	
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import collections
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())
    sunuke = [0]*N
    for _ in range(K):
        A = []
        d = int(input())
        A = map(int, input().split())
        for j in A:
            sunuke[j-1] += 1
    answer = collections.Counter(sunuke)
    print(answer[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9460
//　https://atcoder.jp/contests/abc053/tasks/abc053_b
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    string s;
    cin >> s;
    size_t idxa, idxz;
    for (int i = 0; i < s.size(); ++i)
    {
        if ('A' == s[i])
        {
            idxa = i;
            break;
        }
    }

    for (int i = s.size() - 1; i >= 0; --i)
    {
        if ('Z' == s[i])
        {
            idxz = i;
            break;
        }
    }

    size_t maxlen = idxz - idxa + 1;

    cout << maxlen << endl;
    return 0;
}


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

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int dx[]={-1,0,1,0};
    int dy[]={0,-1,0,1};
    int n,m,si,sj,di,dj;
    const int INF=1e9;
    cin>>n>>m;
    cin>>si>>sj;
    cin>>di>>dj;
    --si,--sj,--di,--dj;
    vector<string> grid(n);
    vector<vector<int> >moves(n,vector<int>(m,INF));
    for(int i=0;i<n;i++)
        cin>>grid[i];
    deque<pair<int,int> >q;
    q.emplace_back(si,sj);
    moves[si][sj]=0;
    while(!q.empty())
    {
        int f=q.front().first;
        int s=q.front().second;
        int d=moves[f][s];
        q.pop_front();
        for(int i=0;i<4;i++)
        {
            int ni=dx[i]+f;
            int nj=dy[i]+s;
            if(ni<0 || ni>=n || nj<0 || nj>=m)  continue;
            if(grid[ni][nj]=='#') continue;
            if(moves[ni][nj]<=d) continue; 
            moves[ni][nj]=d;
            q.emplace_front(ni,nj);
        }
        for(int ai=-2;ai<=2;ai++)
        {
            for(int aj=-2;aj<=2;aj++)
            {
                int bi=f+ai;
                int bj=s+aj;
                if(bi<0 || bi>=n || bj<0 || bj>=m) continue;
                if(grid[bi][bj]=='#') continue;
                if(moves[bi][bj]<=d) continue;
                moves[bi][bj]=d+1;
                q.emplace_back(bi,bj);
            }
        }
    }
    int ans=moves[di][dj];
    if(ans==INF) ans=-1;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int r,g;
  cin >> r >> g;
  int d=g-r;
  g+=d;
  pr(g);
}

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


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

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        long K = scan.nextInt();
        int a[] = new int[N];
        for(int i = 0; i < N; i++) {
            a[i] = scan.nextInt();
        }

        long mother = 1000000007;
        int big, small;
        long answer = 0;

        BigInteger inv = new BigInteger(String.valueOf(2)).modInverse(BigInteger.valueOf(mother));
        int invOf2 = inv.intValue();

        for(int i = 0; i < N; i++) {
            small = 0;
            big = 0;
            int target = a[i];
            //smallの個数の計算
            for(int j = 0; j < i; j++) {
                if(target > a[j])
                    small++;
            }
            //bigの個数の計算
            for(int j = i+1; j < N; j++) {
                if(target > a[j])
                    big++;
            }
            
            answer += (((((big*(K+1)) % mother)*K) % mother) * invOf2  + ((((small*K)% mother)*(K-1)) % mother) * invOf2) % mother;
            answer = answer % mother;
        }
        os.println(answer);
    }
}

Measured memory_bytes: 26456
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b) = (v[0], v[1]);
    println!("{}", (b - 1 + a - 2) / (a - 1));
}

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: 4352
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101010], Q;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	map<int, int> cnt;
	ll tot = 0;
	rep(i, 0, N) {
		cnt[A[i]]++;
		tot += A[i];
	}

	cin >> Q;
	rep(_, 0, Q) {
		int B, C; cin >> B >> C;

		tot += 1LL * (C - B) * cnt[B];
		cnt[C] += cnt[B];
		cnt[B] = 0;

		printf("%lld\n", tot);
	}
}







Measured memory_bytes: 8604
#include <stdio.h>

int size = 0;
int data[234567];

int main(void) {
	int q;
	int i;
	if (scanf("%d", &q) != 1) return 1;
	for (i = 0; i < q; i++) {
		int query, param;
		if (scanf("%d", &query) != 1) return 1;
		if (query != 2 && scanf("%d", &param) != 1) return 1;
		switch (query) {
			case 0:
				data[size++] = param;
				break;
			case 1:
				if (param < 0 || size <= param) return 1;
				printf("%d\n", data[param]);
				break;
			case 2:
				if (size <= 0) return 1;
				size--;
				break;
		}
	}
	return 0;
}



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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	string s;
	cin >> s;
	string ans = "yes";
	REP(i, s.length())
	{
		FOR(j, i + 1, s.length())
		{
			if (s[i] == s[j])
				ans = "no";
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3644
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val X = listOfLong().map { ModInt(it) }.toTypedArray()
    val Y = listOfLong().map { ModInt(it) }.toTypedArray()
    var x = ModInt(0)
    for (k in 1 until N) {
        x += X[k] * k - X[k - 1]
        X[k] += X[k - 1]
    }
    var y = ModInt(0)
    for (k in 1 until M) {
        y += Y[k] * k - Y[k - 1]
        Y[k] += Y[k - 1]
    }
    println(x * y)
}   

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfLong() = listOfString().map(String::toLong)

data class ModInt(private var v: Long) {
    companion object { private const val MOD = 1000000007L }
    init { this.v %= MOD }
    constructor(k: Int): this(k.toLong())
    operator fun plus(other: Int) = ModInt((this.v + other) % MOD)
    operator fun plus(other: ModInt) = ModInt((this.v + other.v) % MOD)
    operator fun minus(other: Int) = ModInt((this.v + MOD - other) % MOD)
    operator fun minus(other: ModInt) = ModInt((this.v + MOD - other.v) % MOD)
    operator fun times(other: Int) = ModInt(this.v * other % MOD)
    operator fun times(other: ModInt) = ModInt(this.v * other.v % MOD)
    operator fun div(other: ModInt) = ModInt(this.v * pow(other.v, MOD - 2) % MOD)
    private fun pow(a: Long, b: Long): Long {
        if (b == 0L) return 1L
        if (b % 2 == 0L) {
            val d = pow(a, b / 2)
            return (d * d) % MOD
        }
        return a * pow(a, b - 1) % MOD
    }
    override fun toString() = this.v.toString()
}

Measured memory_bytes: 93100
#最大距離をkから引けばよい
k,n = gets.chomp.split(' ').map(&:to_i)
arr = gets.chomp.split(' ').map(&:to_i)
arr.push(arr[0]+k)
max = 0
i = 0
while i < n
  if max < arr[i+1] - arr[i]
    max = arr[i+1] - arr[i]
  end
  i += 1
end
puts k - max

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

int main(){
  string S, T;
  T = "";
  cin >> S;
  vector<string> vec = {"dream", "dreamer", "erase", "eraser"};
  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++){
  	string s = vec.at(i);
    reverse(vec.at(i).begin(), vec.at(i).end());
  }
  bool F = true;
  for(int i = 0; i < S.size(); ){
    bool f = false;
    for(int j = 0; j < 4; j++){
  		string t = S.substr(i, vec.at(j).size());
      	if(t == vec.at(j)){
        	i += t.size();
          	f = true;
          	break;
        }
    }
    if(!f){
      F = false;
      break;
    }
  }
  if(!F){
  	cout << "NO" << endl;
  }else{
  	cout << "YES" << endl;
  }
}


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

int main() {
    string a,b;
    cin >> a >> b;
    string s = a+b;
    int k = stoi(s);
    for(int i=1;i*i<=k;++i){
        if(i*i==k){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

int main() {

    int x = 0;
    
    int n;
    int maxN = 0;
    string s;
    
    cin >> n;
    cin >> s;
    
    for (int i = 0; i < n; i ++ ) {
        if (s[i] == 'I') {
            x++;
        }
        else {
            x--;
        }
        
        if (maxN < x) {
            maxN = x;
        }
    }
    
    cout << maxN << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    int N;
    cin>>N;
    vector<ll> A(N),B(N);
    priority_queue<P> PQ;
    rep(i,N)cin>>A[i];
    rep(i,N){
        cin>>B[i];
        PQ.push({B[i],i});
    }
    ll ans = 0;
    while(!PQ.empty()){
        auto maxx = PQ.top();
        PQ.pop();
        int b = maxx.first;
        int i_m = maxx.second;
        int i_r = i_m + 1;
        int i_l = i_m -1; 
      	if(b==A[i_m])continue;
        if(i_m == N-1){
            i_r = 0;
        }
        else if(i_m == 0){
            i_l = N-1;
        }
        ll a = B[i_l];
        ll c = B[i_r];
        if(b<=a+c){
            cout<<-1<<endl;
            return 0;
        }
        if((b-A[i_m])%(a+c)==0){
            ans+=(b-A[i_m])/(a+c);
            B[i_m] = A[i_m];
        }
        else{
            ans += b/(a+c);
            b %= (a+c);
            B[i_m] = b;
        }
        if(A[i_m] == B[i_m]){
            continue;
        }
        PQ.push({b,i_m});
    }
    if(A!=B){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5492
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	std::vector<int> cards(5);

#if INPUT_FROM_FILE
	//std::ifstream ifs("test.txt");
	FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	while(fscanf(fp,"%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3], &cards[4]) != EOF){
#else
	while(scanf("%d,%d,%d,%d,%d", &cards[0], &cards[1], &cards[2], &cards[3], &cards[4]) != EOF){
#endif
		std::sort(cards.begin(), cards.end());

		//4cards
		if((cards[0] == cards[1] && cards[1] == cards[2] && cards[2] == cards[3]) ||
			(cards[1] == cards[2] && cards[2] == cards[3] && cards[3] == cards[4])){
			std::cout << "four card" << std::endl;
		}
		//full house
		else if((cards[0] == cards[1] && cards[2] == cards[3] && cards[3] == cards[4]) ||
			(cards[0] == cards[1] && cards[1] == cards[2] && cards[3] == cards[4])){
			std::cout << "full house" << std::endl;
		}
		else if((cards[0] == 1 && cards[1] == 10 && cards[2] == 11 && cards[3] == 12 && cards[4] == 13) ||
			(cards[0] == (cards[1] - 1) && cards[1] == (cards[2] - 1) && cards[2] == (cards[3] - 1) && cards[3] == (cards[4] - 1))){
			std::cout << "straight" << std::endl;
		}
		else if((cards[0] == cards[1] && cards[1] == cards[2]) ||
			(cards[1] == cards[2] && cards[2] == cards[3]) ||
			(cards[2] == cards[3] && cards[3] == cards[4])){
			std::cout << "three card" << std::endl;
		}
		else{
			cards.erase(std::unique(cards.begin(), cards.end()), cards.end());
			if(cards.size() == 3){
				std::cout << "two pair" << std::endl;
			}
			else if(cards.size() == 4){
				std::cout << "one pair" << std::endl;
			}
			else{
				std::cout << "null" << std::endl;
			}
			cards.resize(5);
		}
		
	}

	return 0;
}


Measured memory_bytes: 3224
import sys

N,A,B,C,D = map(int,input().split())
num = abs(A-B)
nmax = (N-1) * D
nmin = (N-1) * C
flag = False

for i in range(N-1):

    if nmax >= num and num >= nmin:
        flag = True
        break

    nmax -= D + C
    nmin -= C + D

if flag:
    print ("YES")
else:
    print ("NO")


Measured memory_bytes: 40428
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  freopen("gout.txt", "w", stdout);
 
#endif
}


int rs(int m,int k)
{
    int an = 1,a=10;
    while(m>0)
    {
        if(m%2!=0) an = ((an%k) * a%k)%k;
        m/=2;
        a = ((a%k) * a%k)%k;
    }
    return an;
}

const int Mxn = 2e5;
int a[Mxn];
void solve()
{
  // int k,an=-1;
  // cin >> k;
  
  // k/=__gcd(k,(int)7);
  // forf(i,1,Mxn)
  // {
   
  //   if(rs(i,k)==1)
  //   {
  //       an = i;
  //       break;
  //   }
  // }

  // cout<<an;
  
  int n,k;
  cin >> n >> k;

  forf(i,0,n) cin >> a[i];

  int st = 1,en = 1e9,an=big;

  while(st<=en)
  {
    int md = (st+en)/2;
    int cn = 0;
    forf(j,0,n) 
    {
        cn += (a[j]-1)/md;
    }
    //cout<<md<<" "<<cn<<"\n";
    if(cn > k)
    {
        st = md+1;

    }else 
    {
        an = min(an,md);
        en = md-1;
    }
  }

  cout<<an;
  
}
 
 
int32_t main()
{
  pr_init();
  fastio;
 
  auto start = high_resolution_clock::now();
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  // cout << "Time taken by function: "
  //       << duration.count() << " microseconds" << endl;
 
}
 

Measured memory_bytes: 5200
def next_white(s, w, n):
    w += 1
    while s[w] != 'W':
        w += 1
        if w > n - 1:
            return n
    return w


def next_red(s, r,n):
    r -= 1
    while s[r] != 'R':
        r -= 1
        if r < 0:
            return -1
    return r


n = int(input())
s = input()
white = -1
red = n
ans = -1
while red > white:
    ans += 1
    white = next_white(s, white, n)
    red = next_red(s, red, n)
print(ans)


Measured memory_bytes: 9504
#include <iostream>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a>b){
        cout << "a > b" << endl;
    }else if(a<b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3096
#include <iostream>

using namespace std;
#define REP(i, n) for (int i = 0; (i) < (n); ++i)

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    int *a = new int[n];
    int sum = 0;
    REP(i, n)
    {
        cin >> a[i];
        sum += a[i];
    }
    REP(i, m)
    {
        int max = 0;
        REP(j, n)
        {
            max = (a[max] < a[j]) ? j : max;
        }
        if (a[max] < sum / 4.0 / m)
        {
            cout << "No";
            return 0;
        }
        else
        {
            a[max] = 0;
        }
    }
    printf("Yes");

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AC
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var K = input[1];
            var p = ReadArrayInt();
            var exp = new double[1001];
            for (int i = 1; i <= 1000; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    exp[i] += (double)j / i;
                }
            }
            var pp = new double[N + 1];
            for (int i = 0; i < N; i++)
            {
                pp[i + 1] = pp[i] + exp[p[i]];
            }
            var ans = 0d;
            for (int i = 0; i < N - (K - 1); i++)
            {
                if (pp[i + K] - pp[i] > ans)
                {
                    ans = pp[i + K] - pp[i];
                }
            }

            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 34780
#include<iostream>
using namespace std;
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
	int k;cin>>k;
	cout<<a[k-1]<<"\n";
	return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        int count = 0;
        for(int i=0;i<3;i++){
            if(c[i] == 'R'){
                count++;
            }
        }
        if(count == 2 && c[1] != 'R'){
            count = 1;
        }
        System.out.println(count);
    }
}


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

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

    vector<vector<int>> C(10, vector<int>(10));
    for (int i = 1; i <= N; i++)
    {
        int f = to_string(i)[0] - '0';
        int b = i % 10;
        C[f][b]++;
    }

    long long ans = 0;
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            ans += C[i][j] * C[j][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
 
int main() {
 
  int long long A,B,K;
  int long long ansA,ansB;
  
  cin >> A >> B >> K;
 
  ansA=A-K;
  ansB=B;
  if (ansA<0)
  {
    ansA=0;
    ansB=B-(K-A);
  }
  if (ansB<0)
  {
    ansB=0;
  }
  
 
  cout << ansA << " " << ansB << endl;
  
  return 0;
}

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

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (auto&& i : a) {
		cin >> i;
	}
	sort(begin(a), end(a));
	int cnt = 1;
	int i;
	for (i = 1; i < n; i++) {
		if (3200 <= a[i]) break;
		cnt += a[i - 1] / 400 != a[i] / 400;
	}
	cout << cnt << " " << cnt + (n - i) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define INF INT_MAX
vector<ll> dp;

ll f(vector<ll> &v,ll n,ll k)
{
    ll i,j;
    dp[0]=0;
    for(i=1;i<=min(n,k);i++)
    {
        for(j=0;j<i;j++)
        {
            dp[i]=min(dp[i],dp[j]+abs(v[j]-v[i]));
        }
    }

    for(;i<=n;i++)
    {
        for(j=1;j<=k;j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
        }
    }

    // for(i=0;i<=n;i++)
    // {
    //     cout<<dp[i]<<" ";
    // }

    // cout<<endl;

    return dp[n];
}

void solve()
{
    ll n,i,ans,k;
    cin>>n>>k;
    dp.resize(n,INF);
    vector<ll> v(n);

    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }

    ans=f(v,n-1,k);
    cout<<ans;
}

int main()
{
    solve();
}


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

const int MOD = 1e9 + 7;
const int MAX = 510000; 

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    long long t;
    while (b)
    {
        t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long com(int n, int k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

long long perm(int n, int k)
{
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[n-k] % MOD;
}

int main(void)
{
    COMinit();
    int n, a, b; cin >> n >> a >> b;
    long long ans = 1;
    int m = 1;
    while (m * m <= n) m++;
    m--;
    int l = n - m * m;
    int k = 1;

    for (int i = 0; i < m; i++)
    {
        k *= 2;
        k %= MOD;
    }
    for (int i = 0; i < m; i++)
    {
        ans *= k;
        ans %= MOD;
    }
    for (int i = 0; i < l; i++)
    {
        ans *= 2;
        ans %= MOD;
    }
    ans--;
    long long xa = 1, xb = 1;
    for (int i = 0; i < a; i++)
        xa = xa * (n - i) % MOD;
    for (int i = 0; i < b; i++)
        xb = xb * (n - i) % MOD;
    ans = ans - xa * finv[a] % MOD - xb * finv[b] % MOD;
    ans = ans % MOD;
    if (ans < 0)
        ans += MOD;
    cout << ans << endl;
}

Measured memory_bytes: 15572
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  ll n, k, d, i, j, a_tmp, cnt = 0;
  cin >> n >> k;
  vector<ll> a(n, false);
  rep(i, k) {
    cin >> d;
    rep(j, d) {
      cin >> a_tmp;
      a[a_tmp - 1] = true;
    }
  }
  rep(i, n) if (a[i] == false) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 3592
N = int(input())

arr = []

for i in range(N):
  a,b = map(int,input().split())
  arr.append([b,a])
  
arr.sort()

t = 0
ck=0

for i in range(N):
  a = arr[i][0]
  b = arr[i][1]
  t += b  
  if t > a:
    ck = 1

print("Yes" if ck == 0 else "No")

Measured memory_bytes: 35608
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

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

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

  sort(d.begin(), d.end());

  cout << d[n/2] - d[(n-1)/2] << endl; 

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> W(N), S(N), V(N);
    rep(i, 0, N) {
        cin >> W[i] >> S[i] >> V[i];
    }
    vector<int> idx(N);
    rep(i, 0, N) {
        idx[i] = i;
    }
    sort(all(idx), [&](int i1, int i2) {
        return S[i1] + W[i1] < S[i2] + W[i2];
    });
    ll max_val = *max_element(all(S)) + *max_element(all(W));
    vector<vector<ll>> dp(N + 1, vector<ll>(max_val + 1, 0));
    rep(i, 1, N + 1) rep(j, 0, max_val + 1) {
        dp[i][j] = dp[i - 1][j];
        if (j - W[idx[i - 1]] >= 0 && j - W[idx[i - 1]] <= S[idx[i - 1]]) {
            chmax(dp[i][j], dp[i - 1][j - W[idx[i - 1]]] + V[idx[i - 1]]);
        }
    }
    ll ans = 0;
    rep(i, 0, max_val + 1) {
        chmax(ans, dp[N][i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 160640
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
string s;
int nex[200009][26];
int ne[26];
int len[200009], ta[200009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    N=s.size();
    
    rep(i,26) ne[i]=nex[N+1][i]=N+1;
    rrep(i,N){
        len[i]=200009;
        rep(j,26){
            nex[i][j]=ne[j];
            int x=len[ne[j]];
            if(x<len[i]){
                len[i]=x;
                ta[i]=j;
            }
        }
        len[i]++;
        if(i) ne[s[i-1]-'a']=i;
    }
    
    string R;
    int cur=0;
    while(cur!=N+1){
        R+='a'+ta[cur];
        cur=nex[cur][ta[cur]];
    }
    cout1(R);
}

Measured memory_bytes: 22420
#include<iostream>
#include<cmath>
#include<map>


using namespace std;







int main(){

    int N=0;
    
    cin >> N;

    map<int,int> kagami;

    int d=0;

    //while(cin>>d) ++kagami[d];
    for(int i=0;i<N;i++){
        cin >> d;
        ++kagami[d];
    }
     
    //typedef map<int,int>::const_iterator Iter;

    //for(Iter p=kagami.begin();p!=kagami.end();++p){
    //  cout << p->first << ":"<<p->second << endl;
    //}

    cout << kagami.size();

 
    return 0;
}

Measured memory_bytes: 256