akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
ll gcd(ll a, ll b){
    if(a<b) swap(a,b);
    while(b>0){
        ll p= a%b;
        a = b;
        b=p;
    }
    return a;
}
ll lcm(ll a, ll b){
    ll g = gcd(a,b);
    return (a/g) * b;
}
int main(){
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
d = Counter(list(map(int, input().split())))
m = int(input())
t = Counter(list(map(int, input().split())))

Make = True
for i, j in t.items():
    if d[i] < j:
        Make = False

if Make:
    print('YES')
else:
    print('NO')

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

using namespace std;

typedef pair< int, int >    pii;
typedef pair< pii, int >    pipii;
const int N = int(1e5 + 10);
const int inf = int(1e9);
vector< int > adj[N];
int dis[N][3];
queue< pipii > pq;

int dijkstra(int s, int t){
    for(int i = 0 ; i < N ; i++){
        dis[i][0] = dis[i][1] = dis[i][2] = inf;
    }

    dis[s][0] = 0;
    pq.push({{0, 0}, s});

    while(!pq.empty()){
        int u = pq.front().second;
        pii t = pq.front().first;

       // printf("(%d, %d)\n", u, t.second);
        int nxt = (t.second + 1) % 3;
        int di = t.first;
        pq.pop();

        if(di > dis[u][t.second]){
            continue;
        }

        for(auto v: adj[u]){
            if(dis[v][nxt] > dis[u][t.second] + 1){
                dis[v][nxt] = dis[u][t.second] + 1;
                pq.push({{dis[v][nxt], nxt}, v});
            }
        }
    }

    if(dis[t][0] == inf){
        return -1;
    }

    return dis[t][0] / 3;
}

int main(){
    int n, m;

    scanf("%d %d", &n, &m);

    for(int i = 0 ; i < m ; i++){
        int ui, vi;

        scanf("%d %d", &ui, &vi);

        adj[ui].push_back(vi);
    }

    int s, t;

    scanf("%d %d", &s, &t);

    printf("%d\n", dijkstra(s, t));

    return 0;
}

Measured memory_bytes: 6912
#include<iostream>
using namespace std;
int main()
{
   
   
  int b;
  
 

    int num;
    cin >> num;
    b=num;
    int dig;
    int sum = 0;
 
    while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
    
    if(b%sum==0){
        cout << "Yes" << endl;
    return 0;
    }else{
        cout << "No" << endl;
    return 0;
    }
    
}

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

void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}

const int P = 1e9 + 7;

int main(int argc, char const *argv[])
{
    // file();
    
    ll n, k;cin>>n>>k;
    ll A[2002];

    for (int i = 0; i < n; ++i)
    {
        cin>>A[i];
    }
    
    ll self_inv = 0;

    for (int i = 0; i < n - 1; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            self_inv+=A[i] > A[j];
        }
    }

    ll type1_inv = (self_inv % P * k % P) % P; // self inverse * number of copies

    ll cp_inv = 0;

    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            cp_inv+=A[i] > A[j];
        }
    }
    ll pairs_cnt = (k * (k - 1))  / 2 % P; // number of ways to choose pair
    ll type2_inv = (pairs_cnt % P * cp_inv % P) % P; // inverse_between_pair * number_of_pairs

    cout<<(type1_inv % P + type2_inv % P) % P;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/dsu>
#include <cstdio>
using namespace std;
using namespace atcoder;
int main(){
   int n,m,a,b;
   cin >> n >> m;
   dsu d(n);
   for(int i = 0; i < m; i++){
    cin >> a >> b;
    a--;
    b--;
        d.merge(a,b);
   }
   int ans = d.groups().size() - 1;
   cout << ans << endl;
return 0;
}

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

template<class T>
ostream& operator<<(ostream& os,vector<T> const& v){for(auto itr=v.begin();itr!=v.end();++itr){if(itr!=v.begin())os<<' ';os<<*itr;}return os;}

signed main(){

  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  int q;
  cin>>q;
  while(q--){
    int b,m,e;
    cin>>b>>m>>e;
    rotate(a.begin()+b,a.begin()+m,a.begin()+e);
  }
  cout<<(a)<<endl;

}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	int a = n + 999;
	a /= 1000;
	a *= 1000;
	a -= n;

	cout << a;


	return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 55;
const ll MOD = 1000000007;
char ch[2][N];
int n;

ll dfs(int x, int sit, int type = 0){
  ll ret = sit;
  if(x+1 >= n) return ret;
  if(type == 0 && ch[0][x+1] == ch[1][x+1]){ret = (ret*dfs(x+1, 2, 0))%MOD;}
  else if(type == 1 && ch[0][x+1] == ch[1][x+1]){ret = (ret*dfs(x+1, 1, 0))%MOD;}
  else if(type == 0 && ch[0][x+1] != ch[1][x+1]){ret = (ret*dfs(x+2, 2, 1))%MOD;}
  else if(type == 1 && ch[0][x+1] != ch[1][x+1]){ret = (ret*dfs(x+2, 3, 1))%MOD;}
  return ret;
}

int main()
{
  scanf("%d", &n);
  for(int i = 0; i < 2; i++) scanf("%s", ch[i]);
  ll ans = ch[0][0]==ch[1][0]?dfs(0, 3, 0):dfs(1, 6, 1);
  printf("%lld\n", ans);
  return 0;
}


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


int main(){
  int A,B,C;
  cin >> A >> B >> C;
  
  if((A==B && A!=C) || (A==C && A!=B) || (C==B && A!=C)){
    cout << "Yes"  << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3616
def isPrime(num):
    '''int -> boolean
    return True/False of Is num a prime number 
    '''
    if num == 2:
        return True
    elif num <= 1 or num %2 == 0:
        return False
    import math
    maxp = int(math.sqrt(num))
    for p in range(3, maxp + 1):
        if num % p == 0:
            return False
    return True
n = int(input())
cnt = 0
for i in range(n):
    num = int(input())
    if isPrime(num) == True:
        cnt += 1
print(cnt)



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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 2e5 + 10;
const int M = 110;

typedef long long LL;

char S[N];
int n, f[N];

struct Info{
	LL cnt[26];

	Info(){
		memset(cnt, 0, sizeof cnt);
	}

	void operator = (const Info& A){
		For(i, 0, 25) cnt[i] = A.cnt[i];
	}

	Info operator + (const Info& A) const{
		Info ret;
		For(i, 0, 25) ret.cnt[i] = A.cnt[i] + cnt[i];
		return ret;
	}

	Info operator - (const Info& A) const{
		Info ret;
		For(i, 0, 25) ret.cnt[i] = cnt[i] - A.cnt[i];
		return ret;
	}

}A[M];

LL len[M];

Info work(int x, LL r){
	if(x <= 2){
		Info ret;
		For(i, 1, r) ret.cnt[S[i] - 'a']++;
		return ret;
	}
	if(r < len[x - 1]) return work(x - 1, r);
	else return A[x - 1] + work(x - 1, r - len[x - 1]);
}

Info calc(LL r){
	if(r <= n) return work(1, r);
	int i = 1;
	while(len[i] * 2 < r) ++i;
	return A[i] + work(i, r - len[i]);
}

int main(){
	scanf("%s", S + 1);
	n = strlen(S + 1) / 2;

	f[1] = 0;
	For(i, 2, n){
		int p = f[i - 1];
		while(p && S[p + 1] != S[i]) p = f[p];
		f[i] = S[p + 1] == S[i] ? p + 1 : 0;
	}
//	printf("period = %d\n", n - f[n]);

	For(i, 1, n) A[1].cnt[S[i] - 'a']++;
	len[1] = n;
	For(i, 1, n + n - f[n]) A[2].cnt[S[i] - 'a']++;
	len[2] = n + n - f[n];
	For(i, 3, 100) len[i] = len[i - 1] + len[i - 2], A[i] = A[i - 1] + A[i - 2];

	LL l, r;
	scanf("%lld%lld", &l, &r);
	Info ans = calc(r) - calc(l - 1);
	For(i, 0, 25) printf("%lld%c", ans.cnt[i], i == 25 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <bitset>
#include <algorithm>

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	const int MAX_VALUES = 101;
	bitset<MAX_VALUES> bits;
	bitset<MAX_VALUES> reversed;
	bits.flip();
	reversed.flip();
	int x, n, t;
	cin >> x >> n;
	if (n == 0) {
		cout << x;
		exit(0);
	}
	for (int i = 0; i < n; i++) {
		cin >> t;
		bits.reset(t);
		reversed.reset(MAX_VALUES - 1 - t);
	}
	if (bits[x]) {
		cout << x;
		exit(0);
	}
	int rV = bits._Find_next(x);
	int lV = MAX_VALUES - 1 - reversed._Find_next(MAX_VALUES - 1 - x);
	int d1 = abs(rV - x);
	int d2 = abs(lV - x);
	if (d1 < d2) {
		cout << rV;
	}
	else if (d2 < d1) {
		cout << lV;
	}
	else {
		cout << min(rV, lV);
	}
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, x, n) for (ll i = x; i < (ll)(n); i++)
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
//cin.tie(0);
//ios::sync_with_stdio(false);

void solve(int x,int nofs)
{
    cout << nofs << endl;

    cout<<nofs-1<<" ";
    ll cnt=1;
    for(int i=1;i <= x;i+=cnt)
    {
        cout<<i<<" ";
        cnt++;
    }
    cout<<endl;

    cnt=0;
    for(int i=1;i <= x;i+=cnt)
    {
        cout<<nofs-1<<" ";
        ll cnt2=1;
        bool f=true;
        for(int j=i;j <=x ;j+=cnt2)
        {
            cout<<j<<" ";
            if(f && j==i+cnt){
                f=false;
                cnt2=cnt+1;
            }else if(!f){
                cnt2++;
            } 
        }
        cout<<endl;
        cnt++;
    }
}

signed main()
{
    int n;
    cin >> n;
    for(int i=2;i < 2000;i++)
    {
        if(2*n==i*(i-1)){
            cout<<"Yes"<<endl;
            solve(n,i);
            return 0;
        }
    }
    cout<<"No"<<endl;

}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll k,x;cin>>k>>x;
    if(k*500>=x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
using LL = long long;
using ULL = unsigned long long;
#define NUM 1000000007

using namespace std;

int main()
{
    string s;
    cin >> s;
    int a, b, c, d;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    if (a + b + c + d == 7)
    {
        cout << a << '+' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b + c - d == 7)
    {
        cout << a << '+' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a + b - c + d == 7)
    {
        cout << a << '+' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a + b - c - d == 7)
    {
        cout << a << '+' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }

    if (a - b + c + d == 7)
    {
        cout << a << '-' << b << '+' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b + c - d == 7)
    {
        cout << a << '-' << b << '+' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c + d == 7)
    {
        cout << a << '-' << b << '-' << c << '+' << d << '=' << 7 << endl;
        return 0;
    }
    if (a - b - c - d == 7)
    {
        cout << a << '-' << b << '-' << c << '-' << d << '=' << 7 << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define fcout cout << fixed << setprecision(15)
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

int p[10010], c[550], e[550];
int m, n; // m: 饅頭の数, n: 箱の数

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> m >> n;
	rep(i, m) cin >> p[i];
	rep(i, n) cin >> c[i] >> e[i];

	sort(p, p+m, greater<>());
	vector<int> sum(m + 10, 0); // i個目まで取った時の利益
	rep(i, m) sum[i+1] = sum[i] + p[i];

	// dp[i]: i個以上入れられるよう箱を用意した時の最小コスト
	vector<int> dp(m + 10, 0);
	rep(i, m+1) dp[i] = INF;
	dp[0] = 0;

	rep(i, n) {
		for(int j = m; j >= 0; j--) {
			// c: 入れられる個数, e: 価格
			chmin(dp[j], dp[max(0LL, j - c[i])] + e[i]);
		}
	}

	int ans = 0;
	rep(i, m+1) {
		chmax(ans, sum[i] - dp[i]);
		//cout << sum[i] << " " << dp[i] << endl;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3416
#include <iostream>

using namespace std;

// Exchange
void exchange(int A[], int i, int j)
{
	int tmp = A[i];
	A[i] = A[j];
	A[j] = tmp;
}

// Partition
int partition(int A[], int l, int r)
{
	int threshold = A[r - 1];
	int i = l - 1;
	for (int j = l; j < r - 1; j++) {
		if (A[j] <= threshold) {
			i++;
			// Exchange
			exchange(A, i, j);
		}
	}
	i++;
	// Insert threshold
	exchange(A, i, r - 1);
	return i;
}

// MAIN FUNCTION
int main(int argc, char** argv)
{
	// Input
	int A[1000000];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];

	// Partition
	int pivot = partition(A, 0, n);

	// Print all elements
	for (int i = 0; i < n; i++) {
		if (i)
			cout << " ";
		if (i == pivot) {
			cout << "[" << A[i] << "]";
		}
		else {
			cout << A[i];
		}
	}
	cout << endl;

	return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  string str;
  cin>>str;
  int al[30]={};
  ll ans=0;
  for(int i=str.size()-1;i>=0;i--){
    al[str[i]-'a']++;
    for(int j=0;j<26;j++){
      if(str[i]-'a'!=j){
	ans+=al[j];
      }
    }
  }
  cout<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 640
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    long A,B,V,W,T;
    private void solve() {
        A = nextLong();
        V = nextLong();
        B = nextLong();
        W = nextLong();
        T = nextLong();

        if (V <= W) {
            out.println("NO");
            return;
        }

        long D = Math.abs(A - B);
        if (D <= T * (V - W)) {
            out.println("YES");
        } else {
            out.println("NO");
        }
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] x = new int[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextInt();
        }
        return x;
    }

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 32588
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int k,s;
    cin>>k>>s;
    ll ans=0;
    for (int i=0;i<=k;i++){
        for (int j=0;j<=k;j++){
            if (s-(i+j)<=k and s-(i+j)>=0)
                ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
vector<ll> divisor(ll n){
  vector<ll> res;
  for(ll i=1; i*i<=n ; i++){
    while(n%i==0){
      ++res[i];
      n /= i;
    }
  }
  if(n!=1) res[n]=1;
  return res;
}
int main(){
  string s; cin>>s;
  int cnt=0;
  if(s[0]=='R'){
    if(s[1]=='R'){
      if(s[2]=='R') cnt=3;
      else cnt=2;
    }else{
      cnt=1;
    }
  }else if(s[1]=='R'){
    if(s[2]=='R'){
      cnt=2;
    }else{
      cnt=1;
    }
  }else if(s[2]=='R'){
    cnt=1;
  }else{
    cnt=0;
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3560
#include <stdio.h>

int main(void) {
	int n, x, i;
	
	scanf("%d %d", &n, &x);
	
	if(1<x&&x<2*n-1){
		printf("Yes\n");
		
		for(i=0;i<2*n-1;i++)
		printf("%d\n", (i+x+n-1)%(2*n-1)+1);
	}
	else
	printf("No\n");
	
	return 0;
}


Measured memory_bytes: 1408
# seishin.py
from collections import deque
N = int(input())
*P, = map(int, input().split())
MOD = 10**9 + 7

G = [[] for i in range(N+1)]
U = [0]*(N+1)
C = [0]*(N+1)
for i, p in enumerate(P):
    G[p].append(i+1)
    U[i+1] = u = U[p]+1
    C[u] += 1
Q = [None]*(N+1)
PP = {}
def pp(k):
    if k not in PP:
        PP[k] = p = pow(2, k, MOD)
        return p
    return PP[k]
L = [0]*(N+1)

ept = []
sz = L.__getitem__
for i in range(N, -1, -1):
    g = G[i]
    if not g:
        continue

    # 子ノードのdequeを集める
    g.sort(key=sz, reverse=1)
    k = len(g)
    e = [pp(k) - k, k, 0]

    g0 = g[0]
    L[i] = L[g0] + 1
    if L[g0] == 0:
        Q[i] = deque([e])
        continue
    Q[i] = R = Q[g0]
    if k > 1:
        # a0 <- a2
        for s, r in zip(Q[g[1]] or ept, R):
            r[0] += r[2]; r[2] = 0

        for j in g[1:]:
            S = Q[j]
            if not S:
                break

            # dequeの小さい方から大きい方へマージする処理
            for (a0, a1, a2), r in zip(S, R):
                b0, b1, b2 = r; a0 += a2
                r[0] = a0*b0 % MOD
                r[1] = (a0*b1 + a1*b0) % MOD
                r[2] = ((a0+a1)*b2 + a1*b1) % MOD
    R.appendleft(e)
print((pp(N) + sum(pp(N+1-c) * a1 % MOD for (a0, a1, a2), c in zip(Q[0], C[1:]))) % MOD)

Measured memory_bytes: 92488
from collections import deque
n = int(input())
q = deque()
q.append('')
res = set()
while q:
    m = q.popleft()
    for c in '357':
        if int(m+c) > n: continue
        q.append(m+c)
    for c in '357':
        if c not in m: break
    else:
        res.add(m)
print(len(res))


Measured memory_bytes: 7768
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define SORT(v,n) do{sort(v,v+n);reverse(v,v+n);}while(0)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}

ll ORD(ll x,ll n)
{
  if(x==0)return INF;
  if(x%n!=0)return 0;
  return 1+ORD(x/n,n);
}

int main()
{
  ll n,m,a[200000],b[200000],ans;
  cin >> n >> m;
  ans=0;
  rep(i,n)cin >> a[i] >> b[i];
  vector<pair<ll,ll>>p(n);
  rep(i,n)p[i]=make_pair(a[i],b[i]);
  sort(p.begin(),p.end());
  rep(i,n){
    if(m>p[i].second){
      ans+=p[i].first*p[i].second;  
      m-=p[i].second;
    }
    else if(m>0){
      ans+=p[i].first*m;
      m=0;
    }
  }
  printf("%lld",ans);
}

Measured memory_bytes: 4608
s = input()
l,r = 0,len(s)-1
c = 0

while l<r:
	if s[l] == s[r]:
		l,r = l+1,r-1
	elif s[l] == 'x':
		l,c = l+1,c+1
	elif s[r] == 'x':
		r,c = r-1,c+1
	else:
		print(-1)
		exit()
print(c)

Measured memory_bytes: 68200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

ll n, f, t;

int main(){
	while (cin >> n&&n){
		f = 0; t = 0;
		for (int i = 1; i <= n; i++){
			ll k = i;
			while (k % 5 == 0){
				f++;
				k /= 5;
			}
			while (k % 2 == 0){
				t++;
				k /= 2;
			}
		}
		cout << min(t, f) << endl;
	}
}

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

int main(){
	string p,s;
	cin >> p >> s;
	p += p;
	int ok = 0;
	for(int i = 0; i < p.size(); i++){
		string ans = "";
		for(int j = i; j < i + s.size(); j++){
			ans += p[j];
		}
		if(ans == s)ok = 1;
	}
	if(ok)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
long long n,k,arr[100001],fact[100001];
long long total,p;
long long power(long long x,long long y){
    long long res=1;
    while (y>0){
        if (y%2==1) res=(res*x)%p;
        y/=2;
        x=(x*x)%p;
    }
    return res;
}
long long ncr(long long x,long long y){
    if (x<y) return 0;
    long long ans=fact[x];
    ans*=power(fact[y],p-2);
    ans%=p;
    ans*=power(fact[x-y],p-2);
    ans%=p;
    return ans;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>k;
    for (int i=1;i<=n;i++) cin>>arr[i];
    p=1e9+7;
    sort(arr+1,arr+n+1);
    fact[0]=1;
    for (int i=1;i<=n;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=p;
    }
    for (int i=1;i<=n;i++){
        total+=arr[i]*ncr(i-1,k-1);
        total%=p;
        total-=arr[i]*ncr(n-i,k-1);
        total%=p;
    }
    cout<<total;
}

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

int main()
{
	int sx,sy,tx,ty;
	scanf("%d%d%d%d",&sx, &sy, &tx, &ty);
	{
		int disx = tx - sx;
		int disy = ty - sy;
		for(int i = 0; i < disx; i++)
			printf("R");
		for(int i = 0; i < disy; i++)
			printf("U");
		for(int i = 0; i < disx; i++)
			printf("L");
		for(int i = 0; i < disy; i++)
			printf("D");
		printf("L");
		for(int i = 0; i <= disy; i++)
			printf("U");
		for(int i = 0; i <= disx; i++)
			printf("R");
		printf("DR");
		for(int i = 0; i <= disy; i++)
			printf("D");
		for(int i = 0; i <= disx; i++)
			printf("L");
		printf("U\n");
		
	}
	
	
	
	return 0;
 } 

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amin(T& a,T2 b){ if(a > b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, a, b;
	cin >>n >>a >>b;
	VL v(n);
	rep(i, n) cin >>v[i];
	
	VI np = {n/3 , n/3 ,n/3}; np[2]= n-np[0]-np[1];
	VI gt ={ 0, np[0], np[0]+np[1]};
	//for(auto x :np) cerr<<x<<" "; dbg("");
	vector<VL> zsm(3, VL(55)), zct(3, VL(55));

	auto fnc=[&](int p)->void{
		int n=np[p];
		rep(i, 1<<n){
			int ct = __builtin_popcount(i); ll sm = 0;
			rep(j, n) if(i>>j & 1) sm += v[gt[p] + j];
			if(zsm[p][ct] < sm){ zsm[p][ct] = sm; zct[p][ct] = 1;}
			else if(zsm[p][ct] == sm) zct[p][ct]++;
		}
	};

	rep(i, 3) fnc(i);
	VL qsm(55), qct(55);
	rep(i, np[0]+1) rep(j, np[1]+1) rep(k, np[2]+1){
		int zz = i+j+k;
		if( zz >=a && zz <=b ){
			ll psm = zsm[0][i] +zsm[1][j] +zsm[2][k];
			ll pct = zct[0][i] *zct[1][j] *zct[2][k];
			
			if(qsm[zz] < psm && pct > 0){
				qsm[zz] = psm; qct[zz] = pct;
			}else if(qsm[zz] == psm) qct[zz] += pct;
		}
	}
	double mx=0; int svi=-1;
	rep2(i, a, b+1) if(mx < (double)qsm[i] / i){
		mx = (double)qsm[i] / i; svi =i;
	}
	ll ans = 0;
	rep2(i, a, b+1){
		if(qsm[svi] * i == qsm[i] * svi) ans += qct[i];
	}
	printf("%.12f\n%lld\n", mx, ans);

	return 0;
}


Measured memory_bytes: 256
import sys

def count_chars(str):
    lst = [0 for x in range(26)]
    a = ord("a")

    for c in str:
        n = ord(c) - a
        if 0 <= n < 26:
            lst[n] += 1

    return lst

a = ord("a")
str = ""

for line in sys.stdin:
    str += " " + line.lower()

lst = count_chars(str)

for i, x in enumerate(lst):
        print(chr(i+a), ":", x)



Measured memory_bytes: 5580
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e9
#define rep(i,n) for(int i=0;i<n;i++)

struct C{
	int tx,ty,kx,ky;
	C(int tx,int ty,int kx,int ky):
	tx(tx),ty(ty),kx(kx),ky(ky) {}
};

int X,Y,tx,ty,kx,ky,m[51][51],dx[]={1,0,-1,0},dy[]={0,1,0,-1},d[51][51][51][51];

int bfs(int tx,int ty,int kx,int ky){
	queue<C> q;
	rep(i,X)rep(j,Y)rep(k,X)rep(l,Y)d[i][j][k][l]=INF;
	q.push(C(tx,ty,kx,ky));
	d[tx][ty][kx][ky]=0;
	while(!q.empty()){
		C c=q.front();q.pop();
		//cout<<c.tx<<" "<<c.ty<<" "<<c.kx<<" "<<c.ky<<" : "<<d[c.tx][c.ty][c.kx][c.ky]<<endl;
		if(d[c.tx][c.ty][c.kx][c.ky]==100)return -1;
		if(c.tx==c.kx&&c.ty==c.ky)return d[c.tx][c.ty][c.kx][c.ky];
		rep(i,4){
			int ntx=c.tx+dx[i],nty=c.ty+dy[i],nkx=c.kx-dx[i],nky=c.ky-dy[i];
			if(ntx<0||ntx>=X||nty<0||nty>=Y||m[nty][ntx]){ntx=c.tx;nty=c.ty;}
			if(nkx<0||nkx>=X||nky<0||nky>=Y||m[nky][nkx]){nkx=c.kx;nky=c.ky;}
			if(d[ntx][nty][nkx][nky]==INF){
				//cout<<ntx<<" "<<nty<<" "<<nkx<<" "<<nky<<endl;
				q.push(C(ntx,nty,nkx,nky));
				d[ntx][nty][nkx][nky]=d[c.tx][c.ty][c.kx][c.ky]+1;
			}
		}
	}
	return -1;
}

int main(){
	while(cin>>X>>Y&&X){
		cin>>tx>>ty>>kx>>ky;
		tx--;ty--;kx--;ky--;
		rep(i,Y)rep(j,X)cin>>m[i][j];
		int ans=bfs(tx,ty,kx,ky);
		if(ans>=0)cout<<ans<<endl;
		else cout<<"NA"<<endl;
	}
}

Measured memory_bytes: 26000
n = int(input())
a = n // 100
b = (n - 100 * a) // 10
c = n - 100 * a - 10 * b
if a == b == c:
    print(n)
elif a * 111 >= n:
    print(a * 111)
else:
    print((a + 1) * 111)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int r[5], c[4];

int main()
{
	int a, b;

	rep(i, 3) {
		cin >> a >> b;
		r[a]++;
		r[b]++;
	}

	repc(i, 1, 4) c[r[i]]++;

	if (c[1] == 2 && c[2] == 2) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

int main()
{
    while (true)
    {
        int m, f, r;
        cin >> m >> f >>r;

        if (m==-1&&f==-1&&r==-1)
        {
            break;
        }
        else if (m==-1||f==-1)
        {
            cout << "F" <<endl;
        }
        else if (m+f>=80)
        {
            cout << "A" << endl;
        }
        else if (m+f>=65)
        {
            cout << "B" << endl;
        }
        else if (m+f>=50)
        {
            cout << "C" << endl;
        }
        else if (m+f>=30)
        {
            if (r>=50)
            {
                cout << "C" << endl;
            }
            else
            {
                cout << "D" << endl;
            }      
        }
        else
        {
            cout << "F" << endl;
        }
    }
}


Measured memory_bytes: 3100
def factorization(n):
    retlist = []
    tmp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            retlist.append([i, cnt])

    if tmp != 1:
        retlist.append([tmp, 1])

    if retlist == []:
        retlist.append([n, 1])

    return retlist

n = int(input())
ans = 0
for i in range(1,n+1,2):
    d = factorization(i)
    count = 1
    for k,val in d:
        count *= val+1
    if count == 8:
        ans += 1
print(ans)


Measured memory_bytes: 9476
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  string s;
  cin >> s;
  cout << "ABC" << s << endl;
}


Measured memory_bytes: 256
n, t = map(int, input().split())
t_list = list(map(int, input().split()))
total = 0
times = []
for i, x in enumerate(t_list):
	if i < len(t_list) -1:
		next_time = t_list[i+1]
		times.append(next_time - x)
	else:
		times.append(0)
for time in times:
	x = time if time < t else t
	if time == 0:
		x = t
	total += x 
print(total)


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

int main()
{
    int a, b; cin >> a >> b;
    int ans = INF;
    rep(i,20000){
        if(i*8/100 == a && i/10 == b){
            ans = min(ans, i);
        }
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3524
N = int(input())
p = list(map(int, input().split()))

# 条件はN=O(10^5)より、本問はO(N)で解けるはず
# 二重ループをすると、O(N^2)で間に合わない
# 累積和の問題（ABC-154-Dとか）と同じ発想が使える！

# 具体的にO(N)で解くために、最初に各iに対して、i番目までの最小値を求めておく
m = [0]*(N)
m[0] = p[0]
for i in range(N-1):
  m[i+1] = min(m[i], p[i+1])

# 各iまでの最小値とi番目の値を比較し、最小値の方が大きければよい
ans = 1
for i in range(1, N):
  if m[i-1] >= p[i]: ans += 1
    
print(ans)

Measured memory_bytes: 32336
#include<iostream>
typedef long long ll;
using namespace std;
const int N=1000000;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll i,j,w,v,maxis=-1e9,cap,dp[N],n;
	cin>>n>>cap;
	for(i=0;i<n;++i){
		cin>>w>>v;
		for(j=cap;j>=w;--j){
			dp[j]=max(dp[j],dp[j-w]+v);
		}
	}
	for(i=0;i<=cap;++i) maxis=max(maxis,dp[i]);
	cout<<maxis;
}

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

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    ll ans = 0;
    for(int i = 0; i < n-1; i++){
        sum -= a[i];
        ll msum = sum % mod;
        ll pro = msum * a[i];
        pro %= mod;
        ans += pro;
    }
    cout << ans%mod << endl;
    return 0; 
}


Measured memory_bytes: 4728
from sys import stdin

def main():
    M, D = map(int, input().split())

    ans = 0
    for m in range(3, M + 1):
        for d in range(22, D + 1):
            d1, d10 = divmod(d, 10)
            if d10 < 2:
                continue
            ans += m == d1 * d10
    print(ans)

input = lambda: stdin.readline()[:-1]
main()


Measured memory_bytes: 2940
# 2019/11/29
from collections import Counter

n,p=map(int,input().split())
def trial_div(n):
    
    prime=Counter()

    for i in range(2,int(pow(n,0.5)+2)):
        while n%i==0:
            n//=i
            prime[i]+=1
    if n>1:prime[n]+=1
    
    return prime


prime=trial_div(p)
if prime is None:
    print(1)
    exit()
ans=1
for k,v in prime.items():
    if v>=n:
        ans*=k**(v//n)
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
 
int main(){
  while(1){
  double dh,S,x,h,t;
  cin>>x>>h;
  if(x+h==0) break;
  S=x*x;
  dh=sqrt(h*h+(x/2)*(x/2));
  t=4*dh*x/2;
  S+=t;
  printf("%f\n",S);
  }
 
  
  return 0;
}

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

int main(){
    int k,n;
    cin >> k >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    int num=0;
    for(int i=0;i<n-1;i++){
        if(vec[i+1]-vec[i] > num){
            num = vec[i+1]-vec[i];
        }
    }
    if(k-vec[n-1] + vec[0] > num){
        num = k-vec[n-1] + vec[0];
    }
    cout << k-num << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

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

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

int main() {
    int n,k,ans;
    cin >> n >> k;
    if(k == 1) ans = 0;
    else ans = n-k;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  double k, a;
  string s;
  k = 0;
  in(n);
  rep(i, n){
    in2(a, s);
    if(s == "JPY")
      k += a;
    else
      k += a * 380000;
  }
  kono(16);
  out(k);
  memi;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#define ld long double
#define mem(x,y) memset(x,y,sizeof x)

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
/*
 * Be careful of overflow
 * Array bounds
 * Assert a!=0 when performing x/a
 * Check base condition for recursion
 * Iterator -> O(1), Element -> O(log n) while using erase
 * 1LL<<x when x>32
 * Be sure of what you are going to code (exception dp)
 * Don't try fancy tricks during contest
 * You can always make a bad round to a good enough round
 */ 

void solve()
{
	ll x,k,d;
	cin>>x>>k>>d;
	if(x<0) x=-x;
	ll mvs1=(x+d-1)/d;
	ll mvs2=x/d;
	ll ans1=x,ans2=x;
	if(mvs1 > k) ans1=x-k*d;
	else
	{
		k-=mvs1;
		if(k%2) ans1=x-mvs1*d+d;
		else ans1=x-mvs1*d;
		k+=mvs1;
	}
	if(mvs2>k) ans2=x-k*d;
	else
	{
		k-=mvs2;
		if(k%2) ans2=x-mvs2*d-d;
		else ans2=x-mvs2*d;
	}
	cout<<min(abs(ans1),abs(ans2))<<'\n';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

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

double cost[1010][1010];
double d[1010];
bool used[1010];
int V;

#define INF 2000000010000.0

void dijkstra(int s) {
	fill(d, d+V, INF);
	fill(used, used+V, false);
	d[s] = 0.0;

	while (true) {
		int v = -1;
		for (int u = 0; u < V; u++) {
			if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}
		if (v == -1) break;
		used[v] = true;
		for (int u = 0; u < V; u++) {
			d[u] = min(d[u], d[v]+cost[v][u]);
		}
	}
}

double dist(P a, P b, long long int ra, long long int rb) {
	double dd = sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
	if ((double)ra+(double)rb > dd) {
		dd = 0;
	} else {
		dd -= (ra+rb);
	}
	return dd;
}

int main() {
	long long int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	int n;
	cin >> n;
	vector<P> xy(n+2);
	vector<long long int> rr(n+2);
	xy[0] = P(sx, sy);
	rr[0] = 0;
	xy[1] = P(gx, gy);
	rr[1] = 0;
	long long int x, y, r;
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> r;
		xy[i+2] = P(x, y);
		rr[i+2] = r;
	}
	V = n+2;
	for (int i = 0; i < n+2; i++) {
		for (int j = 0; j < n+2; j++) {
			cost[i][j] = dist(xy[i], xy[j], rr[i], rr[j]);
		}
	}
	dijkstra(0);
	printf("%.15f\n", d[1]);
	return 0;
}

Measured memory_bytes: 8192
n = int(input())
p = list(map(int,input().split()))
#n = 8
#p = [5,7,4,2,6,8,1,3]


m = [0] * n
m[0] = p[0]

for i in range(1,n):
  m[i] = min(m[i-1],p[i])

#p , m ([5, 7, 4, 2, 6, 8, 1, 3], [5, 5, 4, 2, 2, 2, 1, 1])

ans = 0
for i in range(n):
  if m[i] >= p[i]:
    ans += 1

print(ans)

Measured memory_bytes: 24744
#include <iostream>

using namespace std;

int main()
{
    int n,temp,x=0,k;
    cin>>n>>k;
    int arr[n];
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    for (int i=0;i<n;i++){
        for( int j=i+1;j<n;j++){
                if(arr[i]>arr[j]){
                    temp=arr[i];
                    arr[i]=arr[j];
                    arr[j]=temp;
        }}
    }
  for(int i=0;i<k;i++){
    x+=arr[i];
  }
  cout<<x;
    return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for(int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for(int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
    vector<int> x(5);
    rep(i, 5) {
        cin >> x[i];
        if(x[i] == 0)
            cout << i + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3172
// Problem : A - Zero-Sum Ranges
// Contest : AtCoder - AtCoder Grand Contest 023
// URL : https://atcoder.jp/contests/agc023/tasks/agc023_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int N;
	cin>>N;
	unordered_map<ll,int> m;
	ll sum=0,ans=0;
	m[0]=1;
	F0R(x,N)
	{
		int nb;
		cin>>nb;
		sum+=nb;
		ans+=m[sum];
		m[sum]++;
	}
	cout<<ans<<nl;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

int H, W;
vector<string> A;
struct position {
    int x;
    int y;
    int count;
};
queue<position> q;
int ans = 0;

int main() {
    cin >> H >> W;
    A.resize(H);

    rep(i, H) {
        cin >> A[i];
        for(int k=0;k<A[i].size();k++) {
            if (A[i][k] == '#') q.push({i, k, 0});
        }
    }

    while (!q.empty()) {
        position now = q.front();
        int x        = now.x;
        int y        = now.y;
        int count    = now.count;
        ans = max(ans,count);
        q.pop();

        if (x != 0 && A[x - 1][y] != '#') {
            q.push({x - 1, y, count + 1});
            A[x - 1][y] = '#';
        }
        if (y != 0 && A[x][y - 1] != '#') {
            q.push({x, y - 1, count + 1});
            A[x][y - 1] = '#';
        }
        if (x != H - 1 && A[x + 1][y] != '#') {
            q.push({x + 1, y, count + 1});
            A[x + 1][y] = '#';
        }
        if (y != W - 1 && A[x][y + 1] != '#') {
            q.push({x, y + 1, count + 1});
            A[x][y + 1] = '#';
        }
    };
    cout << ans << endl;
}

Measured memory_bytes: 13456
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    ll k,n; cin >> k >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> b(n);
    _rep(i,1,n){
        b[i] = a[i] - a[i - 1];
    }
    b[0] = a[0] + (k - a[n - 1]);
    sort(b.begin(),b.end(),greater<>());
    print(k - b[0]);
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>
using namespace std;

int N,M,P[100100],D[100100];

int find(int x)
{
	if (x != P[x]){
		int r = P[x];
		P[x] = find(P[x]);
		D[x] += D[r];
	}
	return P[x];
}

int main()
{
    cin >> N >> M;
	for (int i=1;i<=N;i++) P[i] = i;

	for (int i=0;i<M;i++){
		int l,r,d;
		cin >> l >> r >> d;
		int L = find(l);
		int R = find(r);
		if (L != R){
			P[R] = L;
			D[R] = d + D[l] - D[r];
		}
		else{
			if (D[r] - D[l] != d){
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

Measured memory_bytes: 1024